org.parboiled.matchers
Class CustomMatcher

java.lang.Object
  extended by org.parboiled.trees.ImmutableGraphNode<Matcher>
      extended by org.parboiled.matchers.AbstractMatcher
          extended by org.parboiled.matchers.CustomMatcher
All Implemented Interfaces:
java.lang.Cloneable, Matcher, Rule, GraphNode<Matcher>

public abstract class CustomMatcher
extends AbstractMatcher

Base class of custom matcher implementations. If you want to implement custom matchers they have to be derived from this class. Instances of derived classes can be directly used in rule defining expressions. Caution: For performance reasons the parsing engine delegates the task of taking and restoring value stack snapshots to the matchers. If your custom matcher can run parser actions underneath it your custom matcher implementation therefore has to take care of value stack managment itselves! (See the implementation of the SequenceMatcher for hints on how to do this!)


Constructor Summary
protected CustomMatcher(Rule[] subRules, java.lang.String label)
           
protected CustomMatcher(Rule subRule, java.lang.String label)
           
protected CustomMatcher(java.lang.String label)
           
 
Method Summary
<R> R
accept(MatcherVisitor<R> visitor)
          Accepts the given matcher visitor.
abstract  boolean canMatchEmpty()
          Determines whether this matcher instance allows empty matches.
abstract  char getStarterChar()
          Returns one of possibly several chars that a match can start with.
abstract  boolean isSingleCharMatcher()
          Determines whether this matcher instance always matches exactly one character.
abstract  boolean isStarterChar(char c)
          Determines whether this matcher instance can start a match with the given char.
 
Methods inherited from class org.parboiled.matchers.AbstractMatcher
areMismatchesMemoed, areSubnodesSuppressed, getLabel, getSubContext, getTag, hasCustomLabel, isNodeSkipped, isNodeSuppressed, label, memoMismatches, setTag, skipNode, suppressNode, suppressSubnodes, toString
 
Methods inherited from class org.parboiled.trees.ImmutableGraphNode
getChildren
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.parboiled.matchers.Matcher
match
 
Methods inherited from interface org.parboiled.trees.GraphNode
getChildren
 

Constructor Detail

CustomMatcher

protected CustomMatcher(java.lang.String label)

CustomMatcher

protected CustomMatcher(Rule subRule,
                        java.lang.String label)

CustomMatcher

protected CustomMatcher(Rule[] subRules,
                        java.lang.String label)
Method Detail

isSingleCharMatcher

public abstract boolean isSingleCharMatcher()
Determines whether this matcher instance always matches exactly one character.

Returns:
true if this matcher always matches exactly one character

canMatchEmpty

public abstract boolean canMatchEmpty()
Determines whether this matcher instance allows empty matches.

Returns:
true if this matcher instance allows empty matches

isStarterChar

public abstract boolean isStarterChar(char c)
Determines whether this matcher instance can start a match with the given char.

Parameters:
c - the char
Returns:
true if this matcher instance can start a match with the given char.

getStarterChar

public abstract char getStarterChar()
Returns one of possibly several chars that a match can start with.

Returns:
a starter char

accept

public <R> R accept(MatcherVisitor<R> visitor)
Description copied from interface: Matcher
Accepts the given matcher visitor.

Parameters:
visitor - the visitor
Returns:
the value returned by the given visitor