Class: Opal::AST::Matcher
- Inherits:
-
Object
- Object
- Opal::AST::Matcher
- Defined in:
- lib/opal/ast/matcher.rb
Defined Under Namespace
Classes: Node
Instance Attribute Summary collapse
-
#captures ⇒ Object
Returns the value of attribute captures.
Instance Method Summary collapse
- #cap(capture) ⇒ Object
-
#initialize(&block) ⇒ Matcher
constructor
A new instance of Matcher.
- #inspect ⇒ Object
- #match(ast) ⇒ Object
- #s(type, *children) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Matcher
Returns a new instance of Matcher.
9 10 11 |
# File 'lib/opal/ast/matcher.rb', line 9 def initialize(&block) @root = instance_exec(&block) end |
Instance Attribute Details
#captures ⇒ Object
Returns the value of attribute captures.
31 32 33 |
# File 'lib/opal/ast/matcher.rb', line 31 def captures @captures end |
Instance Method Details
#cap(capture) ⇒ Object
17 18 19 |
# File 'lib/opal/ast/matcher.rb', line 17 def cap(capture) Node.new(:capture, [capture]) end |
#inspect ⇒ Object
27 28 29 |
# File 'lib/opal/ast/matcher.rb', line 27 def inspect "#<Opal::AST::Matcher: #{@root.inspect}>" end |
#match(ast) ⇒ Object
21 22 23 24 25 |
# File 'lib/opal/ast/matcher.rb', line 21 def match(ast) @captures = [] @root.match(ast, self) || (return false) @captures end |