mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.ast: implement Expr.str() for ast.ConcatExpr and ast.IfExpr too
This commit is contained in:
parent
f04dd21e79
commit
84fe2d8c6e
@ -274,6 +274,9 @@ pub fn (x Expr) str() string {
|
|||||||
ComptimeSelector {
|
ComptimeSelector {
|
||||||
return '${x.left}.$$x.field_expr'
|
return '${x.left}.$$x.field_expr'
|
||||||
}
|
}
|
||||||
|
ConcatExpr {
|
||||||
|
return x.vals.map(it.str()).join(',')
|
||||||
|
}
|
||||||
EnumVal {
|
EnumVal {
|
||||||
return '.$x.val'
|
return '.$x.val'
|
||||||
}
|
}
|
||||||
@ -283,6 +286,23 @@ pub fn (x Expr) str() string {
|
|||||||
Ident {
|
Ident {
|
||||||
return x.name
|
return x.name
|
||||||
}
|
}
|
||||||
|
IfExpr {
|
||||||
|
mut parts := []string{}
|
||||||
|
dollar := if x.is_comptime { '$' } else { '' }
|
||||||
|
for i, branch in x.branches {
|
||||||
|
if i != 0 {
|
||||||
|
parts << ' } ${dollar}else '
|
||||||
|
}
|
||||||
|
if i < x.branches.len - 1 || !x.has_else {
|
||||||
|
parts << ' ${dollar}if ' + branch.cond.str() + ' { '
|
||||||
|
}
|
||||||
|
for stmt in branch.stmts {
|
||||||
|
parts << stmt.str()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parts << ' }'
|
||||||
|
return parts.join('')
|
||||||
|
}
|
||||||
IndexExpr {
|
IndexExpr {
|
||||||
return '$x.left.str()[$x.index.str()]'
|
return '$x.left.str()[$x.index.str()]'
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user