1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

simplify vfmt

This commit is contained in:
Alexander Medvednikov
2019-11-11 08:58:50 +03:00
parent d9b29bfb4e
commit e6775913aa
5 changed files with 14 additions and 15 deletions

View File

@ -42,6 +42,8 @@ mut:
line_ends []int // the positions of source lines ends (i.e. \n signs)
nlines int // total number of lines in the source file that were scanned
is_vh bool // Keep newlines
is_fmt bool // Used only for skipping ${} in strings, since we need literal
// string values when generating formatted code.
}
// new scanner from file.
@ -67,6 +69,7 @@ fn new_scanner_file(file_path string) &Scanner {
}
mut s := new_scanner(raw_text)
s.init_fmt()
s.file_path = file_path
return s
@ -688,14 +691,14 @@ fn (s mut Scanner) ident_string() string {
s.error('0 character in a string literal')
}
// ${var}
if c == `{` && prevc == `$` && !is_raw && s.count_symbol_before(s.pos-2, slash) % 2 == 0 {
if c == `{` && prevc == `$` && !is_raw && !s.is_fmt && s.count_symbol_before(s.pos-2, slash) % 2 == 0 {
s.inside_string = true
// so that s.pos points to $ at the next step
s.pos -= 2
break
}
// $var
if (c.is_letter() || c == `_`) && prevc == `$` && !is_raw && s.count_symbol_before(s.pos-2, slash) % 2 == 0 {
if (c.is_letter() || c == `_`) && prevc == `$` && !s.is_fmt && !is_raw && s.count_symbol_before(s.pos-2, slash) % 2 == 0 {
s.inside_string = true
s.inter_start = true
s.pos -= 2