parser: short circuit if conditions in Parser.name_expr

pull/13777/head
Delyan Angelov 2022-03-19 20:31:03 +02:00
parent 4dd68d3965
commit eb7c9cec3d
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 2 additions and 2 deletions

View File

@ -2195,7 +2195,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
}
// Raw string (`s := r'hello \n ')
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()
} else {
// 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`
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)' }
return p.error('cannot use $opt with `byte` and `rune`')
}