File: abstract-syntax/core/declaration/seq-of-declaration.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: AbstractSyntax#8
  module: Core#10
  module: Declaration#12
has properties
function: make_seq_of_declaration / 2 #75
  class: SeqOfDeclaration#14
includes
  Enumerable ( Builtin-Module )
inherits from
  Abstract ( Umu::AbstractSyntax::Core::Declaration )
has properties
attribute: decls [R] #17
method: initialize / 2 #20
method: each #30
alias: to_a decls #39
method: to_s #42
method: pretty_print / 1 #47
method: __evaluate__ / 1 #54

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 Declaration
  13 
  14  class SeqOfDeclaration < Abstract
  15      include Enumerable
  16 
  17      attr_reader :decls
  18 
  19 
  20      def initialize(loc, decls)
  21          ASSERT.kind_of loc, LOC::Entry
  22          ASSERT.assert decls.respond_to?(:each), 'Enumerable'
  23 
  24          super(loc)
  25 
  26          @decls = decls
  27      end
  28 
  29 
  30      def each
  31          self.decls.each do |decl|
  32              ASSERT.kind_of decl, ASCD::Abstract
  33 
  34              yield decl
  35          end
  36      end
  37 
  38 
  39      alias to_a decls
  40 
  41 
  42      def to_s
  43          format "{ %s }", self.map(&:to_s).join(' ')
  44      end
  45 
  46 
  47      def pretty_print(q)
  48          PRT.group_for_enum q, self, bb:'{', eb:'}', sep:' '
  49      end
  50 
  51 
  52  private
  53 
  54      def __evaluate__(old_env)
  55          ASSERT.kind_of old_env, E::Entry
  56 
  57          new_env = self.inject(old_env) { |env, decl|
  58              ASSERT.kind_of env,     E::Entry
  59              ASSERT.kind_of decl,    ASCD::Abstract
  60 
  61              result = decl.evaluate env
  62              ASSERT.kind_of result, ASR::Environment
  63 
  64              result.env
  65          }
  66 
  67          ASSERT.kind_of new_env, E::Entry
  68      end
  69  end
  70 
  71 
  72 
  73  module_function
  74 
  75      def make_seq_of_declaration(loc, decls)
  76          ASSERT.kind_of loc, LOC::Entry
  77          ASSERT.assert decls.respond_to?(:each), 'Enumerable'
  78 
  79          SeqOfDeclaration.new(loc, decls.freeze).freeze
  80      end
  81 
  82  end # Umu::AbstractSyntax::Core::Declaration
  83 
  84  end # Umu::AbstractSyntax::Core
  85 
  86  end # Umu::AbstractSyntax
  87 
  88  end # Umu