Method: Parslet::Pattern#element_match

Defined in:
lib/parslet/pattern.rb

#element_match(tree, exp, bindings) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/parslet/pattern.rb', line 49

def element_match(tree, exp, bindings) 
  # p [:elm, tree, exp]
  if tree.is_a?(Hash) && exp.is_a?(Hash)
    return element_match_hash(tree, exp, bindings)
  elsif tree.is_a?(Array) && exp.is_a?(Array)
    return element_match_ary_single(tree, exp, bindings)
  else
    # If elements match exactly, then that is good enough in all cases
    return true if exp === tree
    
    # If exp is a bind variable: Check if the binding matches
    if exp.respond_to?(:can_bind?) && exp.can_bind?(tree)
      return element_match_binding(tree, exp, bindings)
    end
                
    # Otherwise: No match (we don't know anything about the element
    # combination)
    return false
  end
end