revert parser: simplify array push detection

pull/4587/head
joe-conigliaro 2020-04-25 18:57:12 +10:00
parent 4675656786
commit 41cc96aaec
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
2 changed files with 7 additions and 2 deletions

View File

@ -40,6 +40,7 @@ mut:
returns bool returns bool
inside_match bool // to separate `match A { }` from `Struct{}` inside_match bool // to separate `match A { }` from `Struct{}`
inside_match_case bool // to separate `match_expr { }` from `Struct{}` inside_match_case bool // to separate `match_expr { }` from `Struct{}`
is_stmt_ident bool // true while the beginning of a statement is an ident/selector
inside_is bool // `is Type`, expecting type inside_is bool // `is Type`, expecting type
} }
@ -374,6 +375,7 @@ pub fn (mut p Parser) comment() ast.Comment {
} }
pub fn (mut p Parser) stmt() ast.Stmt { pub fn (mut p Parser) stmt() ast.Stmt {
p.is_stmt_ident = p.tok.kind == .name
match p.tok.kind { match p.tok.kind {
.lcbr { .lcbr {
stmts := p.parse_block() stmts := p.parse_block()

View File

@ -11,12 +11,14 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
// println('\n\nparser.expr()') // println('\n\nparser.expr()')
mut typ := table.void_type mut typ := table.void_type
mut node := ast.Expr{} mut node := ast.Expr{}
expr_prev_tok_line_nr := p.prev_tok.line_nr is_stmt_ident := p.is_stmt_ident
p.is_stmt_ident = false
// Prefix // Prefix
match p.tok.kind { match p.tok.kind {
.name { .name {
p.scope.remove_unused_var(p.tok.lit) p.scope.remove_unused_var(p.tok.lit)
node = p.name_expr() node = p.name_expr()
p.is_stmt_ident = is_stmt_ident
} }
.string { .string {
node = p.string_expr() node = p.string_expr()
@ -134,6 +136,7 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
node = p.assign_expr(node) node = p.assign_expr(node)
} else if p.tok.kind == .dot { } else if p.tok.kind == .dot {
node = p.dot_expr(node) node = p.dot_expr(node)
p.is_stmt_ident = is_stmt_ident
} else if p.tok.kind == .lsbr { } else if p.tok.kind == .lsbr {
node = p.index_expr(node) node = p.index_expr(node)
} else if p.tok.kind == .key_as { } else if p.tok.kind == .key_as {
@ -145,7 +148,7 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
typ: typ typ: typ
pos: pos pos: pos
} }
} else if p.tok.kind == .left_shift && p.tok.line_nr != expr_prev_tok_line_nr { } else if p.tok.kind == .left_shift && p.is_stmt_ident {
// arr << elem // arr << elem
tok := p.tok tok := p.tok
pos := tok.position() pos := tok.position()