class Citrus::Choice

A Choice is a Nonterminal where only one rule must match. The Citrus notation is two or more expressions separated by a vertical bar, e.g.:

expr | expr

Public Instance Methods

exec(input, events=[]) click to toggle source

Returns an array of events for this rule on the given input.

# File lib/citrus.rb, line 1236
def exec(input, events=[])
  events << self

  index = events.size
  n = 0
  m = rules.length

  while n < m && input.exec(rules[n], events).size == index
    n += 1
  end

  if index < events.size
    events << CLOSE
    events << events[-2]
  else
    events.pop
  end

  events
end