Skip to content

Commit 00fcf54

Browse files
authored
v.scanner: remove obsolete .is_crlf and .is_vh fields (#25918)
1 parent e1b3e5b commit 00fcf54

1 file changed

Lines changed: 9 additions & 24 deletions

File tree

‎vlib/v/scanner/scanner.v‎

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub mut:
2929
pos int = -1 // current position in the file, first character is s.text[0]
3030
line_nr int // current line number
3131
last_nl_pos int = -1 // for calculating column
32-
is_crlf bool // special check when computing columns
3332
is_inside_string bool // set to true in a string, *at the start* of an $var or ${expr}
3433
is_nested_string bool // '${'abc':-12s}'
3534
is_inter_start bool // for hacky string interpolation TODO simplify
@@ -42,7 +41,6 @@ pub mut:
4241
is_print_rel_paths_on_error bool
4342
quote u8 // which quote is used to denote current string: ' or "
4443
nr_lines int // total number of lines in the source file that were scanned
45-
is_vh bool // Keep newlines
4644
is_fmt bool // Used for v fmt.
4745
comments_mode CommentsMode
4846
is_inside_toplvl_statement bool // *only* used in comments_mode: .toplevel_comments, toggled by parser
@@ -532,25 +530,19 @@ fn (mut s Scanner) ident_number() string {
532530
fn (mut s Scanner) skip_whitespace() {
533531
for s.pos < s.text.len {
534532
c := s.text[s.pos]
535-
if c == 9 {
536-
// tabs are most common
533+
if c == 9 || c == 32 {
534+
// tabs and spaces are most common
537535
s.pos++
538536
continue
539537
}
540-
if util.non_whitespace_table[c] {
541-
return
538+
if c == b_lf {
539+
s.inc_line_number()
540+
s.pos++
541+
continue
542542
}
543-
c_is_nl := c == b_cr || c == b_lf
544-
if c_is_nl && s.is_vh {
543+
if util.non_whitespace_table[c] {
545544
return
546545
}
547-
if s.pos + 1 < s.text.len && c == b_cr && s.text[s.pos + 1] == b_lf {
548-
s.is_crlf = true
549-
}
550-
// Count \r\n as one line
551-
if c_is_nl && !(s.pos > 0 && s.text[s.pos - 1] == b_cr && c == b_lf) {
552-
s.inc_line_number()
553-
}
554546
s.pos++
555547
}
556548
}
@@ -1663,15 +1655,9 @@ fn (mut s Scanner) eat_to_end_of_line() {
16631655
}
16641656
}
16651657

1666-
@[inline]
1658+
@[direct_array_access; inline]
16671659
fn (mut s Scanner) inc_line_number() {
1668-
s.last_nl_pos = s.text.len - 1
1669-
if s.last_nl_pos > s.pos {
1670-
s.last_nl_pos = s.pos
1671-
}
1672-
if s.is_crlf {
1673-
s.last_nl_pos++
1674-
}
1660+
s.last_nl_pos = if s.text.len - 1 > s.pos { s.pos } else { s.text.len - 1 }
16751661
s.line_nr++
16761662
if s.line_nr > s.nr_lines {
16771663
s.nr_lines = s.line_nr
@@ -1826,7 +1812,6 @@ pub fn (mut s Scanner) prepare_for_new_text(text string) {
18261812
s.nr_lines = 0
18271813
s.line_nr = 0
18281814
s.last_nl_pos = -1
1829-
s.is_crlf = false
18301815
s.is_inside_toplvl_statement = false
18311816
s.is_inside_string = false
18321817
s.is_nested_string = false

0 commit comments

Comments
 (0)