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 Pattern
13
14 class Result
15 attr_reader :ident, :decls, :opt_type_sym
16
17
18 def initialize(ident, decls, opt_type_sym)
19 ASSERT.kind_of ident, ASCEU::Identifier::Short
20 ASSERT.kind_of decls, ::Array
21 ASSERT.opt_kind_of opt_type_sym, ::Symbol
22 ASSERT.assert decls.all? { |decl|
23 decl.kind_of? ASCD::Simple::Value
24 }
25
26 @ident = ident
27 @decls = decls
28 @opt_type_sym = opt_type_sym
29 end
30
31
32 def to_s
33 format("{ident = %s%s, decls = [%s]}",
34 self.ident.to_s,
35
36 if self.opt_type_sym
37 format " : %s", self.opt_type_sym
38 else
39 ''
40 end,
41
42 self.decls.map(&:to_s).join(', ')
43 )
44 end
45 end
46
47
48 module_function
49
50 def make_result(ident, decls, opt_type_sym = nil)
51 ASSERT.kind_of ident, ASCEU::Identifier::Short
52 ASSERT.kind_of decls, ::Array
53 ASSERT.opt_kind_of opt_type_sym, ::Symbol
54
55 Result.new(ident, decls.freeze, opt_type_sym).freeze
56 end
57
58 end # Umu::ConcreteSyntax::Core::Pattern
59
60 end # Umu::ConcreteSyntax::Core
61
62 end # Umu::ConcreteSyntax
63
64 end # Umu