diff --git a/node.go b/node.go index fc9082a..5a8fc65 100644 --- a/node.go +++ b/node.go @@ -69,7 +69,7 @@ func convert(n_ node.Node) (string, error) { // Emit deferred statements if len(statements) > 0 { ret += "func init() {\n" - ret += "\t" + strings.Join(statements, "\n\t") + "\n" + ret += "\t" + strings.Join(statements, "\t") // Statements already added their own newline ret += "}\n" } @@ -79,7 +79,8 @@ func convert(n_ node.Node) (string, error) { return n.Value, nil case Literal: - return n.Value, nil + // We expect literal statements to act like a *Stmt, i.e. be emitted with a trailing NL + return n.Value + "\n", nil // // stmt @@ -95,7 +96,7 @@ func convert(n_ node.Node) (string, error) { return "", parseErr{s, err} } - ret += line + "\n" + ret += line // Statements already added a trailing newline } return ret + "}\n", nil @@ -922,20 +923,18 @@ func convertFunctionCommon(params []node.Node, returnType node.Node, returnsRef } // Build function prototype - ret := "(" + strings.Join(funcParams, ", ") + ") (" + funcReturn + ", error) {\n" + ret := "(" + strings.Join(funcParams, ", ") + ") (" + funcReturn + ", error) " // Recurse through body statements - for _, s := range bodyStmts { - bodyStmt, err := convert(s) - if err != nil { - return "", parseErr{s, err} - } - ret += bodyStmt + "\n" + fullBody, err := convert(stmt.NewStmtList(bodyStmts)) + if err != nil { + return "", err } + ret += fullBody + "\n" + // Done // No extra trailing newline in case this is part of a large expression - ret += "}" return ret, nil }