com.sonar.sslr.api
Interface Rule

All Superinterfaces:
AstNodeType

public interface Rule
extends AstNodeType

A Rule describes a context free grammar syntactic rule.

See Also:
Grammar, Backus�Naur Form

Method Summary
 Rule and(java.lang.Object... matchers)
          The method is(Object...) must be first called to be able to extend this rule definition
 Rule is(java.lang.Object... matchers)
          This method allows to provide the definition of a context-free grammar rule.
 Rule isOr(java.lang.Object... matchers)
          The method is(Object...) is just a utility method which prevents writing is(or());
 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 or(java.lang.Object... matchers)
          The method is(Object...) must be first called to be able to add a new alternative to this rule
 Rule orBefore(java.lang.Object... matchers)
          The method is(Object...) must be first called to be able to add a new alternative to this rule.
 Rule 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 plug(java.lang.Object adapter)
          Experimental
 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.
 void skip()
          Remove this node from the AST and attached its children directly to its parent
 void skipIf(AstNodeSkippingPolicy policy)
          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
 

Method Detail

is

Rule is(java.lang.Object... matchers)
This method allows to provide the definition of a context-free 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. If the rule definition really needs to be redefine, then the override(Object...) method must be used.

Parameters:
matchers - the matchers that define the rule
Returns:
this rule

override

Rule 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. It can be used if the rule has to be redefined later (for instance in a grammar extension).

Parameters:
matchers - the matchers that define the rule
Returns:
this rule

or

Rule or(java.lang.Object... matchers)
The method is(Object...) must be first called to be able to add a new alternative to this rule

Returns:
this rule
See Also:
com.sonar.sslr.impl.matcher.GrammarFunctions.Standard#or(Object...)}

and

Rule and(java.lang.Object... matchers)
The method is(Object...) must be first called to be able to extend this rule definition

Returns:
this rule
See Also:
com.sonar.sslr.impl.matcher.GrammarFunctions.Standard#and(Object...)}

orBefore

Rule orBefore(java.lang.Object... matchers)
The method is(Object...) must be first called to be able to add a new alternative to this rule. This alternative will be the first one to be tested before testing previous ones.

Returns:
this rule
See Also:
com.sonar.sslr.impl.matcher.GrammarFunctions.Standard#or(Object...)}

isOr

Rule isOr(java.lang.Object... matchers)
The method is(Object...) is just a utility method which prevents writing is(or());

Returns:
this rule
See Also:
#is(Object...)}, com.sonar.sslr.impl.matcher.GrammarFunctions.Standard#or(Object...)}

skip

void skip()
Remove this node from the AST and attached its children directly to its parent


skipIf

void skipIf(AstNodeSkippingPolicy policy)
Remove this node from the AST according to a provided policy


skipIfOneChild

void skipIfOneChild()
Remove this node from the AST if it has exactly 1 child


mock

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


plug

void plug(java.lang.Object adapter)
Experimental


recoveryRule

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. In such case, all RecognitionExceptionListener injected into the Parser are automatically notified.

See Also:
RecognitionExceptionListener


Copyright © 2012 SonarSource. All Rights Reserved.