diff --git a/parser/printer.go b/parser/printer.go index d3aad4a..ac7ffe1 100644 --- a/parser/printer.go +++ b/parser/printer.go @@ -173,15 +173,34 @@ func (p *printer) printMap(m *Map) { } func (p *printer) printOperator(operator *Operator) { + p.printOperatorInternal(operator, true) +} + +func (p *printer) printOperatorInternal(operator *Operator, allowIndent bool) { p.printExpression(operator.Args[0]) p.requestSpace() p.printToken(string(operator.Operator), operator.OperatorPos) + + indented := false if operator.Args[0].End().Line == operator.Args[1].Pos().Line { p.requestSpace() } else { + if allowIndent { + indented = true + p.indent(p.curIndent() + 4) + } p.requestNewline() } - p.printExpression(operator.Args[1]) + + if op, isOp := operator.Args[1].(*Operator); isOp { + p.printOperatorInternal(op, false) + } else { + p.printExpression(operator.Args[1]) + } + + if indented { + p.unindent(p.pos) + } } func (p *printer) printProperty(property *Property) { diff --git a/parser/printer_test.go b/parser/printer_test.go index a223fab..7289441 100644 --- a/parser/printer_test.go +++ b/parser/printer_test.go @@ -162,6 +162,22 @@ bar { name: "def", num: 5, } +`, + }, + { + input: ` +foo { + bar: "b" + + "a" + + "z", +} +`, + output: ` +foo { + bar: "b" + + "a" + + "z", +} `, }, { @@ -190,6 +206,18 @@ foo = 100 bar = foo baz = foo + bar baz += foo +`, + }, + { + input: ` +foo = "bar " + + "" + + "baz" +`, + output: ` +foo = "bar " + + "" + + "baz" `, }, {