Class: PatternMatch::PatternQuantifier
Instance Attribute Summary collapse
Attributes inherited from Pattern
#next, #parent, #prev
Instance Method Summary
collapse
Methods inherited from Pattern
#!@, #&, #ancestors, #append, #directly_quantified?, #quantified?, #quasibinding, #root, #root?, #to_a, #vars, #|
#choice_points
Constructor Details
Returns a new instance of PatternQuantifier.
157
158
159
160
161
|
# File 'lib/pattern-match/core.rb', line 157
def initialize(min_k, is_greedy)
super()
@min_k = min_k
@is_greedy = is_greedy
end
|
Instance Attribute Details
Returns the value of attribute min_k.
155
156
157
|
# File 'lib/pattern-match/core.rb', line 155
def min_k
@min_k
end
|
Instance Method Details
#greedy? ⇒ Boolean
185
186
187
|
# File 'lib/pattern-match/core.rb', line 185
def greedy?
@is_greedy
end
|
189
190
191
|
# File 'lib/pattern-match/core.rb', line 189
def inspect
"#<#{self.class.name}: min_k=#{@min_k}, is_greedy=#{@is_greedy}>"
end
|
#match(vals) ⇒ Object
177
178
179
180
181
182
183
|
# File 'lib/pattern-match/core.rb', line 177
def match(vals)
if @next
@next.match(vals)
else
vals.empty?
end
end
|
#quantifier? ⇒ Boolean
173
174
175
|
# File 'lib/pattern-match/core.rb', line 173
def quantifier?
true
end
|
163
164
165
166
167
168
169
170
171
|
# File 'lib/pattern-match/core.rb', line 163
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
|