Class | Parslet::Pattern |
In: |
lib/parslet/pattern.rb
|
Parent: | Object |
Matches trees against expressions. Trees are formed by arrays and hashes for expressing membership and sequence. The leafs of the tree are other classes.
A tree issued by the parslet library might look like this:
{ :function_call => { :name => 'foobar', :args => [1, 2, 3] } }
A pattern that would match against this tree would be:
{ :function_call => { :name => simple(:name), :args => sequence(:args) }}
Note that Parslet::Pattern only matches at a given subtree; it wont try to match recursively. To do that, please use Parslet::Transform.
Returns true if the tree element given by tree matches the expression given by exp. This match must respect bindings already made in bindings. Note that bindings is carried along and modified.
@api private
Decides if the given subtree matches this pattern. Returns the bindings made on a successful match or nil if the match fails. If you specify bindings to be a hash, the mappings in it will be treated like bindings made during an attempted match.
Pattern.new('a').match('a', :foo => 'bar') # => { :foo => 'bar' }
@param subtree [String, Hash, Array] poro subtree returned by a parse @param bindings [Hash] variable bindings to be verified @return [Hash, nil] On success: variable bindings that allow a match. On
failure: nil