Package org.antlr.v4.semantics
Class SymbolCollector
- java.lang.Object
-
- org.antlr.runtime.BaseRecognizer
-
- org.antlr.runtime.tree.TreeParser
-
- org.antlr.v4.parse.GrammarTreeVisitor
-
- org.antlr.v4.semantics.SymbolCollector
-
public class SymbolCollector extends GrammarTreeVisitor
Collects (create) rules, terminals, strings, actions, scopes etc... from AST side-effects: sets resolver field of asts for actions and defines predicates via definePredicateInAlt(), collects actions and stores in alts. TODO: remove side-effects!
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.antlr.v4.parse.GrammarTreeVisitor
GrammarTreeVisitor.action_return, GrammarTreeVisitor.actionElement_return, GrammarTreeVisitor.alternative_return, GrammarTreeVisitor.astOperand_return, GrammarTreeVisitor.atom_return, GrammarTreeVisitor.block_return, GrammarTreeVisitor.blockSet_return, GrammarTreeVisitor.blockSuffix_return, GrammarTreeVisitor.channelSpec_return, GrammarTreeVisitor.channelsSpec_return, GrammarTreeVisitor.delegateGrammar_return, GrammarTreeVisitor.delegateGrammars_return, GrammarTreeVisitor.DFA38, GrammarTreeVisitor.ebnfSuffix_return, GrammarTreeVisitor.element_return, GrammarTreeVisitor.elementOption_return, GrammarTreeVisitor.elementOptions_return, GrammarTreeVisitor.exceptionGroup_return, GrammarTreeVisitor.exceptionHandler_return, GrammarTreeVisitor.finallyClause_return, GrammarTreeVisitor.grammarSpec_return, GrammarTreeVisitor.labeledElement_return, GrammarTreeVisitor.lexerAlternative_return, GrammarTreeVisitor.lexerAtom_return, GrammarTreeVisitor.lexerBlock_return, GrammarTreeVisitor.lexerCommand_return, GrammarTreeVisitor.lexerCommandExpr_return, GrammarTreeVisitor.lexerElement_return, GrammarTreeVisitor.lexerElements_return, GrammarTreeVisitor.lexerOuterAlternative_return, GrammarTreeVisitor.lexerRule_return, GrammarTreeVisitor.lexerRuleBlock_return, GrammarTreeVisitor.lexerSubrule_return, GrammarTreeVisitor.locals_return, GrammarTreeVisitor.mode_return, GrammarTreeVisitor.option_return, GrammarTreeVisitor.optionsSpec_return, GrammarTreeVisitor.optionValue_return, GrammarTreeVisitor.outerAlternative_return, GrammarTreeVisitor.prequelConstruct_return, GrammarTreeVisitor.prequelConstructs_return, GrammarTreeVisitor.range_return, GrammarTreeVisitor.rule_return, GrammarTreeVisitor.ruleAction_return, GrammarTreeVisitor.ruleBlock_return, GrammarTreeVisitor.ruleModifier_return, GrammarTreeVisitor.ruleref_return, GrammarTreeVisitor.ruleReturns_return, GrammarTreeVisitor.rules_return, GrammarTreeVisitor.setElement_return, GrammarTreeVisitor.subrule_return, GrammarTreeVisitor.terminal_return, GrammarTreeVisitor.throwsSpec_return, GrammarTreeVisitor.tokenSpec_return, GrammarTreeVisitor.tokensSpec_return
-
-
Field Summary
Fields Modifier and Type Field Description List<GrammarAST>
channelDefs
Rule
currentRule
ErrorManager
errMgr
Grammar
g
which grammar are we checkingList<GrammarAST>
qualifiedRulerefs
List<GrammarAST>
rulerefs
Set<String>
strings
List<GrammarAST>
terminals
List<GrammarAST>
tokenIDRefs
List<GrammarAST>
tokensDefs
-
Fields inherited from class org.antlr.v4.parse.GrammarTreeVisitor
ACTION, ACTION_CHAR_LITERAL, ACTION_ESC, ACTION_STRING_LITERAL, ALT, ARG_ACTION, ARG_OR_CHARSET, ASSIGN, AT, BLOCK, CATCH, CHANNELS, CLOSURE, COLON, COLONCOLON, COMBINED, COMMA, COMMENT, currentModeName, currentOuterAltNumber, currentOuterAltRoot, currentRuleAST, currentRuleName, dfa38, DOC_COMMENT, DOLLAR, DOT, ELEMENT_OPTIONS, EOF, EPSILON, ERRCHAR, ESC_SEQ, FINALLY, FOLLOW_ACTION_in_action596, FOLLOW_ACTION_in_actionElement1679, FOLLOW_ACTION_in_actionElement1687, FOLLOW_ACTION_in_block2430, FOLLOW_ACTION_in_element1868, FOLLOW_ACTION_in_element1897, FOLLOW_ACTION_in_elementOption2733, FOLLOW_ACTION_in_exceptionHandler998, FOLLOW_ACTION_in_finallyClause1025, FOLLOW_ACTION_in_lexerElement1468, FOLLOW_ACTION_in_lexerElement1497, FOLLOW_action_in_prequelConstruct234, FOLLOW_ACTION_in_ruleAction1139, FOLLOW_ALT_in_alternative1730, FOLLOW_ALT_in_alternative1743, FOLLOW_ALT_in_lexerElements1428, FOLLOW_alternative_in_block2433, FOLLOW_alternative_in_outerAlternative1362, FOLLOW_ARG_ACTION_in_exceptionHandler996, FOLLOW_ARG_ACTION_in_locals1055, FOLLOW_ARG_ACTION_in_rule817, FOLLOW_ARG_ACTION_in_ruleref2467, FOLLOW_ARG_ACTION_in_ruleReturns1080, FOLLOW_ASSIGN_in_delegateGrammar420, FOLLOW_ASSIGN_in_elementOption2683, FOLLOW_ASSIGN_in_elementOption2707, FOLLOW_ASSIGN_in_elementOption2727, FOLLOW_ASSIGN_in_elementOption2749, FOLLOW_ASSIGN_in_option295, FOLLOW_AT_in_action585, FOLLOW_AT_in_ruleAction1135, FOLLOW_atom_in_astOperand1959, FOLLOW_atom_in_element1856, FOLLOW_block_in_astOperand1976, FOLLOW_BLOCK_in_block2422, FOLLOW_block_in_element1937, FOLLOW_BLOCK_in_lexerBlock1543, FOLLOW_BLOCK_in_lexerRuleBlock1217, FOLLOW_BLOCK_in_ruleBlock1281, FOLLOW_block_in_subrule2034, FOLLOW_block_in_subrule2041, FOLLOW_blockSet_in_astOperand1967, FOLLOW_blockSet_in_atom2225, FOLLOW_blockSet_in_element1928, FOLLOW_blockSet_in_lexerAtom1592, FOLLOW_blockSet_in_lexerAtom1603, FOLLOW_blockSuffix_in_lexerSubrule2066, FOLLOW_blockSuffix_in_subrule2032, FOLLOW_CATCH_in_exceptionHandler994, FOLLOW_CHANNELS_in_channelsSpec532, FOLLOW_channelSpec_in_channelsSpec534, FOLLOW_channelsSpec_in_prequelConstruct224, FOLLOW_delegateGrammar_in_delegateGrammars391, FOLLOW_delegateGrammars_in_prequelConstruct204, FOLLOW_DOT_in_atom2163, FOLLOW_DOT_in_atom2174, FOLLOW_ebnfSuffix_in_blockSuffix2102, FOLLOW_element_in_alternative1735, FOLLOW_element_in_labeledElement2007, FOLLOW_ELEMENT_OPTIONS_in_elementOptions2630, FOLLOW_elementOption_in_elementOptions2632, FOLLOW_elementOptions_in_actionElement1689, FOLLOW_elementOptions_in_actionElement1707, FOLLOW_elementOptions_in_alternative1732, FOLLOW_elementOptions_in_alternative1745, FOLLOW_elementOptions_in_atom2190, FOLLOW_elementOptions_in_element1899, FOLLOW_elementOptions_in_element1912, FOLLOW_elementOptions_in_lexerAtom1616, FOLLOW_elementOptions_in_lexerElement1499, FOLLOW_elementOptions_in_lexerElement1512, FOLLOW_elementOptions_in_ruleref2470, FOLLOW_elementOptions_in_setElement2288, FOLLOW_elementOptions_in_setElement2302, FOLLOW_elementOptions_in_terminal2543, FOLLOW_elementOptions_in_terminal2582, FOLLOW_EPSILON_in_alternative1748, FOLLOW_EPSILON_in_lexerElement1520, FOLLOW_exceptionGroup_in_rule918, FOLLOW_exceptionHandler_in_exceptionGroup965, FOLLOW_FINALLY_in_finallyClause1023, FOLLOW_finallyClause_in_exceptionGroup968, FOLLOW_FRAGMENT_in_lexerRule712, FOLLOW_GRAMMAR_in_grammarSpec85, FOLLOW_ID_in_action589, FOLLOW_ID_in_action594, FOLLOW_ID_in_atom2165, FOLLOW_ID_in_atom2176, FOLLOW_ID_in_channelSpec557, FOLLOW_ID_in_delegateGrammar424, FOLLOW_ID_in_delegateGrammar428, FOLLOW_ID_in_delegateGrammar443, FOLLOW_ID_in_elementOption2663, FOLLOW_ID_in_elementOption2687, FOLLOW_ID_in_elementOption2691, FOLLOW_ID_in_elementOption2709, FOLLOW_ID_in_elementOption2729, FOLLOW_ID_in_elementOption2751, FOLLOW_ID_in_grammarSpec87, FOLLOW_ID_in_labeledElement2005, FOLLOW_ID_in_lexerCommand1776, FOLLOW_ID_in_lexerCommand1794, FOLLOW_ID_in_mode664, FOLLOW_ID_in_option297, FOLLOW_ID_in_ruleAction1137, FOLLOW_ID_in_throwsSpec1108, FOLLOW_ID_in_tokenSpec502, FOLLOW_IMPORT_in_delegateGrammars389, FOLLOW_INT_in_elementOption2755, FOLLOW_labeledElement_in_element1851, FOLLOW_LEXER_ACTION_CALL_in_lexerCommand1774, FOLLOW_LEXER_ALT_ACTION_in_lexerAlternative1384, FOLLOW_LEXER_CHAR_SET_in_lexerAtom1635, FOLLOW_LEXER_CHAR_SET_in_setElement2397, FOLLOW_lexerAlternative_in_lexerBlock1548, FOLLOW_lexerAlternative_in_lexerOuterAlternative1340, FOLLOW_lexerAtom_in_lexerElement1456, FOLLOW_lexerBlock_in_lexerSubrule2068, FOLLOW_lexerBlock_in_lexerSubrule2075, FOLLOW_lexerCommand_in_lexerAlternative1388, FOLLOW_lexerCommandExpr_in_lexerCommand1778, FOLLOW_lexerElement_in_lexerElements1430, FOLLOW_lexerElements_in_lexerAlternative1386, FOLLOW_lexerElements_in_lexerAlternative1400, FOLLOW_lexerOuterAlternative_in_lexerRuleBlock1236, FOLLOW_lexerRule_in_mode668, FOLLOW_lexerRule_in_rules631, FOLLOW_lexerRuleBlock_in_lexerRule745, FOLLOW_lexerSubrule_in_lexerElement1461, FOLLOW_LOCALS_in_locals1053, FOLLOW_locals_in_rule856, FOLLOW_mode_in_grammarSpec125, FOLLOW_MODE_in_mode662, FOLLOW_NOT_in_astOperand1965, FOLLOW_NOT_in_astOperand1974, FOLLOW_NOT_in_element1926, FOLLOW_NOT_in_element1935, FOLLOW_NOT_in_lexerAtom1590, FOLLOW_option_in_optionsSpec261, FOLLOW_OPTIONS_in_optionsSpec259, FOLLOW_optionsSpec_in_block2424, FOLLOW_optionsSpec_in_lexerBlock1545, FOLLOW_optionsSpec_in_lexerRule724, FOLLOW_optionsSpec_in_prequelConstruct194, FOLLOW_optionsSpec_in_rule871, FOLLOW_optionValue_in_option301, FOLLOW_outerAlternative_in_ruleBlock1300, FOLLOW_prequelConstruct_in_prequelConstructs167, FOLLOW_prequelConstructs_in_grammarSpec106, FOLLOW_range_in_element1920, FOLLOW_range_in_lexerAtom1645, FOLLOW_RANGE_in_range2507, FOLLOW_RANGE_in_setElement2366, FOLLOW_RETURNS_in_ruleReturns1078, FOLLOW_RULE_in_lexerRule694, FOLLOW_RULE_in_rule790, FOLLOW_rule_in_rules629, FOLLOW_RULE_REF_in_rule792, FOLLOW_RULE_REF_in_ruleref2463, FOLLOW_ruleAction_in_block2427, FOLLOW_ruleAction_in_rule885, FOLLOW_ruleBlock_in_rule916, FOLLOW_ruleModifier_in_rule806, FOLLOW_RULEMODIFIERS_in_lexerRule708, FOLLOW_RULEMODIFIERS_in_rule801, FOLLOW_ruleref_in_atom2178, FOLLOW_ruleref_in_atom2235, FOLLOW_ruleref_in_lexerAtom1655, FOLLOW_ruleReturns_in_rule830, FOLLOW_rules_in_grammarSpec123, FOLLOW_RULES_in_rules624, FOLLOW_SEMPRED_in_actionElement1697, FOLLOW_SEMPRED_in_actionElement1705, FOLLOW_SEMPRED_in_element1882, FOLLOW_SEMPRED_in_element1910, FOLLOW_SEMPRED_in_lexerElement1482, FOLLOW_SEMPRED_in_lexerElement1510, FOLLOW_SET_in_blockSet2260, FOLLOW_set_in_labeledElement1999, FOLLOW_setElement_in_blockSet2262, FOLLOW_STRING_LITERAL_in_elementOption2713, FOLLOW_STRING_LITERAL_in_range2509, FOLLOW_STRING_LITERAL_in_range2511, FOLLOW_STRING_LITERAL_in_setElement2286, FOLLOW_STRING_LITERAL_in_setElement2312, FOLLOW_STRING_LITERAL_in_setElement2370, FOLLOW_STRING_LITERAL_in_setElement2374, FOLLOW_STRING_LITERAL_in_terminal2541, FOLLOW_STRING_LITERAL_in_terminal2566, FOLLOW_subrule_in_element1861, FOLLOW_terminal_in_atom2167, FOLLOW_terminal_in_atom2217, FOLLOW_terminal_in_lexerAtom1579, FOLLOW_THROWS_in_throwsSpec1106, FOLLOW_throwsSpec_in_rule843, FOLLOW_TOKEN_REF_in_lexerRule696, FOLLOW_TOKEN_REF_in_setElement2300, FOLLOW_TOKEN_REF_in_setElement2337, FOLLOW_TOKEN_REF_in_terminal2580, FOLLOW_TOKEN_REF_in_terminal2593, FOLLOW_TOKENS_SPEC_in_tokensSpec477, FOLLOW_tokenSpec_in_tokensSpec479, FOLLOW_tokensSpec_in_prequelConstruct214, FOLLOW_WILDCARD_in_atom2188, FOLLOW_WILDCARD_in_atom2201, FOLLOW_WILDCARD_in_lexerAtom1614, FOLLOW_WILDCARD_in_lexerAtom1627, FRAGMENT, GRAMMAR, grammarName, GT, HEX_DIGIT, ID, IMPORT, INT, LEXER, LEXER_ACTION_CALL, LEXER_ALT_ACTION, LEXER_CHAR_SET, LOCALS, LPAREN, LT, MODE, NameChar, NameStartChar, NESTED_ACTION, NLCHARS, NOT, OPTIONAL, OPTIONS, OR, PARSER, PLUS, PLUS_ASSIGN, POSITIVE_CLOSURE, POUND, PRIVATE, PROTECTED, PUBLIC, QUESTION, RANGE, RARROW, RBRACE, RETURNS, rewriteEBNFLevel, RPAREN, RULE, RULE_REF, RULEMODIFIERS, RULES, SEMI, SEMPRED, SET, SRC, STAR, STRING_LITERAL, THROWS, TOKEN_REF, tokenNames, TOKENS_SPEC, UNICODE_ESC, UNICODE_EXTENDED_ESC, UnicodeBOM, WILDCARD, WS, WSCHARS, WSNLCHARS
-
-
Constructor Summary
Constructors Constructor Description SymbolCollector(Grammar g)
-
Method Summary
-
Methods inherited from class org.antlr.v4.parse.GrammarTreeVisitor
action, actionElement, alternative, astOperand, atom, block, blockSet, blockSuffix, channelSpec, channelsSpec, delegateGrammar, delegateGrammars, discoverAlt, discoverGrammar, discoverRules, ebnfSuffix, element, elementOption, elementOptions, enterAction, enterActionElement, enterAlternative, enterAstOperand, enterAtom, enterBlock, enterBlockSet, enterBlockSuffix, enterChannelSpec, enterChannelsSpec, enterDelegateGrammar, enterDelegateGrammars, enterEbnfSuffix, enterElement, enterElementOption, enterElementOptions, enterExceptionGroup, enterExceptionHandler, enterFinallyClause, enterGrammarSpec, enterLabeledElement, enterLexerAlternative, enterLexerAtom, enterLexerBlock, enterLexerCommand, enterLexerCommandExpr, enterLexerElement, enterLexerElements, enterLexerOuterAlternative, enterLexerRule, enterLexerRuleBlock, enterLexerSubrule, enterLocals, enterMode, enterOption, enterOptionsSpec, enterOptionValue, enterOuterAlternative, enterPrequelConstruct, enterPrequelConstructs, enterRange, enterRule, enterRuleAction, enterRuleBlock, enterRuleModifier, enterRuleref, enterRuleReturns, enterRules, enterSetElement, enterSubrule, enterTerminal, enterThrowsSpec, enterTokenSpec, enterTokensSpec, exceptionGroup, exceptionHandler, exitAction, exitActionElement, exitAlternative, exitAstOperand, exitAtom, exitBlock, exitBlockSet, exitBlockSuffix, exitChannelSpec, exitChannelsSpec, exitDelegateGrammar, exitDelegateGrammars, exitEbnfSuffix, exitElement, exitElementOption, exitElementOptions, exitExceptionGroup, exitExceptionHandler, exitFinallyClause, exitGrammarSpec, exitLabeledElement, exitLexerAlternative, exitLexerAtom, exitLexerBlock, exitLexerCommand, exitLexerCommandExpr, exitLexerElement, exitLexerElements, exitLexerOuterAlternative, exitLexerRule, exitLexerRuleBlock, exitLexerSubrule, exitLocals, exitMode, exitOption, exitOptionsSpec, exitOptionValue, exitOuterAlternative, exitPrequelConstruct, exitPrequelConstructs, exitRange, exitRule, exitRuleAction, exitRuleBlock, exitRuleModifier, exitRuleref, exitRuleReturns, exitRules, exitSetElement, exitSubrule, exitTerminal, exitThrowsSpec, exitTokenSpec, exitTokensSpec, finallyClause, finishAlt, finishGrammar, finishLexerRule, finishOuterAlt, finishPrequels, finishRule, finishRules, getDelegates, getGrammarFileName, getTokenNames, grammarSpec, importGrammar, labeledElement, lexerAlternative, lexerAtom, lexerBlock, lexerCallCommand, lexerCommand, lexerCommand, lexerCommandExpr, lexerElement, lexerElements, lexerOuterAlternative, lexerRule, lexerRuleBlock, lexerSubrule, locals, mode, modeDef, option, optionsSpec, optionValue, outerAlternative, prequelConstruct, prequelConstructs, range, rule, ruleAction, ruleBlock, ruleModifier, ruleref, ruleReturns, rules, setElement, subrule, terminal, throwsSpec, tokenSpec, tokensSpec, traceIn, traceOut, visit, visitGrammar, wildcardRef
-
Methods inherited from class org.antlr.runtime.tree.TreeParser
getAncestor, getCurrentInputSymbol, getErrorHeader, getErrorMessage, getMissingSymbol, getSourceName, getTreeNodeStream, inContext, inContext, matchAny, recoverFromMismatchedToken, reset, setTreeNodeStream
-
Methods inherited from class org.antlr.runtime.BaseRecognizer
alreadyParsedRule, beginResync, combineFollows, computeContextSensitiveRuleFOLLOW, computeErrorRecoverySet, consumeUntil, consumeUntil, displayRecognitionError, emitErrorMessage, endResync, failed, getBacktrackingLevel, getNumberOfSyntaxErrors, getRuleInvocationStack, getRuleInvocationStack, getRuleMemoization, getRuleMemoizationCacheSize, getTokenErrorDisplay, match, memoize, mismatchIsMissingToken, mismatchIsUnwantedToken, pushFollow, recover, recoverFromMismatchedSet, reportError, setBacktrackingLevel, toStrings, traceIn, traceOut
-
-
-
-
Field Detail
-
g
public Grammar g
which grammar are we checking
-
rulerefs
public List<GrammarAST> rulerefs
-
qualifiedRulerefs
public List<GrammarAST> qualifiedRulerefs
-
terminals
public List<GrammarAST> terminals
-
tokenIDRefs
public List<GrammarAST> tokenIDRefs
-
tokensDefs
public List<GrammarAST> tokensDefs
-
channelDefs
public List<GrammarAST> channelDefs
-
errMgr
public ErrorManager errMgr
-
currentRule
public Rule currentRule
-
-
Constructor Detail
-
SymbolCollector
public SymbolCollector(Grammar g)
-
-
Method Detail
-
getErrorManager
public ErrorManager getErrorManager()
- Overrides:
getErrorManager
in classGrammarTreeVisitor
-
process
public void process(GrammarAST ast)
-
globalNamedAction
public void globalNamedAction(GrammarAST scope, GrammarAST ID, ActionAST action)
- Overrides:
globalNamedAction
in classGrammarTreeVisitor
-
defineToken
public void defineToken(GrammarAST ID)
- Overrides:
defineToken
in classGrammarTreeVisitor
-
defineChannel
public void defineChannel(GrammarAST ID)
- Overrides:
defineChannel
in classGrammarTreeVisitor
-
discoverRule
public void discoverRule(RuleAST rule, GrammarAST ID, List<GrammarAST> modifiers, ActionAST arg, ActionAST returns, GrammarAST thrws, GrammarAST options, ActionAST locals, List<GrammarAST> actions, GrammarAST block)
- Overrides:
discoverRule
in classGrammarTreeVisitor
-
discoverLexerRule
public void discoverLexerRule(RuleAST rule, GrammarAST ID, List<GrammarAST> modifiers, GrammarAST options, GrammarAST block)
- Overrides:
discoverLexerRule
in classGrammarTreeVisitor
-
discoverOuterAlt
public void discoverOuterAlt(AltAST alt)
- Overrides:
discoverOuterAlt
in classGrammarTreeVisitor
-
actionInAlt
public void actionInAlt(ActionAST action)
- Overrides:
actionInAlt
in classGrammarTreeVisitor
-
sempredInAlt
public void sempredInAlt(PredAST pred)
- Overrides:
sempredInAlt
in classGrammarTreeVisitor
-
ruleCatch
public void ruleCatch(GrammarAST arg, ActionAST action)
- Overrides:
ruleCatch
in classGrammarTreeVisitor
-
finallyAction
public void finallyAction(ActionAST action)
- Overrides:
finallyAction
in classGrammarTreeVisitor
-
label
public void label(GrammarAST op, GrammarAST ID, GrammarAST element)
- Overrides:
label
in classGrammarTreeVisitor
-
stringRef
public void stringRef(TerminalAST ref)
- Overrides:
stringRef
in classGrammarTreeVisitor
-
tokenRef
public void tokenRef(TerminalAST ref)
- Overrides:
tokenRef
in classGrammarTreeVisitor
-
ruleRef
public void ruleRef(GrammarAST ref, ActionAST arg)
- Overrides:
ruleRef
in classGrammarTreeVisitor
-
grammarOption
public void grammarOption(GrammarAST ID, GrammarAST valueAST)
- Overrides:
grammarOption
in classGrammarTreeVisitor
-
ruleOption
public void ruleOption(GrammarAST ID, GrammarAST valueAST)
- Overrides:
ruleOption
in classGrammarTreeVisitor
-
blockOption
public void blockOption(GrammarAST ID, GrammarAST valueAST)
- Overrides:
blockOption
in classGrammarTreeVisitor
-
elementOption
public void elementOption(GrammarASTWithOptions t, GrammarAST ID, GrammarAST valueAST)
- Overrides:
elementOption
in classGrammarTreeVisitor
-
-