File: concrete-syntax/core/pattern/container/morph/polymorph.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: ConcreteSyntax#8
  module: Core#10
  module: Pattern#12
has properties
function: make_poly / 3 #141
  module: Container#14
  module: Morph#16
  class: Polymorph#18
inherits from
  Abstract ( Umu::ConcreteSyntax::Core::Pattern::Container::Morph )
has properties
method: __bb__ #22
method: __eb__ #27
method: __desugar_value_nil__ / 2 #32
method: __desugar_lambda_nil__ / 1 #104
method: __opt_type_sym_of_morph__ #109
method: __opt_type_sym_of_nil__ #124
method: __opt_type_sym_of_cons__ #129

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 Pattern
  13 
  14  module Container
  15 
  16  module Morph
  17 
  18  class Polymorph < Abstract
  19 
  20  private
  21 
  22      def __bb__
  23          '%['
  24      end
  25 
  26 
  27      def __eb__
  28          ']'
  29      end
  30 
  31 
  32      def __desugar_value_nil__(loc, expr)
  33          ASSERT.kind_of expr, ASCE::Abstract
  34 
  35          bool_expr = ASCE.make_send(
  36                  loc,
  37 
  38                  if expr.simple?
  39                      expr
  40                  else
  41                      ASCE.make_identifier(loc, :'%x')
  42                  end,
  43 
  44                  ASCE.make_message(loc, :'empty?')
  45              )
  46 
  47          decl = ASCD.make_value(
  48                  loc,
  49 
  50                  WILDCARD,
  51 
  52                  ASCE.make_if(
  53                      loc,
  54 
  55                      [
  56                          ASCE.make_rule(
  57                              loc,
  58                              bool_expr,
  59                              ASCE.make_unit(loc)
  60                          )
  61                      ],
  62 
  63                      ASCE.make_raise(
  64                          loc,
  65                          X::UnmatchError,
  66                          ASCE.make_string(
  67                              self.loc,
  68                              "No empty pattern matched"
  69                          )
  70                      )
  71                  )
  72              )
  73 
  74          let_expr = ASCE.make_let(
  75                  loc,
  76 
  77                  ASCD.make_seq_of_declaration(
  78                      loc,
  79 
  80                      (
  81                          if expr.simple?
  82                              []
  83                          else
  84                              [ASCD.make_value(loc, :'%x', expr)]
  85                          end
  86                      ) + [
  87                          decl
  88                      ]
  89                  ),
  90 
  91                  if expr.simple?
  92                      expr
  93                  else
  94                      ASCE.make_identifier(loc, :'%x')
  95                  end
  96              )
  97 
  98          ASCD.make_value(
  99              loc, WILDCARD, let_expr, __opt_type_sym_of_nil__
 100          )
 101      end
 102 
 103 
 104      def __desugar_lambda_nil__(loc)
 105          nil
 106      end
 107 
 108 
 109      def __opt_type_sym_of_morph__
 110          if self.opt_last_pat
 111              last_pat = self.opt_last_pat
 112 
 113              if last_pat.opt_type_sym
 114                  last_pat.opt_type_sym
 115              else
 116                  nil
 117              end
 118          else
 119              nil
 120          end
 121      end
 122 
 123 
 124      def __opt_type_sym_of_nil__
 125          nil
 126      end
 127 
 128 
 129      def __opt_type_sym_of_cons__
 130          nil
 131      end
 132  end
 133 
 134  end # Umu::ConcreteSyntax::Core::Pattern::Container::Morph
 135 
 136  end # Umu::ConcreteSyntax::Core::Pattern::Container
 137 
 138 
 139  module_function
 140 
 141      def make_poly(loc, pats = [], opt_last_pat = nil)
 142          ASSERT.kind_of      loc,            LOC::Entry
 143          ASSERT.kind_of      pats,           ::Array
 144          ASSERT.opt_kind_of  opt_last_pat,   ElementOfContainer::Variable
 145 
 146          Container::Morph::Polymorph.new(
 147              loc, pats.freeze, opt_last_pat
 148          ).freeze
 149      end
 150 
 151  end # Umu::ConcreteSyntax::Core::Pattern
 152 
 153  end # Umu::ConcreteSyntax::Core
 154 
 155  end # Umu::ConcreteSyntax
 156 
 157  end # Umu