File: concrete-syntax/core/expression/binary/apply.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_apply / 4 #82
  module: Binary#14
  class: Apply#16
inherits from
  Abstract ( Umu::ConcreteSyntax::Core::Expression::Binary )
has properties
alias: opr_expr lhs #17
alias: opnd_head_expr rhs #18
attribute: opnd_tail_exprs [R] #19
method: initialize / 4 #22
method: to_s #33
method: pretty_print / 1 #41
method: opnd_exprs #54
method: __desugar__ / 2 #61

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  class Apply < Binary::Abstract
  17      alias       opr_expr            lhs
  18      alias       opnd_head_expr      rhs
  19      attr_reader :opnd_tail_exprs
  20 
  21 
  22      def initialize(loc, opr_expr, opnd_head_expr, opnd_tail_exprs)
  23          ASSERT.kind_of opr_expr,        CSCE::Abstract
  24          ASSERT.kind_of opnd_head_expr,  CSCE::Abstract
  25          ASSERT.kind_of opnd_tail_exprs, ::Array
  26 
  27          super(loc, opr_expr, opnd_head_expr)
  28 
  29          @opnd_tail_exprs = opnd_tail_exprs
  30      end
  31 
  32 
  33      def to_s
  34          format("(%s %s)",
  35                  self.opr_expr.to_s,
  36                  self.opnd_exprs.map(&:to_s).join(' ')
  37          )
  38      end
  39 
  40 
  41      def pretty_print(q)
  42          PRT.group q, bb:'(', eb:')' do
  43              q.pp self.opr_expr
  44 
  45              self.opnd_exprs.each do |expr|
  46                  q.breakable
  47 
  48                  q.pp expr
  49              end
  50          end
  51      end
  52 
  53 
  54      def opnd_exprs
  55          [self.opnd_head_expr] + self.opnd_tail_exprs
  56      end
  57 
  58 
  59  private
  60 
  61      def __desugar__(env, event)
  62          new_env = env.enter event
  63 
  64          ASCE.make_apply(
  65              self.loc,
  66              self.opr_expr.desugar(new_env),
  67              self.opnd_head_expr.desugar(new_env),
  68              self.opnd_tail_exprs.map { |expr|
  69                  ASSERT.kind_of expr, CSCE::Abstract
  70 
  71                  expr.desugar new_env
  72              }
  73          )
  74      end
  75  end
  76 
  77  end # Umu::ConcreteSyntax::Core::Expression::Binary
  78 
  79 
  80  module_function
  81 
  82      def make_apply(loc, opr_expr, opnd_head_expr, opnd_tail_exprs = [])
  83          ASSERT.kind_of loc,             LOC::Entry
  84          ASSERT.kind_of opr_expr,        CSCE::Abstract
  85          ASSERT.kind_of opnd_head_expr,  CSCE::Abstract
  86          ASSERT.kind_of opnd_tail_exprs, ::Array
  87 
  88          Binary::Apply.new(
  89              loc, opr_expr, opnd_head_expr, opnd_tail_exprs.freeze
  90          ).freeze
  91      end
  92 
  93  end # Umu::ConcreteSyntax::Core::Expression
  94 
  95  end # Umu::ConcreteSyntax::Core
  96 
  97  end # Umu::ConcreteSyntax
  98 
  99  end # Umu