Skip to content

Conversation

@khilangudka
Copy link
Contributor

@khilangudka khilangudka commented Oct 20, 2025

When printing an AST using any of the print functions, (e.g. PrintSyntaxTree or SprintSyntaxTree), I found that it is only including the root of the AST. It was also strangely printing a pointer address.

Example:

top "G@tags:tag2"
0xc0000f60e01

Upon looking at the code, I found that in the printFunc function that writes the AST to a io.Writer, the recursive call is incorrectly calling the built-in print function instead of printFunc, so no recursive calls are actually taking place.

But after the fix in this PR:

top "G@tags:tag2"
 expr "G@tags:tag2"
  matcher "G@tags:tag2"
   tagsprefix "G@tags:"
    PegText "G@tags:"
   tag "tag2"
    PegText "tag2"

When printing the AST to a string using the SprintSyntaxTree function, I was seeing pointer addresses being printed to stdout. Upon looking at the code, I found that in the `printFunc` function that writes the AST to a `io.Writer`, the recursive call is incorrectly calling the built-in `print` function instead of `printFunc`.
@pointlander pointlander merged commit 0d99a67 into pointlander:main Oct 20, 2025
0 of 3 checks passed
@khilangudka khilangudka deleted the patch-1 branch October 21, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants