mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: simplify array push detection
This commit is contained in:
parent
1863dda8e5
commit
4675656786
@ -40,7 +40,6 @@ mut:
|
||||
returns bool
|
||||
inside_match bool // to separate `match A { }` 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
|
||||
}
|
||||
|
||||
@ -375,7 +374,6 @@ pub fn (mut p Parser) comment() ast.Comment {
|
||||
}
|
||||
|
||||
pub fn (mut p Parser) stmt() ast.Stmt {
|
||||
p.is_stmt_ident = p.tok.kind == .name
|
||||
match p.tok.kind {
|
||||
.lcbr {
|
||||
stmts := p.parse_block()
|
||||
|
@ -11,14 +11,12 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
|
||||
// println('\n\nparser.expr()')
|
||||
mut typ := table.void_type
|
||||
mut node := ast.Expr{}
|
||||
is_stmt_ident := p.is_stmt_ident
|
||||
p.is_stmt_ident = false
|
||||
expr_prev_tok_line_nr := p.prev_tok.line_nr
|
||||
// Prefix
|
||||
match p.tok.kind {
|
||||
.name {
|
||||
p.scope.remove_unused_var(p.tok.lit)
|
||||
node = p.name_expr()
|
||||
p.is_stmt_ident = is_stmt_ident
|
||||
}
|
||||
.string {
|
||||
node = p.string_expr()
|
||||
@ -136,7 +134,6 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
|
||||
node = p.assign_expr(node)
|
||||
} else if p.tok.kind == .dot {
|
||||
node = p.dot_expr(node)
|
||||
p.is_stmt_ident = is_stmt_ident
|
||||
} else if p.tok.kind == .lsbr {
|
||||
node = p.index_expr(node)
|
||||
} else if p.tok.kind == .key_as {
|
||||
@ -148,7 +145,7 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
|
||||
typ: typ
|
||||
pos: pos
|
||||
}
|
||||
} else if p.tok.kind == .left_shift && p.is_stmt_ident {
|
||||
} else if p.tok.kind == .left_shift && p.tok.line_nr != expr_prev_tok_line_nr {
|
||||
// arr << elem
|
||||
tok := p.tok
|
||||
pos := tok.position()
|
||||
|
Loading…
Reference in New Issue
Block a user