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);
}
}
}
java类org.antlr.v4.runtime.tree.RuleNode的实例源码
ParseTreeNavigator.java 文件源码
项目:kalang
阅读 21
收藏 0
点赞 0
评论 0
NodeUsesProvider.java 文件源码
项目:sonar-tsql-plugin
阅读 17
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
@Override
public Object visitChildren(final RuleNode node) {
final int n = node.getChildCount();
for (int i = 0; i < n; i++) {
final ParseTree c = node.getChild(i);
c.accept(this);
}
final String textToFind = node.getText();
if (StringUtils.containsIgnoreCase(textToFind, tempText)
|| StringUtils.containsIgnoreCase(tempText, textToFind)) {
nodes.add(new ParsedNode(node));
}
return null;
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 23
收藏 0
点赞 0
评论 0
protected void interpretVariable(ParseTree tree) {
String varName = null;
Set<PQLTask> varValue = null;
for (int i = 0; i < tree.getChildCount(); i++) {
ParseTree child = tree.getChild(i);
if(child instanceof RuleNode) {
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
switch (ruleIndex) {
case PQLParser.RULE_varName:
varName = interpretName(child);
break;
case PQLParser.RULE_setOfTasks:
varValue = interpretSetOfTasks(child);
break;
}
}
}
this.variables.put(varName,varValue);
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 25
收藏 0
点赞 0
评论 0
protected void interpretAttribute(ParseTree tree) {
ParseTree child = tree.getChild(0);
if (child instanceof RuleNode) {
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
switch (ruleIndex) {
case PQLParser.RULE_universe :
this.attributes.add(new PQLAttribute());
break;
case PQLParser.RULE_attributeName :
this.attributes.add(new PQLAttribute(this.interpretString(child)));
break;
}
}
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 27
收藏 0
点赞 0
评论 0
protected void interpretLocation(ParseTree tree) {
ParseTree child = tree.getChild(0);
if (child instanceof RuleNode) {
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
switch (ruleIndex) {
case PQLParser.RULE_universe :
this.locations.add(new PQLLocation());
break;
case PQLParser.RULE_locationPath :
this.locations.add(new PQLLocation(this.interpretString(child)));
break;
}
}
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 25
收藏 0
点赞 0
评论 0
protected boolean interpretPredicate(ParseTree tree) {
if (tree==null) return true; // WHERE clause is not specified for this query!
boolean result = false;
ParseTree child = tree.getChild(0);
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
switch (ruleIndex) {
case PQLParser.RULE_proposition:
result = interpretProposition(child);
break;
case PQLParser.RULE_conjunction:
result = interpretConjunction(child);
break;
case PQLParser.RULE_disjunction:
result = interpretDisjunction(child);
break;
case PQLParser.RULE_logicalTest:
result = interpretLogicalTest(child);
break;
}
return result;
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 22
收藏 0
点赞 0
评论 0
protected boolean interpretSetComparison(ParseTree tree) {
Set<PQLTask> A = interpretSetOfTasks(tree.getChild(0));
Set<PQLTask> B = interpretSetOfTasks(tree.getChild(2));
ParseTree child = tree.getChild(1).getChild(0);
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
switch (ruleIndex) {
case PQLParser.RULE_identical:
return A.equals(B) ? true : false;
case PQLParser.RULE_different:
return A.equals(B) ? false : true;
case PQLParser.RULE_overlapsWith:
for (PQLTask task : A)
if (B.contains(task)) return true;
return false;
case PQLParser.RULE_subsetOf:
return B.containsAll(A) ? true : false;
case PQLParser.RULE_properSubsetOf:
return B.containsAll(A) && !A.equals(B) ? true : false;
}
return false;
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 36
收藏 0
点赞 0
评论 0
protected PQLTask interpretTask(ParseTree tree) {
String label = "";
double similarity = 1.0;
for (int i = 0; i < tree.getChildCount(); i++) {
ParseTree child = tree.getChild(i);
if (child instanceof RuleNode) {
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
switch (ruleIndex) {
case PQLParser.RULE_approximate:
similarity = labelMngr.getDefaultLabelSimilarityThreshold();
break;
case PQLParser.RULE_label:
label = this.interpretLabel(child);
break;
case PQLParser.RULE_similarity:
similarity = this.interpretSimilarity(child);
break;
}
}
}
return new PQLTask(label, similarity);
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 20
收藏 0
点赞 0
评论 0
protected PQLTrace interpretInsertTrace(ParseTree tree) {
PQLTrace trace = new PQLTrace();
for (int i = 0; i < tree.getChildCount(); i++) {
ParseTree child = tree.getChild(i).getChild(0); //getting a task or '*'
if(child instanceof RuleNode) {
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
if (ruleIndex == PQLParser.RULE_task) { //is task
trace.addTask(this.interpretTask(child));
}
else { // is '*'
trace.addTask(this.interpretTraceUniverse());
trace.setHasAsterisk(true);
}
}
}
return trace;
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 26
收藏 0
点赞 0
评论 0
protected boolean interpretParentheses(ParseTree tree) {
ParseTree child = tree.getChild(1);
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
switch (ruleIndex) {
case PQLParser.RULE_proposition:
return interpretProposition(child);
case PQLParser.RULE_conjunction:
return interpretConjunction(child);
case PQLParser.RULE_disjunction:
return interpretDisjunction(child);
case PQLParser.RULE_logicalTest:
return interpretLogicalTest(child);
}
return false;
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 37
收藏 0
点赞 0
评论 0
protected boolean interpretLogicalTest(ParseTree tree) {
ParseTree child = tree.getChild(0);
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
switch (ruleIndex) {
case PQLParser.RULE_isTrue:
return interpretLogicalTest(child,true,true);
case PQLParser.RULE_isNotTrue:
return interpretLogicalTest(child,false,true);
case PQLParser.RULE_isFalse:
return interpretLogicalTest(child,true,false);
case PQLParser.RULE_isNotFalse:
return interpretLogicalTest(child,false,false);
}
return false;
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 25
收藏 0
点赞 0
评论 0
protected Set<PQLTask> interpretSetOfTasks(ParseTree tree) {
ParseTree child = tree.getChild(0);
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
switch (ruleIndex) {
case PQLParser.RULE_tasks:
return interpretTasks(child);
case PQLParser.RULE_union:
return interpretUnion(child);
case PQLParser.RULE_difference:
return interpretDifference(child);
case PQLParser.RULE_intersection:
return interpretIntersection(child);
}
return new HashSet<PQLTask>();
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 23
收藏 0
点赞 0
评论 0
protected Set<PQLTask> interpretTasks(ParseTree tree) {
ParseTree child = tree.getChild(0);
if (child instanceof RuleNode) {
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
switch (ruleIndex) {
case PQLParser.RULE_varName:
return this.interpretVarNameSetOfTasks(child);
case PQLParser.RULE_setOfAllTasks:
return this.interpretSetOfAllTasks(child);
case PQLParser.RULE_setOfTasksLiteral:
return interpretSetOfTasksLiteral(child);
case PQLParser.RULE_setOfTasksConstruction:
return interpretSetOfTasksConstruction(child);
case PQLParser.RULE_setOfTasksParentheses:
return interpretSetOfTasksParentheses(child);
}
}
return new HashSet<PQLTask>();
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 32
收藏 0
点赞 0
评论 0
protected Set<PQLTask> interpretSetOfTasksConstruction(ParseTree tree) {
ParseTree child = tree.getChild(0);
if (child instanceof RuleNode) {
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
switch (ruleIndex) {
case PQLParser.RULE_unaryPredicateConstruction:
return interpretUnaryPredicateConstruction(child);
case PQLParser.RULE_binaryPredicateConstruction:
return interpretBinaryPredicateConstruction(child);
}
}
return new HashSet<PQLTask>();
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 21
收藏 0
点赞 0
评论 0
protected Set<PQLTask> interpretSetOfTasksLiteral(ParseTree tree) {
Set<PQLTask> result = new HashSet<PQLTask>();
for (int i = 0; i < tree.getChildCount(); i++) {
ParseTree child = tree.getChild(i);
if(child instanceof RuleNode) {
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
if (ruleIndex == PQLParser.RULE_task) {
result.add(this.interpretTask(child));
}
}
}
return result;
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 30
收藏 0
点赞 0
评论 0
protected Set<PQLTask> interpretUnion(ParseTree tree) {
Set<PQLTask> result = new HashSet<PQLTask>();
for (int i = 0; i < tree.getChildCount(); i++) {
ParseTree child = tree.getChild(i);
if(child instanceof RuleNode) {
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
switch (ruleIndex) {
case PQLParser.RULE_tasks:
result.addAll(interpretTasks(child));
break;
case PQLParser.RULE_difference:
result.addAll(interpretDifference(child));
break;
case PQLParser.RULE_intersection:
result.addAll(interpretIntersection(child));
break;
}
}
}
return result;
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 21
收藏 0
点赞 0
评论 0
protected Set<PQLTask> interpretIntersection(ParseTree tree) {
Set<PQLTask> result = null;
for (int i = 0; i < tree.getChildCount(); i++) {
ParseTree child = tree.getChild(i);
if(child instanceof RuleNode) {
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
switch (ruleIndex) {
case PQLParser.RULE_tasks:
if (result==null) result = this.interpretTasks(child);
else result.retainAll(this.interpretTasks(child));
break;
case PQLParser.RULE_difference:
if (result==null) result = this.interpretDifference(child);
else result.retainAll(this.interpretDifference(child));
break;
}
}
}
return result;
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 28
收藏 0
点赞 0
评论 0
protected Set<PQLTask> interpretDifference(ParseTree tree) {
ParseTree child = tree.getChild(2);
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
Set<PQLTask> set1 = this.interpretTasks(tree.getChild(0));
Set<PQLTask> set2 = new HashSet<PQLTask>();
switch (ruleIndex) {
case PQLParser.RULE_tasks:
set2 = interpretTasks(child);
break;
case PQLParser.RULE_difference:
set2 = interpretDifference(child);
break;
}
set1.removeAll(set2);
return set1;
}
AbstractPQLQuery.java 文件源码
项目:PQL
阅读 19
收藏 0
点赞 0
评论 0
protected boolean interpretDisjunction(ParseTree tree) {
boolean result = false;
for (int i = 0; i < tree.getChildCount(); i++) {
ParseTree child = tree.getChild(i);
if(child instanceof RuleNode) {
int ruleIndex = ((RuleNode)child).getRuleContext().getRuleIndex();
switch (ruleIndex) {
case PQLParser.RULE_proposition:
result |= interpretProposition(child);
break;
case PQLParser.RULE_logicalTest:
result |= interpretLogicalTest(child);
break;
}
if (result==true) return result;
}
}
return result;
}
TestASTFilterSpecHelper.java 文件源码
项目:esper
阅读 27
收藏 0
点赞 0
评论 0
public void testGetPropertyName() throws Exception {
final String PROPERTY = "a('aa').b[1].c";
// Should parse and result in the exact same property name
Pair<Tree, CommonTokenStream> parsed = SupportParserHelper.parseEventProperty(PROPERTY);
Tree propertyNameExprNode = parsed.getFirst().getChild(0);
ASTUtil.dumpAST(propertyNameExprNode);
String propertyName = ((RuleNode) propertyNameExprNode).getText();
assertEquals(PROPERTY, propertyName);
// Try AST with tokens separated, same property name
parsed = SupportParserHelper.parseEventProperty("a( 'aa' ). b [ 1 ] . c");
propertyNameExprNode = parsed.getFirst().getChild(0);
propertyName = ((RuleNode) propertyNameExprNode).getText();
assertEquals(PROPERTY, propertyName);
}
KleeParseTreeWalker.java 文件源码
项目:green-solver
阅读 27
收藏 0
点赞 0
评论 0
public void walk(ParseTreeListener listener, ParseTree t) {
if ( t instanceof ErrorNode) {
listener.visitErrorNode((ErrorNode)t);
return;
}
else if ( t instanceof TerminalNode) {
listener.visitTerminal((TerminalNode)t);
return;
}
RuleNode r = (RuleNode)t;
enterRule(listener, r);
int n = r.getChildCount();
for (int i = 0; i<n; i++) {
walk(listener, r.getChild(i));
}
exitRule(listener, r);
}
SelectorMatchVisitor.java 文件源码
项目:JavaCSS
阅读 16
收藏 0
点赞 0
评论 0
@Override
public ParseTree visit(ParseTree node) {
ParseTree result = null;
if (!this.match) {
if (matches(node, this.currentSelector)) {
if (this.iterator.hasNext()) {
this.currentSelector = this.iterator.next();
result = super.visit(node);
} else if (focusNode.equals(node)) {
match = true;
}
} else if (node.getChildCount() > 0) {
if (!this.match) {
result = super.visitChildren((RuleNode) node);
}
}
}
return result;
}
StringCreatingVisitor.java 文件源码
项目:Cetus
阅读 19
收藏 0
点赞 0
评论 0
public String visitChildren(RuleNode node) {
int n = node.getChildCount();
if (n > 1) {
StringBuilder result = new StringBuilder();
ParseTree child;
String childResult;
for (int i = 0; i < n; i++) {
child = node.getChild(i);
childResult = child.accept(this);
if (childResult != null) {
if (i > 0) {
result.append(' ');
}
result.append(childResult);
}
}
return result.toString();
} else {
if (n == 1) {
return node.getChild(0).accept(this);
} else {
return node.getText();
}
}
}
TypeStringCreatingVisitor.java 文件源码
项目:Cetus
阅读 20
收藏 0
点赞 0
评论 0
public List<String> visitChildren(RuleNode node) {
List<String> result = defaultResult();
List<String> childResult;
ParseTree child;
int n = node.getChildCount();
for (int i = 0; i < n; i++) {
if (!shouldVisitNextChild(node, result)) {
break;
}
child = node.getChild(i);
childResult = child.accept(this);
if (childResult != null) {
if (result != null) {
result.addAll(childResult);
} else {
result = childResult;
}
}
}
return result;
}
GrammarIndentTask.java 文件源码
项目:goworks
阅读 20
收藏 0
点赞 0
评论 0
@Override
@RuleDependencies({
@RuleDependency(recognizer=GrammarParser.class, rule=GrammarParser.RULE_modeSpec, version=3, dependents=Dependents.PARENTS),
@RuleDependency(recognizer=GrammarParser.class, rule=GrammarParser.RULE_ruleSpec, version=3, dependents=Dependents.PARENTS),
})
public Tuple2<? extends ParseTree, Integer> visitModeSpec(ModeSpecContext ctx) {
// use the preceeding rule (if any), otherwise relative to mode
for (int i = priorSiblings.size() - 2; i >= 0; i--) {
ParseTree sibling = priorSiblings.get(i);
if (!(sibling instanceof RuleNode)) {
continue;
}
RuleContext context = ((RuleNode)sibling).getRuleContext();
if (context.getRuleIndex() == GrammarParser.RULE_ruleSpec) {
return Tuple.create(context, 0);
}
}
return Tuple.create(ctx, getCodeStyle().getIndentSize());
}
ParseTrees.java 文件源码
项目:goworks
阅读 37
收藏 0
点赞 0
评论 0
public static Interval getSourceInterval(@NonNull ParseTree context) {
Parameters.notNull("context", context);
if (context instanceof TerminalNode) {
TerminalNode terminalNode = (TerminalNode)context;
Token token = terminalNode.getSymbol();
return new Interval(token.getStartIndex(), token.getStopIndex());
} else if (context instanceof RuleNode) {
RuleNode ruleNode = (RuleNode)context;
RuleContext ruleContext = ruleNode.getRuleContext();
if (ruleContext instanceof ParserRuleContext) {
return getSourceInterval((ParserRuleContext)ruleContext);
} else {
Token startSymbol = getStartSymbol(context);
Token stopSymbol = getStopSymbol(context);
if (startSymbol == null || stopSymbol == null) {
return Interval.INVALID;
}
return new Interval(startSymbol.getStartIndex(), stopSymbol.getStopIndex());
}
} else {
return Interval.INVALID;
}
}
ParseTrees.java 文件源码
项目:goworks
阅读 21
收藏 0
点赞 0
评论 0
public static Token getStartSymbol(ParseTree context) {
TerminalNode node = getStartNode(context);
if (node != null) {
return node.getSymbol();
}
if (!(context instanceof RuleNode)) {
return null;
}
RuleContext ruleContext = ((RuleNode)context).getRuleContext();
if (ruleContext instanceof ParserRuleContext) {
return ((ParserRuleContext)ruleContext).getStart();
}
return null;
}
ParseTrees.java 文件源码
项目:goworks
阅读 25
收藏 0
点赞 0
评论 0
@CheckForNull
public static RuleNode findAncestor(@NonNull ParseTree tree, @NonNull BitSet ruleIndexes) {
for (ParseTree current = tree; current != null; current = current.getParent()) {
if (!(current instanceof RuleNode)) {
continue;
}
RuleNode ruleNode = (RuleNode)current;
int ruleIndex = ruleNode.getRuleContext().getRuleIndex();
if (ruleIndex < 0) {
continue;
}
if (ruleIndexes.get(ruleIndex)) {
return ruleNode;
}
}
return null;
}
ParseTrees.java 文件源码
项目:goworks
阅读 24
收藏 0
点赞 0
评论 0
@CheckForNull
public static <ContextClass> ContextClass findAncestor(@NonNull ParseTree tree, @NonNull Class<ContextClass> nodeType) {
for (ParseTree current = tree; current != null; current = current.getParent()) {
if (!(current instanceof RuleNode)) {
continue;
}
RuleNode ruleNode = (RuleNode)current;
RuleContext ruleContext = ruleNode.getRuleContext();
if (nodeType.isInstance(ruleContext)) {
return nodeType.cast(ruleContext);
}
}
return null;
}
ParseTreeCommand.java 文件源码
项目:antlr4ide
阅读 20
收藏 0
点赞 0
评论 0
private String getNodeText(@NotNull final Tree t, @Nullable final List<String> ruleNames) {
if (ruleNames != null) {
if (t instanceof RuleNode) {
int ruleIndex = ((RuleNode) t).getRuleContext().getRuleIndex();
String ruleName = ruleNames.get(ruleIndex);
return ruleName;
}
else if (t instanceof ErrorNode) {
return "<" + t.toString() + ">";
}
else if (t instanceof TerminalNode) {
Token symbol = ((TerminalNode) t).getSymbol();
if (symbol != null) {
String s = symbol.getText();
return "'" + s + "'";
}
}
}
// no recog for rule names
Object payload = t.getPayload();
if (payload instanceof Token) {
return ((Token) payload).getText();
}
return t.getPayload().toString();
}