Class: DocoptNG::OneOrMore
- Inherits:
-
ParentPattern
- Object
- Pattern
- ParentPattern
- DocoptNG::OneOrMore
- Defined in:
- lib/docopt_ng/one_or_more.rb
Instance Attribute Summary
Attributes inherited from ParentPattern
Attributes inherited from Pattern
Instance Method Summary collapse
Methods inherited from ParentPattern
Methods inherited from Pattern
#==, #dump, #either, #fix, #fix_identities, #fix_repeating_arguments, #to_str
Constructor Details
This class inherits a constructor from DocoptNG::ParentPattern
Instance Method Details
#match(left, collected = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/docopt_ng/one_or_more.rb', line 5 def match(left, collected = nil) raise RuntimeError if children.count != 1 collected ||= [] l = left c = collected l_ = nil matched = true times = 0 while matched # could it be that something didn't match but changed l or c? matched, l, c = children[0].match(l, c) times += (matched ? 1 : 0) break if l_ == l l_ = l end if times.positive? [true, l, c] else [false, left, collected] end end |