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

scanner: fix new string interpolation - print('{a}{{b}}') (#16309)

This commit is contained in:
yuyi 2022-11-03 20:04:41 +08:00 committed by GitHub
parent 9de92eb391
commit a979b3aab8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -811,7 +811,7 @@ fn (mut s Scanner) text_scan() token.Token {
next_char := s.text[s.pos + 1]
// Handle new `hello {name}` string interpolation
if !s.is_inside_interpolation && !next_char.is_space() && next_char != `}`
&& prev_char !in [`$`, `{`] {
&& prev_char != `$` {
s.is_inside_interpolation = true
return s.new_token(.str_lcbr, '', 1)
}

View File

@ -6,4 +6,13 @@ fn test_string_new_interpolation() {
println('{a} {b} {c} {d}')
assert '{a} {b} {c} {d}' == '1 2 3 4'
println('{a}{{b}}')
assert '{a}{{b}}' == '1{2}'
println('{a}\{{b}}')
assert '{a}\{{b}}' == '1{2}'
println('{a}{{{{{b}}}}}')
assert '{a}{{{{{b}}}}}' == '1{{{{2}}}}'
}