public class ParserATNFactory extends Objectimplements ATNFactory
ATN object and returns it.
ATNFactory.Handle | Modifier and Type | Field and Description |
|---|---|
ATN |
atn
|
int |
currentOuterAlt
|
Rule |
currentRule
|
Grammar |
g
|
protected List |
preventEpsilonClosureBlocks
|
protected List |
preventEpsilonOptionalBlocks
|
| Constructor and Description |
|---|
ParserATNFactory(Grammar
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
_createATN(Collection
|
ATNFactory |
_ruleRef(GrammarAST
|
ATNFactory |
action(ActionAST
Build what amounts to an epsilon transition with an action.
|
ATNFactory |
action(String
|
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).
|
void |
addFollowLink(int ruleIndex, ATNState right)
|
void |
addRuleFollowLinks()
|
ATNFactory |
alt(List
|
ATNFactory |
block(BlockAST
From
A|B|..|Z alternative block build
|
static boolean |
blockHasWildcardAlt(GrammarAST
(BLOCK (ALT .)) or
(BLOCK (ALT 'a') (ALT .)).
|
ATNFactory |
charSetLiteral(GrammarAST
[Aa] char sets not allowed in parser
|
ATN |
createATN()
|
ATNFactory |
elemList(List
|
protected void |
epsilon(ATNState a, ATNState b)
|
protected void |
epsilon(ATNState a, ATNState b, boolean prepend)
|
ATNFactory |
epsilon(GrammarAST
From an empty alternative build
o-e->o.
|
boolean |
expectNonGreedy(BlockAST
|
protected int |
getTokenType(GrammarAST
|
ATNFactory |
label(ATNFactory
|
ATNFactory |
lexerAltCommands(ATNFactory
|
ATNFactory |
lexerCallCommand(GrammarAST
|
ATNFactory |
lexerCommand(GrammarAST
|
ATNFactory |
listLabel(ATNFactory
|
protected ATNFactory |
makeBlock(BlockStartState start, BlockAST
|
ATNState |
newState()
|
<T extends ATNState |
newState(Class
|
ATNState |
newState(GrammarAST
|
ATNFactory |
optional(GrammarAST
From
(A)? build either:
|
ATNFactory |
plus(GrammarAST
From
(blk)+ build
|
ATNFactory |
range(GrammarAST
Not valid for non-lexers.
|
ATNFactory |
rule(GrammarAST
|
ATNFactory |
ruleRef(GrammarAST
For reference to rule
r, build
|
ATNFactory |
sempred(PredAST
Build what amounts to an epsilon transition with a semantic predicate action.
|
ATNFactory |
set(GrammarAST
From set build single edge graph
o->o-set->o.
|
void |
setCurrentOuterAlt(int alt)
|
void |
setCurrentRuleName(String
|
ATNFactory |
star(GrammarAST
From
(blk)* build
( blk+ )? with *two* decisions, one for entry and one for choosing alts of
blk.
|
ATNFactory |
stringLiteral(TerminalAST
For a non-lexer, just build a simple token reference atom.
|
ATNFactory |
tokenRef(TerminalAST
From label
A build graph
o-A->o.
|
ATNFactory |
wildcard(GrammarAST
Build an atom with all possible values in its label.
|
public final Grammarg
public final ATN atn
public RulecurrentRule
public int currentOuterAlt
protected final List<<any> > preventEpsilonClosureBlocks
protected final List<<any> > preventEpsilonOptionalBlocks
public ParserATNFactory(Grammarg)
public ATN createATN()
protected void _createATN(Collection<Rule > rules)
public void setCurrentRuleName(Stringname)
public void setCurrentOuterAlt(int alt)
public ATNFactory.Handle rule(GrammarAST ruleAST, String name, ATNFactory .Handle blk)
public ATNFactory.Handle tokenRef(TerminalAST node)
A build graph
o-A->o.
public ATNFactory.Handle set(GrammarAST associatedAST, List <GrammarAST > terminals, boolean invert)
o->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.
public ATNFactory.Handle range(GrammarAST a, GrammarAST b)
protected int getTokenType(GrammarASTatom)
public ATNFactory.Handle stringLiteral(TerminalAST stringLiteralAST)
public ATNFactory.Handle charSetLiteral(GrammarAST charSetAST)
[Aa] char sets not allowed in parser
public ATNFactory.Handle ruleRef(GrammarAST node)
r, build
o->(r) owhere
(r) is the start of rule
r and the trailing
o is not linked to from rule ref state directly (uses
RuleTransition#followState).
public ATNFactory.Handle _ruleRef(GrammarAST node)
public void addFollowLink(int ruleIndex,
ATNState right)public ATNFactory.Handle epsilon(GrammarAST node)
o-e->o.
public ATNFactory.Handle sempred(PredAST pred)
pred is a pointer into the AST of the
ANTLRParser.SEMPRED token.
public ATNFactory.Handle action(ActionAST action)
actionIndex
<0.
public ATNFactory.Handle action(String action)
public ATNFactory.Handle block(BlockAST blkAST, GrammarAST ebnfRoot, List <ATNFactory .Handle > alts)
A|B|..|Z alternative block build
o->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?
protected ATNFactory.Handle makeBlock(BlockStartState start, BlockAST blkAST, List <ATNFactory .Handle > alts)
public ATNFactory.Handle alt(List <ATNFactory .Handle > els)
public ATNFactory.Handle elemList(List <ATNFactory .Handle > els)
public ATNFactory.Handle optional(GrammarAST optAST, ATNFactory .Handle blk)
(A)? build either:
o--A->o | ^ o---->|or, if
A is a block, just add an empty alt to the end of the block
public ATNFactory.Handle plus(GrammarAST plusAST, ATNFactory .Handle blk)
(blk)+ build
|---------| v | [o-blk-o]->o->oWe add a decision for loop back node to the existing one at
blk start.
public ATNFactory.Handle star(GrammarAST starAST, ATNFactory .Handle elem)
(blk)* build
( blk+ )? with *two* decisions, one for entry and one for choosing alts of
blk.
|-------------| 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|)+.
public ATNFactory.Handle wildcard(GrammarAST node)
protected void epsilon(ATNState a,
ATNState b)protected void epsilon(ATNState a,
ATNState b,
boolean prepend)public void addRuleFollowLinks()
public int addEOFTransitionToStartRules()
public ATNFactory.Handle label(ATNFactory .Handle t)
public ATNFactory.Handle listLabel(ATNFactory .Handle t)
public <T extends ATNState> T newState(Class <T> nodeType, GrammarAST node)
public ATNState newState(GrammarASTnode)
public ATNState newState()
public boolean expectNonGreedy(BlockASTblkAST)
public static boolean blockHasWildcardAlt(GrammarASTblock)
(BLOCK (ALT .)) or
(BLOCK (ALT 'a') (ALT .)).
public ATNFactory.Handle lexerAltCommands(ATNFactory .Handle alt, ATNFactory .Handle cmds)
public ATNFactory.Handle lexerCallCommand(GrammarAST ID, GrammarAST arg)
public ATNFactory.Handle lexerCommand(GrammarAST ID)