Top Fields Constructors Methods
org.antlr.v4.tool

public Class Rule

extends Object
implements AttributeResolver
Class Inheritance
All Implemented Interfaces
org.antlr.v4.tool.AttributeResolver
Known Direct Subclasses
org.antlr.v4.tool.LeftRecursiveRule
Imports
org.antlr.v4.runtime.misc.Pair, org.antlr.v4.tool.ast.ActionAST, .AltAST, .GrammarAST, .PredAST, .RuleAST, org.stringtemplate.v4.misc.MultiMap, java.util.ArrayList, .HashMap, .HashSet, .LinkedHashMap, .List, .Map, .Set

Field Summary

Modifier and TypeField and Description
public int
public List<ActionAST>
actions

Track all executable actions other than named actions like @init and catch/finally (not in an alt).

public Alternative[]
alt

1..n alts

public AttributeDict
public RuleAST
public final boolean
caseInsensitive

If null then use value from global option that is false by default

public List<GrammarAST>
exceptions

Track exception handlers; points at "catch" node of (catch exception action) don't track finally action

public ActionAST
public final Grammar
g

In which grammar does this rule live?

public int
index

All rules have unique index 0..n-1

public boolean
public AttributeDict
public final String
mode

If we're in a lexer grammar, we might be in a mode

public List<GrammarAST>
public final String
public Map<String, ActionAST>
namedActions

Map a name to an action for this rule like @init {...}.

public final int
public static final AttributeDict
predefinedRulePropertiesDict

Rule refs have a predefined set of attributes as well as the return values and args.

public AttributeDict
public static final Set<String>

Constructor Summary

AccessConstructor and Description
public
Rule(Grammar g, String name, RuleAST ast, int numberOfAlts)

public
Rule(Grammar g, String name, RuleAST ast, int numberOfAlts, String lexerMode, boolean caseInsensitive)

Method Summary

Modifier and TypeMethod and Description
public void
defineActionInAlt(int currentAlt, ActionAST actionAST)

public void
defineLexerAction(ActionAST actionAST)

Lexer actions are numbered across rules 0..n-1

public void
definePredicateInAlt(int currentAlt, PredAST predAST)

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Map<String, List<Pair<Integer, AltAST>>>
getAltLabels()

Get # labels.

public LabelElementPair
public MultiMap<String, LabelElementPair>
public Set<String>
public int
getOriginalNumberOfAlts()

Used for recursive rules (subclass), which have 1 alt, but many original alts

public AttributeDict
public Set<String>
public List<AltAST>
public boolean
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public boolean
public Attribute
public boolean
public boolean
public boolean
public boolean
public Attribute
resolveToAttribute(String x, ActionAST node)

Implements org.antlr.v4.tool.AttributeResolver.resolveToAttribute.

$x Attribute: rule arguments, return values, predefined rule prop.
public Attribute
resolveToAttribute(String x, String y, ActionAST node)

Implements org.antlr.v4.tool.AttributeResolver.resolveToAttribute.

$x.y Attribute: x is surrounding rule, label ref (in any alts)
public Rule
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

actionIndexback to summary
public int actionIndex
actionsback to summary
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.

altback to summary
public Alternative[] alt

1..n alts

argsback to summary
public AttributeDict args
astback to summary
public RuleAST ast
caseInsensitiveback to summary
public final boolean caseInsensitive

If null then use value from global option that is false by default

exceptionsback to summary
public List<GrammarAST> exceptions

Track exception handlers; points at "catch" node of (catch exception action) don't track finally action

finallyActionback to summary
public ActionAST finallyAction
gback to summary
public final Grammar g

In which grammar does this rule live?

indexback to summary
public int index

All rules have unique index 0..n-1

isStartRuleback to summary
public boolean isStartRule
localsback to summary
public AttributeDict locals
modeback to summary
public final String mode

If we're in a lexer grammar, we might be in a mode

modifiersback to summary
public List<GrammarAST> modifiers
nameback to summary
public final String name
namedActionsback to summary
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.

numberOfAltsback to summary
public final int numberOfAlts
predefinedRulePropertiesDictback to summary
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, ...

retvalsback to summary
public AttributeDict retvals
validLexerCommandsback to summary
public static final Set<String> validLexerCommands

Constructor Detail

Ruleback to summary
public Rule(Grammar g, String name, RuleAST ast, int numberOfAlts)
Ruleback to summary
public Rule(Grammar g, String name, RuleAST ast, int numberOfAlts, String lexerMode, boolean caseInsensitive)

Method Detail

defineActionInAltback to summary
public void defineActionInAlt(int currentAlt, ActionAST actionAST)
defineLexerActionback to summary
public void defineLexerAction(ActionAST actionAST)

Lexer actions are numbered across rules 0..n-1

definePredicateInAltback to summary
public void definePredicateInAlt(int currentAlt, PredAST predAST)
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getAltLabelsback to summary
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 and AltAST) identifying the alternatives with this label. Unlabeled alternatives are not included in the result.

getAnyLabelDefback to summary
public LabelElementPair getAnyLabelDef(String x)
getElementLabelDefsback to summary
public MultiMap<String, LabelElementPair> getElementLabelDefs()
getElementLabelNamesback to summary
public Set<String> getElementLabelNames()
getOriginalNumberOfAltsback to summary
public int getOriginalNumberOfAlts()

Used for recursive rules (subclass), which have 1 alt, but many original alts

getPredefinedScopeback to summary
public AttributeDict getPredefinedScope(LabelType ltype)
getTokenRefsback to summary
public Set<String> getTokenRefs()
getUnlabeledAltASTsback to summary
public List<AltAST> getUnlabeledAltASTs()
hasAltSpecificContextsback to summary
public boolean hasAltSpecificContexts()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isFragmentback to summary
public boolean isFragment()
resolveRetvalOrPropertyback to summary
public Attribute resolveRetvalOrProperty(String y)
resolvesToAttributeDictback to summary
public boolean resolvesToAttributeDict(String x, ActionAST node)

Implements org.antlr.v4.tool.AttributeResolver.resolvesToAttributeDict.

Annotations
@Override
resolvesToLabelback to summary
public boolean resolvesToLabel(String x, ActionAST node)

Implements org.antlr.v4.tool.AttributeResolver.resolvesToLabel.

Annotations
@Override
resolvesToListLabelback to summary
public boolean resolvesToListLabel(String x, ActionAST node)

Implements org.antlr.v4.tool.AttributeResolver.resolvesToListLabel.

Annotations
@Override
resolvesToTokenback to summary
public boolean resolvesToToken(String x, ActionAST node)

Implements org.antlr.v4.tool.AttributeResolver.resolvesToToken.

Annotations
@Override
resolveToAttributeback to summary
public Attribute resolveToAttribute(String x, ActionAST node)

Implements org.antlr.v4.tool.AttributeResolver.resolveToAttribute.

$x Attribute: rule arguments, return values, predefined rule prop.

Annotations
@Override
resolveToAttributeback to summary
public Attribute resolveToAttribute(String x, String y, ActionAST node)

Implements org.antlr.v4.tool.AttributeResolver.resolveToAttribute.

$x.y Attribute: x is surrounding rule, label ref (in any alts)

Annotations
@Override
resolveToRuleback to summary
public Rule resolveToRule(String x)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override