1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: allow deref assign without parens pt1

This commit is contained in:
joe-conigliaro 2020-04-25 18:07:30 +10:00
parent 6696e1a6e2
commit 9fff8733a0
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
2 changed files with 11 additions and 2 deletions

View File

@ -20,6 +20,7 @@ mut:
tok token.Token
prev_tok token.Token
peek_tok token.Token
peek_tok2 token.Token
table &table.Table
is_c bool
is_js bool
@ -179,11 +180,13 @@ pub fn (p &Parser) init_parse_fns() {
}
pub fn (mut p Parser) read_first_token() {
// need to call next() twice to get peek token and current token
// need to call next() three times to get peek token 1 & 2 and current token
p.next()
p.next()
p.next()
}
pub fn (mut p Parser) open_scope() {
p.scope = &ast.Scope{
parent: p.scope
@ -241,7 +244,8 @@ fn (mut p Parser) next_with_comment() {
fn (mut p Parser) next() {
p.prev_tok = p.tok
p.tok = p.peek_tok
p.peek_tok = p.scanner.scan()
p.peek_tok = p.peek_tok2
p.peek_tok2 = p.scanner.scan()
/*
if p.tok.kind==.comment {
p.comments << ast.Comment{text:p.tok.lit, line_nr:p.tok.line_nr}

View File

@ -161,6 +161,11 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
pos: pos
}
} else if p.tok.kind.is_infix() {
// return early for deref assign `*x = 2` goes to prefix expr
if p.tok.kind == .mul && p.tok.line_nr != p.prev_tok.line_nr && p.peek_tok2.kind == .assign {
return node
}
// continue on infix expr
node = p.infix_expr(node)
} else if p.tok.kind in [.inc, .dec] {
// Postfix