File: abstract-syntax/core/expression/memo-stream.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_memo_stream_nil / 1 #83
function: make_memo_stream_cons / 3 #90
  module: MemoStream#14
  class: Abstract#16
inherits from
  Abstract ( Umu::AbstractSyntax::Core::Expression )
has properties
method: __evaluate__ / 2 #20
  class: Nil#27
inherits from
  Abstract ( Umu::AbstractSyntax::Core::Expression::MemoStream )
has properties
method: to_s #28
method: pretty_print / 1 #33
  class: Cons#40
inherits from
  Abstract ( Umu::AbstractSyntax::Core::Expression::MemoStream )
has properties
attribute: head_expr [R] #41
attribute: tail_expr [R] #41
method: initialize / 3 #44
method: to_s #55
method: pretty_print / 1 #63

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 MemoStream
  15 
  16  class Abstract < Expression::Abstract
  17 
  18  private
  19 
  20      def __evaluate__(env, event)
  21          VC.make_memo_stream_entry self, env.va_context
  22      end
  23  end
  24 
  25 
  26 
  27  class Nil < Abstract
  28      def to_s
  29          '&{}'
  30      end
  31 
  32 
  33      def pretty_print(q)
  34          q.text '&{}'
  35      end
  36  end
  37 
  38 
  39 
  40  class Cons < Abstract
  41      attr_reader :head_expr, :tail_expr
  42 
  43 
  44      def initialize(loc, head_expr, tail_expr)
  45          ASSERT.kind_of head_expr,   ASCE::Abstract
  46          ASSERT.kind_of tail_expr,   ASCE::Abstract
  47 
  48          super(loc)
  49 
  50          @head_expr = head_expr
  51          @tail_expr = tail_expr
  52      end
  53 
  54 
  55      def to_s
  56          format("&{%s | %s}", 
  57              self.head_expr.to_s,
  58              self.tail_expr.to_s
  59          )
  60      end
  61 
  62 
  63      def pretty_print(q)
  64          PRT.group q, bb:'&{', eb:'}' do
  65              q.pp self.head_expr
  66 
  67              q.breakable
  68 
  69              q.text '|'
  70 
  71              q.breakable
  72 
  73              q.pp self.tail_expr
  74          end
  75      end
  76  end
  77 
  78  end # Umu::AbstractSyntax::Core::Expression::MemoStream
  79 
  80 
  81  module_function
  82 
  83      def make_memo_stream_nil(loc)
  84          ASSERT.kind_of loc, LOC::Entry
  85 
  86          MemoStream::Nil.new(loc).freeze
  87      end
  88 
  89 
  90      def make_memo_stream_cons(loc, head_expr, tail_expr)
  91          ASSERT.kind_of loc,         LOC::Entry
  92          ASSERT.kind_of head_expr,   ASCE::Abstract
  93          ASSERT.kind_of tail_expr,   ASCE::Abstract
  94 
  95          MemoStream::Cons.new(loc, head_expr, tail_expr).freeze
  96      end
  97 
  98  end # Umu::AbstractSyntax::Core::Expression
  99 
 100  end # Umu::AbstractSyntax::Core
 101 
 102  end # Umu::AbstractSyntax
 103 
 104  end # Umu