org.parboiled.matchers
Class ProxyMatcher

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

public class ProxyMatcher
extends java.lang.Object
implements Matcher, java.lang.Cloneable

A Matcher that delegates all Rule and Matcher interface methods to another Matcher. It can also hold a label and a leaf marker and lazily apply these to the underlying Matcher once it is available.


Constructor Summary
ProxyMatcher()
           
 
Method Summary
<R> R
accept(MatcherVisitor<R> visitor)
          Accepts the given matcher visitor.
 boolean areMismatchesMemoed()
           
 boolean areSubnodesSuppressed()
           
 void arm(Matcher target)
          Supplies this ProxyMatcher with its underlying delegate.
 java.util.List<Matcher> getChildren()
          Returns the sub nodes of this node.
 java.lang.String getLabel()
           
 MatcherContext getSubContext(MatcherContext context)
          Creates a context for the matching of this matcher using the given parent context.
 java.lang.Object getTag()
          Retrieves a previously set tag object.
 boolean hasCustomLabel()
           
 boolean isNodeSkipped()
           
 boolean isNodeSuppressed()
           
 Rule label(java.lang.String label)
          Attaches a label to this Rule.
<V> boolean
match(MatcherContext<V> context)
          Tries a match on the given MatcherContext.
 Rule memoMismatches()
          Enables memoization of rule mismatches for consecutive rule applications at the same input location.
 void setLabel(java.lang.String label)
           
 void setTag(java.lang.Object tagObject)
          Associates an arbitrary object with this matcher.
 Rule skipNode()
          Instructs parboiled to not create a parse tree node for this rule.
 Rule suppressNode()
          Instructs parboiled to not create a parse tree node for this rule and all subrules, which can significantly increase parsing performance.
 Rule suppressSubnodes()
          Instructs parboiled to not create parse tree nodes for the subrules of this rule, which can significantly increase parsing performance.
 java.lang.String toString()
           
static Matcher unwrap(Matcher matcher)
          Retrieves the innermost Matcher that is not a ProxyMatcher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProxyMatcher

public ProxyMatcher()
Method Detail

getChildren

public java.util.List<Matcher> getChildren()
Description copied from interface: GraphNode
Returns the sub nodes of this node.

Specified by:
getChildren in interface GraphNode<Matcher>
Returns:
the sub nodes

setLabel

public void setLabel(java.lang.String label)

match

public <V> boolean match(MatcherContext<V> context)
Description copied from interface: Matcher
Tries a match on the given MatcherContext.

Specified by:
match in interface Matcher
Parameters:
context - the MatcherContext
Returns:
true if the match was successful

getLabel

public java.lang.String getLabel()
Specified by:
getLabel in interface Matcher
Returns:
the label of the matcher (which is identical to the label of the Rule this matcher matches)

hasCustomLabel

public boolean hasCustomLabel()
Specified by:
hasCustomLabel in interface Matcher
Returns:
true if this matcher has been assigned a custom label

isNodeSuppressed

public boolean isNodeSuppressed()
Specified by:
isNodeSuppressed in interface Matcher
Returns:
true if this matcher has been marked with @SuppressNode

areSubnodesSuppressed

public boolean areSubnodesSuppressed()
Specified by:
areSubnodesSuppressed in interface Matcher
Returns:
true if this matcher has been marked with @SuppressSubnodes

isNodeSkipped

public boolean isNodeSkipped()
Specified by:
isNodeSkipped in interface Matcher
Returns:
true if this matcher has been marked with @SkipNode

areMismatchesMemoed

public boolean areMismatchesMemoed()
Specified by:
areMismatchesMemoed in interface Matcher
Returns:
true if this matcher has been marked with @MemoMismatches

setTag

public void setTag(java.lang.Object tagObject)
Description copied from interface: Matcher
Associates an arbitrary object with this matcher. Used for example during profiling and packrat parsing. The matcher implementations themselves completely ignore the contents of this property. It purely serves as a performance optimization for ParseRunners and/or MatchHandlers and saves these from the need to use Map<Matcher, XYZ> structures for associating internal objects with matchers.

Specified by:
setTag in interface Matcher
Parameters:
tagObject - the tag object

getTag

public java.lang.Object getTag()
Description copied from interface: Matcher
Retrieves a previously set tag object.

Specified by:
getTag in interface Matcher
Returns:
the tag object or null if none set

accept

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

Specified by:
accept in interface Matcher
Parameters:
visitor - the visitor
Returns:
the value returned by the given visitor

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

label

public Rule label(java.lang.String label)
Description copied from interface: Rule
Attaches a label to this Rule. Corresponds to the @Label annotation.

Specified by:
label in interface Rule
Parameters:
label - the label
Returns:
this Rule

suppressNode

public Rule suppressNode()
Description copied from interface: Rule
Instructs parboiled to not create a parse tree node for this rule and all subrules, which can significantly increase parsing performance. Corresponds to the @SuppressNode annotation.

Specified by:
suppressNode in interface Rule
Returns:
this Rule

suppressSubnodes

public Rule suppressSubnodes()
Description copied from interface: Rule
Instructs parboiled to not create parse tree nodes for the subrules of this rule, which can significantly increase parsing performance. Corresponds to the @SuppressSubnodes annotation.

Specified by:
suppressSubnodes in interface Rule
Returns:
this Rule

skipNode

public Rule skipNode()
Description copied from interface: Rule
Instructs parboiled to not create a parse tree node for this rule. The parse tree nodes of all subrules are directly attached to the parent of this rule (or more correctly: the first ancestor not having been marked skipNode(). Note that, even though a rule marked as skipNode() does not create a parse tree node of its own and is therefore "invisible" in the parse tree, the rule still exists as a regular rule in the rule tree and is accompanied by a "regular" rule Context during rule matching. Corresponds to the @SkipNode annotation.

Specified by:
skipNode in interface Rule
Returns:
this Rule

memoMismatches

public Rule memoMismatches()
Description copied from interface: Rule
Enables memoization of rule mismatches for consecutive rule applications at the same input location.

Specified by:
memoMismatches in interface Rule
Returns:
this rule

arm

public void arm(Matcher target)
Supplies this ProxyMatcher with its underlying delegate.

Parameters:
target - the Matcher to delegate to

unwrap

public static Matcher unwrap(Matcher matcher)
Retrieves the innermost Matcher that is not a ProxyMatcher.

Parameters:
matcher - the matcher to unwrap
Returns:
the given instance if it is not a ProxyMatcher, otherwise the innermost non-proxy Matcher

getSubContext

public MatcherContext getSubContext(MatcherContext context)
Description copied from interface: Matcher
Creates a context for the matching of this matcher using the given parent context.

Specified by:
getSubContext in interface Matcher
Parameters:
context - the parent context
Returns:
the context this matcher is to be run in