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

v2: minor fixes

This commit is contained in:
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 struct VarDecl {
pub: pub:
name string name string
name2 string // TODO
expr Expr expr Expr
is_mut bool is_mut bool
mut: mut:

View File

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

View File

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