Package org.antlr.v4.tool
Class Rule
java.lang.Object
org.antlr.v4.tool.Rule
- All Implemented Interfaces:
AttributeResolver
- Direct Known Subclasses:
LeftRecursiveRule
-
Field Summary
FieldsModifier and TypeFieldDescriptionint
Track all executable actions other than named actions like @init and catch/finally (not in an alt).1..n altsTrack exception handlers; points at "catch" node of (catch exception action) don't track finally actionIn which grammar does this rule live?int
All rules have unique index 0..n-1boolean
If we're in a lexer grammar, we might be in a modeMap a name to an action for this rule like @init {...}.int
static final AttributeDict
Rule refs have a predefined set of attributes as well as the return values and args. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
defineActionInAlt
(int currentAlt, ActionAST actionAST) void
defineLexerAction
(ActionAST actionAST) Lexer actions are numbered across rules 0..n-1void
definePredicateInAlt
(int currentAlt, PredAST predAST) boolean
Get#
labels.org.stringtemplate.v4.misc.MultiMap
<String, LabelElementPair> int
Used for recursive rules (subclass), which have 1 alt, but many original altsgetPredefinedScope
(LabelType ltype) boolean
int
hashCode()
boolean
boolean
resolvesToAttributeDict
(String x, ActionAST node) boolean
resolvesToLabel
(String x, ActionAST node) boolean
resolvesToListLabel
(String x, ActionAST node) boolean
resolvesToToken
(String x, ActionAST node) resolveToAttribute
(String x, String y, ActionAST node) $x.y Attribute: x is surrounding rule, label ref (in any alts)resolveToAttribute
(String x, ActionAST node) $x Attribute: rule arguments, return values, predefined rule prop.toString()
-
Field Details
-
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
-
name
-
modifiers
-
ast
-
args
-
retvals
-
locals
-
g
In which grammar does this rule live? -
mode
If we're in a lexer grammar, we might be in a mode -
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
Track exception handlers; points at "catch" node of (catch exception action) don't track finally action -
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
-
numberOfAlts
public int numberOfAlts -
isStartRule
public boolean isStartRule -
alt
1..n alts -
index
public int indexAll rules have unique index 0..n-1 -
actionIndex
public int actionIndex
-
-
Constructor Details
-
Rule
-
-
Method Details
-
defineActionInAlt
-
defineLexerAction
Lexer actions are numbered across rules 0..n-1 -
definePredicateInAlt
-
resolveRetvalOrProperty
-
getTokenRefs
-
getElementLabelNames
-
getElementLabelDefs
-
hasAltSpecificContexts
public boolean hasAltSpecificContexts() -
getOriginalNumberOfAlts
public int getOriginalNumberOfAlts()Used for recursive rules (subclass), which have 1 alt, but many original alts -
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
-
resolveToAttribute
$x Attribute: rule arguments, return values, predefined rule prop.- Specified by:
resolveToAttribute
in interfaceAttributeResolver
-
resolveToAttribute
$x.y Attribute: x is surrounding rule, label ref (in any alts)- Specified by:
resolveToAttribute
in interfaceAttributeResolver
-
resolvesToLabel
- Specified by:
resolvesToLabel
in interfaceAttributeResolver
-
resolvesToListLabel
- Specified by:
resolvesToListLabel
in interfaceAttributeResolver
-
resolvesToToken
- Specified by:
resolvesToToken
in interfaceAttributeResolver
-
resolvesToAttributeDict
- Specified by:
resolvesToAttributeDict
in interfaceAttributeResolver
-
resolveToRule
-
getAnyLabelDef
-
getPredefinedScope
-
isFragment
public boolean isFragment() -
hashCode
public int hashCode() -
equals
-
toString
-