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 Object implements AttributeResolver
-
-
Field Summary
Fields Modifier and Type Field Description int
actionIndex
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
boolean
caseInsensitive
If null then use value from global option that is false by defaultList<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
String
mode
If we're in a lexer grammar, we might be in a modeList<GrammarAST>
modifiers
String
name
Map<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 Set<String>
validLexerCommands
-
Method Summary
-
-
-
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, ...
-
name
public final String name
-
modifiers
public List<GrammarAST> modifiers
-
ast
public RuleAST ast
-
args
public AttributeDict args
-
retvals
public AttributeDict retvals
-
locals
public AttributeDict locals
-
g
public final Grammar g
In which grammar does this rule live?
-
mode
public final String mode
If we're in a lexer grammar, we might be in a mode
-
caseInsensitive
public final boolean caseInsensitive
If null then use value from global option that is false by default
-
namedActions
public Map<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 List<GrammarAST> exceptions
Track exception handlers; points at "catch" node of (catch exception action) don't track finally action
-
actions
public 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 final 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)
-
getElementLabelDefs
public org.stringtemplate.v4.misc.MultiMap<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 Map<String,List<Pair<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.
-
resolveToAttribute
public Attribute resolveToAttribute(String x, ActionAST node)
$x Attribute: rule arguments, return values, predefined rule prop.- Specified by:
resolveToAttribute
in interfaceAttributeResolver
-
resolveToAttribute
public Attribute resolveToAttribute(String x, 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(String x, ActionAST node)
- Specified by:
resolvesToLabel
in interfaceAttributeResolver
-
resolvesToListLabel
public boolean resolvesToListLabel(String x, ActionAST node)
- Specified by:
resolvesToListLabel
in interfaceAttributeResolver
-
resolvesToToken
public boolean resolvesToToken(String x, ActionAST node)
- Specified by:
resolvesToToken
in interfaceAttributeResolver
-
resolvesToAttributeDict
public boolean resolvesToAttributeDict(String x, ActionAST node)
- Specified by:
resolvesToAttributeDict
in interfaceAttributeResolver
-
getAnyLabelDef
public LabelElementPair getAnyLabelDef(String x)
-
getPredefinedScope
public AttributeDict getPredefinedScope(LabelType ltype)
-
isFragment
public boolean isFragment()
-
-