Skip to content

Commit

Permalink
fix bang handling in AST printer
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed Dec 28, 2023
1 parent e61d735 commit c7e8129
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/lang/parser/test/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)`,
Expand Down
9 changes: 6 additions & 3 deletions pkg/printer/printer_ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@ 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 {
return p.printVector(vec, nil)
}

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]
Expand Down
1 change: 0 additions & 1 deletion pkg/printer/printer_rudi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit c7e8129

Please sign in to comment.