Class: Docopt::OneOrMore

Inherits:
ParentPattern show all
Defined in:
lib/docopt.rb

Instance Attribute Summary

Attributes inherited from ParentPattern

#children

Attributes inherited from Pattern

#children

Instance Method Summary collapse

Methods inherited from ParentPattern

#flat, #initialize, #inspect

Methods inherited from Pattern

#==, #dump, #either, #fix, #fix_identities, #fix_repeating_arguments, #to_str

Constructor Details

This class inherits a constructor from Docopt::ParentPattern

Instance Method Details

#match(left, collected = nil) ⇒ Object



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/docopt.rb', line 327

def match(left, collected=nil)
  if self.children.count != 1
    raise RuntimeError
  end

  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 = self.children[0].match(l, c)
    times += (matched ? 1 : 0)
    if l_ == l
      break
    end
    l_ = l
  end
  if times >= 1
    return [true, l, c]
  end
  return [false, left, collected]
end