v.ast: implement Expr.str() for ast.ConcatExpr and ast.IfExpr too

pull/9708/head
Delyan Angelov 2021-04-13 12:23:30 +03:00
parent f04dd21e79
commit 84fe2d8c6e
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 20 additions and 0 deletions

View File

@ -274,6 +274,9 @@ pub fn (x Expr) str() string {
ComptimeSelector {
return '${x.left}.$$x.field_expr'
}
ConcatExpr {
return x.vals.map(it.str()).join(',')
}
EnumVal {
return '.$x.val'
}
@ -283,6 +286,23 @@ pub fn (x Expr) str() string {
Ident {
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 {
return '$x.left.str()[$x.index.str()]'
}