parser: short circuit if conditions in Parser.name_expr
parent
4dd68d3965
commit
eb7c9cec3d
|
@ -2195,7 +2195,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
|
||||||
}
|
}
|
||||||
// Raw string (`s := r'hello \n ')
|
// Raw string (`s := r'hello \n ')
|
||||||
if p.peek_tok.kind == .string && !p.inside_str_interp && p.peek_token(2).kind != .colon {
|
if p.peek_tok.kind == .string && !p.inside_str_interp && p.peek_token(2).kind != .colon {
|
||||||
if p.tok.lit in ['r', 'c', 'js'] && p.tok.kind == .name {
|
if p.tok.kind == .name && p.tok.lit in ['r', 'c', 'js'] {
|
||||||
return p.string_expr()
|
return p.string_expr()
|
||||||
} else {
|
} else {
|
||||||
// don't allow any other string prefix except `r`, `js` and `c`
|
// don't allow any other string prefix except `r`, `js` and `c`
|
||||||
|
@ -2203,7 +2203,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// don't allow r`byte` and c`byte`
|
// don't allow r`byte` and c`byte`
|
||||||
if p.tok.lit in ['r', 'c'] && p.peek_tok.kind == .chartoken {
|
if p.peek_tok.kind == .chartoken && p.tok.lit.len == 1 && p.tok.lit[0] in [`r`, `c`] {
|
||||||
opt := if p.tok.lit == 'r' { '`r` (raw string)' } else { '`c` (c string)' }
|
opt := if p.tok.lit == 'r' { '`r` (raw string)' } else { '`c` (c string)' }
|
||||||
return p.error('cannot use $opt with `byte` and `rune`')
|
return p.error('cannot use $opt with `byte` and `rune`')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue