| java.lang.Object org.antlr.tool.Rule
Rule | public class Rule (Code) | | Combine the info associated with a rule
|
Constructor Summary | |
public | Rule(Grammar grammar, String ruleName, int ruleIndex, int numberOfAlts) |
Method Summary | |
public void | defineLabel(antlr.Token label, GrammarAST elementRef, int type) | public void | defineNamedAction(GrammarAST ampersandAST, GrammarAST nameAST, GrammarAST actionAST) Given @scope::name {action} define it for this grammar. | public Map<String, GrammarAST> | getActions() | public Set | getAllRuleRefsInAltsWithRewrites() For use with rewrite rules, we must track all rule AST results on the
left-hand-side; so we need Lists. | public Set | getAllTokenRefsInAltsWithRewrites() For use with rewrite rules, we must track all tokens matched on the
left-hand-side; so we need Lists. | public AttributeScope | getAttributeScope(String name) | public String | getElementLabel(String refdSymbol, int outerAltNum, CodeGenerator generator) For references to tokens rather than by label such as $ID, we
need to get the existing label for the ID ref or create a new
one. | public boolean | getHasMultipleReturnValues() If a rule has no user-defined return values and nobody references
it's start/stop (predefined attributes), then there is no need to
define a struct; otherwise for now we assume a struct. | public boolean | getHasReturnValue() | public boolean | getHasSingleReturnValue() | public List<GrammarAST> | getInlineActions() | public Grammar.LabelElementPair | getLabel(String name) | public AttributeScope | getLocalAttributeScope(String name) | public Grammar.LabelElementPair | getRuleLabel(String name) | public Map | getRuleLabels() | public Grammar.LabelElementPair | getRuleListLabel(String name) | public Map | getRuleListLabels() | public List | getRuleRefsInAlt(String ref, int outerAltNum) | public Set | getRuleRefsInAlt(int outerAltNum) | public String | getSingleValueReturnName() | public String | getSingleValueReturnType() | public Grammar.LabelElementPair | getTokenLabel(String name) | public Grammar.LabelElementPair | getTokenListLabel(String name) | public List | getTokenRefsInAlt(String ref, int outerAltNum) | public Set | getTokenRefsInAlt(int altNum) | public boolean | hasRewrite(int i) | public void | setActions(Map<String, GrammarAST> actions) | public String | setOption(String key, Object value, antlr.Token optionsStartToken) Save the option key/value pair and process it; return the key
or null if invalid option. | public void | setOptions(Map options, antlr.Token optionsStartToken) | public String | toString() | public void | trackAltsWithRewrites(GrammarAST altAST, int outerAltNum) Track which rules have rewrite rules. | public void | trackInlineAction(GrammarAST actionAST) | public void | trackRuleReferenceInAlt(GrammarAST refAST, int outerAltNum) | public void | trackTokenReferenceInAlt(GrammarAST refAST, int outerAltNum) Track a token ID or literal like '+' and "void" as having been referenced
somewhere within the alts (not rewrite sections) of a rule. |
actions | protected Map<String, GrammarAST> actions(Code) | | Map a name to an action for this rule. Currently init is only
one we use, but we can add more in future.
The code generator will use this to fill holes in the rule template.
I track the AST node for the action in case I need the line number
for errors. A better name is probably namedActions, but I don't
want everyone to have to change their code gen templates now.
|
altToRuleRefMap | protected Map<String, List<GrammarAST>>[] altToRuleRefMap(Code) | | Each alt has a Map>; range 1..numberOfAlts
So, if there are 3 expr refs in a rule's alt number 2, you'll have
altToRuleRef[2].get("expr").size()==3. This is used to see if $expr is ok.
There must be only one expr reference in the alt for $expr to be ok in
an action--must be unique.
Rewrite rules force tracking of all rule result ASTs. 1..n
|
altToTokenRefMap | protected Map<String, List<GrammarAST>>[] altToTokenRefMap(Code) | | Each alt has a Map>; range 1..numberOfAlts.
So, if there are 3 ID refs in a rule's alt number 2, you'll have
altToTokenRef[2].get("ID").size()==3. This is used to see if $ID is ok.
There must be only one ID reference in the alt for $ID to be ok in
an action--must be unique.
This also tracks '+' and "int" literal token references
(if not in LEXER).
Rewrite rules force tracking of all tokens.
|
altsWithRewrites | protected boolean[] altsWithRewrites(Code) | | Track which alts have rewrite rules associated with them. 1..n
|
argActionAST | public GrammarAST argActionAST(Code) | | For convenience, track the argument def AST action node if any
|
charLabels | public LinkedHashMap charLabels(Code) | | A list of all LabelElementPair attached to single char literals like x='a'
|
grammar | public Grammar grammar(Code) | | To which grammar does this belong?
|
inlineActions | protected List<GrammarAST> inlineActions(Code) | | Track all executable actions other than named actions like @init.
Also tracks exception handlers, predicates, and rewrite rewrites.
We need to examine these actions before code generation so
that we can detect refs to $rule.attr etc...
|
isSynPred | public boolean isSynPred(Code) | | |
legalOptions | final public static Set legalOptions(Code) | | |
numberOfAlts | public int numberOfAlts(Code) | | |
options | protected Map options(Code) | | This rule's options
|
referencedPredefinedRuleAttributes | public boolean referencedPredefinedRuleAttributes(Code) | | Do not generate start, stop etc... in a return value struct unless
somebody references $r.start somewhere.
|
returnScope | public AttributeScope returnScope(Code) | | The return values of a rule and predefined rule attributes
|
ruleLabels | public LinkedHashMap ruleLabels(Code) | | A list of all LabelElementPair attached to rule references like f=field
|
ruleListLabels | public LinkedHashMap ruleListLabels(Code) | | A list of all rule ref list LabelElementPair like ids+=expr
|
ruleScope | public AttributeScope ruleScope(Code) | | the attributes defined with "scope {...}" inside a rule
|
tokenLabels | public LinkedHashMap tokenLabels(Code) | | A list of all LabelElementPair attached to tokens like id=ID
|
tokenListLabels | public LinkedHashMap tokenListLabels(Code) | | A list of all Token list LabelElementPair like ids+=ID
|
useScopes | public List useScopes(Code) | | A list of scope names (String) used by this rule
|
defineLabel | public void defineLabel(antlr.Token label, GrammarAST elementRef, int type)(Code) | | |
defineNamedAction | public void defineNamedAction(GrammarAST ampersandAST, GrammarAST nameAST, GrammarAST actionAST)(Code) | | Given @scope::name {action} define it for this grammar. Later,
the code generator will ask for the actions table.
|
getAllRuleRefsInAltsWithRewrites | public Set getAllRuleRefsInAltsWithRewrites()(Code) | | For use with rewrite rules, we must track all rule AST results on the
left-hand-side; so we need Lists. This is a unique list of all
rule results for which the rule needs a list of results.
|
getAllTokenRefsInAltsWithRewrites | public Set getAllTokenRefsInAltsWithRewrites()(Code) | | For use with rewrite rules, we must track all tokens matched on the
left-hand-side; so we need Lists. This is a unique list of all
token types for which the rule needs a list of tokens. This
is called from the rule template not directly by the code generator.
|
getElementLabel | public String getElementLabel(String refdSymbol, int outerAltNum, CodeGenerator generator)(Code) | | For references to tokens rather than by label such as $ID, we
need to get the existing label for the ID ref or create a new
one.
|
getHasMultipleReturnValues | public boolean getHasMultipleReturnValues()(Code) | | If a rule has no user-defined return values and nobody references
it's start/stop (predefined attributes), then there is no need to
define a struct; otherwise for now we assume a struct. A rule also
has multiple return values if you are building trees or templates.
|
getHasReturnValue | public boolean getHasReturnValue()(Code) | | |
getHasSingleReturnValue | public boolean getHasSingleReturnValue()(Code) | | |
getLocalAttributeScope | public AttributeScope getLocalAttributeScope(String name)(Code) | | Get the arg, return value, or predefined property for this rule
|
getRuleLabels | public Map getRuleLabels()(Code) | | |
getRuleListLabels | public Map getRuleListLabels()(Code) | | |
getRuleRefsInAlt | public Set getRuleRefsInAlt(int outerAltNum)(Code) | | |
getSingleValueReturnName | public String getSingleValueReturnName()(Code) | | |
getSingleValueReturnType | public String getSingleValueReturnType()(Code) | | |
getTokenRefsInAlt | public List getTokenRefsInAlt(String ref, int outerAltNum)(Code) | | |
getTokenRefsInAlt | public Set getTokenRefsInAlt(int altNum)(Code) | | |
hasRewrite | public boolean hasRewrite(int i)(Code) | | |
setOption | public String setOption(String key, Object value, antlr.Token optionsStartToken)(Code) | | Save the option key/value pair and process it; return the key
or null if invalid option.
|
setOptions | public void setOptions(Map options, antlr.Token optionsStartToken)(Code) | | |
trackAltsWithRewrites | public void trackAltsWithRewrites(GrammarAST altAST, int outerAltNum)(Code) | | Track which rules have rewrite rules. Pass in the ALT node
for the alt so we can check for problems when output=template,
rewrite=true, and grammar type is tree parser.
|
trackRuleReferenceInAlt | public void trackRuleReferenceInAlt(GrammarAST refAST, int outerAltNum)(Code) | | |
trackTokenReferenceInAlt | public void trackTokenReferenceInAlt(GrammarAST refAST, int outerAltNum)(Code) | | Track a token ID or literal like '+' and "void" as having been referenced
somewhere within the alts (not rewrite sections) of a rule.
This differs from Grammar.altReferencesTokenID(), which tracks all
token IDs to check for token IDs without corresponding lexer rules.
|
|
|