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 ')
} }
f.write('$it.name := ') if it.name2 == '' {
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,7 +361,12 @@ fn (f mut Fmt) expr(node ast.Expr) {
f.single_line_if = false f.single_line_if = false
} }
ast.Ident { ast.Ident {
f.write('$it.name') if it.kind == .blank_ident {
f.write('_')
}
else {
f.write('$it.name')
}
} }
ast.InfixExpr { ast.InfixExpr {
f.expr(it.left) f.expr(it.left)

View File

@ -57,7 +57,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
pref: &pref.Preferences{} pref: &pref.Preferences{}
scope: scope scope: scope
// scope: &ast.Scope{start_pos: 0, parent: 0} // scope: &ast.Scope{start_pos: 0, parent: 0}
} }
p.init_parse_fns() p.init_parse_fns()
p.read_first_token() p.read_first_token()
@ -333,7 +333,7 @@ pub fn (p mut Parser) stmt() ast.Stmt {
return ast.ExprStmt{ return ast.ExprStmt{
expr: expr expr: expr
// typ: typ // typ: typ
} }
} }
} }
@ -632,7 +632,7 @@ pub fn (p mut Parser) name_expr() ast.Expr {
p.expr_mod = '' p.expr_mod = ''
return ast.EnumVal{ return ast.EnumVal{
enum_name: enum_name // lp.prepend_mod(enum_name) enum_name: enum_name // lp.prepend_mod(enum_name)
val: val val: val
pos: p.tok.position() 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 expr: left
name: field_name name: field_name
args: args args: args
muts:muts muts: muts
pos: p.tok.position() pos: p.tok.position()
} }
mut node := ast.Expr{} mut node := ast.Expr{}
@ -1179,11 +1179,11 @@ fn (p mut Parser) if_expr() ast.Expr {
stmts: stmts stmts: stmts
else_stmts: else_stmts else_stmts: else_stmts
// typ: typ // typ: typ
pos: pos pos: pos
has_else: has_else has_else: has_else
// left: left // left: left
} }
return node return node
} }
@ -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,11 +1604,12 @@ 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
// typ: typ // typ: typ
pos: p.tok.position() pos: p.tok.position()
} }
p.scope.register_var(node) p.scope.register_var(node)
@ -1726,7 +1728,7 @@ fn (p mut Parser) match_expr() ast.Expr {
blocks: blocks blocks: blocks
match_exprs: match_exprs match_exprs: match_exprs
// typ: typ // typ: typ
cond: cond cond: cond
} }
return node return node