Class: Calyx::Grammar::Production::Choices
- Inherits:
-
Object
- Object
- Calyx::Grammar::Production::Choices
- Defined in:
- lib/calyx/grammar/production/choices.rb
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate ⇒ Object
-
#initialize(collection) ⇒ Choices
constructor
A new instance of Choices.
Constructor Details
#initialize(collection) ⇒ Choices
Returns a new instance of Choices.
16 17 18 |
# File 'lib/calyx/grammar/production/choices.rb', line 16 def initialize(collection) @collection = collection end |
Class Method Details
.parse(productions, registry) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/calyx/grammar/production/choices.rb', line 5 def self.parse(productions, registry) choices = productions.map do |choice| if choice.is_a?(String) Concat.parse(choice, registry) elsif choice.is_a?(Symbol) NonTerminal.new(choice, registry) end end self.new(choices) end |
Instance Method Details
#evaluate ⇒ Object
20 21 22 |
# File 'lib/calyx/grammar/production/choices.rb', line 20 def evaluate @collection.sample.evaluate end |