Class: Opal::AST::Matcher

Inherits:
Object
  • Object
show all
Defined in:
opal/lib/opal/ast/matcher.rb

Defined Under Namespace

Classes: Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Matcher

Returns a new instance of Matcher.



9
10
11
# File 'opal/lib/opal/ast/matcher.rb', line 9

def initialize(&block)
  @root = instance_exec(&block)
end

Instance Attribute Details

#capturesObject

Returns the value of attribute captures.



31
32
33
# File 'opal/lib/opal/ast/matcher.rb', line 31

def captures
  @captures
end

Instance Method Details

#cap(capture) ⇒ Object



17
18
19
# File 'opal/lib/opal/ast/matcher.rb', line 17

def cap(capture)
  Node.new(:capture, [capture])
end

#inspectObject



27
28
29
# File 'opal/lib/opal/ast/matcher.rb', line 27

def inspect
  "#<Opal::AST::Matcher: #{@root.inspect}>"
end

#match(ast) ⇒ Object



21
22
23
24
25
# File 'opal/lib/opal/ast/matcher.rb', line 21

def match(ast)
  @captures = []
  @root.match(ast, self) || (return false)
  @captures
end

#s(type, *children) ⇒ Object



13
14
15
# File 'opal/lib/opal/ast/matcher.rb', line 13

def s(type, *children)
  Node.new(type, children)
end