Class: MetaCL::DSL::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/metacl/dsl/expression.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(program, &block) ⇒ Expression

Returns a new instance of Expression.



6
7
8
9
# File 'lib/metacl/dsl/expression.rb', line 6

def initialize(program, &block)
  @program = program
  @tree = instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



19
20
21
22
23
# File 'lib/metacl/dsl/expression.rb', line 19

def method_missing(name, *args)
  sub_expression = @program.resources.expressions_hash[name.to_sym]
  substitution = sub_expression.args.map.with_index { |param, index| [param, args[index]] }.to_h
  sub_expression.root_node.get_tree_with_substitution(substitution)
end

Instance Attribute Details

#treeObject (readonly)

Returns the value of attribute tree.



4
5
6
# File 'lib/metacl/dsl/expression.rb', line 4

def tree
  @tree
end

Class Method Details

.construct(program, &block) ⇒ Object



25
26
27
# File 'lib/metacl/dsl/expression.rb', line 25

def self.construct(program, &block)
  Expression.new(program, &block).tree
end

Instance Method Details

#mul(index, from, to, expression) ⇒ Object



15
16
17
# File 'lib/metacl/dsl/expression.rb', line 15

def mul(index, from, to, expression)
  Logic::Node.new :aggregator, expression, nil, index: index, from: from, to: to, type: :*
end

#sum(index, from, to, expression) ⇒ Object



11
12
13
# File 'lib/metacl/dsl/expression.rb', line 11

def sum(index, from, to, expression)
  Logic::Node.new :aggregator, expression, nil, index: index, from: from, to: to, type: :+
end