public class ParserATNFactory extends Object implements ATNFactory
ATNFactory.Handle| Modifier and Type | Field and Description |
|---|---|
ATN |
atn |
int |
currentOuterAlt |
Rule |
currentRule |
Grammar |
g |
protected List<Pair<Rule,DecisionState>> |
preventEpsilonDecisions |
| 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,
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 |
ATN |
createATN() |
ATNFactory.Handle |
elemList(List<ATNFactory.Handle> els) |
ATNFactory.Handle |
epsilon(GrammarAST node)
From an empty alternative build
o-e->o. |
boolean |
expectNonGreedy(BlockAST blkAST) |
protected int |
getTokenType(GrammarAST atom) |
ATNFactory.Handle |
label(ATNFactory.Handle t) |
ATNFactory.Handle |
lexerAltCommands(ATNFactory.Handle alt,
ATNFactory.Handle cmds) |
String |
lexerCallCommand(GrammarAST ID,
GrammarAST arg) |
String |
lexerCommand(GrammarAST ID) |
ATNFactory.Handle |
listLabel(ATNFactory.Handle t) |
protected ATNFactory.Handle |
makeBlock(BlockStartState start,
BlockAST blkAST,
List<ATNFactory.Handle> alts) |
ATNState |
newState() |
<T extends ATNState> |
newState(Class<T> nodeType,
GrammarAST node) |
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.
|
public Rule currentRule
public int currentOuterAlt
protected final List<Pair<Rule,DecisionState>> preventEpsilonDecisions
public ATN createATN()
createATN in interface ATNFactoryprotected void _createATN(Collection<Rule> rules)
public void setCurrentRuleName(String name)
setCurrentRuleName in interface ATNFactorypublic void setCurrentOuterAlt(int alt)
setCurrentOuterAlt in interface ATNFactorypublic ATNFactory.Handle rule(GrammarAST ruleAST, String name, ATNFactory.Handle blk)
rule in interface ATNFactorypublic ATNFactory.Handle tokenRef(TerminalAST node)
A build graph o-A->o.tokenRef in interface ATNFactorypublic 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.set in interface ATNFactorypublic ATNFactory.Handle range(GrammarAST a, GrammarAST b)
range in interface ATNFactoryprotected int getTokenType(GrammarAST atom)
public ATNFactory.Handle stringLiteral(TerminalAST stringLiteralAST)
stringLiteral in interface ATNFactorypublic ATNFactory.Handle charSetLiteral(GrammarAST charSetAST)
[Aa] char sets not allowed in parsercharSetLiteral in interface ATNFactorypublic 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).ruleRef in interface ATNFactorypublic ATNFactory.Handle _ruleRef(GrammarAST node)
public void addFollowLink(int ruleIndex,
ATNState right)
public ATNFactory.Handle epsilon(GrammarAST node)
o-e->o.epsilon in interface ATNFactorypublic ATNFactory.Handle sempred(PredAST pred)
pred is a pointer into the AST of
the ANTLRParser.SEMPRED token.sempred in interface ATNFactorypublic ATNFactory.Handle action(ActionAST action)
actionIndex<0.action in interface ATNFactorypublic ATNFactory.Handle action(String action)
action in interface ATNFactorypublic 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?
block in interface ATNFactoryprotected ATNFactory.Handle makeBlock(BlockStartState start, BlockAST blkAST, 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(GrammarAST node)
wildcard in interface ATNFactorypublic void addRuleFollowLinks()
public int addEOFTransitionToStartRules()
public ATNFactory.Handle label(ATNFactory.Handle t)
label in interface ATNFactorypublic ATNFactory.Handle listLabel(ATNFactory.Handle t)
listLabel in interface ATNFactory@NotNull public <T extends ATNState> T newState(@NotNull Class<T> nodeType, GrammarAST node)
@NotNull public ATNState newState(@Nullable GrammarAST node)
@NotNull public ATNState newState()
newState in interface ATNFactorypublic static boolean blockHasWildcardAlt(@NotNull GrammarAST block)
(BLOCK (ALT .)) or (BLOCK (ALT 'a') (ALT .)).public ATNFactory.Handle lexerAltCommands(ATNFactory.Handle alt, ATNFactory.Handle cmds)
lexerAltCommands in interface ATNFactorypublic String lexerCallCommand(GrammarAST ID, GrammarAST arg)
lexerCallCommand in interface ATNFactorypublic String lexerCommand(GrammarAST ID)
lexerCommand in interface ATNFactoryCopyright © 1992-2013 ANTLR. All Rights Reserved.