Class: Calyx::Grammar::Production::Concat
- Inherits:
-
Object
- Object
- Calyx::Grammar::Production::Concat
- Defined in:
- lib/calyx.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.
100 101 102 |
# File 'lib/calyx.rb', line 100 def initialize(expansion) @expansion = expansion end |
Class Method Details
.parse(production, registry) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/calyx.rb', line 78 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) rule = NonTerminal.new(head, registry) unless tail.empty? Expression.new(rule, tail) else rule end else Terminal.new(atom) end elsif atom.is_a?(Symbol) NonTerminal.new(atom, registry) end end self.new(expansion) end |
Instance Method Details
#evaluate ⇒ Object
104 105 106 107 108 |
# File 'lib/calyx.rb', line 104 def evaluate @expansion.reduce('') do |exp, atom| exp << atom.evaluate end end |