diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 48d020849f..a13dc5c361 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -192,6 +192,7 @@ pub struct Stmt { pub struct VarDecl { pub: name string + name2 string // TODO expr Expr is_mut bool mut: diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 455cb4e667..c1cec26c6c 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -208,7 +208,12 @@ fn (f mut Fmt) stmt(node ast.Stmt) { if it.is_mut { f.write('mut ') } - f.write('$it.name := ') + 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,7 +361,12 @@ fn (f mut Fmt) expr(node ast.Expr) { f.single_line_if = false } ast.Ident { - f.write('$it.name') + if it.kind == .blank_ident { + f.write('_') + } + else { + f.write('$it.name') + } } ast.InfixExpr { f.expr(it.left) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index d43d9cb85a..6bb31cd726 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -57,7 +57,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt { pref: &pref.Preferences{} scope: scope // scope: &ast.Scope{start_pos: 0, parent: 0} - + } p.init_parse_fns() p.read_first_token() @@ -333,7 +333,7 @@ pub fn (p mut Parser) stmt() ast.Stmt { return ast.ExprStmt{ expr: expr // typ: typ - + } } } @@ -632,7 +632,7 @@ pub fn (p mut Parser) name_expr() ast.Expr { p.expr_mod = '' return ast.EnumVal{ enum_name: enum_name // lp.prepend_mod(enum_name) - + val: val pos: p.tok.position() } @@ -903,7 +903,7 @@ fn (p mut Parser) dot_expr(left ast.Expr, left_type table.Type) ast.Expr { expr: left name: field_name args: args - muts:muts + muts: muts pos: p.tok.position() } mut node := ast.Expr{} @@ -1179,11 +1179,11 @@ fn (p mut Parser) if_expr() ast.Expr { stmts: stmts else_stmts: else_stmts // typ: typ - + pos: pos has_else: has_else // left: left - + } return node } @@ -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,11 +1604,12 @@ 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 // typ: typ - + pos: p.tok.position() } p.scope.register_var(node) @@ -1726,7 +1728,7 @@ fn (p mut Parser) match_expr() ast.Expr { blocks: blocks match_exprs: match_exprs // typ: typ - + cond: cond } return node