本文整理汇总了Java中org.antlr.v4.runtime.misc.Utils.escapeWhitespace方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.escapeWhitespace方法的具体用法?Java Utils.escapeWhitespace怎么用?Java Utils.escapeWhitespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.v4.runtime.misc.Utils
的用法示例。
在下文中一共展示了Utils.escapeWhitespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toStringTree
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
/** Print out a whole tree in LISP form. Arg nodeTextProvider is used on the
* node payloads to get the text for the nodes.
*
* @since 4.5.1
*/
public static String toStringTree(Tree t, TreeTextProvider nodeTextProvider) {
if ( t==null ) return "null";
String s = Utils.escapeWhitespace(nodeTextProvider.getText(t), false);
if ( t.getChildCount()==0 ) return s;
StringBuilder buf = new StringBuilder();
buf.append("(");
s = Utils.escapeWhitespace(nodeTextProvider.getText(t), false);
buf.append(s);
buf.append(' ');
for (int i = 0; i<t.getChildCount(); i++) {
if ( i>0 ) buf.append(' ');
buf.append(toStringTree(t.getChild(i), nodeTextProvider));
}
buf.append(")");
return buf.toString();
}
示例2: toStringTree
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
private String toStringTree(Tree tree, List<String> ruleNames) {
String s = Utils.escapeWhitespace(getNodeText(tree, ruleNames), false);
if(tree.getChildCount() == 0) return s;
StringBuilder buf = new StringBuilder();
buf.append("(");
s = Utils.escapeWhitespace(getNodeText(tree, ruleNames), false);
buf.append(s);
buf.append(' ');
for(int i = 0; i < tree.getChildCount(); i++)
{
if(i > 0)
buf.append(' ');
buf.append(toStringTree(tree.getChild(i), ruleNames));
}
buf.append(")");
return buf.toString();
}
示例3: toStringTree
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
private String toStringTree(@NotNull final Tree t, @Nullable final List<String> ruleNames) {
if (t.getChildCount() == 0) {
return Utils.escapeWhitespace(getNodeText(t, ruleNames), true);
}
StringBuilder buf = new StringBuilder();
buf.append(" ( ");
String s = Utils.escapeWhitespace(getNodeText(t, ruleNames), true);
buf.append(s);
buf.append(' ');
for (int i = 0; i < t.getChildCount(); i++) {
if (i > 0) {
buf.append(' ');
}
buf.append(toStringTree(t.getChild(i), ruleNames));
}
buf.append(" ) ");
return buf.toString();
}
示例4: toStringTree
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
/** Print out a whole tree in LISP form. {@link #getNodeText} is used on the
* node payloads to get the text for the nodes. Detect
* parse trees and extract data appropriately.
*/
public static String toStringTree(@NotNull Tree t, @Nullable List<String> ruleNames) {
String s = Utils.escapeWhitespace(getNodeText(t, ruleNames), false);
if ( t.getChildCount()==0 ) return s;
StringBuilder buf = new StringBuilder();
buf.append("(");
s = Utils.escapeWhitespace(getNodeText(t, ruleNames), false);
buf.append(s);
buf.append(' ');
for (int i = 0; i<t.getChildCount(); i++) {
if ( i>0 ) buf.append(' ');
buf.append(toStringTree(t.getChild(i), ruleNames));
}
buf.append(")");
return buf.toString();
}
示例5: process
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
private String process(final Tree t, final List<String> ruleNames) {
if (t.getChildCount() == 0) return Utils.escapeWhitespace(Trees.getNodeText(t, ruleNames), false);
StringBuilder sb = new StringBuilder();
sb.append(lead(level));
level++;
String s = Utils.escapeWhitespace(Trees.getNodeText(t, ruleNames), false);
sb.append(s + ' ');
for (int i = 0; i < t.getChildCount(); i++) {
sb.append(process(t.getChild(i), ruleNames));
}
level--;
sb.append(lead(level));
return sb.toString();
}
示例6: visitTerminal
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
@Override
public void visitTerminal(TerminalNode node) {
String text = Utils.escapeWhitespace(Trees.getNodeText(node, ruleNames), false);
if(text.startsWith(" ") || text.endsWith(" ")){
text = "'" + text + "'";
}
stack.get(node.getParent()).add(text);
}
示例7: appendToken
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
/**
* Append the symbol and its position in the input text to the parse tree
* buffer.
*
* @param symbol the symbol which should be appended to the parse tree.
* @return boolean true if symbol is not null, false otherwise.
*/
protected boolean appendToken(Token symbol) {
if (symbol != null) {
buf.append("[");
String s = Utils.escapeWhitespace(symbol.getText(), false);
buf.append(s);
buf.append("] (line ");
buf.append(String.valueOf(symbol.getLine()));
buf.append(":");
buf.append(String.valueOf(symbol.getCharPositionInLine()));
buf.append(")");
return true;
}
return false;
}
示例8: appendNodeText
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
/**
* Determine some string representation for the given node and append it to
* the parse tree buffer.
*
* @param t The sub-tree whose current node needs a string representation.
*/
protected void appendNodeText(@NotNull Tree t) {
if ( ruleNames!=null ) {
if ( t instanceof RuleNode ) {
if (appendRule(((RuleNode)t).getRuleContext())) return;
}
if ( t instanceof ErrorNode) {
buf.append("ERROR: ");
appendToken(((ErrorNode)t).getSymbol());
return;
}
if ( t instanceof TerminalNode) {
if (appendToken(((TerminalNode)t).getSymbol())) return;
}
}
// no recog for rule names
Object payload = t.getPayload();
if ( payload instanceof Token ) {
if (appendToken((Token)payload)) return;
}
if ( payload instanceof RuleContext ) {
if (appendRule((RuleContext)payload)) return;
}
String s = Utils.escapeWhitespace(payload.toString(), false);
buf.append("unknown payload <<");
buf.append(s);
buf.append(">>");
}
示例9: outputSymbol
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
/** Output the current symbol with line and character position. */
public void outputSymbol(Token symbol) {
if ( outputStream != null) {
outputStream.print(", LT(1)=[");
String s = Utils.escapeWhitespace(symbol.getText(), false);
outputStream.print(s);
outputStream.print("] (line ");
outputStream.print(String.valueOf(symbol.getLine()));
outputStream.print(":");
outputStream.print(String.valueOf(symbol.getCharPositionInLine()));
outputStream.println(")");
}
}
示例10: toStringTree
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
/**
* @see org.antlr.v4.runtime.tree.Trees.toStringTree(Tree, List<String>)
*/
public static String toStringTree(final Tree t, @Nullable final List<String> ruleNames, final int depth) {
String s = Utils.escapeWhitespace(Trees.getNodeText(t, ruleNames), false);
if (t.getChildCount() == 0) {
return s;
}
final StringBuilder buf = new StringBuilder();
if (depth > 0) {
buf.append(NEWLINE);
}
buf.append(indent(depth));
buf.append("(");
s = Utils.escapeWhitespace(Trees.getNodeText(t, ruleNames), false);
buf.append(s);
buf.append(' ');
for (int i = 0; i < t.getChildCount(); i++) {
if (i > 0) {
buf.append(' ');
}
buf.append(toStringTree(t.getChild(i), ruleNames, depth + 1));
}
buf.append(")");
return buf.toString();
}
示例11: toString
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
@Override
public String toString() {
String symbol = "";
if (startIndex >= 0 && startIndex < getInputStream().size()) {
symbol = getInputStream().getText(Interval.of(startIndex,startIndex));
symbol = Utils.escapeWhitespace(symbol, false);
}
return String.format(Locale.getDefault(), "%s('%s')", LexerNoViableAltException.class.getSimpleName(), symbol);
}
示例12: getText
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
protected String getText(Tree tree) {
String s = treeTextProvider.getText(tree);
s = Utils.escapeWhitespace(s, false);
return s;
}
示例13: text
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
public void text(Graphics g, String s, int x, int y) {
// System.out.println("drawing '"+s+"' @ "+x+","+y);
s = Utils.escapeWhitespace(s, true);
g.drawString(s, x, y);
}
示例14: getText
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
protected String getText(Tree tree) {
String s = treeTextProvider.getText(tree);
s = Utils.escapeWhitespace(s, true);
return s;
}
示例15: toStringTree
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
private static String toStringTree(Tree t, String[] ruleNames, String[] tokenNames, int indent, boolean prettyPrint) {
String s = Utils.escapeWhitespace(getNodeText(t, ruleNames, tokenNames), false);
if (t.getChildCount() == 0)
return s;
StringBuilder buf = new StringBuilder();
buf.append("(");
s = Utils.escapeWhitespace(getNodeText(t, ruleNames, tokenNames), false);
buf.append(s);
buf.append(" ");
boolean inlined = true;
if (prettyPrint) {
for (int i = 0; i < t.getChildCount(); i++) {
if (t.getChild(i).getChildCount() > 1) {
inlined = false;
}
}
}
for (int i = 0; i < t.getChildCount(); i++) {
if (inlined) {
if (i > 0)
buf.append(" ");
buf.append(toStringTree(t.getChild(i), ruleNames, tokenNames, indent + 1, prettyPrint));
inlined = true;
} else {
buf.append("\n");
for (int k = 0; k < indent + 1; k++)
buf.append(" ");
buf.append(toStringTree(t.getChild(i), ruleNames, tokenNames, indent + 1, prettyPrint));
inlined = false;
}
}
if (!inlined) {
buf.append("\n");
for (int k = 0; k < indent; k++)
buf.append(" ");
}
buf.append(")");
return buf.toString();
}