Class: Opal::AST::Matcher::Node
- Inherits:
- 
      Struct
      
        - Object
- Struct
- Opal::AST::Matcher::Node
 
- Defined in:
- opal/lib/opal/ast/matcher.rb
Instance Attribute Summary collapse
- 
  
    
      #children  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute children. 
- 
  
    
      #type  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute type. 
Instance Method Summary collapse
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children
| 33 34 35 | # File 'opal/lib/opal/ast/matcher.rb', line 33 def children @children end | 
#type ⇒ Object
Returns the value of attribute type
| 33 34 35 | # File 'opal/lib/opal/ast/matcher.rb', line 33 def type @type end | 
Instance Method Details
#inspect ⇒ Object
| 67 68 69 70 71 72 73 | # File 'opal/lib/opal/ast/matcher.rb', line 67 def inspect if type == :capture "{#{children.first.inspect}}" else "s(#{type.inspect}, #{children.inspect[1..-2]})" end end | 
#match(ast, matcher) ⇒ Object
| 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | # File 'opal/lib/opal/ast/matcher.rb', line 34 def match(ast, matcher) return false if ast.nil? ast_parts = [ast.type] + ast.children self_parts = [type] + children return false if ast_parts.length != self_parts.length ast_parts.length.times.all? do |i| ast_elem = ast_parts[i] self_elem = self_parts[i] if self_elem.is_a?(Node) && self_elem.type == :capture capture = true self_elem = self_elem.children.first end res = case self_elem when Node self_elem.match(ast_elem, matcher) when Array self_elem.include?(ast_elem) when :* true else self_elem == ast_elem end matcher.captures << ast_elem if capture res end end |