Skip to content

Feature: Add pretty print AST to CPP runtime#2505

Merged
parrt merged 2 commits into
antlr:masterfrom
foxever:ast-pretty-print
Nov 11, 2019
Merged

Feature: Add pretty print AST to CPP runtime#2505
parrt merged 2 commits into
antlr:masterfrom
foxever:ast-pretty-print

Conversation

@foxever

@foxever foxever commented Mar 7, 2019

Copy link
Copy Markdown
Contributor

Add pretty print option, default is non pretty print, the second argument is pretty print flag.
Ref #2490

tree->toStringTree(&parser, true);

Here's the demo output

(main 
        (stat 
            (expr 
                (id 🍴)) = 
            (expr 
                (expr 
                    (id 🍐)) + 
                (expr "😎")) ;) 
        (stat 
            (expr 
                (expr 
                    (expr ( 
                        (expr ( 
                            (expr ( 
                                (expr 
                                    (expr 
                                        (id x)) * 
                                    (expr 
                                        (id π))) )) )) )) * 
                    (expr 
                        (id µ))) + 
                (expr 
                    (id ∰))) ;) 
        (stat 
            (expr 
                (expr 
                    (id a)) + 
                (expr ( 
                    (expr 
                        (expr 
                            (expr 
                                (id x)) * 
                            (expr ( 
                                (expr 
                                    (expr 
                                        (id y)) ? 
                                    (expr 0) : 
                                    (expr 1)) ))) + 
                        (expr 
                            (id z))) ))) ;) <EOF>)

@mike-lischke mike-lischke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice patch, thanks. Please update your branch to solve the conflict.

Comment thread runtime/Cpp/runtime/src/RuleContext.h Outdated
/// (root child1 .. childN). Print just a node if this is a leaf.
/// </summary>
virtual std::string toStringTree(std::vector<std::string> &ruleNames);
virtual std::string toStringTree(std::vector<std::string> &ruleNames, bool pretty=false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a space on each side of the equal sign (do this for all occurences in this patch).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@mike-lischke mike-lischke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks.

@parrt ready to merge (C++ only changes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants