本文整理匯總了Java中org.antlr.v4.runtime.RuleContext類的典型用法代碼示例。如果您正苦於以下問題:Java RuleContext類的具體用法?Java RuleContext怎麽用?Java RuleContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RuleContext類屬於org.antlr.v4.runtime包,在下文中一共展示了RuleContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: action
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
@Override
public void action(RuleContext _localctx, int ruleIndex, int actionIndex) {
switch (ruleIndex) {
case 6:
MINUS_action((RuleContext) _localctx, actionIndex);
break;
case 7:
SLASH_action((RuleContext) _localctx, actionIndex);
break;
case 8:
LPAR_action((RuleContext) _localctx, actionIndex);
break;
case 9:
RPAR_action((RuleContext) _localctx, actionIndex);
break;
case 19:
WS_action((RuleContext) _localctx, actionIndex);
break;
}
}
示例2: underAbs
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
/**
* En partant d'une noeud permet de déterminer si il est dans l'expression d'une abstraction ou non.
*
* @param ctx Le noeud courant
* @return Retourne vrai si le noeud est sous une abstraction et faux dans l'autre cas.
*/
private boolean underAbs(RuleContext ctx) {
RuleContext parent = ctx.parent;
if (parent == null) {
return false;
}
while (parent.getParent() != null) {
if (parent instanceof LambdaParser.AbstractionContext) {
return true;
}
parent = parent.parent;
}
return false;
}
示例3: createAstBuilder
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
public static AstBuilder createAstBuilder(CompilationUnit source,TokenStream tokens){
KalangParser p = new KalangParser(tokens);
AstBuilder sp = new AstBuilder(source, p);
p.setErrorHandler(new DefaultErrorStrategy() {
@Override
public void reportError(Parser recognizer, RecognitionException e) {
String msg = AntlrErrorString.exceptionString(recognizer, e);
Token end = e.getOffendingToken();
Token start;
RuleContext ctx = e.getCtx();
if(ctx instanceof ParserRuleContext){
start = ((ParserRuleContext) ctx).getStart();
}else{
start = end;
}
sp.getDiagnosisReporter().report(Diagnosis.Kind.ERROR, msg,start,end);
}
});
return sp;
}
示例4: formatMessage
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
@Override
public String formatMessage(SyntaxError error) {
RecognitionException exception = error.getException();
if (exception instanceof InputMismatchException) {
InputMismatchException mismatchException = (InputMismatchException) exception;
RuleContext ctx = mismatchException.getCtx();
int ruleIndex = ctx.getRuleIndex();
switch (ruleIndex) {
case ProtoParser.RULE_ident:
return ProtostuffBundle.message("error.expected.identifier");
default:
break;
}
}
return super.formatMessage(error);
}
示例5: rewriteHaving
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
private static ExprContext rewriteHaving(GeneratorContext ctx, Planner planner, ExprContext expr) {
ExprContext rewritten = new ExprContext(expr.getParent(), expr.invokingState);
for (ParseTree i:expr.children) {
if (i instanceof Expr_functionContext) {
rewritten.addChild(rewriteHaving(ctx, planner, (Expr_functionContext)i));
}
else if (i instanceof ExprContext) {
rewritten.addChild(rewriteHaving(ctx, planner, (ExprContext)i));
}
else if (i instanceof RuleContext) {
rewritten.addChild((RuleContext)i);
}
else if (i instanceof TerminalNode) {
rewritten.addChild((TerminalNode)i);
}
else {
throw new CodingError();
}
}
return rewritten;
}
示例6: getChildContextText
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
/**
* Searches the children of the given context for a context of the given clazz
* type and returns its Text Value. If there are multiple relevant child nodes,
* we will return the text value for one of them at random.
*/
public String getChildContextText(RuleContext ctx) {
if (ctx == null) {
return "";
}
if (ctx instanceof TypeNameContext) {
return ctx.getText();
}
String s = "";
for (int i = 0; i < ctx.getChildCount(); i++) {
if (!(ctx.getChild(i) instanceof TerminalNodeImpl)) {
try {
String t = getChildContextText((RuleContext) ctx.getChild(i));
if (!t.isEmpty()) {
s += t + ",";
}
} catch (Exception e) {
// do nothing
}
}
}
return s.replaceAll(",$", "");
}
示例7: visitPairedTag
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
@Override
public Object visitPairedTag(StpParser.PairedTagContext ctx) {
RuleContext tag = (RuleContext) ctx.getChild(0);
Token firstOTag = searchTokenFromHead(tag, SilverstripeTokenId.OTAG);
Token firstCTag = searchTokenFromHead(tag, SilverstripeTokenId.CTAG);
Token secondOTag = searchTokenFromTail(tag, SilverstripeTokenId.OTAG);
Token secondCTag = searchTokenFromTail(tag, SilverstripeTokenId.CTAG);
boolean offsetMatched = (position >= firstOTag.getStartIndex() && position <= firstCTag.getStopIndex()) ||
(position >= secondOTag.getStartIndex() && position <= secondCTag.getStopIndex());
if(offsetMatched) {
matchedRegions.add(firstOTag.getStartIndex());
matchedRegions.add(firstCTag.getStopIndex()+1);
matchedRegions.add(secondOTag.getStartIndex());
matchedRegions.add(secondCTag.getStopIndex()+1);
}
return super.visitPairedTag(ctx);
}
示例8: translateToAssertionsPushCalls
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
private String translateToAssertionsPushCalls(SingleExpressionContext assertionStatementLeftHandSide, RuleContext ctx) {
String translatedText = ctx.getText();
String xpath = "//singleExpression";
ParseTree parseTree = (ParseTree) ctx;
translatedText = translateAssertionFunctionShortcuts(ctx, false);
ParseTreePattern assertionExpressionPattern = this.parser.compileParseTreePattern(
"<assertionOperator> <singleExpression>",
HL7MappingValidatorParser.RULE_singleExpression);
List<ParseTreeMatch> assertionExpressionMatches = assertionExpressionPattern.findAll(parseTree, xpath);
for (ParseTreeMatch match : assertionExpressionMatches) {
AssertionOperatorContext operator = (AssertionOperatorContext) match.get("assertionOperator");
SingleExpressionContext assertionStatementRightHandSide = (SingleExpressionContext) match.get("singleExpression");
String translatedFunctionCall = translateToAssertionsPushCall(assertionStatementLeftHandSide, operator, assertionStatementRightHandSide);
String matchTextTranslated = translateAssertionFunctionShortcuts((RuleContext) match.getTree(), false);
translatedText = translatedText.replace(matchTextTranslated, translatedFunctionCall);
}
return translatedText;
}
示例9: findProperMethodScopeAround
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
private <ExprType> Declaration findProperMethodScopeAround(final ExprType ctxExpr, final RuleContext ctxParent, final Token ctxGetStart) {
Declaration retval = null;
RuleContext executionContext = ctxParent;
while ((executionContext instanceof ProgramContext) == false) {
if (executionContext instanceof Method_declContext) {
final Method_declContext mdeclContext = (Method_declContext)executionContext;
final Method_decl_hookContext hookContext = mdeclContext.method_decl_hook();
final Method_signatureContext signatureCtx = hookContext.method_signature();
final String methodName = signatureCtx.method_name().getText();
final MethodDeclaration methodDecl = currentScope_.lookupMethodDeclarationRecursive(methodName, null, true);
retval = methodDecl;
break;
} else if (executionContext instanceof Role_bodyContext) {
break;
} else if (executionContext instanceof Role_declContext) {
break;
} else if (executionContext instanceof Class_bodyContext) {
break;
} else if (executionContext instanceof Type_declarationContext) {
break;
}
executionContext = executionContext.parent;
}
return retval;
}
示例10: visitModeSpec
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
@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());
}
示例11: getTopContext
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
public static RuleContext getTopContext(Parser parser, RuleContext context, IntervalSet values, boolean checkTop) {
if (checkTop && context instanceof ParserRuleContext) {
if (values.contains(context.getRuleIndex())) {
return context;
}
}
if (context.isEmpty()) {
return null;
}
if (values.contains(parser.getATN().states.get(context.invokingState).ruleIndex)) {
return context.parent;
}
return getTopContext(parser, context.parent, values, false);
}
示例12: getParseTrees
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
@Override
public Map<RuleContext, CaretReachedException> getParseTrees(TParser parser) {
List<MultipleDecisionData> potentialAlternatives = new ArrayList<>();
IntegerList currentPath = new IntegerList();
Map<RuleContext, CaretReachedException> results = new IdentityHashMap<>();
// make sure the token stream is initialized before getting the index
parser.getInputStream().LA(1);
int initialToken = parser.getInputStream().index();
while (true) {
parser.getInputStream().seek(initialToken);
tryParse(parser, potentialAlternatives, currentPath, results);
if (!incrementCurrentPath(potentialAlternatives, currentPath)) {
break;
}
}
LOGGER.log(Level.FINE, "Forest parser constructed {0} parse trees.", results.size());
if (LOGGER.isLoggable(Level.FINEST)) {
for (Map.Entry<RuleContext, CaretReachedException> entry : results.entrySet()) {
LOGGER.log(Level.FINEST, entry.getKey().toStringTree(parser instanceof Parser ? (Parser)parser : null));
}
}
return results;
}
示例13: getSourceInterval
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
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;
}
}
示例14: getStartSymbol
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
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;
}
示例15: findAncestor
import org.antlr.v4.runtime.RuleContext; //導入依賴的package包/類
@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;
}