Class: PatternMatch::PatternQuantifier
Instance Attribute Summary collapse
Attributes inherited from Pattern
#next, #parent, #prev
Instance Method Summary
collapse
Methods inherited from Pattern
#!@, #&, #ancestors, #append, #quantified?, #quasibinding, #root, #root?, #to_a, #vars, #|
Constructor Details
Returns a new instance of PatternQuantifier.
160
161
162
163
164
|
# File 'lib/pattern-match/core.rb', line 160
def initialize(min_k, longest)
super()
@min_k = min_k
@longest = longest
end
|
Instance Attribute Details
Returns the value of attribute min_k.
158
159
160
|
# File 'lib/pattern-match/core.rb', line 158
def min_k
@min_k
end
|
Instance Method Details
192
193
194
|
# File 'lib/pattern-match/core.rb', line 192
def inspect
"#<#{self.class.name}: min_k=#{@min_k}, longest=#{@longest}>"
end
|
#longest? ⇒ Boolean
188
189
190
|
# File 'lib/pattern-match/core.rb', line 188
def longest?
@longest
end
|
#match(vals) ⇒ Object
180
181
182
183
184
185
186
|
# File 'lib/pattern-match/core.rb', line 180
def match(vals)
if @next
@next.match(vals)
else
vals.empty?
end
end
|
#quantifier? ⇒ Boolean
176
177
178
|
# File 'lib/pattern-match/core.rb', line 176
def quantifier?
true
end
|
166
167
168
169
170
171
172
173
174
|
# File 'lib/pattern-match/core.rb', line 166
def validate
super
raise MalformedPatternError unless @prev and ! @prev.quantifier?
raise MalformedPatternError unless @parent.kind_of?(HasOrderedSubPatterns)
seqs = ancestors.grep(PatternSequence).reverse
if seqs.any? {|i| i.next and i.next.quantifier? and not i.vars.empty? }
raise NotImplementedError
end
end
|