public class RuleDefinition extends Object implements Rule, AstNodeSkippingPolicy, GrammarRuleKey, CompilableGrammarRule, MemoParsingExpression
This class is not intended to be instantiated or subclassed by clients.
| Constructor and Description |
|---|
RuleDefinition(GrammarRuleKey ruleKey) |
RuleDefinition(String name) |
| Modifier and Type | Method and Description |
|---|---|
Instruction[] |
compile(CompilationHandler compiler)
Compiles this expression into a sequence of instructions.
|
void |
enableMemoization() |
ParsingExpression |
getExpression() |
String |
getName() |
AstNodeType |
getRealAstNodeType() |
GrammarRuleKey |
getRuleKey() |
boolean |
hasToBeSkippedFromAst(AstNode node)
Some AstNode can be pretty useless and makes a global AST less readable.
|
RuleDefinition |
is(Object... e)
Allows to provide definition of a 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.
|
RuleDefinition |
override(Object... e)
Allows to override definition of a grammar rule.
|
void |
recoveryRule() |
void |
setExpression(ParsingExpression expression) |
boolean |
shouldMemoize() |
void |
skip()
Indicates that grammar rule should not lead to creation of AST node - its children should be attached directly to its parent.
|
void |
skipIf(AstNodeSkippingPolicy astNodeSkipPolicy)
Defines policy of creation of AST node for this rule.
|
void |
skipIfOneChild()
Indicates that grammar rule should not lead to creation of AST node if it has exactly one child.
|
String |
toString() |
public RuleDefinition(String name)
public RuleDefinition(GrammarRuleKey ruleKey)
public String getName()
public RuleDefinition is(Object... e)
RuleNote: this method can be called only once for a rule. If it is called more than once, an IllegalStateException will be thrown.
public RuleDefinition override(Object... e)
Rule
This method has the same effect as #is(Object), except that it can be called more than once to redefine a rule from scratch.
public void mock()
Rulepublic void skip()
Rulepublic void skipIf(AstNodeSkippingPolicy astNodeSkipPolicy)
Rulepublic void skipIfOneChild()
RuleskipIfOneChild in interface Rulepublic void recoveryRule()
recoveryRule in interface Rulepublic boolean hasToBeSkippedFromAst(AstNode node)
AstNodeSkippingPolicyhasToBeSkippedFromAst in interface AstNodeSkippingPolicynode - the node that should or not be removed from the ASTpublic AstNodeType getRealAstNodeType()
public GrammarRuleKey getRuleKey()
getRuleKey in interface CompilableGrammarRulepublic ParsingExpression getExpression()
getExpression in interface CompilableGrammarRulepublic void setExpression(ParsingExpression expression)
setExpression in interface CompilableGrammarRulepublic Instruction[] compile(CompilationHandler compiler)
ParsingExpressioncompile in interface ParsingExpressionpublic boolean shouldMemoize()
shouldMemoize in interface MemoParsingExpressionpublic void enableMemoization()
Copyright © 2009–2018 SonarSource. All rights reserved.