Class: PatternMatch::PatternWithMatcher

Inherits:
PatternElement show all
Defined in:
lib/egison/core.rb

Instance Attribute Summary collapse

Attributes inherited from Pattern

#quantified

Instance Method Summary collapse

Methods inherited from Pattern

#to_a

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

#matcherObject (readonly)

Returns the value of attribute matcher.



92
93
94
# File 'lib/egison/core.rb', line 92

def matcher
  @matcher
end

#subpatternsObject (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