Class: Calyx::Production::Concat
- Inherits:
-
Object
- Object
- Calyx::Production::Concat
- Defined in:
- lib/calyx/production/concat.rb
Constant Summary collapse
- EXPRESSION =
/(\{[A-Za-z0-9_@\.]+\})/.freeze
- START_TOKEN =
'{'.freeze
- END_TOKEN =
'}'.freeze
- DEREF_TOKEN =
'.'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate ⇒ Object
-
#initialize(expansion) ⇒ Concat
constructor
A new instance of Concat.
Constructor Details
#initialize(expansion) ⇒ Concat
Returns a new instance of Concat.
33 34 35 |
# File 'lib/calyx/production/concat.rb', line 33 def initialize(expansion) @expansion = expansion end |
Class Method Details
.parse(production, registry) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/calyx/production/concat.rb', line 9 def self.parse(production, registry) expansion = production.split(EXPRESSION).map do |atom| if atom.is_a?(String) if atom.chars.first == START_TOKEN && atom.chars.last == END_TOKEN head, *tail = atom.slice(1, atom.length-2).split(DEREF_TOKEN) if head[0] == Memo::SIGIL rule = Memo.new(head, registry) else rule = NonTerminal.new(head, registry) end unless tail.empty? Expression.new(rule, tail, registry) else rule end else Terminal.new(atom) end end end self.new(expansion) end |
Instance Method Details
#evaluate ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/calyx/production/concat.rb', line 37 def evaluate concat = @expansion.reduce([]) do |exp, atom| exp << atom.evaluate end [:concat, concat] end |