Top Description Inners Fields Constructors Methods
org.antlr.v4.analysis

public Class LeftRecursiveRuleAnalyzer

extends LeftRecursiveRuleWalker
Class Inheritance
Imports
org.antlr.runtime.CommonToken, .Token, .TokenStream, org.antlr.runtime.tree.CommonTreeNodeStream, .Tree, org.antlr.v4.Tool, org.antlr.v4.codegen.CodeGenerator, org.antlr.v4.parse.ANTLRParser, .GrammarASTAdaptor, .LeftRecursiveRuleWalker, org.antlr.v4.runtime.misc.IntervalSet, .Pair, org.antlr.v4.tool.ErrorType, org.antlr.v4.tool.ast.AltAST, .GrammarAST, .GrammarASTWithOptions, .RuleRefAST, org.stringtemplate.v4.ST, .STGroup, .STGroupFile, java.io.FileNotFoundException, java.util.ArrayList, .HashMap, .LinkedHashMap, .List, .Map

Using a tree walker on the rules, determine if a rule is directly left-recursive and if it follows our pattern.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Field Summary

Modifier and TypeField and Description
public Map<Integer, LeftRecursiveRuleAnalyzer.ASSOC>
public LinkedHashMap<Integer, LeftRecursiveRuleAltInfo>
public final STGroup
public final String
public List<Pair<GrammarAST, String>>
leftRecursiveRuleRefLabels

Pointer to ID node of ^(= ID element)

public List<LeftRecursiveRuleAltInfo>
public static final STGroup
public GrammarAST
public String
public LinkedHashMap<Integer, LeftRecursiveRuleAltInfo>
public LinkedHashMap<Integer, LeftRecursiveRuleAltInfo>
public final TokenStream
tokenStream

Tokens from which rule AST comes from

public Tool
Inherited from org.antlr.v4.parse.LeftRecursiveRuleWalker:
ACTIONACTION_CHAR_LITERALACTION_ESCACTION_STRING_LITERALALTARG_ACTIONARG_OR_CHARSETASSIGNATBLOCKCATCHCHANNELSCLOSURECOLONCOLONCOLONCOMBINEDCOMMACOMMENTdfa11dfa14DOC_COMMENTDOLLARDOTELEMENT_OPTIONSEOFEPSILONERRCHARESC_SEQFINALLYFOLLOW_ACTION_in_block1179FOLLOW_ACTION_in_elementOption921FOLLOW_ACTION_in_epsilonElement1038FOLLOW_ACTION_in_epsilonElement1054FOLLOW_ACTION_in_exceptionHandler220FOLLOW_ACTION_in_finallyClause235FOLLOW_ACTION_in_rec_rule156FOLLOW_ALT_in_alternative1199FOLLOW_ALT_in_binary541FOLLOW_ALT_in_nonLeftRecur671FOLLOW_ALT_in_prefix579FOLLOW_ALT_in_suffix630FOLLOW_alternative_in_block1182FOLLOW_ARG_ACTION_in_atom1223FOLLOW_ARG_ACTION_in_exceptionHandler218FOLLOW_ARG_ACTION_in_rec_rule117FOLLOW_ARG_ACTION_in_rec_rule96FOLLOW_ASSIGN_in_element978FOLLOW_ASSIGN_in_elementOption885FOLLOW_ASSIGN_in_elementOption901FOLLOW_ASSIGN_in_elementOption917FOLLOW_ASSIGN_in_elementOption933FOLLOW_ASSIGN_in_recurse693FOLLOW_ASSIGN_in_token740FOLLOW_AT_in_rec_rule152FOLLOW_atom_in_element952FOLLOW_atom_in_element969FOLLOW_atom_in_element971FOLLOW_binary_in_outerAlternative362FOLLOW_binary_in_synpred1_LeftRecursiveRuleWalker348FOLLOW_BLOCK_in_block1177FOLLOW_block_in_ebnf1111FOLLOW_block_in_ebnf1125FOLLOW_block_in_ebnf1141FOLLOW_block_in_ebnf1157FOLLOW_BLOCK_in_ruleBlock290FOLLOW_CATCH_in_exceptionHandler216FOLLOW_CLOSURE_in_ebnf1139FOLLOW_DOT_in_atom1286FOLLOW_ebnf_in_element1022FOLLOW_element_in_alternative1204FOLLOW_element_in_atom1290FOLLOW_element_in_binary548FOLLOW_element_in_element960FOLLOW_element_in_element982FOLLOW_element_in_element993FOLLOW_element_in_nonLeftRecur676FOLLOW_element_in_prefix587FOLLOW_element_in_suffix637FOLLOW_ELEMENT_OPTIONS_in_elementOptions853FOLLOW_elementOption_in_elementOptions855FOLLOW_elementOptions_in_alternative1201FOLLOW_elementOptions_in_atom1226FOLLOW_elementOptions_in_atom1240FOLLOW_elementOptions_in_atom1257FOLLOW_elementOptions_in_atom1274FOLLOW_elementOptions_in_binary543FOLLOW_elementOptions_in_epsilonElement1056FOLLOW_elementOptions_in_epsilonElement1065FOLLOW_elementOptions_in_nonLeftRecur673FOLLOW_elementOptions_in_prefix581FOLLOW_elementOptions_in_setElement1080FOLLOW_elementOptions_in_setElement1089FOLLOW_elementOptions_in_suffix632FOLLOW_elementOptions_in_token794FOLLOW_elementOptions_in_token811FOLLOW_EPSILON_in_epsilonElement1048FOLLOW_epsilonElement_in_binary553FOLLOW_epsilonElement_in_element1027FOLLOW_epsilonElement_in_prefix595FOLLOW_exceptionGroup_in_rec_rule179FOLLOW_exceptionHandler_in_exceptionGroup197FOLLOW_FINALLY_in_finallyClause233FOLLOW_finallyClause_in_exceptionGroup200FOLLOW_ID_in_atom1288FOLLOW_ID_in_element980FOLLOW_ID_in_element991FOLLOW_ID_in_elementOption874FOLLOW_ID_in_elementOption887FOLLOW_ID_in_elementOption889FOLLOW_ID_in_elementOption903FOLLOW_ID_in_elementOption919FOLLOW_ID_in_elementOption935FOLLOW_ID_in_rec_rule154FOLLOW_ID_in_recurse695FOLLOW_ID_in_recurse706FOLLOW_ID_in_token742FOLLOW_ID_in_token757FOLLOW_INT_in_elementOption937FOLLOW_LOCALS_in_rec_rule115FOLLOW_nonLeftRecur_in_outerAlternative515FOLLOW_NOT_in_element958FOLLOW_OPTIONAL_in_ebnf1123FOLLOW_OPTIONS_in_rec_rule135FOLLOW_outerAlternative_in_ruleBlock303FOLLOW_PLUS_ASSIGN_in_element989FOLLOW_PLUS_ASSIGN_in_recurse704FOLLOW_PLUS_ASSIGN_in_token755FOLLOW_POSITIVE_CLOSURE_in_ebnf1155FOLLOW_prefix_in_outerAlternative418FOLLOW_prefix_in_synpred2_LeftRecursiveRuleWalker404FOLLOW_RANGE_in_element967FOLLOW_recurse_in_binary546FOLLOW_recurse_in_binary551FOLLOW_recurse_in_prefix593FOLLOW_recurse_in_suffix635FOLLOW_recurseNoLabel_in_recurse697FOLLOW_recurseNoLabel_in_recurse708FOLLOW_recurseNoLabel_in_recurse714FOLLOW_RETURNS_in_rec_rule92FOLLOW_RULE_in_rec_rule72FOLLOW_RULE_REF_in_atom1221FOLLOW_RULE_REF_in_element1017FOLLOW_RULE_REF_in_rec_rule76FOLLOW_RULE_REF_in_recurseNoLabel726FOLLOW_ruleBlock_in_rec_rule172FOLLOW_ruleModifier_in_rec_rule83FOLLOW_SEMPRED_in_epsilonElement1043FOLLOW_SEMPRED_in_epsilonElement1063FOLLOW_SET_in_element1003FOLLOW_setElement_in_element1005FOLLOW_STRING_LITERAL_in_atom1238FOLLOW_STRING_LITERAL_in_atom1246FOLLOW_STRING_LITERAL_in_elementOption905FOLLOW_STRING_LITERAL_in_setElement1078FOLLOW_STRING_LITERAL_in_setElement1095FOLLOW_STRING_LITERAL_in_token771FOLLOW_STRING_LITERAL_in_token792FOLLOW_suffix_in_outerAlternative474FOLLOW_suffix_in_synpred3_LeftRecursiveRuleWalker460FOLLOW_token_in_token746FOLLOW_token_in_token761FOLLOW_TOKEN_REF_in_atom1255FOLLOW_TOKEN_REF_in_atom1263FOLLOW_TOKEN_REF_in_setElement1087FOLLOW_TOKEN_REF_in_setElement1100FOLLOW_TOKEN_REF_in_token809FOLLOW_TOKEN_REF_in_token823FOLLOW_WILDCARD_in_atom1272FOLLOW_WILDCARD_in_atom1280FRAGMENTGRAMMARGTHEX_DIGITIDIMPORTINTLEXERLEXER_ACTION_CALLLEXER_ALT_ACTIONLEXER_CHAR_SETLOCALSLPARENLTMODENameCharNameStartCharNESTED_ACTIONNLCHARSNOTnumAltsOPTIONALOPTIONSORPARSERPLUSPLUS_ASSIGNPOSITIVE_CLOSUREPOUNDPRIVATEPROTECTEDPUBLICQUESTIONRANGERARROWRBRACERETURNSRPARENRULERULE_REFRULEMODIFIERSRULESSEMISEMPREDSETSRCSTARSTRING_LITERALTHROWSTOKEN_REFtokenNamesTOKENS_SPECUNICODE_ESCUNICODE_EXTENDED_ESCUnicodeBOMWILDCARDWSWSCHARSWSNLCHARS

Constructor Summary

AccessConstructor and Description
public
LeftRecursiveRuleAnalyzer(GrammarAST ruleAST, Tool tool, String ruleName, String language)

Method Summary

Modifier and TypeMethod and Description
public AltAST
public void
public String
public static boolean
hasImmediateRecursiveRuleRefs(GrammarAST t, String ruleName)

Match (RULE RULE_REF (BLOCK (ALT .*) (ALT RULE_REF[self] .*) (ALT .*))) Match (RULE RULE_REF (BLOCK (ALT .*) (ALT (ASSIGN ID RULE_REF[self]) .*) (ALT .*)))

public int
nextPrecedence(int alt)

public void
public int
precedence(int alt)

public void
public void
public void
public void
stripAltLabel(GrammarAST altAST)

Strip last 2 tokens if → label; alter indexes in altAST

public GrammarAST
public void
public String
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from org.antlr.v4.parse.LeftRecursiveRuleWalker:
alternativeatombinaryblockebnfelementelementOptionelementOptionsepsilonElementexceptionGroupexceptionHandlerfinallyClausegetDelegatesgetGrammarFileNamegetTokenNamesnonLeftRecurouterAlternativeprefixrec_rulerecurserecurseNoLabelruleBlockruleModifiersetElementsuffixsynpred1_LeftRecursiveRuleWalkersynpred1_LeftRecursiveRuleWalker_fragmentsynpred2_LeftRecursiveRuleWalkersynpred2_LeftRecursiveRuleWalker_fragmentsynpred3_LeftRecursiveRuleWalkersynpred3_LeftRecursiveRuleWalker_fragmenttoken

Field Detail

altAssociativityback to summary
public Map<Integer, LeftRecursiveRuleAnalyzer.ASSOC> altAssociativity
binaryAltsback to summary
public LinkedHashMap<Integer, LeftRecursiveRuleAltInfo> binaryAlts
codegenTemplatesback to summary
public final STGroup codegenTemplates
languageback to summary
public final String language
leftRecursiveRuleRefLabelsback to summary
public List<Pair<GrammarAST, String>> leftRecursiveRuleRefLabels

Pointer to ID node of ^(= ID element)

prefixAndOtherAltsback to summary
public List<LeftRecursiveRuleAltInfo> prefixAndOtherAlts
recRuleTemplatesback to summary
public static final STGroup recRuleTemplates
retvalsback to summary
public GrammarAST retvals
ruleNameback to summary
public String ruleName

Hides org.antlr.v4.parse.LeftRecursiveRuleWalker.ruleName.

suffixAltsback to summary
public LinkedHashMap<Integer, LeftRecursiveRuleAltInfo> suffixAlts
ternaryAltsback to summary
public LinkedHashMap<Integer, LeftRecursiveRuleAltInfo> ternaryAlts
tokenStreamback to summary
public final TokenStream tokenStream

Tokens from which rule AST comes from

toolback to summary
public Tool tool

Constructor Detail

LeftRecursiveRuleAnalyzerback to summary
public LeftRecursiveRuleAnalyzer(GrammarAST ruleAST, Tool tool, String ruleName, String language)

Method Detail

addPrecedenceArgToRulesback to summary
public AltAST addPrecedenceArgToRules(AltAST t, int prec)
binaryAltback to summary
public void binaryAlt(AltAST originalAltTree, int alt)

Overrides org.antlr.v4.parse.LeftRecursiveRuleWalker.binaryAlt.

Annotations
@Override
getArtificialOpPrecRuleback to summary
public String getArtificialOpPrecRule()
hasImmediateRecursiveRuleRefsback to summary
public static boolean hasImmediateRecursiveRuleRefs(GrammarAST t, String ruleName)

Match (RULE RULE_REF (BLOCK (ALT .*) (ALT RULE_REF[self] .*) (ALT .*))) Match (RULE RULE_REF (BLOCK (ALT .*) (ALT (ASSIGN ID RULE_REF[self]) .*) (ALT .*)))

nextPrecedenceback to summary
public int nextPrecedence(int alt)
otherAltback to summary
public void otherAlt(AltAST originalAltTree, int alt)

Overrides org.antlr.v4.parse.LeftRecursiveRuleWalker.otherAlt.

Annotations
@Override
precedenceback to summary
public int precedence(int alt)
prefixAltback to summary
public void prefixAlt(AltAST originalAltTree, int alt)

Overrides org.antlr.v4.parse.LeftRecursiveRuleWalker.prefixAlt.

Annotations
@Override
setAltAssocback to summary
public void setAltAssoc(AltAST t, int alt)

Overrides org.antlr.v4.parse.LeftRecursiveRuleWalker.setAltAssoc.

Annotations
@Override
setReturnValuesback to summary
public void setReturnValues(GrammarAST t)

Overrides org.antlr.v4.parse.LeftRecursiveRuleWalker.setReturnValues.

Annotations
@Override
stripAltLabelback to summary
public void stripAltLabel(GrammarAST altAST)

Strip last 2 tokens if → label; alter indexes in altAST

stripLeftRecursionback to summary
public GrammarAST stripLeftRecursion(GrammarAST altAST)
suffixAltback to summary
public void suffixAlt(AltAST originalAltTree, int alt)

Overrides org.antlr.v4.parse.LeftRecursiveRuleWalker.suffixAlt.

Annotations
@Override
textback to summary
public String text(GrammarAST t)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
org.antlr.v4.analysis back to summary

public final Enum LeftRecursiveRuleAnalyzer.ASSOC

extends Enum<LeftRecursiveRuleAnalyzer.ASSOC>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final LeftRecursiveRuleAnalyzer.ASSOC
public static final LeftRecursiveRuleAnalyzer.ASSOC

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static LeftRecursiveRuleAnalyzer.ASSOC
public static LeftRecursiveRuleAnalyzer.ASSOC[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

leftback to summary
public static final LeftRecursiveRuleAnalyzer.ASSOC left
rightback to summary
public static final LeftRecursiveRuleAnalyzer.ASSOC right

Constructor Detail

ASSOCback to summary
private ASSOC()

Method Detail

valueOfback to summary
public static LeftRecursiveRuleAnalyzer.ASSOC valueOf(String name)
valuesback to summary
public static LeftRecursiveRuleAnalyzer.ASSOC[] values()