File: concrete-syntax/core/declaration/value.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: ConcreteSyntax#8
  module: Core#10
  module: Declaration#12
has properties
function: make_value / 4 #92
  class: Value#14
inherits from
  Abstract ( Umu::ConcreteSyntax::Core::Declaration )
has properties
attribute: pat [R] #15
attribute: expr [R] #15
attribute: decls [R] #15
method: initialize / 4 #18
method: to_s #31
method: pretty_print / 1 #46
method: exported_vars #64
method: __desugar__ / 2 #71

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 Declaration
  13 
  14  class Value < Declaration::Abstract
  15      attr_reader :pat, :expr, :decls
  16 
  17 
  18      def initialize(loc, pat, expr, decls)
  19          ASSERT.kind_of pat,     CSCP::Abstract
  20          ASSERT.kind_of expr,    CSCE::Abstract
  21          ASSERT.kind_of decls,   CSCD::SeqOfDeclaration
  22 
  23          super(loc)
  24 
  25          @pat    = pat
  26          @expr   = expr
  27          @decls  = decls
  28      end
  29 
  30 
  31      def to_s
  32          format("%%VAL %s = %s%s",
  33                  self.pat.to_s,
  34 
  35                  self.expr.to_s,
  36 
  37                  if self.decls.empty?
  38                      ''
  39                  else
  40                      format " %%WHERE {%s}", self.decls.to_s
  41                  end
  42          )
  43      end
  44 
  45 
  46      def pretty_print(q)
  47          q.text '%VAL '
  48          q.pp self.pat
  49          q.text ' = '
  50          PRT.group q do
  51              q.pp self.expr
  52          end
  53 
  54          q.breakable
  55 
  56          unless self.decls.empty?
  57              PRT.group q, bb:'%WHERE {', eb:'}' do
  58                  q.pp self.decls
  59              end
  60          end
  61      end
  62 
  63 
  64      def exported_vars
  65          self.pat.exported_vars
  66      end
  67 
  68 
  69  private
  70 
  71      def __desugar__(env, event)
  72          new_env = env.enter event
  73 
  74          self.pat.desugar_value(
  75              (
  76                  if self.decls.empty?
  77                      self.expr
  78                  else
  79                      CSCE.make_let(self.loc, self.decls, self.expr)
  80                  end
  81              ).desugar(new_env),
  82 
  83              new_env
  84          )
  85      end
  86  end
  87 
  88 
  89 
  90  module_function
  91 
  92      def make_value(loc, pat, expr, decls)
  93          ASSERT.kind_of loc,     LOC::Entry
  94          ASSERT.kind_of pat,     CSCP::Abstract
  95          ASSERT.kind_of expr,    CSCE::Abstract
  96          ASSERT.kind_of decls,   CSCD::SeqOfDeclaration
  97 
  98          Value.new(loc, pat, expr, decls).freeze
  99      end
 100 
 101  end # Umu::ConcreteSyntax::Core::Declaration
 102 
 103  end # Umu::ConcreteSyntax::Core
 104 
 105  end # Umu::ConcreteSyntax
 106 
 107  end # Umu