Ability to get indented string tree
See original GitHub issueAt present time all runtimes have a method for getting result tree in lisp format toStringTree
. It would be also good to have a method toStringTreeIndented
. Indented output more applicable for string trees comparison (diff). See the sample output for input grammar and text below.
Grammar
grammar Test;
expression
: <assoc=right> expression '^' expression
| expression ('*' | '/') expression
| expression ('+' | '-') expression
| '(' expression ')'
| ID
;
ID: [a-zA-Z] [0-9a-zA-Z]*;
DIGIT: [0-9]+;
WS: [ \t\r\n] -> skip;
Text
a1 * (a2 + a3 + a4 - a5 ^ a6 ^ (a8 + a9 / a10)) * a11 * a12
toStringTree method
(expression (expression (expression (expression a1) * (expression ( (expression (expression (expression (expression a2) + (expression a3)) + (expression a4)) - (expression (expression a5) ^ (expression (expression a6) ^ (expression ( (expression (expression a8) + (expression (expression a9) / (expression a10))) ))))) ))) * (expression a11)) * (expression a12))
toStringTreeIndented method
(expression
(expression
(expression
(expression
'a1'
)
'*'
(expression
'('
(expression
(expression
(expression
(expression
'a2'
)
'+'
(expression
'a3'
)
)
'+'
(expression
'a4'
)
)
'-'
(expression
(expression
'a5'
)
'^'
(expression
(expression
'a6'
)
'^'
(expression
'('
(expression
(expression
'a8'
)
'+'
(expression
(expression
'a9'
)
'/'
(expression
'a10'
)
)
)
')'
)
)
)
)
')'
)
)
'*'
(expression
'a11'
)
)
'*'
(expression
'a12'
)
)
Also it is usefull to have a method that returns a tree in JSON format (tree serialization in fact).
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Guitar Shop 101: Happy Little (String) Trees
This indentation should lie exactly between the two strings. Use it as a guide for drilling the mounting screw hole.
Read more >string - Java - Indented list from a tree - Stack Overflow
Here's a simple recursive implementation: public String toIndentedString() { StringBuilder sb = new StringBuilder(rootValue.
Read more >String Tree Replacement - YouTube
The basic string tree on my Fender Stratocaster was causing some trouble - strings were binding on it, causing some issues with tuning ......
Read more >String Tree Spacer Alternative - YouTube
This video is part of a series I've done on how I built my Fender Custom Shop 1962 style heavy relic Stratocaster.
Read more >Parsing indented text into a tree structure in C# - Code Review ...
My goal is to take an input stream (text file), and then parse it into a tree node based on each line's indentation....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
GUI is great, but not very comfortable for me. I am using my own tools and text editors.
I figured you could copy paste to emacs, go to lisp mode
M-x lisp-mode
. Then install https://github.com/tuhdo/semantic-refactor And runM-x srefactor-lisp-format-buffer
but this package doesn’t appear in my MELPA list. so downer.