pest_ascii_tree

Function print_ascii_tree

Source
pub fn print_ascii_tree<R>(parsing_result: Result<Pairs<'_, R>, Error<R>>)
where R: RuleType,
Expand description

Prints the result returned by your pest Parser as an ascii tree.

§Errors

In case of an parsing error, the error is printed. In case of a formating error, the error is printed.

§Examples

pest_ascii_tree::print_ascii_tree(
                    ExpressionParser::parse(Rule::expr,
                                            "(u + (v + w)) + (x + y) + z"));

will result in the output

 expr
 ├─ expr
 │  ├─ val "u"
 │  ├─ op "+"
 │  └─ expr
 │     ├─ val "v"
 │     ├─ op "+"
 │     └─ val "w"
 ├─ op "+"
 ├─ expr
 │  ├─ val "x"
 │  ├─ op "+"
 │  └─ val "y"
 ├─ op "+"
 └─ val "z"