public class Rule extends Object
Modifier and Type | Field and Description |
---|---|
protected Map<String,Object> |
actions
Map a name to an action for this rule.
|
protected Map<String,List<GrammarAST>>[] |
altToRuleRefMap
Each alt has a Map<ruleRefName,List<ruleRefAST>>; 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.
|
protected Map<String,List<GrammarAST>>[] |
altToTokenRefMap
Each alt has a Map<tokenRefName,List<tokenRefAST>>; range 1..numberOfAlts.
|
GrammarAST |
argActionAST
For convenience, track the argument def AST action node if any
|
LinkedHashMap<String,Grammar.LabelElementPair> |
charLabels
A list of all LabelElementPair attached to single char literals like x='a'
|
GrammarAST |
EORNode |
Grammar |
grammar
To which grammar does this belong?
|
boolean |
imported |
int |
index |
protected List<GrammarAST> |
inlineActions
Track all executable actions other than named actions like @init.
|
boolean |
isSynPred |
protected Map<String,Grammar.LabelElementPair> |
labelNameSpace
All labels go in here (plus being split per the above lists) to
catch dup label and label type mismatches.
|
static Set<String> |
legalOptions |
String |
modifier |
String |
name |
int |
numberOfAlts |
protected Map<String,Object> |
options
This rule's options
|
AttributeScope |
parameterScope |
boolean |
referencedPredefinedRuleAttributes
Do not generate start, stop etc...
|
AttributeScope |
returnScope
The return values of a rule and predefined rule attributes
|
LinkedHashMap<String,Grammar.LabelElementPair> |
ruleLabels
A list of all LabelElementPair attached to rule references like f=field
|
LinkedHashMap<String,Grammar.LabelElementPair> |
ruleListLabels
A list of all rule ref list LabelElementPair like ids+=expr
|
AttributeScope |
ruleScope
the attributes defined with "scope {...}" inside a rule
|
NFAState |
startState |
NFAState |
stopState |
static boolean |
supportsLabelOptimization |
Set<String> |
throwsSpec
Exceptions that this rule can throw
|
LinkedHashMap<String,Grammar.LabelElementPair> |
tokenLabels
A list of all LabelElementPair attached to tokens like id=ID
|
LinkedHashMap<String,Grammar.LabelElementPair> |
tokenListLabels
A list of all Token list LabelElementPair like ids+=ID
|
GrammarAST |
tree
The AST representing the whole rule
|
List<String> |
useScopes
A list of scope names (String) used by this rule
|
LinkedHashMap<String,Grammar.LabelElementPair> |
wildcardTreeLabels
A list of all LabelElementPair attached to tokens like x=.
|
LinkedHashMap<String,Grammar.LabelElementPair> |
wildcardTreeListLabels
A list of all LabelElementPair attached to tokens like x+=.
|
Constructor and Description |
---|
Rule(Grammar grammar,
String ruleName,
int ruleIndex,
int numberOfAlts) |
Modifier and Type | Method and Description |
---|---|
void |
defineLabel(Token label,
GrammarAST elementRef,
int type) |
void |
defineNamedAction(GrammarAST ampersandAST,
GrammarAST nameAST,
GrammarAST actionAST)
Given @scope::name {action} define it for this grammar.
|
Map<String,Object> |
getActions() |
Set<String> |
getAllRuleRefsInAltsWithRewrites()
For use with rewrite rules, we must track all rule AST results on the
left-hand-side; so we need Lists.
|
Set<String> |
getAllTokenRefsInAltsWithRewrites()
For use with rewrite rules, we must track all tokens matched on the
left-hand-side; so we need Lists.
|
AttributeScope |
getAttributeScope(String name)
Return the scope containing name
|
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.
|
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.
|
boolean |
getHasReturnValue() |
boolean |
getHasSingleReturnValue() |
List<GrammarAST> |
getInlineActions() |
Grammar.LabelElementPair |
getLabel(String name) |
AttributeScope |
getLocalAttributeScope(String name)
Get the arg, return value, or predefined property for this rule
|
Grammar.LabelElementPair |
getRuleLabel(String name) |
Map<String,Grammar.LabelElementPair> |
getRuleLabels() |
Grammar.LabelElementPair |
getRuleListLabel(String name) |
Map<String,Grammar.LabelElementPair> |
getRuleListLabels() |
Set<String> |
getRuleRefsInAlt(int outerAltNum) |
List<GrammarAST> |
getRuleRefsInAlt(String ref,
int outerAltNum) |
static int |
getRuleType(String ruleName) |
String |
getSingleValueReturnName() |
String |
getSingleValueReturnType() |
Grammar.LabelElementPair |
getTokenLabel(String name) |
Grammar.LabelElementPair |
getTokenListLabel(String name) |
Set<String> |
getTokenRefsInAlt(int altNum) |
List<GrammarAST> |
getTokenRefsInAlt(String ref,
int outerAltNum) |
boolean |
hasRewrite(int i) |
void |
setActions(Map<String,Object> actions) |
String |
setOption(String key,
Object value,
Token optionsStartToken)
Save the option key/value pair and process it; return the key
or null if invalid option.
|
void |
setOptions(Map<String,Object> options,
Token optionsStartToken) |
String |
toString()
Used during grammar imports to see if sets of rules intersect...
|
void |
trackInlineAction(GrammarAST actionAST) |
void |
trackRuleReferenceInAlt(GrammarAST refAST,
int outerAltNum) |
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.
|
public static final boolean supportsLabelOptimization
public String name
public int index
public String modifier
public NFAState startState
public NFAState stopState
public GrammarAST tree
public Grammar grammar
public GrammarAST argActionAST
public GrammarAST EORNode
public AttributeScope returnScope
public AttributeScope parameterScope
public AttributeScope ruleScope
public LinkedHashMap<String,Grammar.LabelElementPair> tokenLabels
public LinkedHashMap<String,Grammar.LabelElementPair> wildcardTreeLabels
public LinkedHashMap<String,Grammar.LabelElementPair> wildcardTreeListLabels
public LinkedHashMap<String,Grammar.LabelElementPair> charLabels
public LinkedHashMap<String,Grammar.LabelElementPair> ruleLabels
public LinkedHashMap<String,Grammar.LabelElementPair> tokenListLabels
public LinkedHashMap<String,Grammar.LabelElementPair> ruleListLabels
protected Map<String,Grammar.LabelElementPair> labelNameSpace
protected Map<String,Object> actions
protected List<GrammarAST> inlineActions
public int numberOfAlts
protected Map<String,List<GrammarAST>>[] altToTokenRefMap
protected Map<String,List<GrammarAST>>[] altToRuleRefMap
public boolean referencedPredefinedRuleAttributes
public boolean isSynPred
public boolean imported
public static int getRuleType(String ruleName)
public void defineLabel(Token label, GrammarAST elementRef, int type)
public Grammar.LabelElementPair getLabel(String name)
public Grammar.LabelElementPair getTokenLabel(String name)
public Map<String,Grammar.LabelElementPair> getRuleLabels()
public Map<String,Grammar.LabelElementPair> getRuleListLabels()
public Grammar.LabelElementPair getRuleLabel(String name)
public Grammar.LabelElementPair getTokenListLabel(String name)
public Grammar.LabelElementPair getRuleListLabel(String name)
public void trackTokenReferenceInAlt(GrammarAST refAST, int outerAltNum)
public List<GrammarAST> getTokenRefsInAlt(String ref, int outerAltNum)
public void trackRuleReferenceInAlt(GrammarAST refAST, int outerAltNum)
public List<GrammarAST> getRuleRefsInAlt(String ref, int outerAltNum)
public Set<String> getAllTokenRefsInAltsWithRewrites()
public Set<String> getAllRuleRefsInAltsWithRewrites()
public List<GrammarAST> getInlineActions()
public boolean hasRewrite(int i)
public AttributeScope getAttributeScope(String name)
public AttributeScope getLocalAttributeScope(String name)
public String getElementLabel(String refdSymbol, int outerAltNum, CodeGenerator generator)
public boolean getHasMultipleReturnValues()
public boolean getHasSingleReturnValue()
public boolean getHasReturnValue()
public String getSingleValueReturnType()
public String getSingleValueReturnName()
public void defineNamedAction(GrammarAST ampersandAST, GrammarAST nameAST, GrammarAST actionAST)
public void trackInlineAction(GrammarAST actionAST)
public String setOption(String key, Object value, Token optionsStartToken)
Copyright © 1992–2015 ANTLR. All rights reserved.