fmt: fix handling of double quotes inside single quotes

pull/5470/head
Uwe Krüger 2020-06-23 23:59:58 +02:00 committed by GitHub
parent 11ad18cd28
commit 56749877ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View File

@ -841,6 +841,9 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
for val in node.vals {
if val.contains("'") {
contains_single_quote = true
}
if val.contains('"') {
contains_single_quote = false
break
}
}

View File

@ -1,8 +1,9 @@
import v.checker
import v.ast
import v.table
import v.gen
pub fn string_inter_lit(mut c checker.Checker, mut node ast.StringInterLiteral) table.Type {
fn string_inter_lit(mut c checker.Checker, mut node ast.StringInterLiteral) table.Type {
for i, expr in node.exprs {
ftyp := c.expr(expr)
node.expr_types << ftyp
@ -34,7 +35,7 @@ pub fn string_inter_lit(mut c checker.Checker, mut node ast.StringInterLiteral)
return table.string_type
}
fn get_some_val(a_test, b_test, c_test, d_test, e_test, f_test f64) {
fn get_some_val(a_test, b_test, c_test, d_test, e_test, f_test f64) f64 {
return a_test * b_test * c_test * d_test +
e_test * f_test * a_test * d_test +
a_test * b_test * c_test
@ -46,3 +47,9 @@ fn main() {
println('ok')
}
}
fn gen_str_for_multi_return(mut g gen.Gen, info table.MultiReturn, styp, str_fn_name string) {
for i, _ in info.types {
println('\tstrings__Builder_write(&sb, _STR("\'%.*s\\000\'", 2, a.arg$i));')
}
}

View File

@ -1,8 +1,9 @@
import v.checker
import v.ast
import v.table
import v.gen
pub fn string_inter_lit(mut c checker.Checker, mut node ast.StringInterLiteral) table.Type {
fn string_inter_lit(mut c checker.Checker, mut node ast.StringInterLiteral) table.Type {
for i, expr in node.exprs {
ftyp := c.expr(expr)
node.expr_types << ftyp
@ -40,7 +41,7 @@ pub fn string_inter_lit(mut c checker.Checker, mut node ast.StringInterLiteral)
return table.string_type
}
fn get_some_val(a_test, b_test, c_test, d_test, e_test, f_test f64) {
fn get_some_val(a_test, b_test, c_test, d_test, e_test, f_test f64) f64 {
return a_test*b_test*c_test*
d_test+e_test*f_test*a_test*d_test+a_test*
b_test*c_test
@ -55,3 +56,10 @@ fn main() {
println('ok')
}
}
fn gen_str_for_multi_return(mut g gen.Gen,
info table.MultiReturn, styp, str_fn_name string) {
for i, _ in info.types {
println('\tstrings__Builder_write(&sb, _STR("\'%.*s\\000\'", 2, a.arg$i));')
}
}