mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
simplify vfmt
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user