本文整理汇总了Java中org.antlr.v4.runtime.tree.ParseTree.getChild方法的典型用法代码示例。如果您正苦于以下问题:Java ParseTree.getChild方法的具体用法?Java ParseTree.getChild怎么用?Java ParseTree.getChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.v4.runtime.tree.ParseTree
的用法示例。
在下文中一共展示了ParseTree.getChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: walk
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
@Override
public WalkResult walk(ParseTree tree, String value) {
String actualValue = getActualValue(tree, value);
String filteredValue;
if (tree.getChildCount() == 1 && (
tree.getChild(0) instanceof SingleVersionContext ||
tree.getChild(0) instanceof SingleVersionWithCommasContext)) {
filteredValue = VersionSplitter.getInstance().getSplitRange(actualValue, firstWord, lastWord);
} else {
filteredValue = WordSplitter.getInstance().getSplitRange(actualValue, firstWord, lastWord);
}
if (filteredValue == null) {
return null;
}
return walkNextStep(tree, filteredValue);
}
示例2: next
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private ParseTree next(ParseTree tree) {
ParseTree parent = up(tree);
ParseTree child;
boolean foundCurrent = false;
for (int i = 0; i < parent.getChildCount(); i++) {
child = parent.getChild(i);
if (foundCurrent) {
if (treeIsSeparator(child)) {
continue;
}
return child;
}
if (child == tree) {
foundCurrent = true;
}
}
return null; // There is no next
}
示例3: prev
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private ParseTree prev(ParseTree tree) {
ParseTree parent = up(tree);
int lastChildIndex = -1;
ParseTree child = null;
int i;
for (i = 0; i < parent.getChildCount(); i++) {
if (!treeIsSeparator(child)) {
lastChildIndex++;
children[lastChildIndex] = child;
}
child = parent.getChild(i);
if (child == tree) {
if (lastChildIndex < steps) {
break; // There is no previous
}
return children[lastChildIndex - steps + 1];
}
}
return null; // There is no previous
}
示例4: prev
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private ParseTree prev(ParseTree tree) {
ParseTree parent = up(tree);
ParseTree prevChild = null;
ParseTree child = null;
int i;
for (i = 0; i < parent.getChildCount(); i++) {
if (!treeIsSeparator(child)) {
prevChild = child;
}
child = parent.getChild(i);
if (child == tree) {
return prevChild;
}
}
return null; // This should never happen
}
示例5: getNextSibling
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
/**
* Gets next sibling of ParseTree node.
* @param node ParseTree node
* @return next sibling of ParseTree node.
*/
private static ParseTree getNextSibling(ParseTree node) {
ParseTree nextSibling = null;
if (node.getParent() != null) {
final ParseTree parent = node.getParent();
int index = 0;
while (true) {
final ParseTree currentNode = parent.getChild(index);
if (currentNode.equals(node)) {
nextSibling = parent.getChild(index + 1);
break;
}
index++;
}
}
return nextSibling;
}
示例6: enterParseTree
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private void enterParseTree(ParseTree tree){
int cc = tree.getChildCount();
for(int i=0;i<cc;i++){
ParseTree c = tree.getChild(i);
if(c instanceof RuleNode){
enterParseTree(c);
}else if (c instanceof TerminalNode){
Token t = ((TerminalNode)c).getSymbol();
index2token.put(tokenCounter, t);
token2tree.put(t, c);
tokenCounter ++;
}else{
System.err.println("unknown node:" + c);
}
}
}
示例7: readValues
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private OperatorNode<ExpressionOperator> readValues(List<Field_defContext> fieldDefs, Scope scope) {
List<String> fieldNames;
List<OperatorNode<ExpressionOperator>> fieldValues;
int numPairs = fieldDefs.size();
fieldNames = Lists.newArrayListWithExpectedSize(numPairs);
fieldValues = Lists.newArrayListWithExpectedSize(numPairs);
for (int j = 0; j < numPairs; j++) {
ParseTree startNode = fieldDefs.get(j);
while (startNode.getChildCount() < 3) {
startNode = startNode.getChild(0);
}
fieldNames.add((String) convertExpr(startNode.getChild(0), scope).getArgument(1));
fieldValues.add(convertExpr(startNode.getChild(2), scope));
}
return OperatorNode.create(ExpressionOperator.MAP, fieldNames, fieldValues);
}
示例8: print
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
public static void print(final ParseTree node, final int level, CommonTokenStream stream) {
final Interval sourceInterval = node.getSourceInterval();
final Token firstToken = stream.get(sourceInterval.a);
int line = firstToken.getLine();
int charStart = firstToken.getCharPositionInLine();
int endLine = line;
int endChar = charStart + firstToken.getText().length();
String data = "@(" + line + ":" + charStart + "," + endLine + ":" + endChar + ") with text: "
+ firstToken.getText();
final int tmp = level + 1;
final StringBuilder sb = new StringBuilder();
sb.append(StringUtils.repeat("\t", level));
sb.append(node.getClass().getSimpleName() + ": " + data + " :" + node.getText());
System.out.println(sb.toString());
final int n = node.getChildCount();
for (int i = 0; i < n; i++) {
final ParseTree c = node.getChild(i);
print(c, tmp, stream);
}
}
示例9: findChildrenByType
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private ParseTree findChildrenByType(ParseTree parseTree, Class<?> classtype) {
for(int i=0; i<parseTree.getChildCount(); i++) {
ParseTree chl = parseTree.getChild(i);
if(chl.getClass().equals(classtype)) {
return chl;
}
}
return null;
}
示例10: visit
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
@Override
public Integer visit(final ParseTree tree) {
final int n = tree.getChildCount();
int s = 0;
for (int i = 0; i < n; i++) {
final ParseTree c = tree.getChild(i);
s += visit(c);
}
final Class<? extends ParseTree> classz = tree.getClass();
if (Sql_unionContext.class.equals(classz)) {
s++;
}
if (Function_callContext.class.isAssignableFrom(classz)) {
s++;
}
if (Join_partContext.class.equals(classz)) {
s++;
}
if (Order_by_expressionContext.class.equals(classz)) {
s++;
}
if (Select_list_elemContext.class.equals(classz)) {
s++;
}
if (Search_condition_notContext.class.equals(classz)) {
s++;
}
if (Dml_clauseContext.class.equals(classz)) {
s++;
}
return s;
}
示例11: enterProductVersion
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private void enterProductVersion(ParseTree ctx) {
if (ctx.getChildCount() != 1) {
// These are the specials with multiple children like keyvalue, etc.
inform(ctx, "version");
return;
}
ParseTree child = ctx.getChild(0);
// Only for the SingleVersion edition we want to have splits of the version.
if (child instanceof SingleVersionContext || child instanceof SingleVersionWithCommasContext) {
return;
}
inform(ctx, "version");
}
示例12: getStartNode
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private static TerminalNode getStartNode(ParseTree tree) {
if (tree instanceof TerminalNode) {
return (TerminalNode) tree;
}
Deque<ParseTree> workList = new ArrayDeque<ParseTree>();
IntegerStack workIndexStack = new IntegerStack();
workList.push(tree);
workIndexStack.push(0);
while (!workList.isEmpty()) {
ParseTree currentTree = workList.peek();
int currentIndex = workIndexStack.peek();
if (currentIndex == currentTree.getChildCount()) {
workList.pop();
workIndexStack.pop();
continue;
}
// move work list to next child
workIndexStack.push(workIndexStack.pop() + 1);
// process the current child
ParseTree child = currentTree.getChild(currentIndex);
if (child instanceof TerminalNode) {
return (TerminalNode) child;
}
workList.push(child);
workIndexStack.push(0);
}
return null;
}
示例13: insertChildrenNodes
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
/**
* Creates child nodes for each node from 'nodes' array.
* @param parseTreeParent original ParseTree parent node
* @param nodes array of JavadocNodeImpl nodes
*/
private void insertChildrenNodes(final JavadocNodeImpl[] nodes, ParseTree parseTreeParent) {
for (int i = 0; i < nodes.length; i++) {
final JavadocNodeImpl currentJavadocNode = nodes[i];
final ParseTree currentParseTreeNodeChild = parseTreeParent.getChild(i);
final JavadocNodeImpl[] subChildren =
createChildrenNodes(currentJavadocNode, currentParseTreeNodeChild);
currentJavadocNode.setChildren((DetailNode[]) subChildren);
}
}
示例14: getTerminal
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
public static TerminalNode getTerminal(ParseTree t, FusionTablesSqlParser parser) {
Check.isTrue(t.getChildCount() == 1);
ParseTree c = t.getChild(0);
TerminalNode result = null;
if (c != null){
Check.isTrue(c instanceof TerminalNode);
result = (TerminalNode) c;
}
return result;
}
示例15: getSqlStatementType
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
public static StatementType getSqlStatementType(ParseTree t, FusionTablesSqlParser parser) {
StatementType result = StatementType.UNKNOWN;
if (t instanceof RuleContext && t.getChildCount() > 0 && t.getChild(0) instanceof RuleContext) {
ParseTree c = t.getChild(0);
RuleContext r = (RuleContext) c;
result = getSqlStatementType((parser.getRuleNames()[r.getRuleIndex()]));
}
return result;
}