Class: Packrat::Repeat
Instance Attribute Summary
#hidden
Instance Method Summary
collapse
#to_packrat_grammar_element
Constructor Details
#initialize(subElement, minimumReps = 0, maximumReps = false) ⇒ Repeat
Returns a new instance of Repeat.
205
206
207
208
|
# File 'lib/packrat/grammar.rb', line 205
def initialize(subElement, minimumReps = 0, maximumReps = false)
@min, @max = minimumReps, maximumReps
@sub = subElement.to_packrat_grammar_element
end
|
Instance Method Details
#inspect ⇒ Object
209
210
211
212
213
214
|
# File 'lib/packrat/grammar.rb', line 209
def inspect
subi = @sub.inspect
return "mult(#{subi})" if @min == 0 && @max == false
return "plus(#{subi})" if @min == 1 && @max == false
return "rep(@min, @max, #{subi})"
end
|
#parse(parser) ⇒ Object
573
574
575
576
577
578
579
580
581
582
583
584
585
586
|
# File 'lib/packrat/grammar.rb', line 573
def parse(parser)
result_list = []
oldpos = parser.pos
while (res = @sub.parse(parser))
result_list << res
end
if valid_result?(result_list)
return result_list
else
parser.pos = oldpos
return false
end
end
|
#valid_result?(list) ⇒ Boolean
587
588
589
590
591
|
# File 'lib/packrat/grammar.rb', line 587
def valid_result?(list)
return false if @min && list.length < @min
return false if @max && list.length > @max
true
end
|