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 SeqOfDeclaration < Declaration::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.kind_of decls, ::Array
23
24 super(loc)
25
26 @decls = decls
27 end
28
29
30 def empty?
31 self.decls.empty?
32 end
33
34
35 def +(other)
36 ASSERT.kind_of other, SeqOfDeclaration
37
38 CSCD.make_seq_of_declaration(self.decls + other.decls)
39 end
40
41
42 def each
43 self.decls.each do |decl|
44 ASSERT.kind_of decl, CSCD::Abstract
45
46 yield decl
47 end
48 end
49
50
51 alias to_a decls
52
53
54 def to_s
55 self.map(&:to_s).join(' ')
56 end
57
58
59 def pretty_print(q)
60 PRT.group_for_enum q, self
61 end
62
63
64 private
65
66 def __desugar__(env, event)
67 new_env = env.enter event
68
69 ASCD.make_seq_of_declaration(
70 self.loc,
71
72 self.decls.map { |decl|
73 decl.desugar(new_env)
74 }
75 )
76 end
77 end
78
79
80 EMPTY_SEQ_OF_DECRALATION = SeqOfDeclaration.new(
81 LOC.make_location(__FILE__, __LINE__),
82 [].freeze
83 ).freeze
84
85
86
87 module_function
88
89 def make_empty_seq_of_declaration
90 EMPTY_SEQ_OF_DECRALATION
91 end
92
93
94 def make_seq_of_declaration(decls)
95 ASSERT.kind_of decls, ::Array
96
97 SeqOfDeclaration.new(
98 LOC.make_location(__FILE__, __LINE__),
99 decls.freeze
100 ).freeze
101 end
102
103 end # Umu::ConcreteSyntax::Core::Declaration
104
105 end # Umu::ConcreteSyntax::Core
106
107 end # Umu::ConcreteSyntax
108
109 end # Umu