v2: fix for position and check
parent
042bce4b6c
commit
bc11419ff9
|
@ -338,9 +338,10 @@ pub:
|
||||||
|
|
||||||
pub struct ForStmt {
|
pub struct ForStmt {
|
||||||
pub:
|
pub:
|
||||||
cond Expr
|
cond Expr
|
||||||
stmts []Stmt
|
stmts []Stmt
|
||||||
pos token.Position
|
pos token.Position
|
||||||
|
is_inf bool // `for {}`
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ForInStmt {
|
pub struct ForInStmt {
|
||||||
|
|
|
@ -273,7 +273,7 @@ fn (c mut Checker) stmt(node ast.Stmt) {
|
||||||
typ := c.expr(it.cond)
|
typ := c.expr(it.cond)
|
||||||
// typ_sym := c.table.get_type_symbol(typ)
|
// typ_sym := c.table.get_type_symbol(typ)
|
||||||
// if typ_sym.kind != .bool {
|
// if typ_sym.kind != .bool {
|
||||||
if table.type_idx(typ) != table.bool_type_idx {
|
if !it.is_inf && table.type_idx(typ) != table.bool_type_idx {
|
||||||
c.error('non-bool used as for condition', it.pos)
|
c.error('non-bool used as for condition', it.pos)
|
||||||
}
|
}
|
||||||
for stmt in it.stmts {
|
for stmt in it.stmts {
|
||||||
|
|
|
@ -56,7 +56,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
|
||||||
pref: &pref.Preferences{}
|
pref: &pref.Preferences{}
|
||||||
scope: scope
|
scope: scope
|
||||||
// scope: &ast.Scope{start_pos: 0, parent: 0}
|
// scope: &ast.Scope{start_pos: 0, parent: 0}
|
||||||
|
|
||||||
}
|
}
|
||||||
p.init_parse_fns()
|
p.init_parse_fns()
|
||||||
p.read_first_token()
|
p.read_first_token()
|
||||||
|
@ -91,7 +91,6 @@ pub fn parse_file(path string, table &table.Table) ast.File {
|
||||||
for p.tok.kind == .key_import {
|
for p.tok.kind == .key_import {
|
||||||
imports << p.import_stmt()
|
imports << p.import_stmt()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: import only mode
|
// TODO: import only mode
|
||||||
for {
|
for {
|
||||||
// res := s.scan()
|
// res := s.scan()
|
||||||
|
@ -321,7 +320,7 @@ pub fn (p mut Parser) stmt() ast.Stmt {
|
||||||
return ast.ExprStmt{
|
return ast.ExprStmt{
|
||||||
expr: expr
|
expr: expr
|
||||||
// typ: typ
|
// typ: typ
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -893,11 +892,13 @@ fn (p mut Parser) for_statement() ast.Stmt {
|
||||||
// defer { p.close_scope() }
|
// defer { p.close_scope() }
|
||||||
// Infinite loop
|
// Infinite loop
|
||||||
if p.tok.kind == .lcbr {
|
if p.tok.kind == .lcbr {
|
||||||
|
pos := p.tok.position()
|
||||||
stmts := p.parse_block()
|
stmts := p.parse_block()
|
||||||
p.close_scope()
|
p.close_scope()
|
||||||
return ast.ForStmt{
|
return ast.ForStmt{
|
||||||
stmts: stmts
|
stmts: stmts
|
||||||
pos: p.tok.position()
|
pos: pos
|
||||||
|
is_inf: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if p.tok.kind == .key_mut {
|
else if p.tok.kind == .key_mut {
|
||||||
|
@ -1063,10 +1064,10 @@ fn (p mut Parser) if_expr() ast.Expr {
|
||||||
stmts: stmts
|
stmts: stmts
|
||||||
else_stmts: else_stmts
|
else_stmts: else_stmts
|
||||||
// typ: typ
|
// typ: typ
|
||||||
|
|
||||||
pos: p.tok.position()
|
pos: p.tok.position()
|
||||||
// left: left
|
// left: left
|
||||||
|
|
||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
@ -1451,10 +1452,10 @@ fn (p mut Parser) var_decl() ast.VarDecl {
|
||||||
node := ast.VarDecl{
|
node := ast.VarDecl{
|
||||||
name: name
|
name: name
|
||||||
expr: expr // p.expr(token.lowest_prec)
|
expr: expr // p.expr(token.lowest_prec)
|
||||||
|
|
||||||
is_mut: is_mut
|
is_mut: is_mut
|
||||||
// typ: typ
|
// typ: typ
|
||||||
|
|
||||||
pos: p.tok.position()
|
pos: p.tok.position()
|
||||||
}
|
}
|
||||||
p.scope.register_var(node)
|
p.scope.register_var(node)
|
||||||
|
@ -1573,7 +1574,7 @@ fn (p mut Parser) match_expr() ast.Expr {
|
||||||
blocks: blocks
|
blocks: blocks
|
||||||
match_exprs: match_exprs
|
match_exprs: match_exprs
|
||||||
// typ: typ
|
// typ: typ
|
||||||
|
|
||||||
cond: cond
|
cond: cond
|
||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
|
|
Loading…
Reference in New Issue