Class Rule

    • 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
      • 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
      • index

        public int index
        All rules have unique index 0..n-1
      • actionIndex

        public int actionIndex
    • Constructor Detail

      • Rule

        public Rule​(Grammar g,
                    java.lang.String name,
                    RuleAST ast,
                    int numberOfAlts)
    • 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 and AltAST) identifying the alternatives with this label. Unlabeled alternatives are not included in the result.
      • getUnlabeledAltASTs

        public java.util.List<AltAST> getUnlabeledAltASTs()
      • resolveToRule

        public Rule resolveToRule​(java.lang.String x)
      • getAnyLabelDef

        public LabelElementPair getAnyLabelDef​(java.lang.String x)
      • isFragment

        public boolean isFragment()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object