Class RuleDefinition

java.lang.Object
com.sonar.sslr.impl.matcher.RuleDefinition
All Implemented Interfaces:
AstNodeSkippingPolicy, AstNodeType, Rule, Matcher, GrammarRuleKey, Matcher, CompilableGrammarRule, MemoParsingExpression, ParsingExpression

This class is not intended to be instantiated or subclassed by clients.

  • Constructor Details

    • RuleDefinition

      public RuleDefinition(String name)
    • RuleDefinition

      public RuleDefinition(GrammarRuleKey ruleKey)
  • Method Details

    • getName

      public String getName()
    • is

      public RuleDefinition is(Object... e)
      Description copied from interface: Rule
      Allows to provide definition of a grammar rule.

      Note: this method can be called only once for a rule. If it is called more than once, an IllegalStateException will be thrown.

      Specified by:
      is in interface Rule
      Parameters:
      e - expression of grammar that defines this rule
      Returns:
      this (for method chaining)
    • override

      public RuleDefinition override(Object... e)
      Description copied from interface: Rule
      Allows to override definition of a grammar rule.

      This method has the same effect as

      invalid reference
      #is(Object)
      , except that it can be called more than once to redefine a rule from scratch.
      Specified by:
      override in interface Rule
      Parameters:
      e - expression of grammar that defines this rule
      Returns:
      this (for method chaining)
    • mock

      public void mock()
      Description copied from interface: Rule
      Utility method used for unit testing in order to dynamically replace the definition of the rule to match as soon as a token whose value equals the name of the rule is encountered.
      Specified by:
      mock in interface Rule
    • skip

      public void skip()
      Description copied from interface: Rule
      Indicates that grammar rule should not lead to creation of AST node - its children should be attached directly to its parent.
      Specified by:
      skip in interface Rule
    • skipIfOneChild

      public void skipIfOneChild()
      Description copied from interface: Rule
      Indicates that grammar rule should not lead to creation of AST node if it has exactly one child.
      Specified by:
      skipIfOneChild in interface Rule
    • hasToBeSkippedFromAst

      public boolean hasToBeSkippedFromAst(AstNode node)
      Description copied from interface: AstNodeSkippingPolicy
      Some AstNode can be pretty useless and makes a global AST less readable. This method allows to automatically remove those AstNode from the AST.
      Specified by:
      hasToBeSkippedFromAst in interface AstNodeSkippingPolicy
      Parameters:
      node - the node that should or not be removed from the AST
      Returns:
      true if AstNode with this type must be skipped from the AST.
    • getRealAstNodeType

      public AstNodeType getRealAstNodeType()
      Since:
      1.18
    • getRuleKey

      public GrammarRuleKey getRuleKey()
      Specified by:
      getRuleKey in interface CompilableGrammarRule
    • getExpression

      public ParsingExpression getExpression()
      Specified by:
      getExpression in interface CompilableGrammarRule
    • setExpression

      public void setExpression(ParsingExpression expression)
      Specified by:
      setExpression in interface CompilableGrammarRule
    • compile

      public Instruction[] compile(CompilationHandler compiler)
      Description copied from interface: ParsingExpression
      Compiles this expression into a sequence of instructions.
      Specified by:
      compile in interface ParsingExpression
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • shouldMemoize

      public boolean shouldMemoize()
      Specified by:
      shouldMemoize in interface MemoParsingExpression
    • enableMemoization

      public void enableMemoization()