Class Citrus::Choice

  1. lib/citrus.rb
Parent: Object

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

Methods

public instance

  1. exec

Included modules

  1. Nonterminal

Public instance methods

exec (input, events=[])

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

[show source]
      # File lib/citrus.rb, line 1237
1237:     def exec(input, events=[])
1238:       events << self
1239: 
1240:       index = events.size
1241:       n = 0
1242:       m = rules.length
1243: 
1244:       while n < m && input.exec(rules[n], events).size == index
1245:         n += 1
1246:       end
1247: 
1248:       if index < events.size
1249:         events << CLOSE
1250:         events << events[-2]
1251:       else
1252:         events.pop
1253:       end
1254: 
1255:       events
1256:     end