当前位置: 首页>>代码示例>>Java>>正文


Java RuleContext类代码示例

本文整理汇总了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;
    }
}
 
开发者ID:servicecatalog,项目名称:oscm-app,代码行数:25,代码来源:FWPolicyLexer.java

示例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;
}
 
开发者ID:Tirke,项目名称:Lambda-Interpreter,代码行数:22,代码来源:ReduceVisitor.java

示例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;
}
 
开发者ID:kasonyang,项目名称:kalang,代码行数:22,代码来源:AstBuilderFactory.java

示例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);
}
 
开发者ID:protostuff,项目名称:protobuf-jetbrains-plugin,代码行数:17,代码来源:ProtoParserDefinition.java

示例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;
}
 
开发者ID:waterguo,项目名称:antsdb,代码行数:22,代码来源:Select_or_valuesGenerator.java

示例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(",$", "");
}
 
开发者ID:Zir0-93,项目名称:clarpse,代码行数:30,代码来源:GoLangTreeListener.java

示例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);
}
 
开发者ID:jdemeschew,项目名称:stpnb,代码行数:18,代码来源:BraceMatchingVisitor.java

示例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;
}
 
开发者ID:marcotabago,项目名称:hl7-mapping-validator,代码行数:22,代码来源:JavascriptCodeGenerator.java

示例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;
}
 
开发者ID:jcoplien,项目名称:trygve,代码行数:26,代码来源:Pass3Listener.java

示例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());
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:22,代码来源:GrammarIndentTask.java

示例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);
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:18,代码来源:GoCompletionQuery.java

示例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;
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:27,代码来源:AbstractForestParser.java

示例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;
    }
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:26,代码来源:ParseTrees.java

示例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;
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:18,代码来源:ParseTrees.java

示例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;
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:17,代码来源:ParseTrees.java


注:本文中的org.antlr.v4.runtime.RuleContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。