v2: minor fixes

pull/3866/head
Alexander Medvednikov 2020-02-27 21:51:40 +01:00
parent 3204f036da
commit 87205367d1
3 changed files with 28 additions and 12 deletions

View File

@ -192,6 +192,7 @@ pub struct Stmt {
pub struct VarDecl {
pub:
name string
name2 string // TODO
expr Expr
is_mut bool
mut:

View File

@ -208,7 +208,12 @@ fn (f mut Fmt) stmt(node ast.Stmt) {
if it.is_mut {
f.write('mut ')
}
if it.name2 == '' {
f.write('$it.name := ')
}
else {
f.write('/*2*/$it.name, $it.name2 := ')
}
f.expr(it.expr)
f.writeln('')
}
@ -311,6 +316,9 @@ fn (f mut Fmt) expr(node ast.Expr) {
}
f.write(')')
}
ast.CharLiteral {
f.write('`$it.val`')
}
ast.EnumVal {
f.write(it.enum_name + '.' + it.val)
}
@ -353,8 +361,13 @@ fn (f mut Fmt) expr(node ast.Expr) {
f.single_line_if = false
}
ast.Ident {
if it.kind == .blank_ident {
f.write('_')
}
else {
f.write('$it.name')
}
}
ast.InfixExpr {
f.expr(it.left)
f.write(' $it.op.str() ')

View File

@ -1575,9 +1575,10 @@ fn (p mut Parser) var_decl() ast.VarDecl {
// p.fspace()
}
name := p.check_name()
mut name2 := ''
if p.tok.kind == .comma {
p.check(.comma)
p.check_name()
name2 = p.check_name()
}
p.next() // :=
// expr,typ := p.expr(0)
@ -1603,6 +1604,7 @@ fn (p mut Parser) var_decl() ast.VarDecl {
// println(p.table.names)
node := ast.VarDecl{
name: name
name2: name2
expr: expr // p.expr(token.lowest_prec)
is_mut: is_mut