public class ParserATNFactory extends Object implements ATNFactory
ATN object and returns it.ATNFactory.Handle| Modifier and Type | Field and Description |
|---|---|
org.antlr.v4.runtime.atn.ATN |
atn |
int |
currentOuterAlt |
Rule |
currentRule |
Grammar |
g |
protected List<org.antlr.v4.runtime.misc.Tuple3<? extends Rule,? extends org.antlr.v4.runtime.atn.ATNState,? extends org.antlr.v4.runtime.atn.ATNState>> |
preventEpsilonClosureBlocks |
protected List<org.antlr.v4.runtime.misc.Tuple3<? extends Rule,? extends org.antlr.v4.runtime.atn.ATNState,? extends org.antlr.v4.runtime.atn.ATNState>> |
preventEpsilonOptionalBlocks |
| Constructor and Description |
|---|
ParserATNFactory(Grammar g) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
_createATN(Collection<Rule> rules) |
ATNFactory.Handle |
_ruleRef(GrammarAST node) |
ATNFactory.Handle |
action(ActionAST action)
Build what amounts to an epsilon transition with an action.
|
ATNFactory.Handle |
action(String action) |
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,
org.antlr.v4.runtime.atn.ATNState right) |
void |
addRuleFollowLinks() |
ATNFactory.Handle |
alt(List<ATNFactory.Handle> els) |
ATNFactory.Handle |
block(BlockAST blkAST,
GrammarAST ebnfRoot,
List<ATNFactory.Handle> alts)
From
A|B|..|Z alternative block build |
static boolean |
blockHasWildcardAlt(GrammarAST block)
(BLOCK (ALT .)) or (BLOCK (ALT 'a') (ALT .)). |
ATNFactory.Handle |
charSetLiteral(GrammarAST charSetAST)
[Aa] char sets not allowed in parser |
org.antlr.v4.runtime.atn.ATN |
createATN() |
ATNFactory.Handle |
elemList(List<ATNFactory.Handle> els) |
protected void |
epsilon(org.antlr.v4.runtime.atn.ATNState a,
org.antlr.v4.runtime.atn.ATNState b) |
protected void |
epsilon(org.antlr.v4.runtime.atn.ATNState a,
org.antlr.v4.runtime.atn.ATNState b,
boolean prepend) |
ATNFactory.Handle |
epsilon(GrammarAST node)
From an empty alternative build
o-e->o. |
boolean |
expectNonGreedy(BlockAST blkAST) |
protected int |
getTokenType(GrammarAST atom) |
boolean |
isSLLDecision(BlockAST blkAST) |
ATNFactory.Handle |
label(ATNFactory.Handle t) |
ATNFactory.Handle |
lexerAltCommands(ATNFactory.Handle alt,
ATNFactory.Handle cmds) |
ATNFactory.Handle |
lexerCallCommand(GrammarAST ID,
GrammarAST arg) |
ATNFactory.Handle |
lexerCommand(GrammarAST ID) |
ATNFactory.Handle |
listLabel(ATNFactory.Handle t) |
protected ATNFactory.Handle |
makeBlock(org.antlr.v4.runtime.atn.BlockStartState start,
BlockAST blkAST,
List<ATNFactory.Handle> alts) |
org.antlr.v4.runtime.atn.ATNState |
newState() |
<T extends org.antlr.v4.runtime.atn.ATNState> |
newState(Class<T> nodeType,
GrammarAST node) |
org.antlr.v4.runtime.atn.ATNState |
newState(GrammarAST node) |
ATNFactory.Handle |
optional(GrammarAST optAST,
ATNFactory.Handle blk)
From
(A)? build either: |
ATNFactory.Handle |
plus(GrammarAST plusAST,
ATNFactory.Handle blk)
From
(blk)+ build |
ATNFactory.Handle |
range(GrammarAST a,
GrammarAST b)
Not valid for non-lexers.
|
ATNFactory.Handle |
rule(GrammarAST ruleAST,
String name,
ATNFactory.Handle blk) |
ATNFactory.Handle |
ruleRef(GrammarAST node)
For reference to rule
r, build |
ATNFactory.Handle |
sempred(PredAST pred)
Build what amounts to an epsilon transition with a semantic
predicate action.
|
ATNFactory.Handle |
set(GrammarAST associatedAST,
List<GrammarAST> terminals,
boolean invert)
From set build single edge graph
o->o-set->o. |
void |
setCurrentOuterAlt(int alt) |
void |
setCurrentRuleName(String name) |
ATNFactory.Handle |
star(GrammarAST starAST,
ATNFactory.Handle elem)
From
(blk)* build ( blk+ )? with *two* decisions, one for
entry and one for choosing alts of blk. |
ATNFactory.Handle |
stringLiteral(TerminalAST stringLiteralAST)
For a non-lexer, just build a simple token reference atom.
|
ATNFactory.Handle |
tokenRef(TerminalAST node)
From label
A build graph o-A->o. |
ATNFactory.Handle |
wildcard(GrammarAST node)
Build an atom with all possible values in its label.
|
@NotNull public final Grammar g
@NotNull public final org.antlr.v4.runtime.atn.ATN atn
public Rule currentRule
public int currentOuterAlt
@NotNull protected final List<org.antlr.v4.runtime.misc.Tuple3<? extends Rule,? extends org.antlr.v4.runtime.atn.ATNState,? extends org.antlr.v4.runtime.atn.ATNState>> preventEpsilonClosureBlocks
public ParserATNFactory(@NotNull
Grammar g)
@NotNull public org.antlr.v4.runtime.atn.ATN createATN()
createATN in interface ATNFactoryprotected void _createATN(@NotNull
Collection<Rule> rules)
public void setCurrentRuleName(@NotNull
String name)
setCurrentRuleName in interface ATNFactorypublic void setCurrentOuterAlt(int alt)
setCurrentOuterAlt in interface ATNFactory@NotNull public ATNFactory.Handle rule(@NotNull GrammarAST ruleAST, @NotNull String name, @NotNull ATNFactory.Handle blk)
rule in interface ATNFactory@NotNull public ATNFactory.Handle tokenRef(@NotNull TerminalAST node)
A build graph o-A->o.tokenRef in interface ATNFactory@NotNull public ATNFactory.Handle set(@NotNull GrammarAST associatedAST, @NotNull 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.set in interface ATNFactory@NotNull public ATNFactory.Handle range(@NotNull GrammarAST a, @NotNull GrammarAST b)
range in interface ATNFactoryprotected int getTokenType(@NotNull
GrammarAST atom)
@NotNull public ATNFactory.Handle stringLiteral(@NotNull TerminalAST stringLiteralAST)
stringLiteral in interface ATNFactory@NotNull public ATNFactory.Handle charSetLiteral(@NotNull GrammarAST charSetAST)
[Aa] char sets not allowed in parsercharSetLiteral in interface ATNFactory@NotNull public ATNFactory.Handle ruleRef(@NotNull 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).ruleRef in interface ATNFactory@NotNull public ATNFactory.Handle _ruleRef(@NotNull GrammarAST node)
public void addFollowLink(int ruleIndex,
org.antlr.v4.runtime.atn.ATNState right)
@NotNull public ATNFactory.Handle epsilon(@NotNull GrammarAST node)
o-e->o.epsilon in interface ATNFactory@NotNull public ATNFactory.Handle sempred(@NotNull PredAST pred)
pred is a pointer into the AST of
the ANTLRParser.SEMPRED token.sempred in interface ATNFactory@NotNull public ATNFactory.Handle action(@NotNull ActionAST action)
actionIndex<0.action in interface ATNFactory@NotNull public ATNFactory.Handle action(@NotNull String action)
action in interface ATNFactory@NotNull public ATNFactory.Handle block(@NotNull BlockAST blkAST, @NotNull GrammarAST ebnfRoot, @NotNull 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?
block in interface ATNFactory@NotNull protected ATNFactory.Handle makeBlock(@NotNull org.antlr.v4.runtime.atn.BlockStartState start, @NotNull BlockAST blkAST, @NotNull List<ATNFactory.Handle> alts)
@NotNull public ATNFactory.Handle alt(@NotNull List<ATNFactory.Handle> els)
alt in interface ATNFactory@NotNull public ATNFactory.Handle elemList(@NotNull List<ATNFactory.Handle> els)
@NotNull public ATNFactory.Handle optional(@NotNull GrammarAST optAST, @NotNull 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
blockoptional in interface ATNFactory@NotNull public ATNFactory.Handle plus(@NotNull GrammarAST plusAST, @NotNull 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.plus in interface ATNFactory@NotNull public ATNFactory.Handle star(@NotNull GrammarAST starAST, @NotNull 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|)+.star in interface ATNFactory@NotNull public ATNFactory.Handle wildcard(@NotNull GrammarAST node)
wildcard in interface ATNFactoryprotected void epsilon(org.antlr.v4.runtime.atn.ATNState a,
@NotNull
org.antlr.v4.runtime.atn.ATNState b)
protected void epsilon(org.antlr.v4.runtime.atn.ATNState a,
@NotNull
org.antlr.v4.runtime.atn.ATNState b,
boolean prepend)
public void addRuleFollowLinks()
public int addEOFTransitionToStartRules()
@NotNull public ATNFactory.Handle label(@NotNull ATNFactory.Handle t)
label in interface ATNFactory@NotNull public ATNFactory.Handle listLabel(@NotNull ATNFactory.Handle t)
listLabel in interface ATNFactory@NotNull
public <T extends org.antlr.v4.runtime.atn.ATNState> T newState(@NotNull
Class<T> nodeType,
GrammarAST node)
@NotNull
public org.antlr.v4.runtime.atn.ATNState newState(@Nullable
GrammarAST node)
@NotNull public org.antlr.v4.runtime.atn.ATNState newState()
newState in interface ATNFactorypublic boolean expectNonGreedy(@NotNull
BlockAST blkAST)
public boolean isSLLDecision(@NotNull
BlockAST blkAST)
public static boolean blockHasWildcardAlt(@NotNull
GrammarAST block)
(BLOCK (ALT .)) or (BLOCK (ALT 'a') (ALT .)).@NotNull public ATNFactory.Handle lexerAltCommands(@NotNull ATNFactory.Handle alt, @NotNull ATNFactory.Handle cmds)
lexerAltCommands in interface ATNFactory@NotNull public ATNFactory.Handle lexerCallCommand(@NotNull GrammarAST ID, @NotNull GrammarAST arg)
lexerCallCommand in interface ATNFactory@NotNull public ATNFactory.Handle lexerCommand(@NotNull GrammarAST ID)
lexerCommand in interface ATNFactoryCopyright © 1992–2022 Daniel Sun. All rights reserved.