Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

209 lines (122 sloc) 5.863 kB

NAME

PAST::Pattern::Node and subclasses - PAST::Pattern subclasses for matching specific node types.

SYNOPSIS

DESCRIPTION

PAST::Pattern::Node subclasses correspond to PAST::Node subclasses. They match nodes of the corresponding types. If the pattern has child sub-patterns, the matched node must have the same number of children and each child of the node must match the corresponding child of the pattern. If the pattern has attribute sub-patterns, the matched node must have each attribute that the pattern has, and that attribute value must match the value of the corresponding attribute of the pattern.

PAST::Pattern::Node is PAST::Pattern

PAST::Pattern::Node is the superclass for all the PAST::Pattern types that are specific to a certain PAST::Node subclass.

Attributes

Each attribute can contain a PAST::Pattern or other object with an ACCEPTS method, an object that does the invokable role(such as a Sub), or any other object. If the value of an attribute does not have an ACCEPTS method, PAST::Pattern::patternize is called on it to produce an object that does. Invokable objects are used to create PAST::Pattern::Closure objects, which match any object for which their associated invokable object returns true. For other objects without an ACCEPTS method, the object is used to create a PAST::Pattern::Constant object which matches any object for which the result of the is_equal vtable of the object is true.

Attributes can be set or accessed using hash indexing(in which case, you must manually call PAST::Pattern::patternize if necessary), using the attr method, or as named arguments to the new method.

The attributes of PAST::Nodes and their subclasses can be set or accessed using accessor methods with the appropriate name. PAST::Pattern::Node has attributes with accessors for the following PAST::Node and PCT::Node attributes:

name
source
pos
returns
arity
name
flat
lvalue

Methods

new([child0, ...], [attrib0=>value0, ...])

Creates a new pattern with the supplied children and attribute values.

Subroutines

These subroutines are used in subclasses to simplify checking of attribute and child sub-patterns.

check_attribute(pattern, node, attr, match)

Verifies that node's attribute attr matches pattern's attribute attr, if one exists. The success and attributes of match, which should be a PAST::Pattern::Match object, will are then modified appropriately. If a sub-pattern is not found, it returns 1. Otherwise, it returns the boolean value of the result of attempting to match node's attr attribute with the sub-pattern. If there is a sub-pattern and it matches, then match's attribute attr is set to the result. If the sub-pattern does not match, then the success value of match will be set to 0.

check_children(pattern, node, match)

Verifies that the children of pattern match the corresponding children of node. The match argument should be a PAST::Pattern::Match variable. If there are no child sub-patterns of pattern or all of the child sub-patterns match the corresponding children of node, it returns 1. The children of match with the same index as the child sub-patterns are set to the result of their matches if they are successful. If any child sub-patterns do not match the corresponding child of node, the success value of match is set to 0 and 0 is returned.

check_node_attributes(pattern, node, match)

A convenience sub for checking the PAST::Node attributes of pattern and node. check_attribute is called with pattern, node, each attribute, and match. The checking aborts as soon as any existing pattern attribute does not match.

PAST::Pattern::Block is PAST::Pattern::Node

PAST::Pattern::Block patterns are used to match PAST::Block nodes. Their attributes correspond to those of PAST::Block.

Attributes

blocktype
closure
control
loadinit
namespace
multi
hll
nsentry
symtable
lexical
compiler
compiler_args
subid
pirflags

PAST::Pattern::Op is PAST::Pattern::Node

PAST::Pattern::Op patterns are used to match PAST::Op nodes. Their attributes correspond to those of PAST::Op.

Attributes

pasttype
pirop
inline

PAST::Pattern::Stmts is PAST::Pattern::Node

PAST::Pattern::Stmts patterns are used to match PAST::Stmts nodes. They have no additional attributes beyond those of PAST::Pattern::Node.

PAST::Pattern::Val is PAST::Pattern::Node

PAST::Pattern::Val patterns are used to match PAST::Val nodes. Their attributes correspond to those of PAST::Val. Since PAST::Val nodes cannot have lvalue attributes, the lvalue attribute of PAST::Pattern::Node is unimportant for PAST::Pattern::Val nodes.

Attributes

value

PAST::Pattern::Var is PAST::Pattern::Node

PAST::Pattern::Var patterns are used to match PAST::Var nodes. Their attributes correspond to those of PAST::Var.

Attributes

scope
isdecl
namespace
slurpy
call_sig
viviself
vivibase
multitype

PAST::Pattern::VarList is PAST::Pattern::Node

PAST::Pattern::VarList patterns are used to match PAST::VarList nodes. They have no additional attributes beyond those of PAST::Pattern::Node

Jump to Line
Something went wrong with that request. Please try again.