Class: Calyx::Production::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/calyx/production/expression.rb

Overview

A type of production rule representing a single template substitution.

Instance Method Summary collapse

Constructor Details

#initialize(production, methods, registry) ⇒ Expression

Constructs a node representing a single template substitution.

Parameters:



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.

Parameters:

Returns:

  • (Array)


22
23
24
25
26
27
28
29
# File 'lib/calyx/production/expression.rb', line 22

def evaluate(options)
  terminal = @production.evaluate(options).flatten.reject { |o| o.is_a?(Symbol) }.join
  expression = @methods.reduce(terminal) do |value, method|
    @registry.transform(method, value)
  end

  [:expression, expression]
end