mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
run vfmt on more files
This commit is contained in:
parent
1cef83aea4
commit
df2f98e276
8 changed files with 403 additions and 320 deletions
|
@ -1,7 +1,6 @@
|
|||
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
module compiler
|
||||
|
||||
fn (p mut Parser) string_expr() {
|
||||
|
@ -13,12 +12,13 @@ fn (p mut Parser) string_expr() {
|
|||
str := p.lit
|
||||
// No ${}, just return a simple string
|
||||
if p.peek() != .str_dollar || is_raw {
|
||||
f := if is_raw { cescaped_path(str) } else { format_str(str) }
|
||||
f := if is_raw {cescaped_path(str)}else {format_str(str)}
|
||||
// `C.puts('hi')` => `puts("hi");`
|
||||
/*
|
||||
Calling a C function sometimes requires a call to a string method
|
||||
C.fun('ssss'.to_wide()) => fun(string_to_wide(tos3("ssss")))
|
||||
*/
|
||||
|
||||
if (p.calling_c && p.peek() != .dot) || is_cstr || (p.pref.translated && p.mod == 'main') {
|
||||
p.gen('"$f"')
|
||||
}
|
||||
|
@ -40,12 +40,12 @@ fn (p mut Parser) string_expr() {
|
|||
p.is_alloc = true // $ interpolation means there's allocation
|
||||
mut args := '"'
|
||||
mut format := '"'
|
||||
mut complex_inter := false // for vfmt
|
||||
mut complex_inter := false // for vfmt
|
||||
for p.tok == .str {
|
||||
// Add the string between %d's
|
||||
p.lit = p.lit.replace('%', '%%')
|
||||
format += format_str(p.lit)
|
||||
p.next()// skip $
|
||||
p.next() // skip $
|
||||
if p.tok != .str_dollar {
|
||||
continue
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ fn (p mut Parser) string_expr() {
|
|||
complex_inter = true
|
||||
}
|
||||
// Get bool expr inside a temp var
|
||||
typ, val_ := p.tmp_expr()
|
||||
typ,val_ := p.tmp_expr()
|
||||
val := val_.trim_space()
|
||||
args += ', $val'
|
||||
if typ == 'string' {
|
||||
|
@ -70,7 +70,7 @@ fn (p mut Parser) string_expr() {
|
|||
args += '.len, ${val}.s.str'
|
||||
}
|
||||
if typ == 'bool' {
|
||||
//args += '.len, ${val}.str'
|
||||
// args += '.len, ${val}.str'
|
||||
}
|
||||
// Custom format? ${t.hour:02d}
|
||||
custom := p.tok == .colon
|
||||
|
@ -81,16 +81,17 @@ fn (p mut Parser) string_expr() {
|
|||
cformat += '.'
|
||||
p.next()
|
||||
}
|
||||
if p.tok == .minus { // support for left aligned formatting
|
||||
if p.tok == .minus {
|
||||
// support for left aligned formatting
|
||||
cformat += '-'
|
||||
p.next()
|
||||
}
|
||||
cformat += p.lit// 02
|
||||
cformat += p.lit // 02
|
||||
p.next()
|
||||
fspec := p.lit // f
|
||||
cformat += fspec
|
||||
if fspec == 's' {
|
||||
//println('custom str F=$cformat | format_specifier: "$fspec" | typ: $typ ')
|
||||
// println('custom str F=$cformat | format_specifier: "$fspec" | typ: $typ ')
|
||||
if typ != 'string' {
|
||||
p.error('only V strings can be formatted with a :${cformat} format, but you have given "${val}", which has type ${typ}')
|
||||
}
|
||||
|
@ -120,12 +121,12 @@ fn (p mut Parser) string_expr() {
|
|||
}
|
||||
format += f
|
||||
}
|
||||
//println('interpolation format is: |${format}| args are: |${args}| ')
|
||||
// println('interpolation format is: |${format}| args are: |${args}| ')
|
||||
}
|
||||
if complex_inter {
|
||||
p.fgen('}')
|
||||
}
|
||||
//p.fgen('\'')
|
||||
// p.fgen('\'')
|
||||
// println("hello %d", num) optimization.
|
||||
if p.cgen.nogen {
|
||||
return
|
||||
|
@ -151,4 +152,3 @@ fn (p mut Parser) string_expr() {
|
|||
p.gen('_STR($format$args)')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue