Class: Peggy::Alternatives

Inherits:
Sequence show all
Defined in:
lib/builder.rb,
lib/Copy of builder.rb

Overview

An element which matches any one of its children. The children are tested in order. The first to match wins.

Instance Method Summary collapse

Methods inherited from Sequence

#[], #add, #each

Methods inherited from Element

build, #report

Instance Method Details

#match(parser, index) ⇒ Object

Match any one of the children. The children are tried in order. The first to match wins. The result is the end index of the first matching child. If none match this returns NO_MATCH.



64
65
66
67
68
69
70
71
# File 'lib/builder.rb', line 64

def match parser, index
  raise "no children added to alternate" unless @list
  each do |element|
    found = element.match parser, index
    return report(found) if found
  end
  report NO_MATCH
end