parser: allow deref assign without parens pt1
parent
6696e1a6e2
commit
9fff8733a0
|
@ -20,6 +20,7 @@ mut:
|
||||||
tok token.Token
|
tok token.Token
|
||||||
prev_tok token.Token
|
prev_tok token.Token
|
||||||
peek_tok token.Token
|
peek_tok token.Token
|
||||||
|
peek_tok2 token.Token
|
||||||
table &table.Table
|
table &table.Table
|
||||||
is_c bool
|
is_c bool
|
||||||
is_js bool
|
is_js bool
|
||||||
|
@ -179,11 +180,13 @@ pub fn (p &Parser) init_parse_fns() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut p Parser) read_first_token() {
|
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()
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn (mut p Parser) open_scope() {
|
pub fn (mut p Parser) open_scope() {
|
||||||
p.scope = &ast.Scope{
|
p.scope = &ast.Scope{
|
||||||
parent: p.scope
|
parent: p.scope
|
||||||
|
@ -241,7 +244,8 @@ fn (mut p Parser) next_with_comment() {
|
||||||
fn (mut p Parser) next() {
|
fn (mut p Parser) next() {
|
||||||
p.prev_tok = p.tok
|
p.prev_tok = p.tok
|
||||||
p.tok = p.peek_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 {
|
if p.tok.kind==.comment {
|
||||||
p.comments << ast.Comment{text:p.tok.lit, line_nr:p.tok.line_nr}
|
p.comments << ast.Comment{text:p.tok.lit, line_nr:p.tok.line_nr}
|
||||||
|
|
|
@ -161,6 +161,11 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
|
||||||
pos: pos
|
pos: pos
|
||||||
}
|
}
|
||||||
} else if p.tok.kind.is_infix() {
|
} 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)
|
node = p.infix_expr(node)
|
||||||
} else if p.tok.kind in [.inc, .dec] {
|
} else if p.tok.kind in [.inc, .dec] {
|
||||||
// Postfix
|
// Postfix
|
||||||
|
|
Loading…
Reference in New Issue