mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.scanner: fix string interpolation when quote is directly after '}' (#18961)
This commit is contained in:
parent
b29f3caeec
commit
fab915782d
@ -46,7 +46,8 @@ pub mut:
|
||||
is_print_rel_paths_on_error bool
|
||||
quote u8 // which quote is used to denote current string: ' or "
|
||||
inter_quote u8
|
||||
nr_lines int // total number of lines in the source file that were scanned
|
||||
just_closed_inter bool // if is_enclosed_inter was set to false on the previous character: `}`
|
||||
nr_lines int // total number of lines in the source file that were scanned
|
||||
is_vh bool // Keep newlines
|
||||
is_fmt bool // Used for v fmt.
|
||||
comments_mode CommentsMode
|
||||
@ -836,6 +837,7 @@ fn (mut s Scanner) text_scan() token.Token {
|
||||
return s.new_token(.string, '', 1)
|
||||
}
|
||||
s.is_enclosed_inter = false
|
||||
s.just_closed_inter = true
|
||||
ident_string := s.ident_string()
|
||||
return s.new_token(.string, ident_string, ident_string.len + 2) // + two quotes
|
||||
} else {
|
||||
@ -1149,13 +1151,16 @@ fn (mut s Scanner) ident_string() string {
|
||||
is_quote := q == scanner.single_quote || q == scanner.double_quote
|
||||
is_raw := is_quote && s.pos > 0 && s.text[s.pos - 1] == `r` && !s.is_inside_string
|
||||
is_cstr := is_quote && s.pos > 0 && s.text[s.pos - 1] == `c` && !s.is_inside_string
|
||||
if is_quote {
|
||||
// don't interpret quote as "start of string" quote when a string interpolation has
|
||||
// just ended on the previous character meaning it's not the start of a new string
|
||||
if is_quote && !s.just_closed_inter {
|
||||
if s.is_inside_string || s.is_enclosed_inter || s.is_inter_start {
|
||||
s.inter_quote = q
|
||||
} else {
|
||||
s.quote = q
|
||||
}
|
||||
}
|
||||
s.just_closed_inter = false
|
||||
mut n_cr_chars := 0
|
||||
mut start := s.pos
|
||||
start_char := s.text[start]
|
||||
|
@ -28,4 +28,6 @@ fn test_interpolation_string_args() {
|
||||
|
||||
assert '1_${show_more_info('aaa', '111')} 2_${show_more_info('bbb', '222')}' == '1_aaa111 2_bbb222'
|
||||
assert '1_${show_more_info('aaa', '111')} 2_${show_more_info('bbb', '222')}' == '1_aaa111 2_bbb222'
|
||||
|
||||
assert '"${show_info('abc')}"' == '"abc"'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user