本文整理汇总了Java中org.antlr.v4.runtime.RuleContext.getRuleIndex方法的典型用法代码示例。如果您正苦于以下问题:Java RuleContext.getRuleIndex方法的具体用法?Java RuleContext.getRuleIndex怎么用?Java RuleContext.getRuleIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.v4.runtime.RuleContext
的用法示例。
在下文中一共展示了RuleContext.getRuleIndex方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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());
}
示例3: enterBeq_beq
import org.antlr.v4.runtime.RuleContext; //导入方法依赖的package包/类
@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);
}
}
示例4: enterD_recv_buf
import org.antlr.v4.runtime.RuleContext; //导入方法依赖的package包/类
@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);
}
}
示例5: enterD_send_buf
import org.antlr.v4.runtime.RuleContext; //导入方法依赖的package包/类
@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);
}
}
示例6: exitTypeLiteral
import org.antlr.v4.runtime.RuleContext; //导入方法依赖的package包/类
@Override
@RuleDependencies({
@RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_typeLiteral, version=0, dependents=Dependents.PARENTS),
@RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_arrayType, version=0, dependents=Dependents.SELF),
@RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_structType, version=0, dependents=Dependents.SELF),
@RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_pointerType, version=0, dependents=Dependents.SELF),
@RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_functionType, version=0, dependents=Dependents.SELF),
@RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_interfaceType, version=0, dependents=Dependents.SELF),
@RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_sliceType, version=0, dependents=Dependents.SELF),
@RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_mapType, version=0, dependents=Dependents.SELF),
@RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_channelType, version=0, dependents=Dependents.SELF),
})
public void exitTypeLiteral(TypeLiteralContext ctx) {
@NonNull
TypeModelImpl result = _unknownType;
if (ctx.getChildCount() > 0) {
ParseTree child = ctx.getChild(0);
if (child instanceof RuleNode) {
RuleContext ruleContext = ((RuleNode)child).getRuleContext();
switch (ruleContext.getRuleIndex()) {
case GoParser.RULE_arrayType:
case GoParser.RULE_structType:
case GoParser.RULE_pointerType:
case GoParser.RULE_functionType:
case GoParser.RULE_interfaceType:
case GoParser.RULE_sliceType:
case GoParser.RULE_mapType:
case GoParser.RULE_channelType:
result = popTypeModel((ParserRuleContext)ruleContext);
break;
default:
break;
}
}
}
_typeModelStack.push(result);
}
示例7: enterAl_load_balance
import org.antlr.v4.runtime.RuleContext; //导入方法依赖的package包/类
@Override
public void enterAl_load_balance(tnsnamesParser.Al_load_balanceContext ctx)
{
// Who is my parent? We need this to prevent errors when, for example,
// an ADDRESS_LIST FAIL_OVER parameter is flagged as redefining a parent
// DESCRIPTION FAIL_OVER parameter, which is not actually the case.
RuleContext parentCtx = ctx.getParent();
// We get the rule name, from the grammar, for the parent of this
// rule. In lower case as we are dealing with parser rules.
String parentRule = this.ruleNames[parentCtx.getRuleIndex()];
// Check for redefinitions, DESCRIPTION_LIST.
if (parentRule == "dl_parameter")
{
checkForRedefinition("LOAD_BALANCE", firstDL_LoadBalanceLine, this.lineNumber);
}
// Check for redefinitions, DESCRIPTION.
if (parentRule == "d_parameter")
{
checkForRedefinition("LOAD_BALANCE", firstLoadBalanceLine, this.lineNumber);
}
// Check for redefinitions, ADDRESS_LIST.
if (parentRule == "al_parameter")
{
checkForRedefinition("LOAD_BALANCE", firstAL_LoadBalanceLine, this.lineNumber);
}
}
示例8: enterAl_failover
import org.antlr.v4.runtime.RuleContext; //导入方法依赖的package包/类
@Override
public void enterAl_failover(tnsnamesParser.Al_failoverContext ctx)
{
// Who is my parent? We need this top prevent errors when, for example,
// an ADDRESS_LIST FAIL_OVER parameter is flagged as redefining a parent
// DESCRIPTION FAIL_OVER parameter, which is not actually the case.
RuleContext parentCtx = ctx.getParent();
// We get the rule name, from the grammar, for the parent of this
// rule. In lower case as we are dealing with parser rules.
String parentRule = this.ruleNames[parentCtx.getRuleIndex()];
// Check for redefinitions, DESCRIPTION_LIST.
if (parentRule == "dl_parameter")
{
checkForRedefinition("FAILOVER", firstDL_FailOverLine, this.lineNumber);
}
// Check for redefinitions, DESCRIPTION.
if (parentRule == "d_parameter")
{
checkForRedefinition("FAILOVER", firstFailOverLine, this.lineNumber);
}
// Check for redefinitions, ADDRESS_LIST.
if (parentRule == "al_parameter")
{
checkForRedefinition("FAILOVER", firstAL_FailOverLine, this.lineNumber);
}
}
示例9: enterAl_source_route
import org.antlr.v4.runtime.RuleContext; //导入方法依赖的package包/类
@Override
public void enterAl_source_route(tnsnamesParser.Al_source_routeContext ctx)
{
// Who is my parent?
RuleContext parentCtx = ctx.getParent();
// We get the rule name, from the grammar, for the parent of this
// rule. In lower case as we are dealing with parser rules.
String parentRule = this.ruleNames[parentCtx.getRuleIndex()];
// Check for redefinitions, DESCRIPTION_LIST.
if (parentRule == "dl_parameter")
{
checkForRedefinition("SOURCE_ROUTE", firstDL_SourceRouteLine, this.lineNumber);
}
// Check for redefinitions, DESCRIPTION.
if (parentRule == "d_parameter")
{
checkForRedefinition("SOURCE_ROUTE", firstSourceRouteLine, this.lineNumber);
}
// Check for redefinitions, ADDRESS_LIST.
if (parentRule == "al_parameter")
{
checkForRedefinition("SOURCE_ROUTE", firstAL_SourceRouteLine, this.lineNumber);
}
}
示例10: getRuleName
import org.antlr.v4.runtime.RuleContext; //导入方法依赖的package包/类
public static String getRuleName(ParseTree ruleContext, FusionTablesSqlParser parser) {
Check.isTrue((ruleContext instanceof RuleContext));
RuleContext r = (RuleContext) ruleContext;
return parser.getRuleNames()[r.getRuleIndex()];
}
示例11: analyzeKeywords
import org.antlr.v4.runtime.RuleContext; //导入方法依赖的package包/类
@RuleDependencies({
@RuleDependency(recognizer=GrammarParser.class, rule=GrammarParser.RULE_lexerCommandName, version=0, dependents=Dependents.SELF),
@RuleDependency(recognizer=GrammarParser.class, rule=GrammarParser.RULE_id, version=6, dependents=Dependents.PARENTS),
})
private void analyzeKeywords(Map<RuleContext, CaretReachedException> parseTrees, Map<String, CompletionItem> intermediateResults) {
boolean maybeLexerCommand = false;
IntervalSet remainingKeywords = new IntervalSet(KeywordCompletionItem.KEYWORD_TYPES);
for (Map.Entry<RuleContext, CaretReachedException> entry : parseTrees.entrySet()) {
CaretReachedException caretReachedException = entry.getValue();
if (caretReachedException == null || caretReachedException.getTransitions() == null) {
continue;
}
RuleContext finalContext = caretReachedException.getFinalContext();
if (finalContext.getRuleIndex() == GrammarParser.RULE_id) {
RuleContext parent = finalContext.getParent();
if (parent != null && parent.getRuleIndex() == GrammarParser.RULE_lexerCommandName) {
maybeLexerCommand = true;
}
continue;
}
Map<ATNConfig, List<Transition>> transitions = caretReachedException.getTransitions();
for (List<Transition> transitionList : transitions.values()) {
for (Transition transition : transitionList) {
if (transition.isEpsilon() || transition instanceof WildcardTransition || transition instanceof NotSetTransition) {
continue;
}
IntervalSet label = transition.label();
if (label == null) {
continue;
}
for (int keyword : remainingKeywords.toArray()) {
if (label.contains(keyword)) {
remainingKeywords.remove(keyword);
KeywordCompletionItem item = KeywordCompletionItem.KEYWORD_ITEMS.get(keyword);
intermediateResults.put(item.getInsertPrefix().toString(), item);
}
}
}
}
}
if (maybeLexerCommand) {
addLexerCommands(intermediateResults);
}
}
示例12: ParseTreeNode
import org.antlr.v4.runtime.RuleContext; //导入方法依赖的package包/类
public ParseTreeNode(@NonNull ParseTree tree, @NullAllowed List<String> ruleNames) {
super(Children.LEAF);
_tree = tree;
_ruleNames = ruleNames;
if (tree.getChildCount() > 0) {
setChildren(Children.createLazy(new ChildrenOfParseTreeNodeCreator()));
}
if (tree instanceof RuleNode) {
RuleNode ruleNode = (RuleNode)tree;
RuleContext ruleContext = ruleNode.getRuleContext();
if (ruleContext instanceof ParserRuleContext && ruleContext.getClass() != ParserRuleContext.class && ruleContext.getClass() != InterpreterRuleContext.class) {
String contextName = ruleContext.getClass().getSimpleName();
if (!"Context".equals(contextName) && contextName.endsWith("Context")) {
contextName = contextName.substring(0, contextName.length() - "Context".length());
}
contextName = Character.toLowerCase(contextName.charAt(0)) + contextName.substring(1);
setDisplayName(contextName);
} else {
String displayName = null;
if (ruleNames != null && ruleContext.getRuleIndex() >= 0 && ruleContext.getRuleIndex() < ruleNames.size()) {
displayName = ruleNames.get(ruleContext.getRuleIndex());
}
if (displayName == null || displayName.isEmpty()) {
displayName = "Rule Node";
}
setDisplayName(displayName);
}
} else if (tree instanceof ErrorNode) {
setDisplayName("Error Node");
} else if (tree instanceof TerminalNode) {
String nodeText = tree.getText();
if (nodeText != null && !nodeText.isEmpty()) {
nodeText = nodeText.substring(0, Math.min(nodeText.length(), 100));
nodeText = nodeText.replace("\\", "\\\\");
nodeText = nodeText.replace("\r", "\\r");
nodeText = nodeText.replace("\n", "\\n");
nodeText = nodeText.replace("\t", "\\t");
nodeText = nodeText.replace("'", "\\'");
setDisplayName("'" + nodeText + "'");
} else {
setDisplayName("Terminal Node");
}
}
}