forked from jasder/antlr
whitespace was being escaped to special characters even when printing to string should only do so when doing GUI tree
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9904]
This commit is contained in:
parent
15d537ce6e
commit
adcf72b9a2
|
@ -80,10 +80,11 @@ public class Trees {
|
||||||
* parse trees and extract data appropriately.
|
* parse trees and extract data appropriately.
|
||||||
*/
|
*/
|
||||||
public static String toStringTree(Tree t, Parser recog) {
|
public static String toStringTree(Tree t, Parser recog) {
|
||||||
if ( t.getChildCount()==0 ) return getNodeText(t, recog);
|
boolean escapeWhitespace = false;
|
||||||
|
if ( t.getChildCount()==0 ) return getNodeText(t, recog, escapeWhitespace);
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
buf.append("(");
|
buf.append("(");
|
||||||
buf.append(getNodeText(t, recog));
|
buf.append(getNodeText(t, recog, escapeWhitespace));
|
||||||
buf.append(' ');
|
buf.append(' ');
|
||||||
for (int i = 0; i<t.getChildCount(); i++) {
|
for (int i = 0; i<t.getChildCount(); i++) {
|
||||||
if ( i>0 ) buf.append(' ');
|
if ( i>0 ) buf.append(' ');
|
||||||
|
@ -93,7 +94,7 @@ public class Trees {
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <Symbol> String getNodeText(Tree t, Parser recog) {
|
public static <Symbol> String getNodeText(Tree t, Parser recog, boolean escapeWhitespace) {
|
||||||
if ( recog!=null ) {
|
if ( recog!=null ) {
|
||||||
if ( t instanceof ParseTree.RuleNode ) {
|
if ( t instanceof ParseTree.RuleNode ) {
|
||||||
int ruleIndex = ((ParseTree.RuleNode)t).getRuleContext().getRuleIndex();
|
int ruleIndex = ((ParseTree.RuleNode)t).getRuleContext().getRuleIndex();
|
||||||
|
@ -107,7 +108,7 @@ public class Trees {
|
||||||
Object symbol = ((ParseTree.TerminalNode<?>)t).getSymbol();
|
Object symbol = ((ParseTree.TerminalNode<?>)t).getSymbol();
|
||||||
if (symbol instanceof Token) {
|
if (symbol instanceof Token) {
|
||||||
String s = ((Token)symbol).getText();
|
String s = ((Token)symbol).getText();
|
||||||
s = Utils.escapeWhitespace(s);
|
if ( escapeWhitespace ) s = Utils.escapeWhitespace(s);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,8 @@ public class TreeViewer extends JComponent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getText(Tree node) {
|
public String getText(Tree node) {
|
||||||
return String.valueOf(Trees.getNodeText(node, parser));
|
boolean escapeWhitespace = true;
|
||||||
|
return String.valueOf(Trees.getNodeText(node, parser, escapeWhitespace));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue