public final class RuleDefinition extends java.lang.Object implements Rule, AstNodeSkippingPolicy
Modifier and Type | Method and Description |
---|---|
RuleMatcher |
getRule() |
boolean |
hasToBeSkippedFromAst(AstNode node)
Some AstNode can be pretty useless and makes a global AST less readable.
|
RuleDefinition |
is(java.lang.Object... matchers)
This method allows to provide the definition of a context-free grammar rule.
|
void |
mock()
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
|
static RuleDefinition |
newRuleBuilder(RuleMatcher ruleMatcher) |
static RuleDefinition |
newRuleBuilder(java.lang.String ruleName) |
RuleDefinition |
override(java.lang.Object... matchers)
This method has the same effect as
RuleImpl#is(Object...) , except that it can be called more than once to redefine a rule from
scratch. |
void |
recoveryRule()
A rule should be flagged as being a "Recovery" rule if it's responsibility is to consume
some bad tokens in order to recover from a parsing error.
|
protected void |
setMatcher(Matcher matcher) |
void |
setRuleMatcher(RuleMatcher ruleMatcher) |
void |
skip()
Remove this node from the AST and attached its children directly to its parent
|
void |
skipIf(AstNodeSkippingPolicy astNodeSkipPolicy)
Remove this node from the AST according to a provided policy
|
void |
skipIfOneChild()
Remove this node from the AST if it has exactly 1 child
|
java.lang.String |
toString() |
public static RuleDefinition newRuleBuilder(java.lang.String ruleName)
public static RuleDefinition newRuleBuilder(RuleMatcher ruleMatcher)
public RuleMatcher getRule()
public void setRuleMatcher(RuleMatcher ruleMatcher)
public RuleDefinition is(java.lang.Object... matchers)
Rule
Rule.override(Object...)
method must be used.public RuleDefinition override(java.lang.Object... matchers)
Rule
RuleImpl#is(Object...)
, except that it can be called more than once to redefine a rule from
scratch. It can be used if the rule has to be redefined later (for instance in a grammar extension).public void mock()
Rule
public void skip()
Rule
protected void setMatcher(Matcher matcher)
public void skipIf(AstNodeSkippingPolicy astNodeSkipPolicy)
Rule
public void skipIfOneChild()
Rule
skipIfOneChild
in interface Rule
public void recoveryRule()
Rule
RecognitionExceptionListener
injected into the Parser
are automatically
notified.recoveryRule
in interface Rule
RecognitionExceptionListener
public java.lang.String toString()
toString
in class java.lang.Object
public boolean hasToBeSkippedFromAst(AstNode node)
AstNodeSkippingPolicy
hasToBeSkippedFromAst
in interface AstNodeSkippingPolicy
node
- the node that should or not be removed from the ASTCopyright © 2012 SonarSource. All Rights Reserved.