Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the AbstractTrees interface for RuleNodes #23

Open
ReubenJ opened this issue May 13, 2024 · 1 comment
Open

Implement the AbstractTrees interface for RuleNodes #23

ReubenJ opened this issue May 13, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@ReubenJ
Copy link
Member

ReubenJ commented May 13, 2024

Implementing the interface (described here) would give us access to useful functions, especially print_tree(...). The most basic implementation would only consist of defining

AbstractTrees.children(node::AbstractRuleNode) = get_children(node)

Out of the box, this would allow for

r = RuleNode(1, [RuleNode(2), RuleNode(2), RuleNode(3, [RuleNode(5)])])

to be displayed by

julia> AbstractTrees.print_tree(r)
1{2,2,3{5}}
├─ 2,
├─ 2,
└─ 3{5}
   └─ 5,

and with a little extra tweaking

julia> AbstractTrees.print_tree((io, x) -> print(io, get_rule(x)), stdout, r)
1
├─ 2
├─ 2
└─ 3
   └─ 5

The current, default, output (Base.show(...)) looks like this.

1{2,2,3{5}}

We could add the tree pretty-printing as an alternative or replace Base.show(...) for rule nodes with this.

I don't know whether printing the actual expressions using the grammar (instead of the rule number seen above) is straightforward with this API, but it would be nice to have that as well.

@ReubenJ ReubenJ added the enhancement New feature or request label May 13, 2024
@ReubenJ
Copy link
Member Author

ReubenJ commented May 13, 2024

Just found that this is somewhat addressed in HerbGrammar here, but it seems like this functionality should be here in HerbCore as it's only concerned with RuleNodes.

We should probably also expand this to AbstractRuleNodes as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant