PAST::Pattern - A library for pattern matching on PAST::Nodes.
load_bytecode('PAST/Pattern.pbc'); $P1 = get_hll_global ['PAST';'Pattern'], 'Val' $P0 = $P1.'new'('value'=>1) $P2 = get_a_past_node_from_somewhere() $P3 = $P0.match($P2) $I0 = istrue $P3 print "Result as bool is " say $I0
PAST::Pattern and its subclasses allow determining whether a PAST::Node matches a certain pattern, in addition to allowing modification of any matches sub-trees similarly to regex substitution.
PAST::Pattern is Capture
Converts an object that is not a pattern(does not implement the
ACCEPTSmethod) into one that is. If value does the
invokablerole, it is used to create a
PAST::Pattern::Closurepattern. Otherwise, it is used to create a
PAST::Transformerin transform to transform any sub-trees of past that match the pattern.
ACCEPTS(node, [option1 =value1, option2 => value2, ...])>
Tests whether the node or any sub-tree thereof matches the pattern. Returns a
PAST::Pattern::Matchresult object. Valid options are
globalare true, the match is global. After the first match is found, the search will continue until every sub-tree has been checked for matching. If no matches are found, a false
PAST::Pattern::Matchobject will be returned. If only one match is found,
ACCEPTSreturns the same value with or without
global. If multiple matches are found, the result is a true
PAST::Pattern::Matchobject whose array part contains the individual match results. If
posare provided, they specify a PAST::Node that must exactly match the pattern. Supplying one of both
posproduces an error.
The following method should be implemented in any subclass, as
.ACCEPTS relies on it.
Tests whether the specific node matches the pattern without recursing into children. The result should be a PAST::Pattern::Match object. Every PAST::Pattern subclass MUST implement this method.
attr(name, value, has_value)
A helper method for defining attribute accessors.
ACCEPTSto implement global matching.