Package org.sonar.sslr.internal.grammar
Class MutableParsingRule
- java.lang.Object
-
- org.sonar.sslr.internal.grammar.MutableParsingRule
-
- All Implemented Interfaces:
AstNodeSkippingPolicy
,AstNodeType
,Rule
,Matcher
,GrammarRuleKey
,Matcher
,CompilableGrammarRule
,MemoParsingExpression
,ParsingExpression
public class MutableParsingRule extends Object implements CompilableGrammarRule, Matcher, Rule, AstNodeSkippingPolicy, MemoParsingExpression, GrammarRuleKey
-
-
Constructor Summary
Constructors Constructor Description MutableParsingRule(String name)
MutableParsingRule(GrammarRuleKey ruleKey)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Instruction[]
compile(CompilationHandler compiler)
Compiles this expression into a sequence of instructions.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.Rule
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.Rule
override(Object... e)
Allows to override definition of a grammar rule.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
skipIfOneChild()
Indicates that grammar rule should not lead to creation of AST node if it has exactly one child.String
toString()
-
-
-
Constructor Detail
-
MutableParsingRule
public MutableParsingRule(String name)
-
MutableParsingRule
public MutableParsingRule(GrammarRuleKey ruleKey)
-
-
Method Detail
-
getName
public String getName()
-
getRealAstNodeType
public AstNodeType getRealAstNodeType()
-
getRuleKey
public GrammarRuleKey getRuleKey()
- Specified by:
getRuleKey
in interfaceCompilableGrammarRule
-
getExpression
public ParsingExpression getExpression()
- Specified by:
getExpression
in interfaceCompilableGrammarRule
-
is
public Rule 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.
-
override
public Rule override(Object... e)
Description copied from interface:Rule
Allows to override definition of a grammar 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.
-
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.
-
setExpression
public void setExpression(ParsingExpression expression)
- Specified by:
setExpression
in interfaceCompilableGrammarRule
-
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.
-
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 interfaceRule
-
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 interfaceAstNodeSkippingPolicy
- 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.
-
compile
public Instruction[] compile(CompilationHandler compiler)
Description copied from interface:ParsingExpression
Compiles this expression into a sequence of instructions.- Specified by:
compile
in interfaceParsingExpression
-
shouldMemoize
public boolean shouldMemoize()
- Specified by:
shouldMemoize
in interfaceMemoParsingExpression
-
-