File: concrete-syntax/core/expression/binary/infix/composite.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: ConcreteSyntax#8
  module: Core#10
  module: Expression#12
has properties
function: make_comp_left / 5 #86
function: make_comp_right / 5 #99
  module: Binary#14
  module: Infix#16
  module: Composite#18
  class: Abstract#20
  class: Left#49
inherits from
  Abstract ( Umu::ConcreteSyntax::Core::Expression::Binary::Infix::Composite )
has properties
method: __desugar__ / 2 #57
  class: Right#64
inherits from
  Abstract ( Umu::ConcreteSyntax::Core::Expression::Binary::Infix::Composite )
has properties
method: __desugar__ / 2 #72

Code

   1  # coding: utf-8
   2  # frozen_string_literal: true
   3 
   4 
   5 
   6  module Umu
   7 
   8  module ConcreteSyntax
   9 
  10  module Core
  11 
  12  module Expression
  13 
  14  module Binary
  15 
  16  module Infix
  17 
  18  module Composite
  19 
  20  class Abstract < Abstraction::WithRepetition
  21 
  22  private
  23 
  24  =begin
  25      f1 >> f2 >> f3 = { x -> x |> f1 |> f2 |> f3 }
  26  =end
  27 
  28      def __desugar_composite__(env, event, &_block)
  29          new_env = env.enter event
  30          ident_x = ASCE.make_identifier self.loc, :'%x'
  31 
  32          hd_opnd,
  33          *tl_opnds = self.then { |exprs|
  34                          yield exprs
  35                      }.map { |opnd|
  36                           opnd.desugar new_env
  37                      }
  38 
  39          ASCE.make_lambda(
  40              self.loc,
  41              [ASCE.make_parameter(self.loc, ident_x)],
  42              ASCE.make_pipe(self.loc, ident_x, hd_opnd, tl_opnds)
  43          )
  44      end
  45  end
  46 
  47 
  48 
  49  class Left < Abstract
  50 
  51  private
  52 
  53  =begin
  54      f1 >> f2 >> f3 = { x -> x |> f1 |> f2 |> f3 }
  55  =end
  56 
  57      def __desugar__(env, event)
  58          __desugar_composite__ env, event, &:each
  59      end
  60  end
  61 
  62 
  63 
  64  class Right < Abstract
  65 
  66  private
  67 
  68  =begin
  69      f1 << f2 << f3 = { x -> x |> f3 |> f2 |> f1 }
  70  =end
  71 
  72      def __desugar__(env, event)
  73          __desugar_composite__ env, event, &:reverse_each
  74      end
  75  end
  76 
  77  end # Umu::ConcreteSyntax::Core::Expression::Binary::Infix::Composite
  78 
  79  end # Umu::ConcreteSyntax::Core::Expression::Binary::Infix
  80 
  81  end # Umu::ConcreteSyntax::Core::Expression::Binary
  82 
  83 
  84  module_function
  85 
  86      def make_comp_left(loc, lhs_opnd, opr_sym, hd_rhs_opnd, tl_rhs_opnds)
  87          ASSERT.kind_of loc,             LOC::Entry
  88          ASSERT.kind_of lhs_opnd,        CSCE::Abstract
  89          ASSERT.kind_of opr_sym,         ::Symbol
  90          ASSERT.kind_of hd_rhs_opnd,     CSCE::Abstract
  91          ASSERT.kind_of tl_rhs_opnds,    ::Array
  92 
  93          Binary::Infix::Composite::Left.new(
  94              loc, lhs_opnd, opr_sym, hd_rhs_opnd, tl_rhs_opnds.freeze
  95          ).freeze
  96      end
  97 
  98 
  99      def make_comp_right(loc, lhs_opnd, opr_sym, hd_rhs_opnd, tl_rhs_opnds)
 100          ASSERT.kind_of loc,             LOC::Entry
 101          ASSERT.kind_of lhs_opnd,        CSCE::Abstract
 102          ASSERT.kind_of opr_sym,         ::Symbol
 103          ASSERT.kind_of hd_rhs_opnd,     CSCE::Abstract
 104          ASSERT.kind_of tl_rhs_opnds,    ::Array
 105 
 106          Binary::Infix::Composite::Right.new(
 107              loc, lhs_opnd, opr_sym, hd_rhs_opnd, tl_rhs_opnds.freeze
 108          ).freeze
 109      end
 110 
 111  end # Umu::ConcreteSyntax::Core::Expression
 112 
 113  end # Umu::ConcreteSyntax::Core
 114 
 115  end # Umu::ConcreteSyntax
 116 
 117  end # Umu