fmt: keep char literal, `'` (#11060)
parent
b95224aa20
commit
490dec222f
|
@ -44,7 +44,7 @@ fn (mut r Repl) checks() bool {
|
||||||
mut in_string := false
|
mut in_string := false
|
||||||
was_indent := r.indent > 0
|
was_indent := r.indent > 0
|
||||||
for i := 0; i < r.line.len; i++ {
|
for i := 0; i < r.line.len; i++ {
|
||||||
if r.line[i] == `\'` && (i == 0 || r.line[i - 1] != `\\`) {
|
if r.line[i] == `'` && (i == 0 || r.line[i - 1] != `\\`) {
|
||||||
in_string = !in_string
|
in_string = !in_string
|
||||||
}
|
}
|
||||||
if r.line[i] == `{` && !in_string {
|
if r.line[i] == `{` && !in_string {
|
||||||
|
|
|
@ -651,7 +651,7 @@ fn test_for_loop_two() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_quote() {
|
fn test_quote() {
|
||||||
a := `\'`
|
a := `'`
|
||||||
println('testing double quotes')
|
println('testing double quotes')
|
||||||
b := 'hi'
|
b := 'hi'
|
||||||
assert b == 'hi'
|
assert b == 'hi'
|
||||||
|
|
|
@ -111,10 +111,10 @@ pub fn (mut parser Parser) split_parse(data string) {
|
||||||
parser.init()
|
parser.init()
|
||||||
for chr in data {
|
for chr in data {
|
||||||
// returns true if byte is a " or '
|
// returns true if byte is a " or '
|
||||||
is_quote := chr == `"` || chr == `\'`
|
is_quote := chr == `"` || chr == `'`
|
||||||
string_code := match chr {
|
string_code := match chr {
|
||||||
`"` { 1 } // "
|
`"` { 1 } // "
|
||||||
`\'` { 2 } // '
|
`'` { 2 } // '
|
||||||
else { 0 }
|
else { 0 }
|
||||||
}
|
}
|
||||||
if parser.lexical_attributes.open_code { // here will verify all needed to know if open_code finishes and string in code
|
if parser.lexical_attributes.open_code { // here will verify all needed to know if open_code finishes and string in code
|
||||||
|
|
|
@ -113,7 +113,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
continue
|
continue
|
||||||
} else if ch == `\'` {
|
} else if ch == `'` {
|
||||||
i++
|
i++
|
||||||
continue
|
continue
|
||||||
} else if ch == `.` && fc_ch1 >= `1` && fc_ch1 <= `9` {
|
} else if ch == `.` && fc_ch1 >= `1` && fc_ch1 <= `9` {
|
||||||
|
|
|
@ -521,7 +521,11 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
|
||||||
f.chan_init(mut node)
|
f.chan_init(mut node)
|
||||||
}
|
}
|
||||||
ast.CharLiteral {
|
ast.CharLiteral {
|
||||||
f.write('`$node.val`')
|
if node.val == r"\'" {
|
||||||
|
f.write("`'`")
|
||||||
|
} else {
|
||||||
|
f.write('`$node.val`')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ast.Comment {
|
ast.Comment {
|
||||||
f.comment(node, inline: true)
|
f.comment(node, inline: true)
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
fn char_backtick() {
|
|
||||||
println(`\``)
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
println(`"`)
|
||||||
|
printrn(`'`)
|
||||||
|
println(`\``)
|
|
@ -5074,7 +5074,7 @@ fn (mut g Gen) const_decl_precomputed(mod string, name string, ct_value ast.Comp
|
||||||
rune {
|
rune {
|
||||||
rune_code := u32(ct_value)
|
rune_code := u32(ct_value)
|
||||||
if rune_code <= 255 {
|
if rune_code <= 255 {
|
||||||
if rune_code in [`"`, `\\`, `\'`] {
|
if rune_code in [`"`, `\\`, `'`] {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
escval := util.smart_quote(byte(rune_code).ascii_str(), false)
|
escval := util.smart_quote(byte(rune_code).ascii_str(), false)
|
||||||
|
|
|
@ -13,7 +13,7 @@ import v.vet
|
||||||
import v.errors
|
import v.errors
|
||||||
|
|
||||||
const (
|
const (
|
||||||
single_quote = `\'`
|
single_quote = `'`
|
||||||
double_quote = `"`
|
double_quote = `"`
|
||||||
// char used as number separator
|
// char used as number separator
|
||||||
num_sep = `_`
|
num_sep = `_`
|
||||||
|
@ -677,7 +677,7 @@ fn (mut s Scanner) text_scan() token.Token {
|
||||||
// end of `$expr`
|
// end of `$expr`
|
||||||
// allow `'$a.b'` and `'$a.c()'`
|
// allow `'$a.b'` and `'$a.c()'`
|
||||||
if s.is_inter_start && next_char == `\\`
|
if s.is_inter_start && next_char == `\\`
|
||||||
&& s.look_ahead(2) !in [`x`, `n`, `r`, `\\`, `t`, `e`, `"`, `\'`] {
|
&& s.look_ahead(2) !in [`x`, `n`, `r`, `\\`, `t`, `e`, `"`, `'`] {
|
||||||
s.warn('unknown escape sequence \\${s.look_ahead(2)}')
|
s.warn('unknown escape sequence \\${s.look_ahead(2)}')
|
||||||
}
|
}
|
||||||
if s.is_inter_start && next_char == `(` {
|
if s.is_inter_start && next_char == `(` {
|
||||||
|
|
|
@ -75,7 +75,7 @@ pub fn resolve_env_value(str string, check_for_presence bool) ?string {
|
||||||
if ch.is_letter() || ch.is_digit() || ch == `_` {
|
if ch.is_letter() || ch.is_digit() || ch == `_` {
|
||||||
env_lit += ch.ascii_str()
|
env_lit += ch.ascii_str()
|
||||||
} else {
|
} else {
|
||||||
if !(ch == `\'` || ch == `)`) {
|
if !(ch == `'` || ch == `)`) {
|
||||||
if ch == `$` {
|
if ch == `$` {
|
||||||
return error('cannot use string interpolation in compile time \$env() expression')
|
return error('cannot use string interpolation in compile time \$env() expression')
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,7 @@ fn (mut s Scanner) scan_all() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c in [`\'`, `\"`] && !s.peek_char(`\\`) {
|
if c in [`'`, `\"`] && !s.peek_char(`\\`) {
|
||||||
s.pos++
|
s.pos++
|
||||||
str := s.create_string(c)
|
str := s.create_string(c)
|
||||||
s.tokenize(.str, str)
|
s.tokenize(.str, str)
|
||||||
|
|
Loading…
Reference in New Issue