1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: assoc

This commit is contained in:
Alexander Medvednikov 2020-02-22 14:39:25 +01:00
parent cd41967aa1
commit 5fef8390a1
2 changed files with 42 additions and 16 deletions

View File

@ -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())
}

View File

@ -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)
}
}
}
@ -684,11 +687,14 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) {
}
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)