Class: Calyx::Production::Expression
- Inherits:
-
Object
- Object
- Calyx::Production::Expression
- Defined in:
- lib/calyx/production/expression.rb
Overview
A type of production rule representing a single template substitution.
Instance Method Summary collapse
-
#evaluate(options) ⇒ Array
Evaluate the expression by expanding the non-terminal to produce a terminal string, then passing it through the given modifier chain and returning the transformed result.
-
#initialize(production, methods, registry) ⇒ Expression
constructor
Constructs a node representing a single template substitution.
Constructor Details
#initialize(production, methods, registry) ⇒ Expression
Constructs a node representing a single template substitution.
10 11 12 13 14 |
# File 'lib/calyx/production/expression.rb', line 10 def initialize(production, methods, registry) @production = production @methods = methods.map { |m| m.to_sym } @registry = registry end |
Instance Method Details
#evaluate(options) ⇒ Array
Evaluate the expression by expanding the non-terminal to produce a terminal string, then passing it through the given modifier chain and returning the transformed result.
22 23 24 25 26 27 28 29 |
# File 'lib/calyx/production/expression.rb', line 22 def evaluate() terminal = @production.evaluate().flatten.reject { |o| o.is_a?(Symbol) }.join expression = @methods.reduce(terminal) do |value, method| @registry.transform(method, value) end [:expression, expression] end |