parser: add an error for an invalid string prefix (#7019)
parent
39b46e95a0
commit
e3fab7e076
|
@ -1037,8 +1037,13 @@ pub fn (mut p Parser) name_expr() ast.Expr {
|
|||
}
|
||||
}
|
||||
// Raw string (`s := r'hello \n ')
|
||||
if p.tok.lit in ['r', 'c', 'js'] && p.peek_tok.kind == .string && !p.inside_str_interp {
|
||||
return p.string_expr()
|
||||
if p.peek_tok.kind == .string && !p.inside_str_interp && p.peek_tok2.kind != .colon {
|
||||
if p.tok.lit in ['r', 'c', 'js'] && p.tok.kind == .name {
|
||||
return p.string_expr()
|
||||
} else {
|
||||
// don't allow any other string prefix except `r`, `js` and `c`
|
||||
p.error('only `c`, `r`, `js` are recognized string prefixes, but you tried to use `$p.tok.lit`')
|
||||
}
|
||||
}
|
||||
// don't allow r`byte` and c`byte`
|
||||
if p.tok.lit in ['r', 'c'] && p.peek_tok.kind == .chartoken {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
vlib/v/parser/tests/string_invalid_prefix_err.vv:2:12: error: only `c`, `r`, `js` are recognized string prefixes, but you tried to use `w`
|
||||
1 | fn main() {
|
||||
2 | why := w'why'
|
||||
| ^
|
||||
3 | println(why)
|
||||
4 | }
|
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
why := w'why'
|
||||
println(why)
|
||||
}
|
Loading…
Reference in New Issue