File: abstract-syntax/core/expression/nary/lambda.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: AbstractSyntax#8
  module: Core#10
  module: Expression#12
has properties
function: make_parameter / 3 #114
function: make_lambda / 4 #123
  module: Nary#14
  module: Lambda#16
  class: Parameter#18
inherits from
  Model ( Umu::Abstraction )
has properties
attribute: ident [R] #19
attribute: opt_type_sym [R] #19
method: initialize / 3 #22
method: to_s #33
method: pretty_print / 1 #46
  class: Entry#57
inherits from
  Abstract ( Umu::AbstractSyntax::Core::Expression )
has properties
attribute: params [R] #58
attribute: expr [R] #58
attribute: opt_name [R] #58
method: initialize / 4 #61
method: to_s #74
method: pretty_print / 1 #82
method: __evaluate__ / 2 #99

Code

   1  # coding: utf-8
   2  # frozen_string_literal: true
   3 
   4 
   5 
   6  module Umu
   7 
   8  module AbstractSyntax
   9 
  10  module Core
  11 
  12  module Expression
  13 
  14  module Nary
  15 
  16  module Lambda
  17 
  18  class Parameter < Abstraction::Model
  19      attr_reader :ident, :opt_type_sym
  20 
  21 
  22      def initialize(loc, ident, opt_type_sym)
  23          ASSERT.kind_of      ident,          ASCEU::Identifier::Short
  24          ASSERT.opt_kind_of  opt_type_sym,   ::Symbol
  25 
  26          super(loc)
  27 
  28          @ident          = ident
  29          @opt_type_sym   = opt_type_sym
  30      end
  31 
  32 
  33      def to_s
  34          format("%s%s",
  35              self.ident.to_s,
  36 
  37              if self.opt_type_sym
  38                  format " : %s", self.opt_type_sym
  39              else
  40                  ''
  41              end
  42          )
  43      end
  44 
  45 
  46      def pretty_print(q)
  47          q.pp self.ident
  48          if self.opt_type_sym
  49              q.text ' : '
  50              q.text self.opt_type_sym.to_s
  51          end
  52      end
  53  end
  54 
  55 
  56 
  57  class Entry < Expression::Abstract
  58      attr_reader :params, :expr, :opt_name
  59 
  60 
  61      def initialize(loc, params, expr, opt_name)
  62          ASSERT.kind_of      params,     ::Array
  63          ASSERT.kind_of      expr,       ASCE::Abstract
  64          ASSERT.opt_kind_of  opt_name,   ::Symbol
  65 
  66          super(loc)
  67 
  68          @params     = params
  69          @expr       = expr
  70          @opt_name   = opt_name
  71      end
  72 
  73 
  74      def to_s
  75          format("{%s -> %s}",
  76              self.params.map(&:to_s).join(' ').to_s,
  77              self.expr.to_s
  78          )
  79      end
  80 
  81 
  82      def pretty_print(q)
  83          PRT.group_for_enum q, self.params, bb:'{ ', join:' '
  84 
  85          q.breakable
  86 
  87          PRT.group q, bb:'-> ' do
  88              q.pp expr
  89          end
  90 
  91          q.breakable
  92 
  93          q.text '}'
  94      end
  95 
  96 
  97  private
  98 
  99      def __evaluate__(env, event)
 100          ASSERT.kind_of env,     E::Entry
 101          ASSERT.kind_of event,   E::Tracer::Event
 102 
 103          VC.make_function self, env.va_context
 104      end
 105  end
 106 
 107  end # Umu::AbstractSyntax::Core::Expression::Nary::Lambda
 108 
 109  end # Umu::AbstractSyntax::Core::Expression::Nary
 110 
 111 
 112  module_function
 113 
 114      def make_parameter(loc, ident, opt_type_sym = nil)
 115          ASSERT.kind_of      loc,            LOC::Entry
 116          ASSERT.kind_of      ident,          ASCEU::Identifier::Short
 117          ASSERT.opt_kind_of  opt_type_sym,   ::Symbol
 118 
 119          Nary::Lambda::Parameter.new(loc, ident, opt_type_sym).freeze
 120      end
 121 
 122 
 123      def make_lambda(loc, params, expr, opt_name = nil)
 124          ASSERT.kind_of      loc,            LOC::Entry
 125          ASSERT.kind_of      params,         ::Array
 126          ASSERT.kind_of      expr,           ASCE::Abstract
 127          ASSERT.opt_kind_of  opt_name,       ::Symbol
 128 
 129          Nary::Lambda::Entry.new(loc, params, expr, opt_name).freeze
 130      end
 131 
 132  end # Umu::AbstractSyntax::Core::Expression
 133 
 134  end # Umu::AbstractSyntax::Core
 135 
 136  end # Umu::AbstractSyntax
 137 
 138  end # Umu