Skip to content

Document print_tree for RuleNodes #142

@ReubenJ

Description

@ReubenJ

Somewhere in the documentation, we should highlight that you can pretty-print RuleNodes in tree form using print_tree from AbstractTrees. Assuming Herb-AI/HerbCore.jl#39 is merged, this will be available from within Herb without the need for an extra using AbstractTree.

Also, while not specific to Herb, it'd be nice to note that Exprs can be pretty-printed in the same way.

julia> using Herb
julia> using AbstractTrees: print_tree # until HerbCore.jl#39 is merged

julia> g = @csgrammar begin
                   Int = 1 | 2
                   Int = 3 + Int
               end

julia> rn = @rulenode 3{3{3{2}}}

julia> print_tree(rn)
3
└─ 3
   └─ 3
      └─ 2

julia> print_tree(rulenode2expr(rn, g))
:(3 + (3 + (3 + 2)))
├─ :+
├─ 3
└─ :(3 + (3 + 2))
   ├─ :+
   ├─ 3
   └─ :(3 + 2)
      ├─ :+
      ├─ 3
      └─ 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions