@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;
}
}
java类org.antlr.v4.runtime.RuleContext的实例源码
FWPolicyLexer.java 文件源码
项目:oscm-app
阅读 21
收藏 0
点赞 0
评论 0
FWPolicyLexer.java 文件源码
项目:oscm
阅读 22
收藏 0
点赞 0
评论 0
@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;
}
}
ReduceVisitor.java 文件源码
项目:Lambda-Interpreter
阅读 16
收藏 0
点赞 0
评论 0
/**
* 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;
}
AstBuilderFactory.java 文件源码
项目:kalang
阅读 15
收藏 0
点赞 0
评论 0
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;
}
ProtoParserDefinition.java 文件源码
项目:protobuf-jetbrains-plugin
阅读 18
收藏 0
点赞 0
评论 0
@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);
}
Select_or_valuesGenerator.java 文件源码
项目:antsdb
阅读 21
收藏 0
点赞 0
评论 0
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;
}
Select_or_valuesGenerator.java 文件源码
项目:antsdb
阅读 20
收藏 0
点赞 0
评论 0
private static RuleContext rewriteHaving(GeneratorContext ctx, Planner planner, Expr_functionContext rule) {
String funcname = rule.function_name().getText().toLowerCase();
if (_aggregates.contains(funcname)) {
OutputField field = findExisting(ctx, planner, rule);
if (field != null) {
return createColumnName_(rule, field);
}
else {
Operator expr = ExprGenerator.gen(ctx, planner, (ExprContext)rule.getParent());
field = planner.addOutputField("*" + planner.getOutputFields().size(), expr);
return createColumnName_(rule, field);
}
}
else {
return rule;
}
}
GoLangTreeListener.java 文件源码
项目:clarpse
阅读 14
收藏 0
点赞 0
评论 0
/**
* 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(",$", "");
}
FWPolicyLexer.java 文件源码
项目:development
阅读 23
收藏 0
点赞 0
评论 0
@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;
}
}
BraceMatchingVisitor.java 文件源码
项目:stpnb
阅读 16
收藏 0
点赞 0
评论 0
@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);
}
JavascriptCodeGenerator.java 文件源码
项目:hl7-mapping-validator
阅读 20
收藏 0
点赞 0
评论 0
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;
}
Pass3Listener.java 文件源码
项目:trygve
阅读 14
收藏 0
点赞 0
评论 0
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;
}
GrammarIndentTask.java 文件源码
项目:goworks
阅读 19
收藏 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());
}
GoCompletionQuery.java 文件源码
项目:goworks
阅读 17
收藏 0
点赞 0
评论 0
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);
}
AbstractForestParser.java 文件源码
项目:goworks
阅读 23
收藏 0
点赞 0
评论 0
@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;
}
ParseTrees.java 文件源码
项目:goworks
阅读 22
收藏 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
阅读 30
收藏 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
阅读 27
收藏 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;
}
tnsnamesInterfaceListener.java 文件源码
项目:Tnsnames_checker
阅读 17
收藏 0
点赞 0
评论 0
@Override
public void enterBeq_beq(tnsnamesParser.Beq_beqContext ctx)
{
RuleContext parentCtx = ctx.getParent();
String parentRule = this.ruleNames[parentCtx.getRuleIndex()];
// Check for redefinitions. BEQ.
if (parentRule == "beq_parameter")
{
checkForRedefinition("PROTOCOL", firstBEQ_ProtocolLine, this.lineNumber);
}
// Check for redefinitions. ARGS.
if (parentRule == "bad_address")
{
checkForRedefinition("PROTOCOL", firstBAD_ProtocolLine, this.lineNumber);
}
}
tnsnamesInterfaceListener.java 文件源码
项目:Tnsnames_checker
阅读 24
收藏 0
点赞 0
评论 0
@Override
public void enterD_recv_buf(tnsnamesParser.D_recv_bufContext ctx)
{
// Who is my parent rule?
RuleContext parentCtx = ctx.getParent();
String parentRule = this.ruleNames[parentCtx.getRuleIndex()];
// Check for redefinitions, DESCRIPTION.
if (parentRule == "d_parameter")
{
checkForRedefinition("RECV_BUF_SIZE", firstRecvBufLine, this.lineNumber);
}
// Check for redefinitions, DESCRIPTION.
if (parentRule == "a_parameter")
{
checkForRedefinition("RECV_BUF_SIZE", firstA_RecvBufLine, this.lineNumber);
}
}
tnsnamesInterfaceListener.java 文件源码
项目:Tnsnames_checker
阅读 17
收藏 0
点赞 0
评论 0
@Override
public void enterD_send_buf(tnsnamesParser.D_send_bufContext ctx)
{
// Who is my parent rule?
RuleContext parentCtx = ctx.getParent();
String parentRule = this.ruleNames[parentCtx.getRuleIndex()];
// Check for redefinitions, DESCRIPTION.
if (parentRule == "d_parameter")
{
checkForRedefinition("SEND_BUF_SIZE", firstSendBufLine, this.lineNumber);
}
// Check for redefinitions, DESCRIPTION.
if (parentRule == "a_parameter")
{
checkForRedefinition("SEND_BUF_SIZE", firstA_SendBufLine, this.lineNumber);
}
}
ParserATNSimulator.java 文件源码
项目:Scratch-ApuC
阅读 25
收藏 0
点赞 0
评论 0
@NotNull
protected ATNConfigSet computeStartState(@NotNull ATNState p,
@Nullable RuleContext ctx,
boolean fullCtx)
{
// always at least the implicit call to start rule
PredictionContext initialContext = PredictionContext.fromRuleContext(atn, ctx);
ATNConfigSet configs = new ATNConfigSet(fullCtx);
for (int i=0; i<p.getNumberOfTransitions(); i++) {
ATNState target = p.transition(i).target;
ATNConfig c = new ATNConfig(target, i+1, initialContext);
Set<ATNConfig> closureBusy = new HashSet<ATNConfig>();
closure(c, configs, closureBusy, true, fullCtx, false);
}
return configs;
}
GrammarIndentTask.java 文件源码
项目:antlrworks2
阅读 26
收藏 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());
}
AbstractForestParser.java 文件源码
项目:antlrworks2
阅读 23
收藏 0
点赞 0
评论 0
@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;
}
ParseTrees.java 文件源码
项目:antlrworks2
阅读 25
收藏 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 文件源码
项目:antlrworks2
阅读 23
收藏 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 文件源码
项目:antlrworks2
阅读 25
收藏 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;
}
FWPolicyLexer.java 文件源码
项目:oscm-app
阅读 23
收藏 0
点赞 0
评论 0
private void RPAR_action(RuleContext _localctx, int actionIndex) {
switch (actionIndex) {
case 3:
_channel = HIDDEN;
break;
}
}
FWPolicyLexer.java 文件源码
项目:oscm-app
阅读 22
收藏 0
点赞 0
评论 0
private void WS_action(RuleContext _localctx, int actionIndex) {
switch (actionIndex) {
case 4:
_channel = HIDDEN;
break;
}
}
FWPolicyLexer.java 文件源码
项目:oscm-app
阅读 23
收藏 0
点赞 0
评论 0
private void SLASH_action(RuleContext _localctx, int actionIndex) {
switch (actionIndex) {
case 1:
_channel = HIDDEN;
break;
}
}