本文整理汇总了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;
}