本文整理匯總了Java中org.antlr.v4.runtime.tree.TerminalNode.getParent方法的典型用法代碼示例。如果您正苦於以下問題:Java TerminalNode.getParent方法的具體用法?Java TerminalNode.getParent怎麽用?Java TerminalNode.getParent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.antlr.v4.runtime.tree.TerminalNode
的用法示例。
在下文中一共展示了TerminalNode.getParent方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: visitTerminal
import org.antlr.v4.runtime.tree.TerminalNode; //導入方法依賴的package包/類
@Override
public Boolean visitTerminal(final TerminalNode node) {
if (node.getSymbol().getType() == FOLLexer.IDENTIFIER
&& node.getParent() instanceof QuantifierContext) {
final QuantifierContext parent = (QuantifierContext) node.getParent();
final String currentConst = this.constOfIdent.get(node.getText());
String nextConst = this.universe.getNextAtomText(currentConst);
if (nextConst == null) { // if last const
nextConst = this.universe.getFirstAtomText();
this.constOfIdent.replace(node.getText(), nextConst);
for (int i = 1; i < parent.IDENTIFIER().size(); i++) {
// if node is not only identifier of parent
if (parent.IDENTIFIER(i).getText().equals(node.getText())) {
this.visit(parent.IDENTIFIER(i - 1));
return true;
}
}
return false; // if node is only identifier of parent
} // if not last const
this.constOfIdent.replace(node.getText(), nextConst);
}
return true;
}
示例2: visitTerminal
import org.antlr.v4.runtime.tree.TerminalNode; //導入方法依賴的package包/類
@Override
public String visitTerminal(final TerminalNode node) {
String nodeText = node == null ? "" : node.getText();
switch (nodeText) {
case "[":
case "{":
case "(":
case "!":
case "~":
case "^":
case "*":
case ".":
case "]":
case "}":
case ")":
break;
case ",":
case ":":
case "|":
nodeText = nodeText + " ";
break;
case "#":
nodeText = " " + nodeText;
break;
default:
final ParseTree parent = node.getParent();
for (int i = 0; i < parent.getChildCount(); i++) {
final ParseTree child = parent.getChild(i);
if (child.getText().equals(node.getText())) {
if (parent.getChild(i + 1) instanceof TerminalNode) {
nodeText = i == 0 ? "" + nodeText : " " + nodeText;
} else {
nodeText = i == 0 ? "" + nodeText + " " : " " + nodeText + " ";
}
break;
}
}
break;
}
return nodeText;
}