public class Rule extends java.lang.Object implements AttributeResolver
| Modifier and Type | Field and Description |
|---|---|
int |
actionIndex |
java.util.List<ActionAST> |
actions
Track all executable actions other than named actions like @init
and catch/finally (not in an alt).
|
Alternative[] |
alt
1..n alts
|
AttributeDict |
args |
RuleAST |
ast |
java.util.List<GrammarAST> |
exceptions
Track exception handlers; points at "catch" node of (catch exception action)
don't track finally action
|
ActionAST |
finallyAction |
Grammar |
g
In which grammar does this rule live?
|
int |
index
All rules have unique index 0..n-1
|
boolean |
isStartRule |
AttributeDict |
locals |
java.lang.String |
mode
If we're in a lexer grammar, we might be in a mode
|
java.util.List<GrammarAST> |
modifiers |
java.lang.String |
name |
java.util.Map<java.lang.String,ActionAST> |
namedActions
Map a name to an action for this rule like @init {...}.
|
int |
numberOfAlts |
static AttributeDict |
predefinedRulePropertiesDict
Rule refs have a predefined set of attributes as well as
the return values and args.
|
AttributeDict |
retvals |
static java.util.Set<java.lang.String> |
validLexerCommands |
| Constructor and Description |
|---|
Rule(Grammar g,
java.lang.String name,
RuleAST ast,
int numberOfAlts) |
| Modifier and Type | Method and Description |
|---|---|
void |
defineActionInAlt(int currentAlt,
ActionAST actionAST) |
void |
defineLexerAction(ActionAST actionAST)
Lexer actions are numbered across rules 0..n-1
|
void |
definePredicateInAlt(int currentAlt,
PredAST predAST) |
boolean |
equals(java.lang.Object obj) |
java.util.Map<java.lang.String,java.util.List<Pair<java.lang.Integer,AltAST>>> |
getAltLabels()
Get
# labels. |
LabelElementPair |
getAnyLabelDef(java.lang.String x) |
org.stringtemplate.v4.misc.MultiMap<java.lang.String,LabelElementPair> |
getElementLabelDefs() |
java.util.Set<java.lang.String> |
getElementLabelNames() |
int |
getOriginalNumberOfAlts()
Used for recursive rules (subclass), which have 1 alt, but many original alts
|
AttributeDict |
getPredefinedScope(LabelType ltype) |
java.util.Set<java.lang.String> |
getTokenRefs() |
java.util.List<AltAST> |
getUnlabeledAltASTs() |
boolean |
hasAltSpecificContexts() |
int |
hashCode() |
boolean |
isFragment() |
Attribute |
resolveRetvalOrProperty(java.lang.String y) |
boolean |
resolvesToAttributeDict(java.lang.String x,
ActionAST node) |
boolean |
resolvesToLabel(java.lang.String x,
ActionAST node) |
boolean |
resolvesToListLabel(java.lang.String x,
ActionAST node) |
boolean |
resolvesToToken(java.lang.String x,
ActionAST node) |
Attribute |
resolveToAttribute(java.lang.String x,
ActionAST node)
$x Attribute: rule arguments, return values, predefined rule prop.
|
Attribute |
resolveToAttribute(java.lang.String x,
java.lang.String y,
ActionAST node)
$x.y Attribute: x is surrounding rule, label ref (in any alts)
|
Rule |
resolveToRule(java.lang.String x) |
java.lang.String |
toString() |
public static final AttributeDict predefinedRulePropertiesDict
public static final java.util.Set<java.lang.String> validLexerCommands
public java.lang.String name
public java.util.List<GrammarAST> modifiers
public RuleAST ast
public AttributeDict args
public AttributeDict retvals
public AttributeDict locals
public Grammar g
public java.lang.String mode
public java.util.Map<java.lang.String,ActionAST> namedActions
public java.util.List<GrammarAST> exceptions
public java.util.List<ActionAST> actions
public ActionAST finallyAction
public int numberOfAlts
public boolean isStartRule
public Alternative[] alt
public int index
public int actionIndex
public void defineActionInAlt(int currentAlt,
ActionAST actionAST)
public void defineLexerAction(ActionAST actionAST)
public void definePredicateInAlt(int currentAlt,
PredAST predAST)
public Attribute resolveRetvalOrProperty(java.lang.String y)
public java.util.Set<java.lang.String> getTokenRefs()
public java.util.Set<java.lang.String> getElementLabelNames()
public org.stringtemplate.v4.misc.MultiMap<java.lang.String,LabelElementPair> getElementLabelDefs()
public boolean hasAltSpecificContexts()
public int getOriginalNumberOfAlts()
public java.util.Map<java.lang.String,java.util.List<Pair<java.lang.Integer,AltAST>>> getAltLabels()
# labels. The keys of the map are the labels applied to outer
alternatives of a lexer rule, and the values are collections of pairs
(alternative number and AltAST) identifying the alternatives with
this label. Unlabeled alternatives are not included in the result.public java.util.List<AltAST> getUnlabeledAltASTs()
public Attribute resolveToAttribute(java.lang.String x, ActionAST node)
resolveToAttribute in interface AttributeResolverpublic Attribute resolveToAttribute(java.lang.String x, java.lang.String y, ActionAST node)
resolveToAttribute in interface AttributeResolverpublic boolean resolvesToLabel(java.lang.String x,
ActionAST node)
resolvesToLabel in interface AttributeResolverpublic boolean resolvesToListLabel(java.lang.String x,
ActionAST node)
resolvesToListLabel in interface AttributeResolverpublic boolean resolvesToToken(java.lang.String x,
ActionAST node)
resolvesToToken in interface AttributeResolverpublic boolean resolvesToAttributeDict(java.lang.String x,
ActionAST node)
resolvesToAttributeDict in interface AttributeResolverpublic Rule resolveToRule(java.lang.String x)
public LabelElementPair getAnyLabelDef(java.lang.String x)
public AttributeDict getPredefinedScope(LabelType ltype)
public boolean isFragment()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object