Class: PatternMatch::PatternWithMatcher
- Inherits:
-
PatternElement
- Object
- Pattern
- PatternElement
- PatternMatch::PatternWithMatcher
- Defined in:
- lib/egison/core.rb
Instance Attribute Summary collapse
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#subpatterns ⇒ Object
readonly
Returns the value of attribute subpatterns.
Attributes inherited from Pattern
Instance Method Summary collapse
-
#initialize(matcher, *subpatterns) ⇒ PatternWithMatcher
constructor
A new instance of PatternWithMatcher.
- #match(tgt, bindings) ⇒ Object
Methods inherited from Pattern
Constructor Details
#initialize(matcher, *subpatterns) ⇒ PatternWithMatcher
94 95 96 97 98 |
# File 'lib/egison/core.rb', line 94 def initialize(matcher, *subpatterns) super() @matcher = matcher @subpatterns = subpatterns end |
Instance Attribute Details
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
92 93 94 |
# File 'lib/egison/core.rb', line 92 def matcher @matcher end |
#subpatterns ⇒ Object (readonly)
Returns the value of attribute subpatterns.
92 93 94 |
# File 'lib/egison/core.rb', line 92 def subpatterns @subpatterns end |
Instance Method Details
#match(tgt, bindings) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/egison/core.rb', line 100 def match(tgt, bindings) if subpatterns.empty? then if tgt.empty? then return [[[], []]] else return [] end else subpatterns = @subpatterns.clone px = subpatterns.shift if px.quantified then if subpatterns.empty? then [[[[px.pattern, tgt]], []]] else unjoineds = @matcher.unjoin(tgt) unjoineds.map { |xs, ys| [[[px.pattern, xs], [PatternWithMatcher.new(@matcher, *subpatterns), ys]], []] } end else if tgt.empty? then [] else unconseds = @matcher.uncons(tgt) unconseds.map { |x, xs| [[[px, x], [PatternWithMatcher.new(@matcher, *subpatterns), xs]], []] } end end end end |