v.scanner: fix error line numbers when comments end with CRLF

pull/6228/head
Delyan Angelov 2020-08-26 11:39:32 +03:00
parent 84b8e0a7e4
commit 47f59d3fb6
6 changed files with 22 additions and 4 deletions

View File

@ -0,0 +1,2 @@
*_crlf_* binary
*_lf_* binary

View File

@ -0,0 +1,4 @@
vlib/v/checker/tests/error_with_comment_with_crlf_ending.vv:2:6: error: unexpected name `should`
1 | // Empty lines don't cause an issue but as soon as there's a comment with a CRLF ending, it fails
2 | This should cause an error!
| ~~~~~~

View File

@ -0,0 +1,2 @@
// Empty lines don't cause an issue but as soon as there's a comment with a CRLF ending, it fails
This should cause an error!

View File

@ -0,0 +1,4 @@
vlib/v/checker/tests/error_with_comment_with_lf_ending.vv:2:6: error: unexpected name `should`
1 | // Empty lines don't cause an issue but as soon as there's a comment with a CRLF ending, it fails
2 | This should cause an error!
| ~~~~~~

View File

@ -0,0 +1,2 @@
// Empty lines don't cause an issue but as soon as there's a comment with a CRLF ending, it fails
This should cause an error!

View File

@ -1092,10 +1092,14 @@ fn (mut s Scanner) text_scan() token.Token {
if nextc == `/` {
start := s.pos + 1
s.ignore_line()
comment_line_end := s.pos
s.pos--
mut comment_line_end := s.pos
if s.text[s.pos-1] == `\r` {
comment_line_end--
} else {
// fix line_nr, \n was read; the comment is marked on the next line
s.pos--
s.line_nr--
}
if s.should_parse_comment() {
s.line_comment = s.text[start + 1..comment_line_end]
mut comment := s.line_comment.trim_space()