Package org.antlr.v4.tool
Class Rule
- java.lang.Object
-
- org.antlr.v4.tool.Rule
-
- All Implemented Interfaces:
AttributeResolver
- Direct Known Subclasses:
LeftRecursiveRule
public class Rule extends java.lang.Object implements AttributeResolver
-
-
Field Summary
Fields Modifier and Type Field 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 altsAttributeDict
args
RuleAST
ast
java.util.List<GrammarAST>
exceptions
Track exception handlers; points at "catch" node of (catch exception action) don't track finally actionActionAST
finallyAction
Grammar
g
In which grammar does this rule live?int
index
All rules have unique index 0..n-1boolean
isStartRule
AttributeDict
locals
java.lang.String
mode
If we're in a lexer grammar, we might be in a modejava.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
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
defineActionInAlt(int currentAlt, ActionAST actionAST)
void
defineLexerAction(ActionAST actionAST)
Lexer actions are numbered across rules 0..n-1void
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 altsAttributeDict
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, java.lang.String y, ActionAST node)
$x.y Attribute: x is surrounding rule, label ref (in any alts)Attribute
resolveToAttribute(java.lang.String x, ActionAST node)
$x Attribute: rule arguments, return values, predefined rule prop.Rule
resolveToRule(java.lang.String x)
java.lang.String
toString()
-
-
-
Field Detail
-
predefinedRulePropertiesDict
public static final AttributeDict predefinedRulePropertiesDict
Rule refs have a predefined set of attributes as well as the return values and args. These must be consistent with ActionTranslator.rulePropToModelMap, ...
-
validLexerCommands
public static final java.util.Set<java.lang.String> validLexerCommands
-
name
public java.lang.String name
-
modifiers
public java.util.List<GrammarAST> modifiers
-
ast
public RuleAST ast
-
args
public AttributeDict args
-
retvals
public AttributeDict retvals
-
locals
public AttributeDict locals
-
g
public Grammar g
In which grammar does this rule live?
-
mode
public java.lang.String mode
If we're in a lexer grammar, we might be in a mode
-
namedActions
public java.util.Map<java.lang.String,ActionAST> namedActions
Map a name to an action for this rule like @init {...}. 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.
-
exceptions
public java.util.List<GrammarAST> exceptions
Track exception handlers; points at "catch" node of (catch exception action) don't track finally action
-
actions
public java.util.List<ActionAST> actions
Track all executable actions other than named actions like @init and catch/finally (not in an alt). Also tracks predicates, rewrite actions. We need to examine these actions before code generation so that we can detect refs to $rule.attr etc... This tracks per rule; Alternative objs also track per alt.
-
finallyAction
public ActionAST finallyAction
-
numberOfAlts
public int numberOfAlts
-
isStartRule
public boolean isStartRule
-
alt
public Alternative[] alt
1..n alts
-
index
public int index
All rules have unique index 0..n-1
-
actionIndex
public int actionIndex
-
-
Method Detail
-
defineActionInAlt
public void defineActionInAlt(int currentAlt, ActionAST actionAST)
-
defineLexerAction
public void defineLexerAction(ActionAST actionAST)
Lexer actions are numbered across rules 0..n-1
-
definePredicateInAlt
public void definePredicateInAlt(int currentAlt, PredAST predAST)
-
resolveRetvalOrProperty
public Attribute resolveRetvalOrProperty(java.lang.String y)
-
getTokenRefs
public java.util.Set<java.lang.String> getTokenRefs()
-
getElementLabelNames
public java.util.Set<java.lang.String> getElementLabelNames()
-
getElementLabelDefs
public org.stringtemplate.v4.misc.MultiMap<java.lang.String,LabelElementPair> getElementLabelDefs()
-
hasAltSpecificContexts
public boolean hasAltSpecificContexts()
-
getOriginalNumberOfAlts
public int getOriginalNumberOfAlts()
Used for recursive rules (subclass), which have 1 alt, but many original alts
-
getAltLabels
public java.util.Map<java.lang.String,java.util.List<Pair<java.lang.Integer,AltAST>>> getAltLabels()
Get#
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 andAltAST
) identifying the alternatives with this label. Unlabeled alternatives are not included in the result.
-
getUnlabeledAltASTs
public java.util.List<AltAST> getUnlabeledAltASTs()
-
resolveToAttribute
public Attribute resolveToAttribute(java.lang.String x, ActionAST node)
$x Attribute: rule arguments, return values, predefined rule prop.- Specified by:
resolveToAttribute
in interfaceAttributeResolver
-
resolveToAttribute
public Attribute resolveToAttribute(java.lang.String x, java.lang.String y, ActionAST node)
$x.y Attribute: x is surrounding rule, label ref (in any alts)- Specified by:
resolveToAttribute
in interfaceAttributeResolver
-
resolvesToLabel
public boolean resolvesToLabel(java.lang.String x, ActionAST node)
- Specified by:
resolvesToLabel
in interfaceAttributeResolver
-
resolvesToListLabel
public boolean resolvesToListLabel(java.lang.String x, ActionAST node)
- Specified by:
resolvesToListLabel
in interfaceAttributeResolver
-
resolvesToToken
public boolean resolvesToToken(java.lang.String x, ActionAST node)
- Specified by:
resolvesToToken
in interfaceAttributeResolver
-
resolvesToAttributeDict
public boolean resolvesToAttributeDict(java.lang.String x, ActionAST node)
- Specified by:
resolvesToAttributeDict
in interfaceAttributeResolver
-
resolveToRule
public Rule resolveToRule(java.lang.String x)
-
getAnyLabelDef
public LabelElementPair getAnyLabelDef(java.lang.String x)
-
getPredefinedScope
public AttributeDict getPredefinedScope(LabelType ltype)
-
isFragment
public boolean isFragment()
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-