From c7e8129c1d94ceeb8f264a6da39effd23a57e271 Mon Sep 17 00:00:00 2001 From: xrstf Date: Thu, 28 Dec 2023 10:25:15 +0100 Subject: [PATCH] fix bang handling in AST printer --- pkg/lang/parser/test/parser_test.go | 2 +- pkg/printer/printer_ast.go | 9 ++++++--- pkg/printer/printer_rudi.go | 1 - 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/lang/parser/test/parser_test.go b/pkg/lang/parser/test/parser_test.go index ddbdfe4..dfe2664 100644 --- a/pkg/lang/parser/test/parser_test.go +++ b/pkg/lang/parser/test/parser_test.go @@ -48,7 +48,7 @@ func TestParseProgram(t *testing.T) { }, { input: `(func+ -foo bar!)`, - expected: `(tuple (identifier func+) (identifier -foo) (identifier bar!))`, + expected: `(tuple (identifier func+) (identifier -foo) (identifier bar (bang)))`, }, { input: `(1)`, diff --git a/pkg/printer/printer_ast.go b/pkg/printer/printer_ast.go index 85cd3c8..20b021f 100644 --- a/pkg/printer/printer_ast.go +++ b/pkg/printer/printer_ast.go @@ -41,8 +41,12 @@ func (p *astPrinter) String(str string) error { } func (p *astPrinter) Identifier(ident *ast.Identifier) error { - // TODO: Include Bang modifier - return p.write(fmt.Sprintf("(identifier %s)", *ident)) + var bang string + if ident.Bang { + bang = " (bang)" + } + + return p.write(fmt.Sprintf("(identifier %s%s)", ident.Name, bang)) } func (p *astPrinter) Vector(vec []any) error { @@ -50,7 +54,6 @@ func (p *astPrinter) Vector(vec []any) error { } func (p *astPrinter) VectorNode(vec *ast.VectorNode) error { - // TODO: Use copy()? data := make([]any, len(vec.Expressions)) for i := range vec.Expressions { data[i] = vec.Expressions[i] diff --git a/pkg/printer/printer_rudi.go b/pkg/printer/printer_rudi.go index 39d63c0..b7beed5 100644 --- a/pkg/printer/printer_rudi.go +++ b/pkg/printer/printer_rudi.go @@ -55,7 +55,6 @@ func (p *rudiPrinter) Vector(vec []any) error { } func (p *rudiPrinter) VectorNode(vec *ast.VectorNode) error { - // TODO: Use copy()? data := make([]any, len(vec.Expressions)) for i := range vec.Expressions { data[i] = vec.Expressions[i]