File: concrete-syntax/module/expression/identifier.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: ConcreteSyntax#8
  module: Module#10
  module: Expression#12
has properties
function: make_identifier / 2 #116
function: make_long_identifier / 3 #124
  module: Identifier#14
  class: Abstract#16
inherits from
  Abstract ( Umu::ConcreteSyntax::Module::Expression )
has properties
method: to_a #17
method: head #22
method: tail #27
  class: Short#34
inherits from
  Abstract ( Umu::ConcreteSyntax::Module::Expression::Identifier )
has properties
attribute: sym [R] #35
method: initialize / 2 #38
method: to_s #47
method: head #52
method: tail #57
method: __desugar__ / 2 #64
  class: Long#71
inherits from
  Abstract ( Umu::ConcreteSyntax::Module::Expression::Identifier )
has properties
attribute: head [R] #72
attribute: tail [R] #72
method: initialize / 3 #75
method: to_s #86
method: __desugar__ / 2 #100

Code

   1  # coding: utf-8
   2  # frozen_string_literal: true
   3 
   4 
   5 
   6  module Umu
   7 
   8  module ConcreteSyntax
   9 
  10  module Module
  11 
  12  module Expression
  13 
  14  module Identifier
  15 
  16  class Abstract < Expression::Abstract
  17      def to_a
  18          ([self.head] + self.tail).freeze
  19      end
  20 
  21 
  22      def head
  23          raise X::InternalSubclassResponsibility
  24      end
  25 
  26 
  27      def tail
  28          raise X::InternalSubclassResponsibility
  29      end
  30  end
  31 
  32 
  33 
  34  class Short < Abstract
  35      attr_reader :sym
  36 
  37 
  38      def initialize(loc, sym)
  39          ASSERT.kind_of sym, ::Symbol
  40 
  41          super(loc)
  42 
  43          @sym = sym
  44      end
  45 
  46 
  47      def to_s
  48          self.sym.to_s
  49      end
  50 
  51 
  52      def head
  53          self
  54      end
  55 
  56 
  57      def tail
  58          [].freeze
  59      end
  60 
  61 
  62  private
  63 
  64      def __desugar__(_env, _event)
  65          ASCE.make_identifier self.loc, self.sym
  66      end
  67  end
  68 
  69 
  70 
  71  class Long < Abstract
  72      attr_reader :head, :tail
  73 
  74 
  75      def initialize(loc, head, tail)
  76          ASSERT.kind_of head, Short
  77          ASSERT.kind_of tail, ::Array
  78 
  79          super(loc)
  80 
  81          @head = head
  82          @tail = tail
  83      end
  84 
  85 
  86      def to_s
  87          if tail.empty?
  88              self.head.to_s
  89          else
  90              format("%s::%s",
  91                  self.head.to_s,
  92                  self.tail.map(&:to_s).join('::')
  93              )
  94          end
  95      end
  96 
  97 
  98  private
  99 
 100      def __desugar__(env, event)
 101          new_env = env.enter event
 102 
 103          ASCE.make_long_identifier(
 104              loc,
 105              self.head.desugar(new_env),
 106              self.tail.map { |id| id.desugar new_env }
 107          )
 108      end
 109  end
 110 
 111  end # Umu::ConcreteSyntax::Core::Expression::Identifier
 112 
 113 
 114  module_function
 115 
 116      def make_identifier(loc, sym)
 117          ASSERT.kind_of loc, LOC::Entry
 118          ASSERT.kind_of sym, ::Symbol
 119 
 120          Identifier::Short.new(loc, sym).freeze
 121      end
 122 
 123 
 124      def make_long_identifier(loc, head, tail)
 125          ASSERT.kind_of head, Identifier::Short
 126          ASSERT.kind_of tail, ::Array
 127 
 128          Identifier::Long.new(loc, head, tail.freeze).freeze
 129      end
 130 
 131  end # Umu::ConcreteSyntax::Module::Expression
 132 
 133  end # Umu::ConcreteSyntax::Module
 134 
 135  end # Umu::ConcreteSyntax
 136 
 137  end # Umu