From 05a217aaf0b647d628b436d36e6ff446b23e32cd Mon Sep 17 00:00:00 2001 From: yuyi Date: Wed, 9 Dec 2020 09:09:46 +0800 Subject: [PATCH] scanner: minor cleanup and optimization in scanner.v (#7204) --- vlib/v/scanner/scanner.v | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 674a55627c..f348e3ed4a 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -117,25 +117,22 @@ pub fn new_scanner(text string, comments_mode CommentsMode, pref &pref.Preferenc } pub fn new_vet_scanner(text string, comments_mode CommentsMode, pref &pref.Preferences) &Scanner { - is_fmt := pref.is_fmt - mut s := &Scanner{ + return &Scanner{ pref: pref text: text is_print_line_on_error: true is_print_colored_error: true is_print_rel_paths_on_error: true - is_fmt: is_fmt + is_fmt: pref.is_fmt comments_mode: comments_mode + file_path: 'internal_memory' } - s.file_path = 'internal_memory' - return s } [inline] fn (s &Scanner) should_parse_comment() bool { - res := (s.comments_mode == .parse_comments) || + return (s.comments_mode == .parse_comments) || (s.comments_mode == .toplevel_comments && !s.is_inside_toplvl_statement) - return res } // NB: this is called by v's parser @@ -1026,7 +1023,7 @@ fn (mut s Scanner) ident_string() string { s.inc_line_number() } // Don't allow \0 - if c == `0` && s.pos > 2 && s.text[s.pos - 1] == slash { + if c == `0` && s.pos > 2 && prevc == slash { if (s.pos < s.text.len - 1 && s.text[s.pos + 1].is_digit()) || s.count_symbol_before(s.pos - 1, slash) % 2 == 0 { } else if !is_cstr && !is_raw {