vfmt: fix multiline comments

pull/4253/head
Alexander Medvednikov 2020-04-05 19:35:10 +02:00
parent 8260236331
commit 08bbc251ff
3 changed files with 83 additions and 66 deletions

View File

@ -93,7 +93,11 @@ fn (f mut Fmt) imports(imports []ast.Import) {
fn (f Fmt) imp_stmt_str(imp ast.Import) string {
is_diff := imp.alias != imp.mod && !imp.mod.ends_with('.' + imp.alias)
imp_alias_suffix := if is_diff { ' as ${imp.alias}' } else { '' }
imp_alias_suffix := if is_diff {
' as ${imp.alias}'
} else {
''
}
return '${imp.mod}${imp_alias_suffix}'
}
@ -271,7 +275,11 @@ fn (f mut Fmt) stmt(node ast.Stmt) {
f.writeln('')
}
ast.CompIf {
inversion := if it.is_not { '!' } else { '' }
inversion := if it.is_not {
'!'
} else {
''
}
f.writeln('\$if ${inversion}${it.val} {')
f.stmts(it.stmts)
if it.has_else {
@ -538,7 +546,11 @@ fn (f mut Fmt) expr(node ast.Expr) {
f.write(it.field)
}
ast.StringLiteral {
if it.val.contains("'") { f.write('"$it.val"') } else { f.write("'$it.val'") }
if it.val.contains("'") {
f.write('"$it.val"')
} else {
f.write("'$it.val'")
}
}
ast.StringInterLiteral {
f.write("'")
@ -637,6 +649,7 @@ fn (f mut Fmt) comment(node ast.Comment) {
f.writeln('/*')
for line in lines {
f.writeln(line)
f.empty_line = false
}
f.writeln('*/')
}
@ -669,7 +682,11 @@ fn (f mut Fmt) if_expr(it ast.IfExpr) {
} else if i == it.branches.len - 1 && it.has_else {
f.write('} else {')
}
if single_line { f.write(' ') } else { f.writeln('') }
if single_line {
f.write(' ')
} else {
f.writeln('')
}
f.stmts(branch.stmts)
if single_line {
f.write(' ')

View File

@ -834,7 +834,7 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) {
g.definitions.write(', ')
}
}
*/
*/
//
g.fn_args(it.args, it.is_variadic)
if it.no_body {
@ -1754,7 +1754,7 @@ fn (g mut Gen) index_expr(node ast.IndexExpr) {
g.write(', ')
g.expr(node.index)
g.write('))')
*/
*/
zero := g.type_default(info.value_type)
g.write('(*($elem_type_str*)map_get3(')
g.expr(node.left)
@ -2401,8 +2401,8 @@ fn (g mut Gen) method_call(node ast.CallExpr) {
print('$sym.name ')
}
println('')
}
*/
}
*/
// ///////
g.call_args(node.args, node.expected_arg_types)
g.write(')')
@ -2438,7 +2438,7 @@ fn (g mut Gen) fn_call(node ast.CallExpr) {
g.writeln('; //memory')
}
}
*/
*/
if is_print && node.args[0].typ != table.string_type_idx {
typ := node.args[0].typ
mut styp := g.typ(typ)
@ -2728,7 +2728,7 @@ fn (g Gen) type_default(typ table.Type) string {
}
else {}
}
*/
*/
match sym.name {
'string' {
return 'tos3("")'
@ -2760,8 +2760,8 @@ fn (g Gen) type_default(typ table.Type) string {
'byteptr'{ '0'}
'voidptr'{ '0'}
else { '{0} '}
}
*/
}
*/
}
pub fn (g mut Gen) write_tests_main() {

View File

@ -36,7 +36,7 @@ mut:
returns bool
inside_match_case bool // to separate `match_expr { }` from `Struct{}`
comments []ast.Comment
//comments []ast.Comment
}
// for tests