mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: assoc
This commit is contained in:
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user