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:
parrt 2012-01-26 14:11:30 -08:00
parent 15d537ce6e
commit adcf72b9a2
2 changed files with 7 additions and 5 deletions

View File

@ -80,10 +80,11 @@ public class Trees {
* parse trees and extract data appropriately.
*/
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();
buf.append("(");
buf.append(getNodeText(t, recog));
buf.append(getNodeText(t, recog, escapeWhitespace));
buf.append(' ');
for (int i = 0; i<t.getChildCount(); i++) {
if ( i>0 ) buf.append(' ');
@ -93,7 +94,7 @@ public class Trees {
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 ( t instanceof ParseTree.RuleNode ) {
int ruleIndex = ((ParseTree.RuleNode)t).getRuleContext().getRuleIndex();
@ -107,7 +108,7 @@ public class Trees {
Object symbol = ((ParseTree.TerminalNode<?>)t).getSymbol();
if (symbol instanceof Token) {
String s = ((Token)symbol).getText();
s = Utils.escapeWhitespace(s);
if ( escapeWhitespace ) s = Utils.escapeWhitespace(s);
return s;
}
}

View File

@ -62,7 +62,8 @@ public class TreeViewer extends JComponent {
@Override
public String getText(Tree node) {
return String.valueOf(Trees.getNodeText(node, parser));
boolean escapeWhitespace = true;
return String.valueOf(Trees.getNodeText(node, parser, escapeWhitespace));
}
}