fmt: assoc
parent
cd41967aa1
commit
5fef8390a1
|
@ -145,6 +145,11 @@ fn (f mut Fmt) stmt(node ast.Stmt) {
|
|||
f.stmts(it.stmts)
|
||||
f.writeln('}\n')
|
||||
}
|
||||
ast.ForInStmt {
|
||||
f.writeln(' for in {')
|
||||
f.stmts(it.stmts)
|
||||
f.writeln('}')
|
||||
}
|
||||
ast.ForStmt {
|
||||
f.write('for ')
|
||||
f.expr(it.cond)
|
||||
|
@ -241,6 +246,19 @@ fn (f mut Fmt) expr(node ast.Expr) {
|
|||
f.write(' $it.op.str() ')
|
||||
f.expr(it.val)
|
||||
}
|
||||
ast.Assoc {
|
||||
f.writeln('{')
|
||||
// f.indent++
|
||||
f.writeln('\t$it.name |')
|
||||
// TODO StructInit copy pasta
|
||||
for i, field in it.fields {
|
||||
f.write('\t$field: ')
|
||||
f.expr(it.exprs[i])
|
||||
f.writeln('')
|
||||
}
|
||||
// f.indent--
|
||||
f.write('}')
|
||||
}
|
||||
ast.BoolLiteral {
|
||||
f.write(it.val.str())
|
||||
}
|
||||
|
|
|
@ -466,7 +466,10 @@ pub fn (p mut Parser) parse_ident(is_c bool) ast.Ident {
|
|||
else {
|
||||
// handle consts/fns in checker
|
||||
ident.kind = .unresolved
|
||||
return {ident | name: p.prepend_mod(name)}
|
||||
return {
|
||||
ident |
|
||||
name:p.prepend_mod(name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -666,8 +669,8 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) {
|
|||
mut keys := []ast.Expr
|
||||
mut vals := []ast.Expr
|
||||
for p.tok.kind != .rcbr && p.tok.kind != .eof {
|
||||
//p.check(.str)
|
||||
key, _ := p.expr(0)
|
||||
// p.check(.str)
|
||||
key,_ := p.expr(0)
|
||||
keys << key
|
||||
p.check(.colon)
|
||||
val,_ := p.expr(0)
|
||||
|
@ -676,19 +679,22 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) {
|
|||
p.next()
|
||||
}
|
||||
}
|
||||
node = ast.MapInit {
|
||||
keys:keys
|
||||
node = ast.MapInit{
|
||||
keys: keys
|
||||
vals: vals
|
||||
pos: p.tok.position()
|
||||
}
|
||||
}
|
||||
else {
|
||||
name := p.check_name()
|
||||
mut fields := []string
|
||||
mut vals := []ast.Expr
|
||||
p.check(.pipe)
|
||||
for {
|
||||
p.check_name()
|
||||
fields << p.check_name()
|
||||
p.check(.colon)
|
||||
p.expr(0)
|
||||
expr,_ := p.expr(0)
|
||||
vals << expr
|
||||
if p.tok.kind == .comma {
|
||||
p.check(.comma)
|
||||
}
|
||||
|
@ -698,6 +704,8 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) {
|
|||
}
|
||||
node = ast.Assoc{
|
||||
name: name
|
||||
fields: fields
|
||||
exprs: vals
|
||||
}
|
||||
}
|
||||
p.check(.rcbr)
|
||||
|
|
Loading…
Reference in New Issue