v2: fix more ast positions

pull/3779/head
Alexander Medvednikov 2020-02-19 11:31:33 +01:00
parent bc11419ff9
commit 082acfad49
2 changed files with 7 additions and 4 deletions

View File

@ -71,6 +71,7 @@ fn (m mut map) set(key string, value voidptr) {
mut child_index := 0 mut child_index := 0
mut parent := &mapnode(0) mut parent := &mapnode(0)
for { for {
if node.size == max_size { if node.size == max_size {
if isnil(parent) { if isnil(parent) {
parent = new_node() parent = new_node()

View File

@ -850,6 +850,7 @@ fn (p mut Parser) infix_expr(left ast.Expr) (ast.Expr,table.Type) {
// mut typ := p. // mut typ := p.
// println('infix op=$op.str()') // println('infix op=$op.str()')
precedence := p.tok.precedence() precedence := p.tok.precedence()
pos := p.tok.position()
p.next() p.next()
mut typ := table.Type{} mut typ := table.Type{}
mut right := ast.Expr{} mut right := ast.Expr{}
@ -863,7 +864,7 @@ fn (p mut Parser) infix_expr(left ast.Expr) (ast.Expr,table.Type) {
right: right right: right
right_type: typ right_type: typ
op: op op: op
pos: p.tok.position() pos: pos
} }
return expr,typ return expr,typ
} }
@ -1019,6 +1020,7 @@ fn (p mut Parser) if_expr() ast.Expr {
// } // }
mut node := ast.Expr{} mut node := ast.Expr{}
p.check(.key_if) p.check(.key_if)
pos := p.tok.position()
// `if x := opt() {` // `if x := opt() {`
mut cond := ast.Expr{} mut cond := ast.Expr{}
if p.peek_tok.kind == .decl_assign { if p.peek_tok.kind == .decl_assign {
@ -1065,7 +1067,7 @@ fn (p mut Parser) if_expr() ast.Expr {
else_stmts: else_stmts else_stmts: else_stmts
// typ: typ // typ: typ
pos: p.tok.position() pos: pos
// left: left // left: left
} }
@ -1539,7 +1541,7 @@ fn (p mut Parser) match_expr() ast.Expr {
p.check(.comma) p.check(.comma)
} }
} }
p.warn('match block') // p.warn('match block')
stmts := p.parse_block() stmts := p.parse_block()
blocks << ast.StmtBlock{ blocks << ast.StmtBlock{
stmts: stmts stmts: stmts
@ -1593,7 +1595,7 @@ fn (p mut Parser) enum_decl() ast.EnumDecl {
for p.tok.kind != .eof && p.tok.kind != .rcbr { for p.tok.kind != .eof && p.tok.kind != .rcbr {
val := p.check_name() val := p.check_name()
vals << val vals << val
p.warn('enum val $val') // p.warn('enum val $val')
if p.tok.kind == .assign { if p.tok.kind == .assign {
p.next() p.next()
p.expr(0) p.expr(0)