Class: Pione::Lang::ParamContext

Inherits:
StructuralContext show all
Defined in:
lib/pione/lang/context.rb

Overview

ParamContext is a context for parameter block. This context takes special interpretation of variable binding declaration.

Instance Method Summary collapse

Methods inherited from StructuralContext

#+, accept, acceptances, inherited, #initialize, #pos, #try_to_eval, #validate

Methods inherited from Context

#eval!

Constructor Details

This class inherits a constructor from Pione::Lang::StructuralContext

Instance Method Details

#eval(env) ⇒ Object



139
140
141
142
143
144
145
# File 'lib/pione/lang/context.rb', line 139

def eval(env)
  if elements.any? {|elt| elt.is_a?(VariableBindingDeclaration)}
    set(elements: elements.map {|elt| transform(elt)}).eval(env)
  else
    super
  end
end

#transform(declaration) ⇒ Object

Trasform variable binding declarations into param declarations.



148
149
150
151
152
153
154
# File 'lib/pione/lang/context.rb', line 148

def transform(declaration)
  if declaration.is_a?(VariableBindingDeclaration)
    ParamDeclaration.new(type, declaration.expr1, declaration.expr2)
  else
    declaration
  end
end