Class ParserATNFactory
java.lang.Object
org.antlr.v4.automata.ParserATNFactory
- All Implemented Interfaces:
ATNFactory
- Direct Known Subclasses:
LexerATNFactory
ATN construction routines triggered by ATNBuilder.g.
No side-effects. It builds an
ATN object and returns it.-
Nested Class Summary
Nested classes/interfaces inherited from interface ATNFactory
ATNFactory.Handle -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void_createATN(Collection<Rule> rules) _ruleRef(GrammarAST node) Build what amounts to an epsilon transition with an action.intAdd an EOF transition to any rule end ATNState that points to nothing (i.e., for all those rules not invoked by another rule).voidaddFollowLink(int ruleIndex, ATNState right) voidalt(List<ATNFactory.Handle> els) block(BlockAST blkAST, GrammarAST ebnfRoot, List<ATNFactory.Handle> alts) FromA|B|..|Zalternative block buildstatic booleanblockHasWildcardAlt(GrammarAST block) (BLOCK (ALT .))or(BLOCK (ALT 'a') (ALT .)).charSetLiteral(GrammarAST charSetAST) [Aa]char sets not allowed in parserprotected void(package private) voidDefine all the rule begin/end ATNStates to solve forward reference issues.elemList(List<ATNFactory.Handle> els) protected voidprotected voidepsilon(GrammarAST node) From an empty alternative buildo-e->o.booleanexpectNonGreedy(BlockAST blkAST) protected intgetTokenType(GrammarAST atom) lexerAltCommands(ATNFactory.Handle alt, ATNFactory.Handle cmds) lexerCallCommand(GrammarAST ID, GrammarAST arg) protected ATNFactory.HandlemakeBlock(BlockStartState start, BlockAST blkAST, List<ATNFactory.Handle> alts) newState()<T extends ATNState>
TnewState(Class<T> nodeType, GrammarAST node) newState(GrammarAST node) optional(GrammarAST optAST, ATNFactory.Handle blk) From(A)?build either:plus(GrammarAST plusAST, ATNFactory.Handle blk) From(blk)+buildrange(GrammarAST a, GrammarAST b) Not valid for non-lexers.rule(GrammarAST ruleAST, String name, ATNFactory.Handle blk) ruleRef(GrammarAST node) For reference to ruler, buildBuild what amounts to an epsilon transition with a semantic predicate action.set(GrammarAST associatedAST, List<GrammarAST> terminals, boolean invert) From set build single edge grapho->o-set->o.voidsetCurrentOuterAlt(int alt) voidsetCurrentRuleName(String name) star(GrammarAST starAST, ATNFactory.Handle elem) From(blk)*build( blk+ )?with *two* decisions, one for entry and one for choosing alts ofblk.stringLiteral(TerminalAST stringLiteralAST) For a non-lexer, just build a simple token reference atom.tokenRef(TerminalAST node) From labelAbuild grapho-A->o.wildcard(GrammarAST node) Build an atom with all possible values in its label.
-
Field Details
-
g
-
atn
-
currentRule
-
currentOuterAlt
public int currentOuterAlt -
preventEpsilonClosureBlocks
-
preventEpsilonOptionalBlocks
-
-
Constructor Details
-
ParserATNFactory
-
-
Method Details
-
createATN
- Specified by:
createATNin interfaceATNFactory
-
checkEpsilonClosure
protected void checkEpsilonClosure() -
_createATN
-
setCurrentRuleName
- Specified by:
setCurrentRuleNamein interfaceATNFactory
-
setCurrentOuterAlt
public void setCurrentOuterAlt(int alt) - Specified by:
setCurrentOuterAltin interfaceATNFactory
-
rule
- Specified by:
rulein interfaceATNFactory
-
tokenRef
From labelAbuild grapho-A->o.- Specified by:
tokenRefin interfaceATNFactory
-
set
From set build single edge grapho->o-set->o. To conform to what an alt block looks like, must have extra state on left. This also handles~A, converted to~{A}set.- Specified by:
setin interfaceATNFactory
-
range
Not valid for non-lexers.- Specified by:
rangein interfaceATNFactory
-
getTokenType
-
stringLiteral
For a non-lexer, just build a simple token reference atom.- Specified by:
stringLiteralin interfaceATNFactory
-
charSetLiteral
[Aa]char sets not allowed in parser- Specified by:
charSetLiteralin interfaceATNFactory
-
ruleRef
For reference to ruler, buildo->(r) o
where(r)is the start of rulerand the trailingois not linked to from rule ref state directly (usesRuleTransition.followState).- Specified by:
ruleRefin interfaceATNFactory- Parameters:
node-
-
_ruleRef
-
addFollowLink
-
epsilon
From an empty alternative buildo-e->o.- Specified by:
epsilonin interfaceATNFactory
-
sempred
Build what amounts to an epsilon transition with a semantic predicate action. Thepredis a pointer into the AST of theANTLRParser.SEMPREDtoken.- Specified by:
sempredin interfaceATNFactory
-
action
Build what amounts to an epsilon transition with an action. The action goes into ATN though it is ignored during prediction ifactionIndex<0.- Specified by:
actionin interfaceATNFactory
-
action
- Specified by:
actionin interfaceATNFactory
-
block
FromA|B|..|Zalternative block buildo->o-A->o->o (last ATNState is BlockEndState pointed to by all alts) | ^ |->o-B->o--| | | ... | | | |->o-Z->o--|
So start node points at every alternative with epsilon transition and every alt right side points at a block end ATNState.Special case: only one alternative: don't make a block with alt begin/end.
Special case: if just a list of tokens/chars/sets, then collapse to a single edged o-set->o graph.
TODO: Set alt number (1..n) in the states?
- Specified by:
blockin interfaceATNFactory
-
makeBlock
protected ATNFactory.Handle makeBlock(BlockStartState start, BlockAST blkAST, List<ATNFactory.Handle> alts) -
alt
- Specified by:
altin interfaceATNFactory
-
elemList
-
optional
From(A)?build either:o--A->o | ^ o---->|
or, ifAis a block, just add an empty alt to the end of the block- Specified by:
optionalin interfaceATNFactory
-
plus
From(blk)+build|---------| v | [o-blk-o]->o->o
We add a decision for loop back node to the existing one atblkstart.- Specified by:
plusin interfaceATNFactory
-
star
From(blk)*build( blk+ )?with *two* decisions, one for entry and one for choosing alts ofblk.|-------------| v | o--[o-blk-o]->o o | ^ -----------------|
Note that the optional bypass must jump outside the loop as(A|B)*is not the same thing as(A|B|)+.- Specified by:
starin interfaceATNFactory
-
wildcard
Build an atom with all possible values in its label.- Specified by:
wildcardin interfaceATNFactory
-
epsilon
-
epsilon
-
createRuleStartAndStopATNStates
void createRuleStartAndStopATNStates()Define all the rule begin/end ATNStates to solve forward reference issues. -
addRuleFollowLinks
public void addRuleFollowLinks() -
addEOFTransitionToStartRules
public int addEOFTransitionToStartRules()Add an EOF transition to any rule end ATNState that points to nothing (i.e., for all those rules not invoked by another rule). These are start symbols then. Return the number of grammar entry points; i.e., how many rules are not invoked by another rule (they can only be invoked from outside). These are the start rules. -
label
- Specified by:
labelin interfaceATNFactory
-
listLabel
- Specified by:
listLabelin interfaceATNFactory
-
newState
-
newState
-
newState
- Specified by:
newStatein interfaceATNFactory
-
expectNonGreedy
-
blockHasWildcardAlt
(BLOCK (ALT .))or(BLOCK (ALT 'a') (ALT .)). -
lexerAltCommands
- Specified by:
lexerAltCommandsin interfaceATNFactory
-
lexerCallCommand
- Specified by:
lexerCallCommandin interfaceATNFactory
-
lexerCommand
- Specified by:
lexerCommandin interfaceATNFactory
-