Class: Calyx::Grammar::Production::Concat
- Inherits:
-
Object
- Object
- Calyx::Grammar::Production::Concat
- Defined in:
- lib/calyx.rb
Constant Summary collapse
- DELIMITER =
/(\{[A-Za-z0-9_]+\})/.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(registry) ⇒ Object
-
#initialize(expansion) ⇒ Concat
constructor
A new instance of Concat.
Constructor Details
#initialize(expansion) ⇒ Concat
72 73 74 |
# File 'lib/calyx.rb', line 72 def initialize(expansion) @expansion = expansion end |
Class Method Details
.parse(production) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/calyx.rb', line 56 def self.parse(production) expansion = production.split(DELIMITER).map do |atom| if atom.is_a?(String) if atom.chars.first == '{' && atom.chars.last == '}' NonTerminal.new(atom.slice(1, atom.length-2)) else Terminal.new(atom) end elsif atom.is_a?(Symbol) NonTerminal.new end end self.new(expansion) end |
Instance Method Details
#evaluate(registry) ⇒ Object
76 77 78 79 80 |
# File 'lib/calyx.rb', line 76 def evaluate(registry) @expansion.reduce('') do |exp, atom| exp << atom.evaluate(registry) end end |