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)
Rule
Note: 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()
Rule
public void skip()
Rule
public void skipIf(AstNodeSkippingPolicy astNodeSkipPolicy)
Rule
public void skipIfOneChild()
Rule
skipIfOneChild
in interface Rule
public void recoveryRule()
recoveryRule
in interface Rule
public boolean hasToBeSkippedFromAst(AstNode node)
AstNodeSkippingPolicy
hasToBeSkippedFromAst
in interface AstNodeSkippingPolicy
node
- the node that should or not be removed from the ASTpublic AstNodeType getRealAstNodeType()
public GrammarRuleKey getRuleKey()
getRuleKey
in interface CompilableGrammarRule
public ParsingExpression getExpression()
getExpression
in interface CompilableGrammarRule
public void setExpression(ParsingExpression expression)
setExpression
in interface CompilableGrammarRule
public Instruction[] compile(CompilationHandler compiler)
ParsingExpression
compile
in interface ParsingExpression
public boolean shouldMemoize()
shouldMemoize
in interface MemoParsingExpression
public void enableMemoization()
Copyright © 2009–2017 SonarSource. All rights reserved.