expressir 0.2.7-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. checksums.yaml +7 -0
  2. data/.cross_rubies +30 -0
  3. data/.github/workflows/rake.yml +45 -0
  4. data/.github/workflows/release.yml +84 -0
  5. data/.gitignore +17 -0
  6. data/.gitmodules +3 -0
  7. data/.rspec +2 -0
  8. data/.rubocop.yml +508 -0
  9. data/Gemfile +4 -0
  10. data/README.adoc +147 -0
  11. data/Rakefile +11 -0
  12. data/bin/console +12 -0
  13. data/bin/rspec +29 -0
  14. data/bin/setup +8 -0
  15. data/demo.rb +18 -0
  16. data/docs/development.md +90 -0
  17. data/exe/expressir +20 -0
  18. data/exe/generate-parser +48 -0
  19. data/expressir.gemspec +43 -0
  20. data/lib/expressir.rb +21 -0
  21. data/lib/expressir/cli.rb +27 -0
  22. data/lib/expressir/cli/ui.rb +36 -0
  23. data/lib/expressir/config.rb +23 -0
  24. data/lib/expressir/express.rb +11 -0
  25. data/lib/expressir/express/aggregate_dimension.rb +38 -0
  26. data/lib/expressir/express/attribute.rb +15 -0
  27. data/lib/expressir/express/comment.rb +7 -0
  28. data/lib/expressir/express/defined_type.rb +36 -0
  29. data/lib/expressir/express/derived.rb +65 -0
  30. data/lib/expressir/express/derived_aggregate.rb +43 -0
  31. data/lib/expressir/express/entity.rb +137 -0
  32. data/lib/expressir/express/explicit.rb +70 -0
  33. data/lib/expressir/express/explicit_aggregate.rb +46 -0
  34. data/lib/expressir/express/explicit_or_derived.rb +16 -0
  35. data/lib/expressir/express/global_rule.rb +44 -0
  36. data/lib/expressir/express/interface_specification.rb +51 -0
  37. data/lib/expressir/express/interfaced_item.rb +38 -0
  38. data/lib/expressir/express/inverse.rb +46 -0
  39. data/lib/expressir/express/inverse_aggregate.rb +37 -0
  40. data/lib/expressir/express/model_element.rb +7 -0
  41. data/lib/expressir/express/named_type.rb +19 -0
  42. data/lib/expressir/express/remark.rb +8 -0
  43. data/lib/expressir/express/repository.rb +306 -0
  44. data/lib/expressir/express/schema_definition.rb +96 -0
  45. data/lib/expressir/express/subtype_constraint.rb +14 -0
  46. data/lib/expressir/express/type.rb +26 -0
  47. data/lib/expressir/express/type_aggregate.rb +42 -0
  48. data/lib/expressir/express/type_enum.rb +29 -0
  49. data/lib/expressir/express/type_parser.rb +45 -0
  50. data/lib/expressir/express/type_select.rb +82 -0
  51. data/lib/expressir/express/unique_rule.rb +35 -0
  52. data/lib/expressir/express/where_rule.rb +32 -0
  53. data/lib/expressir/express_exp/2.4/express_parser.so +0 -0
  54. data/lib/expressir/express_exp/2.5/express_parser.so +0 -0
  55. data/lib/expressir/express_exp/2.6/express_parser.so +0 -0
  56. data/lib/expressir/express_exp/2.7/express_parser.so +0 -0
  57. data/lib/expressir/express_exp/3.0/express_parser.so +0 -0
  58. data/lib/expressir/express_exp/formatter.rb +1450 -0
  59. data/lib/expressir/express_exp/parser.rb +41 -0
  60. data/lib/expressir/express_exp/visitor.rb +2464 -0
  61. data/lib/expressir/express_parser.rb +30 -0
  62. data/lib/expressir/model.rb +65 -0
  63. data/lib/expressir/model/attribute.rb +27 -0
  64. data/lib/expressir/model/constant.rb +17 -0
  65. data/lib/expressir/model/entity.rb +46 -0
  66. data/lib/expressir/model/enumeration_item.rb +11 -0
  67. data/lib/expressir/model/expressions/aggregate_initializer.rb +13 -0
  68. data/lib/expressir/model/expressions/aggregate_item.rb +15 -0
  69. data/lib/expressir/model/expressions/attribute_reference.rb +15 -0
  70. data/lib/expressir/model/expressions/binary_expression.rb +40 -0
  71. data/lib/expressir/model/expressions/call.rb +15 -0
  72. data/lib/expressir/model/expressions/entity_constructor.rb +15 -0
  73. data/lib/expressir/model/expressions/group_reference.rb +15 -0
  74. data/lib/expressir/model/expressions/index_reference.rb +17 -0
  75. data/lib/expressir/model/expressions/interval.rb +21 -0
  76. data/lib/expressir/model/expressions/query_expression.rb +26 -0
  77. data/lib/expressir/model/expressions/simple_reference.rb +13 -0
  78. data/lib/expressir/model/expressions/unary_expression.rb +19 -0
  79. data/lib/expressir/model/function.rb +62 -0
  80. data/lib/expressir/model/identifier.rb +10 -0
  81. data/lib/expressir/model/interface.rb +18 -0
  82. data/lib/expressir/model/literals/binary.rb +13 -0
  83. data/lib/expressir/model/literals/integer.rb +13 -0
  84. data/lib/expressir/model/literals/logical.rb +17 -0
  85. data/lib/expressir/model/literals/real.rb +13 -0
  86. data/lib/expressir/model/literals/string.rb +15 -0
  87. data/lib/expressir/model/parameter.rb +17 -0
  88. data/lib/expressir/model/procedure.rb +60 -0
  89. data/lib/expressir/model/renamed_ref.rb +13 -0
  90. data/lib/expressir/model/repository.rb +19 -0
  91. data/lib/expressir/model/rule.rb +62 -0
  92. data/lib/expressir/model/schema.rb +67 -0
  93. data/lib/expressir/model/scope.rb +17 -0
  94. data/lib/expressir/model/statements/alias.rb +26 -0
  95. data/lib/expressir/model/statements/assignment.rb +15 -0
  96. data/lib/expressir/model/statements/call.rb +15 -0
  97. data/lib/expressir/model/statements/case.rb +17 -0
  98. data/lib/expressir/model/statements/case_action.rb +15 -0
  99. data/lib/expressir/model/statements/compound.rb +13 -0
  100. data/lib/expressir/model/statements/escape.rb +8 -0
  101. data/lib/expressir/model/statements/if.rb +17 -0
  102. data/lib/expressir/model/statements/null.rb +8 -0
  103. data/lib/expressir/model/statements/repeat.rb +34 -0
  104. data/lib/expressir/model/statements/return.rb +13 -0
  105. data/lib/expressir/model/statements/skip.rb +8 -0
  106. data/lib/expressir/model/subtype_constraint.rb +27 -0
  107. data/lib/expressir/model/type.rb +24 -0
  108. data/lib/expressir/model/types/aggregate.rb +17 -0
  109. data/lib/expressir/model/types/array.rb +21 -0
  110. data/lib/expressir/model/types/bag.rb +17 -0
  111. data/lib/expressir/model/types/binary.rb +15 -0
  112. data/lib/expressir/model/types/boolean.rb +8 -0
  113. data/lib/expressir/model/types/enumeration.rb +19 -0
  114. data/lib/expressir/model/types/generic.rb +13 -0
  115. data/lib/expressir/model/types/generic_entity.rb +13 -0
  116. data/lib/expressir/model/types/integer.rb +8 -0
  117. data/lib/expressir/model/types/list.rb +19 -0
  118. data/lib/expressir/model/types/logical.rb +8 -0
  119. data/lib/expressir/model/types/number.rb +8 -0
  120. data/lib/expressir/model/types/real.rb +13 -0
  121. data/lib/expressir/model/types/select.rb +21 -0
  122. data/lib/expressir/model/types/set.rb +17 -0
  123. data/lib/expressir/model/types/string.rb +15 -0
  124. data/lib/expressir/model/unique.rb +15 -0
  125. data/lib/expressir/model/variable.rb +17 -0
  126. data/lib/expressir/model/where.rb +15 -0
  127. data/lib/expressir/parser.rb +6 -0
  128. data/lib/expressir/parser/owl_parser.rb +8 -0
  129. data/lib/expressir/version.rb +3 -0
  130. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.exp +9589 -0
  131. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.owl +36619 -0
  132. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.xml +13294 -0
  133. data/original/examples/employment/eclipse/.project +17 -0
  134. data/original/examples/employment/eclipse/Export/Employment.png +0 -0
  135. data/original/examples/employment/eclipse/Express/employment_schema.exp +33 -0
  136. data/original/examples/employment/eclipse/Express/employment_schema.xmi +77 -0
  137. data/original/examples/employment/eclipse/Express/employment_schema.xml +93 -0
  138. data/original/examples/employment/eclipse/Models/Employment.uml +4 -0
  139. data/original/examples/employment/eclipse/Models/Employment.umldi +240 -0
  140. data/original/examples/employment/eclipse/readme.txt +7 -0
  141. data/original/examples/employment/employment_schema.exp +33 -0
  142. data/original/examples/employment/employment_schema.rb +232 -0
  143. data/original/examples/employment/employment_schema.xml +93 -0
  144. data/original/examples/employment/employment_schema___module.rb +46 -0
  145. data/original/examples/employment/employment_schema___p28attr.rb +126 -0
  146. data/original/examples/employment/employment_schema___p28inst.rb +26 -0
  147. data/original/examples/employment/example_employment_data.xml +1 -0
  148. data/original/examples/employment/example_employment_data_copy.xml +1 -0
  149. data/original/examples/employment/example_employment_reader.rb +30 -0
  150. data/original/examples/employment/example_employment_writer.rb +51 -0
  151. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.exp +3710 -0
  152. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.owl +35880 -0
  153. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xmi +15357 -0
  154. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xml +9468 -0
  155. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.exp +8404 -0
  156. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.owl +43147 -0
  157. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xmi +18341 -0
  158. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xml +11632 -0
  159. data/original/examples/syntax/remark.exp +146 -0
  160. data/original/examples/syntax/remark_formatted.exp +175 -0
  161. data/original/examples/syntax/syntax.exp +311 -0
  162. data/original/examples/syntax/syntax_formatted.exp +1191 -0
  163. data/original/exp2ruby.rb +525 -0
  164. data/original/expsm.rb +34 -0
  165. data/original/mapping_owl.rb +1018 -0
  166. data/original/mapping_sysml.rb +2281 -0
  167. data/original/mapping_uml2.rb +599 -0
  168. data/original/mapping_uml2_eclipse.rb +433 -0
  169. data/original/reeper.rb +134 -0
  170. data/rakelib/cross-ruby.rake +308 -0
  171. data/spec/acceptance/express_to_owl_spec.rb +18 -0
  172. data/spec/acceptance/version_spec.rb +12 -0
  173. data/spec/expressir/express/repository_spec.rb +25 -0
  174. data/spec/expressir/express_exp/ap233_spec.rb +22 -0
  175. data/spec/expressir/express_exp/format_remark_spec.rb +28 -0
  176. data/spec/expressir/express_exp/format_syntax_spec.rb +28 -0
  177. data/spec/expressir/express_exp/parse_remark_spec.rb +346 -0
  178. data/spec/expressir/express_exp/parse_syntax_spec.rb +3003 -0
  179. data/spec/expressir/model/find_spec.rb +110 -0
  180. data/spec/expressr_spec.rb +5 -0
  181. data/spec/spec_helper.rb +17 -0
  182. data/spec/support/console_helper.rb +29 -0
  183. metadata +357 -0
@@ -0,0 +1,41 @@
1
+ begin
2
+ RUBY_VERSION =~ /(\d+\.\d+)/
3
+ require_relative "#{$1}/express_parser"
4
+ rescue LoadError
5
+ require_relative "express_parser"
6
+ end
7
+ require 'expressir/express_exp/visitor'
8
+
9
+ module Expressir
10
+ module ExpressExp
11
+ class Parser
12
+ def self.from_exp(file)
13
+ input = File.read(file)
14
+
15
+ =begin
16
+ char_stream = Antlr4::Runtime::CharStreams.from_string(input, 'String')
17
+ lexer = ::ExpressParser::Lexer.new(char_stream)
18
+ token_stream = Antlr4::Runtime::CommonTokenStream.new(lexer)
19
+ parser = ::ExpressParser::Parser.new(token_stream)
20
+
21
+ # don't attempt to recover from any parsing error
22
+ parser.instance_variable_set(:@_err_handler, Antlr4::Runtime::BailErrorStrategy.new)
23
+
24
+ parse_tree = parser.syntax()
25
+
26
+ visitor = Visitor.new(token_stream)
27
+ repo = visitor.visit(parse_tree)
28
+ =end
29
+
30
+ parser = ::ExpressParser::Parser.parse(input)
31
+
32
+ parse_tree = parser.syntax()
33
+
34
+ visitor = Visitor.new(parser.tokens)
35
+ repo = visitor.visit(parse_tree)
36
+
37
+ repo
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,2464 @@
1
+ begin
2
+ RUBY_VERSION =~ /(\d+\.\d+)/
3
+ require_relative "#{$1}/express_parser"
4
+ rescue LoadError
5
+ require_relative "express_parser"
6
+ end
7
+ require "expressir/model"
8
+
9
+ # static shorthands are unwrapped
10
+ # - entity attributes, function/procedure parameters, local variables
11
+ #
12
+ # reference type is not recognized
13
+ # see note in A.1.5 Interpreted identifiers
14
+ # > It is expected that identifiers matching these syntax rules are known to an implementation.
15
+ # > How the implementation obtains this information is of no concern to the definition of the language. One
16
+ # > method of gaining this information is multi-pass parsing: the first pass collects the identifiers from their
17
+ # > declarations, so that subsequent passes are then able to distinguish a veriable_ref from a function_ref,
18
+ # > for example.
19
+ #
20
+ # - xxxRef - merged to SimpleReference
21
+ # - entityConstructor, functionCall - merged to Call
22
+ #
23
+ # difference between generalized and instantiable types is not recognized
24
+ # see note in 8.6.2 Parameter data types
25
+ # > A syntactic construct such as ARRAY[1:3] OF REAL satisfies two syntactic productions —
26
+ # > aggregation_type and general_aggregation_type. It is considered to be instantiable no matter which
27
+ # > production it is required to satisfy in the syntax.
28
+
29
+ module Expressir
30
+ module ExpressExp
31
+ class Visitor < ::ExpressParser::Visitor
32
+ REMARK_CHANNEL = 2
33
+
34
+ def initialize(tokens)
35
+ @tokens = tokens
36
+ @attached_remarks = Set.new
37
+
38
+ super()
39
+ end
40
+
41
+ def visit(ctx)
42
+ result = super(ctx)
43
+ attach_source(ctx, result)
44
+ attach_parent(ctx, result)
45
+ attach_remarks(ctx, result)
46
+ result
47
+ end
48
+
49
+ def visit_if(ctx)
50
+ visit(ctx) if ctx
51
+ end
52
+
53
+ def visit_if_map(ctx)
54
+ ctx.map{|ctx2| visit(ctx2)} if ctx
55
+ end
56
+
57
+ def visit_if_map_flatten(ctx)
58
+ ctx.map{|ctx2| visit(ctx2)}.flatten if ctx
59
+ end
60
+
61
+ def attach_source(ctx, node)
62
+ if node.class.method_defined? :source
63
+ start_index, stop_index = [ctx.start.token_index, ctx.stop.token_index]
64
+ node.source = @tokens[start_index..stop_index].map{|x| x.text}.join('').force_encoding('UTF-8')
65
+ end
66
+ end
67
+
68
+ def attach_parent(ctx, node)
69
+ if node.class.method_defined? :children
70
+ node.children.each do |child_node|
71
+ if child_node.class.method_defined? :parent
72
+ child_node.parent = node
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ def attach_remarks(ctx, node)
79
+ # get remark tokens
80
+ start_index, stop_index = if ctx.instance_of? ::ExpressParser::SyntaxContext
81
+ [0, @tokens.size - 1]
82
+ else
83
+ [ctx.start.token_index, ctx.stop.token_index]
84
+ end
85
+ # puts [start_index, stop_index, ctx.class].inspect
86
+
87
+ remark_tokens = @tokens[start_index..stop_index].select{|x| x.channel == REMARK_CHANNEL}
88
+ if remark_tokens
89
+ remark_tokens.each do |remark_token|
90
+ remark_text = remark_token.text
91
+
92
+ # check if it is tagged remark
93
+ match = if remark_text.start_with?('--')
94
+ remark_text[2..-1].match(/^"([^"]*)"(.*)$/)
95
+ elsif remark_text.start_with?('(*') and remark_text.end_with?('*)')
96
+ remark_text[2..-3].match(/^"([^"]*)"(.*)$/m)
97
+ end
98
+ if !match
99
+ next
100
+ end
101
+
102
+ # don't attach already attached tagged remark
103
+ if @attached_remarks.include? remark_token
104
+ next
105
+ end
106
+
107
+ # attach tagged remark
108
+ remark_tag = match[1]
109
+ remark_content = match[2].strip.force_encoding('UTF-8')
110
+
111
+ target_node = nil
112
+ current_node = node
113
+ if current_node.class.method_defined? :find
114
+ target_node = current_node.find(remark_tag)
115
+ end
116
+ while !target_node and current_node.class.method_defined? :parent and current_node.parent.class.method_defined? :find
117
+ current_node = current_node.parent
118
+ target_node = current_node.find(remark_tag)
119
+ end
120
+
121
+ if target_node
122
+ target_node.remarks ||= []
123
+ target_node.remarks << remark_content
124
+
125
+ # mark remark as attached, so that it is not attached again at higher nesting level
126
+ @attached_remarks << remark_token
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ def visit_attribute_ref(ctx)
133
+ ctx__attribute_id = ctx.attribute_id
134
+
135
+ id = visit_if(ctx__attribute_id)
136
+
137
+ Model::Expressions::SimpleReference.new({
138
+ id: id
139
+ })
140
+ end
141
+
142
+ def visit_constant_ref(ctx)
143
+ ctx__constant_id = ctx.constant_id
144
+
145
+ id = visit_if(ctx__constant_id)
146
+
147
+ Model::Expressions::SimpleReference.new({
148
+ id: id
149
+ })
150
+ end
151
+
152
+ def visit_entity_ref(ctx)
153
+ ctx__entity_id = ctx.entity_id
154
+
155
+ id = visit_if(ctx__entity_id)
156
+
157
+ Model::Expressions::SimpleReference.new({
158
+ id: id
159
+ })
160
+ end
161
+
162
+ def visit_enumeration_ref(ctx)
163
+ ctx__enumeration_id = ctx.enumeration_id
164
+
165
+ id = visit_if(ctx__enumeration_id)
166
+
167
+ Model::Expressions::SimpleReference.new({
168
+ id: id
169
+ })
170
+ end
171
+
172
+ def visit_function_ref(ctx)
173
+ ctx__function_id = ctx.function_id
174
+
175
+ id = visit_if(ctx__function_id)
176
+
177
+ Model::Expressions::SimpleReference.new({
178
+ id: id
179
+ })
180
+ end
181
+
182
+ def visit_parameter_ref(ctx)
183
+ ctx__parameter_id = ctx.parameter_id
184
+
185
+ id = visit_if(ctx__parameter_id)
186
+
187
+ Model::Expressions::SimpleReference.new({
188
+ id: id
189
+ })
190
+ end
191
+
192
+ def visit_procedure_ref(ctx)
193
+ ctx__procedure_id = ctx.procedure_id
194
+
195
+ id = visit_if(ctx__procedure_id)
196
+
197
+ Model::Expressions::SimpleReference.new({
198
+ id: id
199
+ })
200
+ end
201
+
202
+ def visit_rule_label_ref(ctx)
203
+ ctx__rule_label_id = ctx.rule_label_id
204
+
205
+ id = visit_if(ctx__rule_label_id)
206
+
207
+ Model::Expressions::SimpleReference.new({
208
+ id: id
209
+ })
210
+ end
211
+
212
+ def visit_rule_ref(ctx)
213
+ ctx__rule_id = ctx.rule_id
214
+
215
+ id = visit_if(ctx__rule_id)
216
+
217
+ Model::Expressions::SimpleReference.new({
218
+ id: id
219
+ })
220
+ end
221
+
222
+ def visit_schema_ref(ctx)
223
+ ctx__schema_id = ctx.schema_id
224
+
225
+ id = visit_if(ctx__schema_id)
226
+
227
+ Model::Expressions::SimpleReference.new({
228
+ id: id
229
+ })
230
+ end
231
+
232
+ def visit_subtype_constraint_ref(ctx)
233
+ ctx__subtype_constraint_id = ctx.subtype_constraint_id
234
+
235
+ id = visit_if(ctx__subtype_constraint_id)
236
+
237
+ Model::Expressions::SimpleReference.new({
238
+ id: id
239
+ })
240
+ end
241
+
242
+ def visit_type_label_ref(ctx)
243
+ ctx__type_label_id = ctx.type_label_id
244
+
245
+ id = visit_if(ctx__type_label_id)
246
+
247
+ Model::Expressions::SimpleReference.new({
248
+ id: id
249
+ })
250
+ end
251
+
252
+ def visit_type_ref(ctx)
253
+ ctx__type_id = ctx.type_id
254
+
255
+ id = visit_if(ctx__type_id)
256
+
257
+ Model::Expressions::SimpleReference.new({
258
+ id: id
259
+ })
260
+ end
261
+
262
+ def visit_variable_ref(ctx)
263
+ ctx__variable_id = ctx.variable_id
264
+
265
+ id = visit_if(ctx__variable_id)
266
+
267
+ Model::Expressions::SimpleReference.new({
268
+ id: id
269
+ })
270
+ end
271
+
272
+ def visit_abstract_entity_declaration(ctx)
273
+ raise 'Invalid state'
274
+ end
275
+
276
+ def visit_abstract_supertype(ctx)
277
+ raise 'Invalid state'
278
+ end
279
+
280
+ def visit_abstract_supertype_declaration(ctx)
281
+ ctx__subtype_constraint = ctx.subtype_constraint
282
+
283
+ visit_if(ctx__subtype_constraint)
284
+ end
285
+
286
+ def visit_actual_parameter_list(ctx)
287
+ ctx__parameter = ctx.parameter
288
+
289
+ visit_if_map(ctx__parameter)
290
+ end
291
+
292
+ def visit_add_like_op(ctx)
293
+ ctx__text = ctx.text
294
+ ctx__ADDITION = ctx__text == '+'
295
+ ctx__SUBTRACTION = ctx__text == '-'
296
+ ctx__OR = ctx.OR
297
+ ctx__XOR = ctx.XOR
298
+
299
+ if ctx__ADDITION
300
+ Model::Expressions::BinaryExpression::ADDITION
301
+ elsif ctx__SUBTRACTION
302
+ Model::Expressions::BinaryExpression::SUBTRACTION
303
+ elsif ctx__OR
304
+ Model::Expressions::BinaryExpression::OR
305
+ elsif ctx__XOR
306
+ Model::Expressions::BinaryExpression::XOR
307
+ else
308
+ raise 'Invalid state'
309
+ end
310
+ end
311
+
312
+ def visit_aggregate_initializer(ctx)
313
+ ctx__element = ctx.element
314
+
315
+ items = visit_if_map(ctx__element)
316
+
317
+ Model::Expressions::AggregateInitializer.new({
318
+ items: items
319
+ })
320
+ end
321
+
322
+ def visit_aggregate_source(ctx)
323
+ ctx__simple_expression = ctx.simple_expression
324
+
325
+ visit_if(ctx__simple_expression)
326
+ end
327
+
328
+ def visit_aggregate_type(ctx)
329
+ ctx__type_label = ctx.type_label
330
+ ctx__parameter_type = ctx.parameter_type
331
+
332
+ id = visit_if(ctx__type_label)
333
+ base_type = visit_if(ctx__parameter_type)
334
+
335
+ Model::Types::Aggregate.new({
336
+ id: id,
337
+ base_type: base_type
338
+ })
339
+ end
340
+
341
+ def visit_aggregation_types(ctx)
342
+ ctx__array_type = ctx.array_type
343
+ ctx__bag_type = ctx.bag_type
344
+ ctx__list_type = ctx.list_type
345
+ ctx__set_type = ctx.set_type
346
+
347
+ visit_if(ctx__array_type || ctx__bag_type || ctx__list_type || ctx__set_type)
348
+ end
349
+
350
+ def visit_algorithm_head(ctx)
351
+ raise 'Invalid state'
352
+ end
353
+
354
+ def visit_alias_stmt(ctx)
355
+ ctx__variable_id = ctx.variable_id
356
+ ctx__general_ref = ctx.general_ref
357
+ ctx__qualifier = ctx.qualifier
358
+ ctx__stmt = ctx.stmt
359
+
360
+ id = visit_if(ctx__variable_id)
361
+ expression = handle_qualified_ref(visit_if(ctx__general_ref), ctx__qualifier)
362
+ statements = visit_if_map(ctx__stmt)
363
+
364
+ Model::Statements::Alias.new({
365
+ id: id,
366
+ expression: expression,
367
+ statements: statements
368
+ })
369
+ end
370
+
371
+ def visit_array_type(ctx)
372
+ ctx__bound_spec = ctx.bound_spec
373
+ ctx__OPTIONAL = ctx.OPTIONAL
374
+ ctx__UNIQUE = ctx.UNIQUE
375
+ ctx__instantiable_type = ctx.instantiable_type
376
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
377
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
378
+
379
+ bound1 = visit_if(ctx__bound_spec__bound1)
380
+ bound2 = visit_if(ctx__bound_spec__bound2)
381
+ optional = !!ctx__OPTIONAL
382
+ unique = !!ctx__UNIQUE
383
+ base_type = visit_if(ctx__instantiable_type)
384
+
385
+ Model::Types::Array.new({
386
+ bound1: bound1,
387
+ bound2: bound2,
388
+ optional: optional,
389
+ unique: unique,
390
+ base_type: base_type
391
+ })
392
+ end
393
+
394
+ def visit_assignment_stmt(ctx)
395
+ ctx__general_ref = ctx.general_ref
396
+ ctx__qualifier = ctx.qualifier
397
+ ctx__expression = ctx.expression
398
+
399
+ ref = handle_qualified_ref(visit_if(ctx__general_ref), ctx__qualifier)
400
+ expression = visit_if(ctx__expression)
401
+
402
+ Model::Statements::Assignment.new({
403
+ ref: ref,
404
+ expression: expression
405
+ })
406
+ end
407
+
408
+ def visit_attribute_decl(ctx)
409
+ ctx__attribute_id = ctx.attribute_id
410
+ ctx__redeclared_attribute = ctx.redeclared_attribute
411
+ ctx__redeclared_attribute__qualified_attribute = ctx__redeclared_attribute&.qualified_attribute
412
+ ctx__redeclared_attribute__attribute_id = ctx__redeclared_attribute&.attribute_id
413
+
414
+ id = visit_if(ctx__attribute_id || ctx__redeclared_attribute__attribute_id)
415
+ supertype_attribute = visit_if(ctx__redeclared_attribute__qualified_attribute)
416
+
417
+ Model::Attribute.new({
418
+ id: id,
419
+ supertype_attribute: supertype_attribute
420
+ })
421
+ end
422
+
423
+ def visit_attribute_id(ctx)
424
+ ctx__SimpleId = ctx.SimpleId
425
+
426
+ handle_simple_id(ctx__SimpleId)
427
+ end
428
+
429
+ def visit_attribute_qualifier(ctx)
430
+ ctx__attribute_ref = ctx.attribute_ref
431
+
432
+ attribute = visit_if(ctx__attribute_ref)
433
+
434
+ Model::Expressions::AttributeReference.new({
435
+ attribute: attribute
436
+ })
437
+ end
438
+
439
+ def visit_attribute_reference(ctx)
440
+ raise 'Invalid state'
441
+ end
442
+
443
+ def visit_bag_type(ctx)
444
+ ctx__bound_spec = ctx.bound_spec
445
+ ctx__instantiable_type = ctx.instantiable_type
446
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
447
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
448
+
449
+ bound1 = visit_if(ctx__bound_spec__bound1)
450
+ bound2 = visit_if(ctx__bound_spec__bound2)
451
+ base_type = visit_if(ctx__instantiable_type)
452
+
453
+ Model::Types::Bag.new({
454
+ bound1: bound1,
455
+ bound2: bound2,
456
+ base_type: base_type
457
+ })
458
+ end
459
+
460
+ def visit_binary_type(ctx)
461
+ ctx__width_spec = ctx.width_spec
462
+ ctx__width_spec__width = ctx__width_spec&.width
463
+ ctx__width_spec__FIXED = ctx__width_spec&.FIXED
464
+
465
+ width = visit_if(ctx__width_spec__width)
466
+ fixed = !!ctx__width_spec__FIXED
467
+
468
+ Model::Types::Binary.new({
469
+ width: width,
470
+ fixed: fixed
471
+ })
472
+ end
473
+
474
+ def visit_boolean_type(ctx)
475
+ Model::Types::Boolean.new
476
+ end
477
+
478
+ def visit_bound1(ctx)
479
+ ctx__numeric_expression = ctx.numeric_expression
480
+
481
+ visit_if(ctx__numeric_expression)
482
+ end
483
+
484
+ def visit_bound2(ctx)
485
+ ctx__numeric_expression = ctx.numeric_expression
486
+
487
+ visit_if(ctx__numeric_expression)
488
+ end
489
+
490
+ def visit_bound_spec(ctx)
491
+ raise 'Invalid state'
492
+ end
493
+
494
+ def visit_built_in_constant(ctx)
495
+ ctx__text = ctx.text
496
+
497
+ id = ctx__text
498
+
499
+ Model::Expressions::SimpleReference.new({
500
+ id: id
501
+ })
502
+ end
503
+
504
+ def visit_built_in_function(ctx)
505
+ ctx__text = ctx.text
506
+
507
+ id = ctx__text
508
+
509
+ Model::Expressions::SimpleReference.new({
510
+ id: id
511
+ })
512
+ end
513
+
514
+ def visit_built_in_procedure(ctx)
515
+ ctx__text = ctx.text
516
+
517
+ id = ctx__text
518
+
519
+ Model::Expressions::SimpleReference.new({
520
+ id: id
521
+ })
522
+ end
523
+
524
+ def visit_case_action(ctx)
525
+ ctx__case_label = ctx.case_label
526
+ ctx__stmt = ctx.stmt
527
+
528
+ labels = visit_if_map(ctx__case_label)
529
+ statement = visit_if(ctx__stmt)
530
+
531
+ Model::Statements::CaseAction.new({
532
+ labels: labels,
533
+ statement: statement
534
+ })
535
+ end
536
+
537
+ def visit_case_label(ctx)
538
+ ctx__expression = ctx.expression
539
+
540
+ visit_if(ctx__expression)
541
+ end
542
+
543
+ def visit_case_stmt(ctx)
544
+ ctx__selector = ctx.selector
545
+ ctx__case_action = ctx.case_action
546
+ ctx__stmt = ctx.stmt
547
+ ctx__selector__expression = ctx__selector&.expression
548
+
549
+ expression = visit_if(ctx__selector__expression)
550
+ actions = visit_if_map_flatten(ctx__case_action)
551
+ otherwise_statement = visit_if(ctx__stmt)
552
+
553
+ Model::Statements::Case.new({
554
+ expression: expression,
555
+ actions: actions,
556
+ otherwise_statement: otherwise_statement
557
+ })
558
+ end
559
+
560
+ def visit_compound_stmt(ctx)
561
+ ctx__stmt = ctx.stmt
562
+
563
+ statements = visit_if_map(ctx__stmt)
564
+
565
+ Model::Statements::Compound.new({
566
+ statements: statements
567
+ })
568
+ end
569
+
570
+ def visit_concrete_types(ctx)
571
+ ctx__aggregation_types = ctx.aggregation_types
572
+ ctx__simple_types = ctx.simple_types
573
+ ctx__type_ref = ctx.type_ref
574
+
575
+ visit_if(ctx__aggregation_types || ctx__simple_types || ctx__type_ref)
576
+ end
577
+
578
+ def visit_constant_body(ctx)
579
+ ctx__constant_id = ctx.constant_id
580
+ ctx__instantiable_type = ctx.instantiable_type
581
+ ctx__expression = ctx.expression
582
+
583
+ id = visit_if(ctx__constant_id)
584
+ type = visit_if(ctx__instantiable_type)
585
+ expression = visit_if(ctx__expression)
586
+
587
+ Model::Constant.new({
588
+ id: id,
589
+ type: type,
590
+ expression: expression
591
+ })
592
+ end
593
+
594
+ def visit_constant_decl(ctx)
595
+ ctx__constant_body = ctx.constant_body
596
+
597
+ visit_if_map(ctx__constant_body)
598
+ end
599
+
600
+ def visit_constant_factor(ctx)
601
+ ctx__built_in_constant = ctx.built_in_constant
602
+ ctx__constant_ref = ctx.constant_ref
603
+
604
+ visit_if(ctx__built_in_constant || ctx__constant_ref)
605
+ end
606
+
607
+ def visit_constant_id(ctx)
608
+ ctx__SimpleId = ctx.SimpleId
609
+
610
+ handle_simple_id(ctx__SimpleId)
611
+ end
612
+
613
+ def visit_constructed_types(ctx)
614
+ ctx__enumeration_type = ctx.enumeration_type
615
+ ctx__select_type = ctx.select_type
616
+
617
+ visit_if(ctx__enumeration_type || ctx__select_type)
618
+ end
619
+
620
+ def visit_declaration(ctx)
621
+ ctx__entity_decl = ctx.entity_decl
622
+ ctx__function_decl = ctx.function_decl
623
+ ctx__procedure_decl = ctx.procedure_decl
624
+ ctx__subtype_constraint_decl = ctx.subtype_constraint_decl
625
+ ctx__type_decl = ctx.type_decl
626
+
627
+ visit_if(ctx__entity_decl || ctx__function_decl || ctx__procedure_decl || ctx__subtype_constraint_decl || ctx__type_decl)
628
+ end
629
+
630
+ def visit_derived_attr(ctx)
631
+ ctx__attribute_decl = ctx.attribute_decl
632
+ ctx__parameter_type = ctx.parameter_type
633
+ ctx__expression = ctx.expression
634
+
635
+ attribute = visit_if(ctx__attribute_decl)
636
+ type = visit_if(ctx__parameter_type)
637
+ expression = visit_if(ctx__expression)
638
+
639
+ Model::Attribute.new({
640
+ id: attribute.id,
641
+ kind: Model::Attribute::DERIVED,
642
+ supertype_attribute: attribute.supertype_attribute,
643
+ type: type,
644
+ expression: expression
645
+ })
646
+ end
647
+
648
+ def visit_derive_clause(ctx)
649
+ ctx__derived_attr = ctx.derived_attr
650
+
651
+ visit_if_map(ctx__derived_attr)
652
+ end
653
+
654
+ def visit_domain_rule(ctx)
655
+ ctx__rule_label_id = ctx.rule_label_id
656
+ ctx__expression = ctx.expression
657
+
658
+ id = visit_if(ctx__rule_label_id)
659
+ expression = visit_if(ctx__expression)
660
+
661
+ Model::Where.new({
662
+ id: id,
663
+ expression: expression
664
+ })
665
+ end
666
+
667
+ def visit_element(ctx)
668
+ ctx__expression = ctx.expression
669
+ ctx__repetition = ctx.repetition
670
+
671
+ if ctx__repetition
672
+ expression = visit_if(ctx__expression)
673
+ repetition = visit_if(ctx__repetition)
674
+
675
+ Model::Expressions::AggregateItem.new({
676
+ expression: expression,
677
+ repetition: repetition
678
+ })
679
+ else
680
+ visit_if(ctx__expression)
681
+ end
682
+ end
683
+
684
+ def visit_entity_body(ctx)
685
+ raise 'Invalid state'
686
+ end
687
+
688
+ def visit_entity_constructor(ctx)
689
+ ctx__entity_ref = ctx.entity_ref
690
+ ctx__expression = ctx.expression
691
+
692
+ ref = visit_if(ctx__entity_ref)
693
+ parameters = visit_if_map(ctx__expression)
694
+
695
+ Model::Expressions::Call.new({
696
+ ref: ref,
697
+ parameters: parameters
698
+ })
699
+ end
700
+
701
+ def visit_entity_decl(ctx)
702
+ ctx__entity_head = ctx.entity_head
703
+ ctx__entity_body = ctx.entity_body
704
+ ctx__entity_head__entity_id = ctx__entity_head&.entity_id
705
+ ctx__entity_head__subsuper = ctx__entity_head&.subsuper
706
+ ctx__entity_head__subsuper__supertype_constraint = ctx__entity_head__subsuper&.supertype_constraint
707
+ ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration = ctx__entity_head__subsuper__supertype_constraint&.abstract_entity_declaration
708
+ ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration = ctx__entity_head__subsuper__supertype_constraint&.abstract_supertype_declaration
709
+ ctx__entity_head__subsuper__supertype_constraint__supertype_rule = ctx__entity_head__subsuper__supertype_constraint&.supertype_rule
710
+ ctx__entity_head__subsuper__subtype_declaration = ctx__entity_head__subsuper&.subtype_declaration
711
+ ctx__entity_body__explicit_attr = ctx__entity_body&.explicit_attr
712
+ ctx__entity_body__derive_clause = ctx__entity_body&.derive_clause
713
+ ctx__entity_body__inverse_clause = ctx__entity_body&.inverse_clause
714
+ ctx__entity_body__unique_clause = ctx__entity_body&.unique_clause
715
+ ctx__entity_body__where_clause = ctx__entity_body&.where_clause
716
+
717
+ id = visit_if(ctx__entity_head__entity_id)
718
+ abstract = !!(ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration || ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration)
719
+ supertype_expression = visit_if(ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration || ctx__entity_head__subsuper__supertype_constraint__supertype_rule)
720
+ subtype_of = visit_if(ctx__entity_head__subsuper__subtype_declaration)
721
+ attributes = [
722
+ *visit_if_map_flatten(ctx__entity_body__explicit_attr),
723
+ *visit_if(ctx__entity_body__derive_clause),
724
+ *visit_if(ctx__entity_body__inverse_clause)
725
+ ]
726
+ unique = visit_if(ctx__entity_body__unique_clause)
727
+ where = visit_if(ctx__entity_body__where_clause)
728
+
729
+ Model::Entity.new({
730
+ id: id,
731
+ abstract: abstract,
732
+ supertype_expression: supertype_expression,
733
+ subtype_of: subtype_of,
734
+ attributes: attributes,
735
+ unique: unique,
736
+ where: where
737
+ })
738
+ end
739
+
740
+ def visit_entity_head(ctx)
741
+ raise 'Invalid state'
742
+ end
743
+
744
+ def visit_entity_id(ctx)
745
+ ctx__SimpleId = ctx.SimpleId
746
+
747
+ handle_simple_id(ctx__SimpleId)
748
+ end
749
+
750
+ def visit_enumeration_extension(ctx)
751
+ raise 'Invalid state'
752
+ end
753
+
754
+ def visit_enumeration_id(ctx)
755
+ ctx__SimpleId = ctx.SimpleId
756
+
757
+ handle_simple_id(ctx__SimpleId)
758
+ end
759
+
760
+ def visit_enumeration_items(ctx)
761
+ ctx__enumeration_item = ctx.enumeration_item
762
+
763
+ visit_if_map(ctx__enumeration_item)
764
+ end
765
+
766
+ def visit_enumeration_item(ctx)
767
+ ctx__enumeration_id = ctx.enumeration_id
768
+
769
+ id = visit_if(ctx__enumeration_id)
770
+
771
+ Model::EnumerationItem.new({
772
+ id: id
773
+ })
774
+ end
775
+
776
+ def visit_enumeration_reference(ctx)
777
+ ctx__type_ref = ctx.type_ref
778
+ ctx__enumeration_ref = ctx.enumeration_ref
779
+
780
+ if ctx__type_ref
781
+ ref = visit_if(ctx__type_ref)
782
+ attribute = visit_if(ctx__enumeration_ref)
783
+
784
+ Model::Expressions::AttributeReference.new({
785
+ ref: ref,
786
+ attribute: attribute
787
+ })
788
+ else
789
+ visit_if(ctx__enumeration_ref)
790
+ end
791
+ end
792
+
793
+ def visit_enumeration_type(ctx)
794
+ ctx__EXTENSIBLE = ctx.EXTENSIBLE
795
+ ctx__enumeration_items = ctx.enumeration_items
796
+ ctx__enumeration_extension = ctx.enumeration_extension
797
+ ctx__enumeration_extension__type_ref = ctx__enumeration_extension&.type_ref
798
+ ctx__enumeration_extension__enumeration_items = ctx__enumeration_extension&.enumeration_items
799
+
800
+ extensible = !!ctx__EXTENSIBLE
801
+ items = visit_if(ctx__enumeration_items)
802
+ extension_type = visit_if(ctx__enumeration_extension__type_ref)
803
+ extension_items = visit_if(ctx__enumeration_extension__enumeration_items)
804
+
805
+ Model::Types::Enumeration.new({
806
+ extensible: extensible,
807
+ items: items,
808
+ extension_type: extension_type,
809
+ extension_items: extension_items
810
+ })
811
+ end
812
+
813
+ def visit_escape_stmt(ctx)
814
+ Model::Statements::Escape.new
815
+ end
816
+
817
+ def visit_explicit_attr(ctx)
818
+ ctx__attribute_decl = ctx.attribute_decl
819
+ ctx__OPTIONAL = ctx.OPTIONAL
820
+ ctx__parameter_type = ctx.parameter_type
821
+
822
+ attributes = visit_if_map(ctx__attribute_decl)
823
+ optional = !!ctx__OPTIONAL
824
+ type = visit_if(ctx__parameter_type)
825
+
826
+ attributes.map do |attribute|
827
+ Model::Attribute.new({
828
+ id: attribute.id,
829
+ kind: Model::Attribute::EXPLICIT,
830
+ supertype_attribute: attribute.supertype_attribute,
831
+ optional: optional,
832
+ type: type
833
+ })
834
+ end
835
+ end
836
+
837
+ def visit_expression(ctx)
838
+ ctx__simple_expression = ctx.simple_expression
839
+ ctx__rel_op_extended = ctx.rel_op_extended
840
+
841
+ if ctx__simple_expression.length == 2
842
+ operator = visit_if(ctx__rel_op_extended)
843
+ operand1 = visit_if(ctx__simple_expression[0])
844
+ operand2 = visit_if(ctx__simple_expression[1])
845
+
846
+ Model::Expressions::BinaryExpression.new({
847
+ operator: operator,
848
+ operand1: operand1,
849
+ operand2: operand2
850
+ })
851
+ else
852
+ visit_if(ctx__simple_expression[0])
853
+ end
854
+ end
855
+
856
+ def visit_factor(ctx)
857
+ ctx__simple_factor = ctx.simple_factor
858
+
859
+ if ctx__simple_factor.length == 2
860
+ operator = Model::Expressions::BinaryExpression::EXPONENTIATION
861
+ operand1 = visit(ctx__simple_factor[0])
862
+ operand2 = visit(ctx__simple_factor[1])
863
+
864
+ Model::Expressions::BinaryExpression.new({
865
+ operator: operator,
866
+ operand1: operand1,
867
+ operand2: operand2
868
+ })
869
+ elsif ctx__simple_factor.length == 1
870
+ visit_if(ctx__simple_factor[0])
871
+ else
872
+ raise 'Invalid state'
873
+ end
874
+ end
875
+
876
+ def visit_formal_parameter(ctx)
877
+ ctx__parameter_id = ctx.parameter_id
878
+ ctx__parameter_type = ctx.parameter_type
879
+
880
+ ids = visit_if_map(ctx__parameter_id)
881
+ type = visit_if(ctx__parameter_type)
882
+
883
+ ids.map do |id|
884
+ Model::Parameter.new({
885
+ id: id,
886
+ type: type
887
+ })
888
+ end
889
+ end
890
+
891
+ def visit_function_call(ctx)
892
+ ctx__built_in_function = ctx.built_in_function
893
+ ctx__function_ref = ctx.function_ref
894
+ ctx__actual_parameter_list = ctx.actual_parameter_list
895
+
896
+ ref = visit_if(ctx__built_in_function || ctx__function_ref)
897
+ parameters = visit_if(ctx__actual_parameter_list)
898
+
899
+ Model::Expressions::Call.new({
900
+ ref: ref,
901
+ parameters: parameters
902
+ })
903
+ end
904
+
905
+ def visit_function_decl(ctx)
906
+ ctx__function_head = ctx.function_head
907
+ ctx__algorithm_head = ctx.algorithm_head
908
+ ctx__stmt = ctx.stmt
909
+ ctx__function_head__function_id = ctx__function_head&.function_id
910
+ ctx__function_head__formal_parameter = ctx__function_head&.formal_parameter
911
+ ctx__function_head__parameter_type = ctx__function_head&.parameter_type
912
+ ctx__algorithm_head__declaration = ctx__algorithm_head&.declaration
913
+ ctx__algorithm_head__constant_decl = ctx__algorithm_head&.constant_decl
914
+ ctx__algorithm_head__local_decl = ctx__algorithm_head&.local_decl
915
+
916
+ id = visit_if(ctx__function_head__function_id)
917
+ parameters = visit_if_map_flatten(ctx__function_head__formal_parameter)
918
+ return_type = visit_if(ctx__function_head__parameter_type)
919
+ declarations = visit_if_map(ctx__algorithm_head__declaration)
920
+ constants = visit_if(ctx__algorithm_head__constant_decl)
921
+ variables = visit_if(ctx__algorithm_head__local_decl)
922
+ statements = visit_if_map(ctx__stmt)
923
+
924
+ Model::Function.new({
925
+ id: id,
926
+ parameters: parameters,
927
+ return_type: return_type,
928
+ declarations: declarations,
929
+ constants: constants,
930
+ variables: variables,
931
+ statements: statements
932
+ })
933
+ end
934
+
935
+ def visit_function_head(ctx)
936
+ raise 'Invalid state'
937
+ end
938
+
939
+ def visit_function_id(ctx)
940
+ ctx__SimpleId = ctx.SimpleId
941
+
942
+ handle_simple_id(ctx__SimpleId)
943
+ end
944
+
945
+ def visit_generalized_types(ctx)
946
+ ctx__aggregate_type = ctx.aggregate_type
947
+ ctx__general_aggregation_types = ctx.general_aggregation_types
948
+ ctx__generic_entity_type = ctx.generic_entity_type
949
+ ctx__generic_type = ctx.generic_type
950
+
951
+ visit_if(ctx__aggregate_type || ctx__general_aggregation_types || ctx__generic_entity_type || ctx__generic_type)
952
+ end
953
+
954
+ def visit_general_aggregation_types(ctx)
955
+ ctx__general_array_type = ctx.general_array_type
956
+ ctx__general_bag_type = ctx.general_bag_type
957
+ ctx__general_list_type = ctx.general_list_type
958
+ ctx__general_set_type = ctx.general_set_type
959
+
960
+ visit_if(ctx__general_array_type || ctx__general_bag_type || ctx__general_list_type || ctx__general_set_type)
961
+ end
962
+
963
+ def visit_general_array_type(ctx)
964
+ ctx__bound_spec = ctx.bound_spec
965
+ ctx__OPTIONAL = ctx.OPTIONAL
966
+ ctx__UNIQUE = ctx.UNIQUE
967
+ ctx__parameter_type = ctx.parameter_type
968
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
969
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
970
+
971
+ bound1 = visit_if(ctx__bound_spec__bound1)
972
+ bound2 = visit_if(ctx__bound_spec__bound2)
973
+ optional = !!ctx__OPTIONAL
974
+ unique = !!ctx__UNIQUE
975
+ base_type = visit_if(ctx__parameter_type)
976
+
977
+ Model::Types::Array.new({
978
+ bound1: bound1,
979
+ bound2: bound2,
980
+ optional: optional,
981
+ unique: unique,
982
+ base_type: base_type
983
+ })
984
+ end
985
+
986
+ def visit_general_bag_type(ctx)
987
+ ctx__bound_spec = ctx.bound_spec
988
+ ctx__parameter_type = ctx.parameter_type
989
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
990
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
991
+
992
+ bound1 = visit_if(ctx__bound_spec__bound1)
993
+ bound2 = visit_if(ctx__bound_spec__bound2)
994
+ base_type = visit_if(ctx__parameter_type)
995
+
996
+ Model::Types::Bag.new({
997
+ bound1: bound1,
998
+ bound2: bound2,
999
+ base_type: base_type
1000
+ })
1001
+ end
1002
+
1003
+ def visit_general_list_type(ctx)
1004
+ ctx__bound_spec = ctx.bound_spec
1005
+ ctx__UNIQUE = ctx.UNIQUE
1006
+ ctx__parameter_type = ctx.parameter_type
1007
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
1008
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
1009
+
1010
+ bound1 = visit_if(ctx__bound_spec__bound1)
1011
+ bound2 = visit_if(ctx__bound_spec__bound2)
1012
+ unique = !!ctx__UNIQUE
1013
+ base_type = visit_if(ctx__parameter_type)
1014
+
1015
+ Model::Types::List.new({
1016
+ bound1: bound1,
1017
+ bound2: bound2,
1018
+ unique: unique,
1019
+ base_type: base_type
1020
+ })
1021
+ end
1022
+
1023
+ def visit_general_ref(ctx)
1024
+ ctx__parameter_ref = ctx.parameter_ref
1025
+ ctx__variable_id = ctx.variable_id
1026
+
1027
+ visit_if(ctx__parameter_ref || ctx__variable_id)
1028
+ end
1029
+
1030
+ def visit_general_set_type(ctx)
1031
+ ctx__bound_spec = ctx.bound_spec
1032
+ ctx__parameter_type = ctx.parameter_type
1033
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
1034
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
1035
+
1036
+ bound1 = visit_if(ctx__bound_spec__bound1)
1037
+ bound2 = visit_if(ctx__bound_spec__bound2)
1038
+ base_type = visit_if(ctx__parameter_type)
1039
+
1040
+ Model::Types::Set.new({
1041
+ bound1: bound1,
1042
+ bound2: bound2,
1043
+ base_type: base_type
1044
+ })
1045
+ end
1046
+
1047
+ def visit_generic_entity_type(ctx)
1048
+ ctx__type_label = ctx.type_label
1049
+
1050
+ id = visit_if(ctx__type_label)
1051
+
1052
+ Model::Types::GenericEntity.new({
1053
+ id: id
1054
+ })
1055
+ end
1056
+
1057
+ def visit_generic_type(ctx)
1058
+ ctx__type_label = ctx.type_label
1059
+
1060
+ id = visit_if(ctx__type_label)
1061
+
1062
+ Model::Types::Generic.new({
1063
+ id: id
1064
+ })
1065
+ end
1066
+
1067
+ def visit_group_qualifier(ctx)
1068
+ ctx__entity_ref = ctx.entity_ref
1069
+
1070
+ entity = visit_if(ctx__entity_ref)
1071
+
1072
+ Model::Expressions::GroupReference.new({
1073
+ entity: entity
1074
+ })
1075
+ end
1076
+
1077
+ def visit_group_reference(ctx)
1078
+ raise 'Invalid state'
1079
+ end
1080
+
1081
+ def visit_if_stmt(ctx)
1082
+ ctx__logical_expression = ctx.logical_expression
1083
+ ctx__if_stmt_statements = ctx.if_stmt_statements
1084
+ ctx__if_stmt_else_statements = ctx.if_stmt_else_statements
1085
+
1086
+ expression = visit_if(ctx__logical_expression)
1087
+ statements = visit_if(ctx__if_stmt_statements)
1088
+ else_statements = visit_if(ctx__if_stmt_else_statements)
1089
+
1090
+ Model::Statements::If.new({
1091
+ expression: expression,
1092
+ statements: statements,
1093
+ else_statements: else_statements
1094
+ })
1095
+ end
1096
+
1097
+ def visit_if_stmt_statements(ctx)
1098
+ ctx__stmt = ctx.stmt
1099
+
1100
+ visit_if_map(ctx__stmt)
1101
+ end
1102
+
1103
+ def visit_if_stmt_else_statements(ctx)
1104
+ ctx__stmt = ctx.stmt
1105
+
1106
+ visit_if_map(ctx__stmt)
1107
+ end
1108
+
1109
+ def visit_increment(ctx)
1110
+ ctx__numeric_expression = ctx.numeric_expression
1111
+
1112
+ visit_if(ctx__numeric_expression)
1113
+ end
1114
+
1115
+ def visit_increment_control(ctx)
1116
+ raise 'Invalid state'
1117
+ end
1118
+
1119
+ def visit_index(ctx)
1120
+ ctx__numeric_expression = ctx.numeric_expression
1121
+
1122
+ visit_if(ctx__numeric_expression)
1123
+ end
1124
+
1125
+ def visit_index1(ctx)
1126
+ ctx__index = ctx.index
1127
+
1128
+ visit_if(ctx__index)
1129
+ end
1130
+
1131
+ def visit_index2(ctx)
1132
+ ctx__index = ctx.index
1133
+
1134
+ visit_if(ctx__index)
1135
+ end
1136
+
1137
+ def visit_index_qualifier(ctx)
1138
+ ctx__index1 = ctx.index1
1139
+ ctx__index2 = ctx.index2
1140
+
1141
+ index1 = visit_if(ctx__index1)
1142
+ index2 = visit_if(ctx__index2)
1143
+
1144
+ Model::Expressions::IndexReference.new({
1145
+ index1: index1,
1146
+ index2: index2
1147
+ })
1148
+ end
1149
+
1150
+ def visit_index_reference(ctx)
1151
+ raise 'Invalid state'
1152
+ end
1153
+
1154
+ def visit_instantiable_type(ctx)
1155
+ ctx__concrete_types = ctx.concrete_types
1156
+ ctx__entity_ref = ctx.entity_ref
1157
+
1158
+ visit_if(ctx__concrete_types || ctx__entity_ref)
1159
+ end
1160
+
1161
+ def visit_integer_type(ctx)
1162
+ Model::Types::Integer.new
1163
+ end
1164
+
1165
+ def visit_interface_specification(ctx)
1166
+ ctx__reference_clause = ctx.reference_clause
1167
+ ctx__use_clause = ctx.use_clause
1168
+
1169
+ visit_if(ctx__reference_clause || ctx__use_clause)
1170
+ end
1171
+
1172
+ def visit_interval(ctx)
1173
+ ctx__interval_low = ctx.interval_low
1174
+ ctx__interval_op = ctx.interval_op
1175
+ ctx__interval_item = ctx.interval_item
1176
+ ctx__interval_high = ctx.interval_high
1177
+
1178
+ low = visit_if(ctx__interval_low)
1179
+ operator1 = visit_if(ctx__interval_op[0])
1180
+ item = visit_if(ctx__interval_item)
1181
+ operator2 = visit_if(ctx__interval_op[1])
1182
+ high = visit_if(ctx__interval_high)
1183
+
1184
+ Model::Expressions::Interval.new({
1185
+ low: low,
1186
+ operator1: operator1,
1187
+ item: item,
1188
+ operator2: operator2,
1189
+ high: high
1190
+ })
1191
+ end
1192
+
1193
+ def visit_interval_high(ctx)
1194
+ ctx__simple_expression = ctx.simple_expression
1195
+
1196
+ visit_if(ctx__simple_expression)
1197
+ end
1198
+
1199
+ def visit_interval_item(ctx)
1200
+ ctx__simple_expression = ctx.simple_expression
1201
+
1202
+ visit_if(ctx__simple_expression)
1203
+ end
1204
+
1205
+ def visit_interval_low(ctx)
1206
+ ctx__simple_expression = ctx.simple_expression
1207
+
1208
+ visit_if(ctx__simple_expression)
1209
+ end
1210
+
1211
+ def visit_interval_op(ctx)
1212
+ ctx__text = ctx.text
1213
+ ctx__LESS_THAN = ctx__text == '<'
1214
+ ctx__LESS_THAN_OR_EQUAL = ctx__text == '<='
1215
+
1216
+ if ctx__LESS_THAN
1217
+ Model::Expressions::BinaryExpression::LESS_THAN
1218
+ elsif ctx__LESS_THAN_OR_EQUAL
1219
+ Model::Expressions::BinaryExpression::LESS_THAN_OR_EQUAL
1220
+ else
1221
+ raise 'Invalid state'
1222
+ end
1223
+ end
1224
+
1225
+ def visit_inverse_attr(ctx)
1226
+ ctx__attribute_decl = ctx.attribute_decl
1227
+ ctx__inverse_attr_type = ctx.inverse_attr_type
1228
+ ctx__entity_ref = ctx.entity_ref
1229
+ ctx__attribute_ref = ctx.attribute_ref
1230
+
1231
+ attribute = visit_if(ctx__attribute_decl)
1232
+ type = visit_if(ctx__inverse_attr_type)
1233
+ expression = if ctx__entity_ref
1234
+ ref = visit(ctx__entity_ref)
1235
+ attribute_ref = visit(ctx__attribute_ref)
1236
+
1237
+ Model::Expressions::AttributeReference.new({
1238
+ ref: ref,
1239
+ attribute: attribute_ref
1240
+ })
1241
+ else
1242
+ visit(ctx__attribute_ref)
1243
+ end
1244
+
1245
+ Model::Attribute.new({
1246
+ id: attribute.id,
1247
+ kind: Model::Attribute::INVERSE,
1248
+ supertype_attribute: attribute.supertype_attribute,
1249
+ type: type,
1250
+ expression: expression
1251
+ })
1252
+ end
1253
+
1254
+ def visit_inverse_attr_type(ctx)
1255
+ ctx__SET = ctx.SET
1256
+ ctx__BAG = ctx.BAG
1257
+ ctx__bound_spec = ctx.bound_spec
1258
+ ctx__entity_ref = ctx.entity_ref
1259
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
1260
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
1261
+
1262
+ if ctx__SET
1263
+ bound1 = visit_if(ctx__bound_spec__bound1)
1264
+ bound2 = visit_if(ctx__bound_spec__bound2)
1265
+ base_type = visit_if(ctx__entity_ref)
1266
+
1267
+ Model::Types::Set.new({
1268
+ bound1: bound1,
1269
+ bound2: bound2,
1270
+ base_type: base_type
1271
+ })
1272
+ elsif ctx__BAG
1273
+ bound1 = visit_if(ctx__bound_spec__bound1)
1274
+ bound2 = visit_if(ctx__bound_spec__bound2)
1275
+ base_type = visit_if(ctx__entity_ref)
1276
+
1277
+ Model::Types::Bag.new({
1278
+ bound1: bound1,
1279
+ bound2: bound2,
1280
+ base_type: base_type
1281
+ })
1282
+ else
1283
+ visit_if(ctx__entity_ref)
1284
+ end
1285
+ end
1286
+
1287
+ def visit_inverse_clause(ctx)
1288
+ ctx__inverse_attr = ctx.inverse_attr
1289
+
1290
+ visit_if_map(ctx__inverse_attr)
1291
+ end
1292
+
1293
+ def visit_list_type(ctx)
1294
+ ctx__bound_spec = ctx.bound_spec
1295
+ ctx__UNIQUE = ctx.UNIQUE
1296
+ ctx__instantiable_type = ctx.instantiable_type
1297
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
1298
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
1299
+
1300
+ bound1 = visit_if(ctx__bound_spec__bound1)
1301
+ bound2 = visit_if(ctx__bound_spec__bound2)
1302
+ unique = !!ctx__UNIQUE
1303
+ base_type = visit_if(ctx__instantiable_type)
1304
+
1305
+ Model::Types::List.new({
1306
+ bound1: bound1,
1307
+ bound2: bound2,
1308
+ unique: unique,
1309
+ base_type: base_type
1310
+ })
1311
+ end
1312
+
1313
+ def visit_literal(ctx)
1314
+ ctx__BinaryLiteral = ctx.BinaryLiteral
1315
+ ctx__IntegerLiteral = ctx.IntegerLiteral
1316
+ ctx__logical_literal = ctx.logical_literal
1317
+ ctx__RealLiteral = ctx.RealLiteral
1318
+ ctx__string_literal = ctx.string_literal
1319
+
1320
+ if ctx__BinaryLiteral
1321
+ handle_binary_literal(ctx__BinaryLiteral)
1322
+ elsif ctx__IntegerLiteral
1323
+ handle_integer_literal(ctx__IntegerLiteral)
1324
+ elsif ctx__logical_literal
1325
+ visit(ctx__logical_literal)
1326
+ elsif ctx__RealLiteral
1327
+ handle_real_literal(ctx__RealLiteral)
1328
+ elsif ctx__string_literal
1329
+ visit(ctx__string_literal)
1330
+ else
1331
+ raise 'Invalid state'
1332
+ end
1333
+ end
1334
+
1335
+ def visit_local_decl(ctx)
1336
+ ctx__local_variable = ctx.local_variable
1337
+
1338
+ visit_if_map_flatten(ctx__local_variable)
1339
+ end
1340
+
1341
+ def visit_local_variable(ctx)
1342
+ ctx__variable_id = ctx.variable_id
1343
+ ctx__parameter_type = ctx.parameter_type
1344
+ ctx__expression = ctx.expression
1345
+
1346
+ ids = visit_if_map(ctx__variable_id)
1347
+ type = visit_if(ctx__parameter_type)
1348
+ expression = visit_if(ctx__expression)
1349
+
1350
+ ids.map do |id|
1351
+ Model::Variable.new({
1352
+ id: id,
1353
+ type: type,
1354
+ expression: expression
1355
+ })
1356
+ end
1357
+ end
1358
+
1359
+ def visit_logical_expression(ctx)
1360
+ ctx__expression = ctx.expression
1361
+
1362
+ visit_if(ctx__expression)
1363
+ end
1364
+
1365
+ def visit_logical_literal(ctx)
1366
+ ctx__TRUE = ctx.TRUE
1367
+ ctx__FALSE = ctx.FALSE
1368
+ ctx__UNKNOWN = ctx.UNKNOWN
1369
+
1370
+ value = if ctx__TRUE
1371
+ Model::Literals::Logical::TRUE
1372
+ elsif ctx__FALSE
1373
+ Model::Literals::Logical::FALSE
1374
+ elsif ctx__UNKNOWN
1375
+ Model::Literals::Logical::UNKNOWN
1376
+ else
1377
+ raise 'Invalid state'
1378
+ end
1379
+
1380
+ Model::Literals::Logical.new({
1381
+ value: value
1382
+ })
1383
+ end
1384
+
1385
+ def visit_logical_type(ctx)
1386
+ Model::Types::Logical.new
1387
+ end
1388
+
1389
+ def visit_multiplication_like_op(ctx)
1390
+ ctx__text = ctx.text
1391
+ ctx__MULTIPLICATION = ctx__text == '*'
1392
+ ctx__REAL_DIVISION = ctx__text == '/'
1393
+ ctx__INTEGER_DIVISION = ctx.DIV
1394
+ ctx__MODULO = ctx.MOD
1395
+ ctx__AND = ctx.AND
1396
+ ctx__COMBINE = ctx__text == '||'
1397
+
1398
+ if ctx__MULTIPLICATION
1399
+ Model::Expressions::BinaryExpression::MULTIPLICATION
1400
+ elsif ctx__REAL_DIVISION
1401
+ Model::Expressions::BinaryExpression::REAL_DIVISION
1402
+ elsif ctx__INTEGER_DIVISION
1403
+ Model::Expressions::BinaryExpression::INTEGER_DIVISION
1404
+ elsif ctx__MODULO
1405
+ Model::Expressions::BinaryExpression::MODULO
1406
+ elsif ctx__AND
1407
+ Model::Expressions::BinaryExpression::AND
1408
+ elsif ctx__COMBINE
1409
+ Model::Expressions::BinaryExpression::COMBINE
1410
+ else
1411
+ raise 'Invalid state'
1412
+ end
1413
+ end
1414
+
1415
+ def visit_named_types(ctx)
1416
+ ctx__entity_ref = ctx.entity_ref
1417
+ ctx__type_ref = ctx.type_ref
1418
+
1419
+ visit_if(ctx__entity_ref || ctx__type_ref)
1420
+ end
1421
+
1422
+ def visit_named_type_or_rename(ctx)
1423
+ ctx__named_types = ctx.named_types
1424
+ ctx__entity_id = ctx.entity_id
1425
+ ctx__type_id = ctx.type_id
1426
+
1427
+ ref = visit_if(ctx__named_types)
1428
+ id = visit_if(ctx__entity_id || ctx__type_id)
1429
+
1430
+ if id
1431
+ Model::RenamedRef.new({
1432
+ ref: ref,
1433
+ id: id
1434
+ })
1435
+ else
1436
+ ref
1437
+ end
1438
+ end
1439
+
1440
+ def visit_null_stmt(ctx)
1441
+ Model::Statements::Null.new
1442
+ end
1443
+
1444
+ def visit_number_type(ctx)
1445
+ Model::Types::Number.new
1446
+ end
1447
+
1448
+ def visit_numeric_expression(ctx)
1449
+ ctx__simple_expression = ctx.simple_expression
1450
+
1451
+ visit_if(ctx__simple_expression)
1452
+ end
1453
+
1454
+ def visit_one_of(ctx)
1455
+ ctx__supertype_expression = ctx.supertype_expression
1456
+
1457
+ ref = Model::Expressions::SimpleReference.new({ id: 'ONEOF' })
1458
+ parameters = visit_if_map(ctx__supertype_expression)
1459
+
1460
+ Model::Expressions::Call.new({
1461
+ ref: ref,
1462
+ parameters: parameters
1463
+ })
1464
+ end
1465
+
1466
+ def visit_parameter(ctx)
1467
+ ctx__expression = ctx.expression
1468
+
1469
+ visit_if(ctx__expression)
1470
+ end
1471
+
1472
+ def visit_parameter_id(ctx)
1473
+ ctx__SimpleId = ctx.SimpleId
1474
+
1475
+ handle_simple_id(ctx__SimpleId)
1476
+ end
1477
+
1478
+ def visit_parameter_type(ctx)
1479
+ ctx__generalized_types = ctx.generalized_types
1480
+ ctx__named_types = ctx.named_types
1481
+ ctx__simple_types = ctx.simple_types
1482
+
1483
+ visit_if(ctx__generalized_types || ctx__named_types || ctx__simple_types)
1484
+ end
1485
+
1486
+ def visit_population(ctx)
1487
+ ctx__entity_ref = ctx.entity_ref
1488
+
1489
+ visit_if(ctx__entity_ref)
1490
+ end
1491
+
1492
+ def visit_precision_spec(ctx)
1493
+ ctx__numeric_expression = ctx.numeric_expression
1494
+
1495
+ visit_if(ctx__numeric_expression)
1496
+ end
1497
+
1498
+ def visit_primary(ctx)
1499
+ ctx__literal = ctx.literal
1500
+ ctx__qualifiable_factor = ctx.qualifiable_factor
1501
+ ctx__qualifier = ctx.qualifier
1502
+
1503
+ if ctx__literal
1504
+ visit(ctx__literal)
1505
+ elsif ctx__qualifiable_factor
1506
+ handle_qualified_ref(visit(ctx__qualifiable_factor), ctx__qualifier)
1507
+ else
1508
+ raise 'Invalid state'
1509
+ end
1510
+ end
1511
+
1512
+ def visit_procedure_call_stmt(ctx)
1513
+ ctx__built_in_procedure = ctx.built_in_procedure
1514
+ ctx__procedure_ref = ctx.procedure_ref
1515
+ ctx__actual_parameter_list = ctx.actual_parameter_list
1516
+
1517
+ ref = visit_if(ctx__built_in_procedure || ctx__procedure_ref)
1518
+ parameters = visit_if(ctx__actual_parameter_list)
1519
+
1520
+ Model::Statements::Call.new({
1521
+ ref: ref,
1522
+ parameters: parameters
1523
+ })
1524
+ end
1525
+
1526
+ def visit_procedure_decl(ctx)
1527
+ ctx__procedure_head = ctx.procedure_head
1528
+ ctx__algorithm_head = ctx.algorithm_head
1529
+ ctx__stmt = ctx.stmt
1530
+ ctx__procedure_head__procedure_id = ctx__procedure_head&.procedure_id
1531
+ ctx__procedure_head__procedure_head_parameter = ctx__procedure_head&.procedure_head_parameter
1532
+ ctx__algorithm_head__declaration = ctx__algorithm_head&.declaration
1533
+ ctx__algorithm_head__constant_decl = ctx__algorithm_head&.constant_decl
1534
+ ctx__algorithm_head__local_decl = ctx__algorithm_head&.local_decl
1535
+
1536
+ id = visit_if(ctx__procedure_head__procedure_id)
1537
+ parameters = visit_if_map_flatten(ctx__procedure_head__procedure_head_parameter)
1538
+ declarations = visit_if_map(ctx__algorithm_head__declaration)
1539
+ constants = visit_if(ctx__algorithm_head__constant_decl)
1540
+ variables = visit_if(ctx__algorithm_head__local_decl)
1541
+ statements = visit_if_map(ctx__stmt)
1542
+
1543
+ Model::Procedure.new({
1544
+ id: id,
1545
+ parameters: parameters,
1546
+ declarations: declarations,
1547
+ constants: constants,
1548
+ variables: variables,
1549
+ statements: statements
1550
+ })
1551
+ end
1552
+
1553
+ def visit_procedure_head(ctx)
1554
+ raise 'Invalid state'
1555
+ end
1556
+
1557
+ def visit_procedure_head_parameter(ctx)
1558
+ ctx__formal_parameter = ctx.formal_parameter
1559
+ ctx__VAR = ctx.VAR
1560
+
1561
+ parameters = visit(ctx__formal_parameter)
1562
+
1563
+ if ctx.VAR
1564
+ parameters.map do |parameter|
1565
+ Model::Parameter.new({
1566
+ id: parameter.id,
1567
+ var: true,
1568
+ type: parameter.type
1569
+ })
1570
+ end
1571
+ else
1572
+ parameters
1573
+ end
1574
+ end
1575
+
1576
+ def visit_procedure_id(ctx)
1577
+ ctx__SimpleId = ctx.SimpleId
1578
+
1579
+ handle_simple_id(ctx__SimpleId)
1580
+ end
1581
+
1582
+ def visit_qualifiable_factor(ctx)
1583
+ ctx__attribute_ref = ctx.attribute_ref
1584
+ ctx__constant_factor = ctx.constant_factor
1585
+ ctx__function_call = ctx.function_call
1586
+ ctx__general_ref = ctx.general_ref
1587
+ ctx__population = ctx.population
1588
+
1589
+ visit_if(ctx__attribute_ref || ctx__constant_factor || ctx__function_call || ctx__general_ref || ctx__population)
1590
+ end
1591
+
1592
+ def visit_qualified_attribute(ctx)
1593
+ ctx__group_qualifier = ctx.group_qualifier
1594
+ ctx__attribute_qualifier = ctx.attribute_qualifier
1595
+
1596
+ id = 'SELF'
1597
+ group_reference = visit_if(ctx__group_qualifier)
1598
+ attribute_reference = visit_if(ctx__attribute_qualifier)
1599
+
1600
+ Model::Expressions::AttributeReference.new({
1601
+ ref: Model::Expressions::GroupReference.new({
1602
+ ref: Model::Expressions::SimpleReference.new({
1603
+ id: id
1604
+ }),
1605
+ entity: group_reference.entity
1606
+ }),
1607
+ attribute: attribute_reference.attribute
1608
+ })
1609
+ end
1610
+
1611
+ def visit_qualifier(ctx)
1612
+ ctx__attribute_qualifier = ctx.attribute_qualifier
1613
+ ctx__group_qualifier = ctx.group_qualifier
1614
+ ctx__index_qualifier = ctx.index_qualifier
1615
+
1616
+ visit_if(ctx__attribute_qualifier || ctx__group_qualifier || ctx__index_qualifier)
1617
+ end
1618
+
1619
+ def visit_query_expression(ctx)
1620
+ ctx__variable_id = ctx.variable_id
1621
+ ctx__aggregate_source = ctx.aggregate_source
1622
+ ctx__logical_expression = ctx.logical_expression
1623
+
1624
+ id = visit_if(ctx__variable_id)
1625
+ aggregate_source = visit_if(ctx__aggregate_source)
1626
+ expression = visit_if(ctx__logical_expression)
1627
+
1628
+ Model::Expressions::QueryExpression.new({
1629
+ id: id,
1630
+ aggregate_source: aggregate_source,
1631
+ expression: expression
1632
+ })
1633
+ end
1634
+
1635
+ def visit_real_type(ctx)
1636
+ ctx__precision_spec = ctx.precision_spec
1637
+
1638
+ precision = visit_if(ctx__precision_spec)
1639
+
1640
+ Model::Types::Real.new({
1641
+ precision: precision
1642
+ })
1643
+ end
1644
+
1645
+ def visit_redeclared_attribute(ctx)
1646
+ raise 'Invalid state'
1647
+ end
1648
+
1649
+ def visit_referenced_attribute(ctx)
1650
+ ctx__attribute_ref = ctx.attribute_ref
1651
+ ctx__qualified_attribute = ctx.qualified_attribute
1652
+
1653
+ visit_if(ctx__attribute_ref || ctx__qualified_attribute)
1654
+ end
1655
+
1656
+ def visit_reference_clause(ctx)
1657
+ ctx__schema_ref = ctx.schema_ref
1658
+ ctx__resource_or_rename = ctx.resource_or_rename
1659
+
1660
+ schema = visit_if(ctx__schema_ref)
1661
+ items = visit_if_map(ctx__resource_or_rename)
1662
+
1663
+ Model::Interface.new({
1664
+ kind: Model::Interface::REFERENCE,
1665
+ schema: schema,
1666
+ items: items
1667
+ })
1668
+ end
1669
+
1670
+ def visit_rel_op(ctx)
1671
+ ctx__text = ctx.text
1672
+ ctx__LESS_THAN = ctx__text == '<'
1673
+ ctx__GREATER_THAN = ctx__text == '>'
1674
+ ctx__LESS_THAN_OR_EQUAL = ctx__text == '<='
1675
+ ctx__GREATER_THAN_OR_EQUAL = ctx__text == '>='
1676
+ ctx__NOT_EQUAL = ctx__text == '<>'
1677
+ ctx__EQUAL = ctx__text == '='
1678
+ ctx__INSTANCE_NOT_EQUAL = ctx__text == ':<>:'
1679
+ ctx__INSTANCE_EQUAL = ctx__text == ':=:'
1680
+
1681
+ if ctx__LESS_THAN
1682
+ Model::Expressions::BinaryExpression::LESS_THAN
1683
+ elsif ctx__GREATER_THAN
1684
+ Model::Expressions::BinaryExpression::GREATER_THAN
1685
+ elsif ctx__LESS_THAN_OR_EQUAL
1686
+ Model::Expressions::BinaryExpression::LESS_THAN_OR_EQUAL
1687
+ elsif ctx__GREATER_THAN_OR_EQUAL
1688
+ Model::Expressions::BinaryExpression::GREATER_THAN_OR_EQUAL
1689
+ elsif ctx__NOT_EQUAL
1690
+ Model::Expressions::BinaryExpression::NOT_EQUAL
1691
+ elsif ctx__EQUAL
1692
+ Model::Expressions::BinaryExpression::EQUAL
1693
+ elsif ctx__INSTANCE_NOT_EQUAL
1694
+ Model::Expressions::BinaryExpression::INSTANCE_NOT_EQUAL
1695
+ elsif ctx__INSTANCE_EQUAL
1696
+ Model::Expressions::BinaryExpression::INSTANCE_EQUAL
1697
+ else
1698
+ raise 'Invalid state'
1699
+ end
1700
+ end
1701
+
1702
+ def visit_rel_op_extended(ctx)
1703
+ ctx__rel_op = ctx.rel_op
1704
+ ctx__IN = ctx.IN
1705
+ ctx__LIKE = ctx.LIKE
1706
+
1707
+ if ctx__rel_op
1708
+ visit(ctx__rel_op)
1709
+ elsif ctx__IN
1710
+ Model::Expressions::BinaryExpression::IN
1711
+ elsif ctx__LIKE
1712
+ Model::Expressions::BinaryExpression::LIKE
1713
+ else
1714
+ raise 'Invalid state'
1715
+ end
1716
+ end
1717
+
1718
+ def visit_rename_id(ctx)
1719
+ ctx__constant_id = ctx.constant_id
1720
+ ctx__entity_id = ctx.entity_id
1721
+ ctx__function_id = ctx.function_id
1722
+ ctx__procedure_id = ctx.procedure_id
1723
+ ctx__type_id = ctx.type_id
1724
+
1725
+ visit_if(ctx__constant_id || ctx__entity_id || ctx__function_id || ctx__procedure_id || ctx__type_id)
1726
+ end
1727
+
1728
+ def visit_repeat_control(ctx)
1729
+ raise 'Invalid state'
1730
+ end
1731
+
1732
+ def visit_repeat_stmt(ctx)
1733
+ ctx__repeat_control = ctx.repeat_control
1734
+ ctx__stmt = ctx.stmt
1735
+ ctx__repeat_control__increment_control = ctx__repeat_control&.increment_control
1736
+ ctx__repeat_control__increment_control__variable_id = ctx__repeat_control__increment_control&.variable_id
1737
+ ctx__repeat_control__increment_control__bound1 = ctx__repeat_control__increment_control&.bound1
1738
+ ctx__repeat_control__increment_control__bound2 = ctx__repeat_control__increment_control&.bound2
1739
+ ctx__repeat_control__increment_control__increment = ctx__repeat_control__increment_control&.increment
1740
+ ctx__repeat_control__while_control = ctx__repeat_control&.while_control
1741
+ ctx__repeat_control__until_control = ctx__repeat_control&.until_control
1742
+
1743
+ id = visit_if(ctx__repeat_control__increment_control__variable_id)
1744
+ bound1 = visit_if(ctx__repeat_control__increment_control__bound1)
1745
+ bound2 = visit_if(ctx__repeat_control__increment_control__bound2)
1746
+ increment = visit_if(ctx__repeat_control__increment_control__increment)
1747
+ while_expression = visit_if(ctx__repeat_control__while_control)
1748
+ until_expression = visit_if(ctx__repeat_control__until_control)
1749
+ statements = visit_if_map(ctx__stmt)
1750
+
1751
+ Model::Statements::Repeat.new({
1752
+ id: id,
1753
+ bound1: bound1,
1754
+ bound2: bound2,
1755
+ increment: increment,
1756
+ while_expression: while_expression,
1757
+ until_expression: until_expression,
1758
+ statements: statements
1759
+ })
1760
+ end
1761
+
1762
+ def visit_repetition(ctx)
1763
+ ctx__numeric_expression = ctx.numeric_expression
1764
+
1765
+ visit_if(ctx__numeric_expression)
1766
+ end
1767
+
1768
+ def visit_resource_or_rename(ctx)
1769
+ ctx__resource_ref = ctx.resource_ref
1770
+ ctx__rename_id = ctx.rename_id
1771
+
1772
+ if ctx__resource_ref
1773
+ if ctx__rename_id
1774
+ ref = visit(ctx__resource_ref)
1775
+ id = visit(ctx__rename_id)
1776
+
1777
+ Model::RenamedRef.new({
1778
+ ref: ref,
1779
+ id: id
1780
+ })
1781
+ else
1782
+ visit(ctx__resource_ref)
1783
+ end
1784
+ else
1785
+ raise 'Invalid state'
1786
+ end
1787
+ end
1788
+
1789
+ def visit_resource_ref(ctx)
1790
+ ctx__constant_ref = ctx.constant_ref
1791
+ ctx__entity_ref = ctx.entity_ref
1792
+ ctx__function_ref = ctx.function_ref
1793
+ ctx__procedure_ref = ctx.procedure_ref
1794
+ ctx__type_ref = ctx.type_ref
1795
+
1796
+ visit_if(ctx__constant_ref || ctx__entity_ref || ctx__function_ref || ctx__procedure_ref || ctx__type_ref)
1797
+ end
1798
+
1799
+ def visit_return_stmt(ctx)
1800
+ ctx__expression = ctx.expression
1801
+
1802
+ expression = visit_if(ctx__expression)
1803
+
1804
+ Model::Statements::Return.new({
1805
+ expression: expression
1806
+ })
1807
+ end
1808
+
1809
+ def visit_rule_decl(ctx)
1810
+ ctx__rule_head = ctx.rule_head
1811
+ ctx__algorithm_head = ctx.algorithm_head
1812
+ ctx__stmt = ctx.stmt
1813
+ ctx__where_clause = ctx.where_clause
1814
+ ctx__rule_head__rule_id = ctx__rule_head&.rule_id
1815
+ ctx__rule_head__entity_ref = ctx__rule_head&.entity_ref
1816
+ ctx__algorithm_head__declaration = ctx__algorithm_head&.declaration
1817
+ ctx__algorithm_head__constant_decl = ctx__algorithm_head&.constant_decl
1818
+ ctx__algorithm_head__local_decl = ctx__algorithm_head&.local_decl
1819
+
1820
+ id = visit_if(ctx__rule_head__rule_id)
1821
+ applies_to = visit_if_map(ctx__rule_head__entity_ref)
1822
+ declarations = visit_if_map(ctx__algorithm_head__declaration)
1823
+ constants = visit_if(ctx__algorithm_head__constant_decl)
1824
+ variables = visit_if(ctx__algorithm_head__local_decl)
1825
+ statements = visit_if_map(ctx__stmt)
1826
+ where = visit_if(ctx__where_clause)
1827
+
1828
+ Model::Rule.new({
1829
+ id: id,
1830
+ applies_to: applies_to,
1831
+ declarations: declarations,
1832
+ constants: constants,
1833
+ variables: variables,
1834
+ statements: statements,
1835
+ where: where
1836
+ })
1837
+ end
1838
+
1839
+ def visit_rule_head(ctx)
1840
+ raise 'Invalid state'
1841
+ end
1842
+
1843
+ def visit_rule_id(ctx)
1844
+ ctx__SimpleId = ctx.SimpleId
1845
+
1846
+ handle_simple_id(ctx__SimpleId)
1847
+ end
1848
+
1849
+ def visit_rule_label_id(ctx)
1850
+ ctx__SimpleId = ctx.SimpleId
1851
+
1852
+ handle_simple_id(ctx__SimpleId)
1853
+ end
1854
+
1855
+ def visit_schema_body(ctx)
1856
+ raise 'Invalid state'
1857
+ end
1858
+
1859
+ def visit_schema_body_declaration(ctx)
1860
+ ctx__declaration = ctx.declaration
1861
+ ctx__rule_decl = ctx.rule_decl
1862
+
1863
+ visit_if(ctx__declaration || ctx__rule_decl)
1864
+ end
1865
+
1866
+ def visit_schema_decl(ctx)
1867
+ ctx__schema_id = ctx.schema_id
1868
+ ctx__schema_version_id = ctx.schema_version_id
1869
+ ctx__schema_body = ctx.schema_body
1870
+ ctx__schema_body__interface_specification = ctx__schema_body&.interface_specification
1871
+ ctx__schema_body__constant_decl = ctx__schema_body&.constant_decl
1872
+ ctx__schema_body__schema_body_declaration = ctx__schema_body&.schema_body_declaration
1873
+
1874
+ id = visit_if(ctx__schema_id)
1875
+ version = visit_if(ctx__schema_version_id)
1876
+ interfaces = visit_if_map(ctx__schema_body__interface_specification)
1877
+ constants = visit_if(ctx__schema_body__constant_decl)
1878
+ declarations = visit_if_map(ctx__schema_body__schema_body_declaration)
1879
+
1880
+ Model::Schema.new({
1881
+ id: id,
1882
+ version: version,
1883
+ interfaces: interfaces,
1884
+ constants: constants,
1885
+ declarations: declarations
1886
+ })
1887
+ end
1888
+
1889
+ def visit_schema_id(ctx)
1890
+ ctx__SimpleId = ctx.SimpleId
1891
+
1892
+ handle_simple_id(ctx__SimpleId)
1893
+ end
1894
+
1895
+ def visit_schema_version_id(ctx)
1896
+ ctx__string_literal = ctx.string_literal
1897
+
1898
+ visit_if(ctx__string_literal)
1899
+ end
1900
+
1901
+ def visit_selector(ctx)
1902
+ raise 'Invalid state'
1903
+ end
1904
+
1905
+ def visit_select_extension(ctx)
1906
+ ctx__named_types = ctx.named_types
1907
+
1908
+ visit_if_map(ctx__named_types)
1909
+ end
1910
+
1911
+ def visit_select_list(ctx)
1912
+ ctx__named_types = ctx.named_types
1913
+
1914
+ visit_if_map(ctx__named_types)
1915
+ end
1916
+
1917
+ def visit_select_type(ctx)
1918
+ ctx__EXTENSIBLE = ctx.EXTENSIBLE
1919
+ ctx__GENERIC_ENTITY = ctx.GENERIC_ENTITY
1920
+ ctx__select_list = ctx.select_list
1921
+ ctx__select_extension = ctx.select_extension
1922
+ ctx__select_extension__type_ref = ctx.select_extension&.type_ref
1923
+ ctx__select_extension__select_list = ctx__select_extension&.select_list
1924
+
1925
+ extensible = !!ctx__EXTENSIBLE
1926
+ generic_entity = !!ctx__GENERIC_ENTITY
1927
+ items = visit_if(ctx__select_list)
1928
+ extension_type = visit_if(ctx__select_extension__type_ref)
1929
+ extension_items = visit_if(ctx__select_extension__select_list)
1930
+
1931
+ Model::Types::Select.new({
1932
+ extensible: extensible,
1933
+ generic_entity: generic_entity,
1934
+ items: items,
1935
+ extension_type: extension_type,
1936
+ extension_items: extension_items
1937
+ })
1938
+ end
1939
+
1940
+ def visit_set_type(ctx)
1941
+ ctx__bound_spec = ctx.bound_spec
1942
+ ctx__instantiable_type = ctx.instantiable_type
1943
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
1944
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
1945
+
1946
+ bound1 = visit_if(ctx__bound_spec__bound1)
1947
+ bound2 = visit_if(ctx__bound_spec__bound2)
1948
+ base_type = visit_if(ctx__instantiable_type)
1949
+
1950
+ Model::Types::Set.new({
1951
+ bound1: bound1,
1952
+ bound2: bound2,
1953
+ base_type: base_type
1954
+ })
1955
+ end
1956
+
1957
+ def visit_simple_expression(ctx)
1958
+ ctx__term = ctx.term
1959
+ ctx__add_like_op = ctx.add_like_op
1960
+
1961
+ if ctx__term
1962
+ if ctx__term.length >= 2
1963
+ if ctx__add_like_op and ctx__add_like_op.length == ctx__term.length - 1
1964
+ operands = ctx__term.map(&self.method(:visit))
1965
+ operators = ctx__add_like_op.map(&self.method(:visit))
1966
+
1967
+ handle_binary_expression(operands, operators)
1968
+ else
1969
+ raise 'Invalid state'
1970
+ end
1971
+ elsif ctx__term.length == 1
1972
+ visit(ctx__term[0])
1973
+ else
1974
+ raise 'Invalid state'
1975
+ end
1976
+ end
1977
+ end
1978
+
1979
+ def visit_simple_factor(ctx)
1980
+ ctx__aggregate_initializer = ctx.aggregate_initializer
1981
+ ctx__entity_constructor = ctx.entity_constructor
1982
+ ctx__enumeration_reference = ctx.enumeration_reference
1983
+ ctx__interval = ctx.interval
1984
+ ctx__query_expression = ctx.query_expression
1985
+ ctx__simple_factor_expression = ctx.simple_factor_expression
1986
+ ctx__simple_factor_unary_expression = ctx.simple_factor_unary_expression
1987
+
1988
+ visit_if(ctx__aggregate_initializer || ctx__entity_constructor || ctx__enumeration_reference || ctx__interval || ctx__query_expression || ctx__simple_factor_expression || ctx__simple_factor_unary_expression)
1989
+ end
1990
+
1991
+ def visit_simple_factor_expression(ctx)
1992
+ ctx__expression = ctx.expression
1993
+ ctx__primary = ctx.primary
1994
+
1995
+ visit_if(ctx__expression || ctx__primary)
1996
+ end
1997
+
1998
+ def visit_simple_factor_unary_expression(ctx)
1999
+ ctx__unary_op = ctx.unary_op
2000
+ ctx__simple_factor_expression = ctx.simple_factor_expression
2001
+
2002
+ operator = visit_if(ctx__unary_op)
2003
+ operand = visit_if(ctx__simple_factor_expression)
2004
+
2005
+ Model::Expressions::UnaryExpression.new({
2006
+ operator: operator,
2007
+ operand: operand
2008
+ })
2009
+ end
2010
+
2011
+ def visit_simple_types(ctx)
2012
+ ctx__binary_type = ctx.binary_type
2013
+ ctx__boolean_type = ctx.boolean_type
2014
+ ctx__integer_type = ctx.integer_type
2015
+ ctx__logical_type = ctx.logical_type
2016
+ ctx__number_type = ctx.number_type
2017
+ ctx__real_type = ctx.real_type
2018
+ ctx__string_type = ctx.string_type
2019
+
2020
+ visit_if(ctx__binary_type || ctx__boolean_type || ctx__integer_type || ctx__logical_type || ctx__number_type || ctx__real_type || ctx__string_type)
2021
+ end
2022
+
2023
+ def visit_skip_stmt(ctx)
2024
+ Model::Statements::Skip.new
2025
+ end
2026
+
2027
+ def visit_stmt(ctx)
2028
+ ctx__alias_stmt = ctx.alias_stmt
2029
+ ctx__assignment_stmt = ctx.assignment_stmt
2030
+ ctx__case_stmt = ctx.case_stmt
2031
+ ctx__compound_stmt = ctx.compound_stmt
2032
+ ctx__escape_stmt = ctx.escape_stmt
2033
+ ctx__if_stmt = ctx.if_stmt
2034
+ ctx__null_stmt = ctx.null_stmt
2035
+ ctx__procedure_call_stmt = ctx.procedure_call_stmt
2036
+ ctx__repeat_stmt = ctx.repeat_stmt
2037
+ ctx__return_stmt = ctx.return_stmt
2038
+ ctx__skip_stmt = ctx.skip_stmt
2039
+
2040
+ visit_if(ctx__alias_stmt || ctx__assignment_stmt || ctx__case_stmt || ctx__compound_stmt || ctx__escape_stmt || ctx__if_stmt || ctx__null_stmt || ctx__procedure_call_stmt || ctx__repeat_stmt || ctx__return_stmt || ctx__skip_stmt)
2041
+ end
2042
+
2043
+ def visit_string_literal(ctx)
2044
+ ctx__SimpleStringLiteral = ctx.SimpleStringLiteral
2045
+ ctx__EncodedStringLiteral = ctx.EncodedStringLiteral
2046
+
2047
+ if ctx__SimpleStringLiteral
2048
+ handle_simple_string_literal(ctx__SimpleStringLiteral)
2049
+ elsif ctx__EncodedStringLiteral
2050
+ handle_encoded_string_literal(ctx__EncodedStringLiteral)
2051
+ else
2052
+ raise 'Invalid state'
2053
+ end
2054
+ end
2055
+
2056
+ def visit_string_type(ctx)
2057
+ ctx__width_spec = ctx.width_spec
2058
+ ctx__width_spec__width = ctx__width_spec&.width
2059
+ ctx__width_spec__FIXED = ctx__width_spec&.FIXED
2060
+
2061
+ width = visit_if(ctx__width_spec__width)
2062
+ fixed = !!ctx__width_spec__FIXED
2063
+
2064
+ Model::Types::String.new({
2065
+ width: width,
2066
+ fixed: fixed
2067
+ })
2068
+ end
2069
+
2070
+ def visit_subsuper(ctx)
2071
+ raise 'Invalid state'
2072
+ end
2073
+
2074
+ def visit_subtype_constraint(ctx)
2075
+ ctx__supertype_expression = ctx.supertype_expression
2076
+
2077
+ visit_if(ctx__supertype_expression)
2078
+ end
2079
+
2080
+ def visit_subtype_constraint_body(ctx)
2081
+ raise 'Invalid state'
2082
+ end
2083
+
2084
+ def visit_subtype_constraint_decl(ctx)
2085
+ ctx__subtype_constraint_head = ctx.subtype_constraint_head
2086
+ ctx__subtype_constraint_body = ctx.subtype_constraint_body
2087
+ ctx__subtype_constraint_head__subtype_constraint_id = ctx__subtype_constraint_head&.subtype_constraint_id
2088
+ ctx__subtype_constraint_head__entity_ref = ctx__subtype_constraint_head&.entity_ref
2089
+ ctx__subtype_constraint_body__abstract_supertype = ctx__subtype_constraint_body&.abstract_supertype
2090
+ ctx__subtype_constraint_body__total_over = ctx__subtype_constraint_body&.total_over
2091
+ ctx__subtype_constraint_body__supertype_expression = ctx__subtype_constraint_body&.supertype_expression
2092
+
2093
+ id = visit_if(ctx__subtype_constraint_head__subtype_constraint_id)
2094
+ applies_to = visit_if(ctx__subtype_constraint_head__entity_ref)
2095
+ abstract = !!ctx__subtype_constraint_body__abstract_supertype
2096
+ total_over = visit_if(ctx__subtype_constraint_body__total_over)
2097
+ supertype_expression = visit_if(ctx__subtype_constraint_body__supertype_expression)
2098
+
2099
+ Model::SubtypeConstraint.new({
2100
+ id: id,
2101
+ applies_to: applies_to,
2102
+ abstract: abstract,
2103
+ total_over: total_over,
2104
+ supertype_expression: supertype_expression
2105
+ })
2106
+ end
2107
+
2108
+ def visit_subtype_constraint_head(ctx)
2109
+ raise 'Invalid state'
2110
+ end
2111
+
2112
+ def visit_subtype_constraint_id(ctx)
2113
+ ctx__SimpleId = ctx.SimpleId
2114
+
2115
+ handle_simple_id(ctx__SimpleId)
2116
+ end
2117
+
2118
+ def visit_subtype_declaration(ctx)
2119
+ ctx__entity_ref = ctx.entity_ref
2120
+
2121
+ visit_if_map(ctx__entity_ref)
2122
+ end
2123
+
2124
+ def visit_supertype_constraint(ctx)
2125
+ raise 'Invalid state'
2126
+ end
2127
+
2128
+ def visit_supertype_expression(ctx)
2129
+ ctx__supertype_factor = ctx.supertype_factor
2130
+ ctx__ANDOR = ctx.ANDOR
2131
+
2132
+ if ctx__supertype_factor
2133
+ if ctx__supertype_factor.length >= 2
2134
+ if ctx__ANDOR and ctx__ANDOR.length == ctx__supertype_factor.length - 1
2135
+ operands = ctx__supertype_factor.map(&self.method(:visit))
2136
+ operators = ctx__ANDOR.map{Model::Expressions::BinaryExpression::ANDOR}
2137
+
2138
+ handle_binary_expression(operands, operators)
2139
+ else
2140
+ raise 'Invalid state'
2141
+ end
2142
+ elsif ctx__supertype_factor.length == 1
2143
+ visit(ctx__supertype_factor[0])
2144
+ else
2145
+ raise 'Invalid state'
2146
+ end
2147
+ end
2148
+ end
2149
+
2150
+ def visit_supertype_factor(ctx)
2151
+ ctx__supertype_term = ctx.supertype_term
2152
+ ctx__AND = ctx.AND
2153
+
2154
+ if ctx__supertype_term
2155
+ if ctx__supertype_term.length >= 2
2156
+ if ctx__AND and ctx__AND.length == ctx__supertype_term.length - 1
2157
+ operands = ctx__supertype_term.map(&self.method(:visit))
2158
+ operators = ctx__AND.map{Model::Expressions::BinaryExpression::AND}
2159
+
2160
+ handle_binary_expression(operands, operators)
2161
+ else
2162
+ raise 'Invalid state'
2163
+ end
2164
+ elsif ctx__supertype_term.length == 1
2165
+ visit(ctx__supertype_term[0])
2166
+ else
2167
+ raise 'Invalid state'
2168
+ end
2169
+ end
2170
+ end
2171
+
2172
+ def visit_supertype_rule(ctx)
2173
+ ctx__subtype_constraint = ctx.subtype_constraint
2174
+
2175
+ visit_if(ctx__subtype_constraint)
2176
+ end
2177
+
2178
+ def visit_supertype_term(ctx)
2179
+ ctx__entity_ref = ctx.entity_ref
2180
+ ctx__one_of = ctx.one_of
2181
+ ctx__supertype_expression = ctx.supertype_expression
2182
+
2183
+ visit_if(ctx__entity_ref || ctx__one_of || ctx__supertype_expression)
2184
+ end
2185
+
2186
+ def visit_syntax(ctx)
2187
+ ctx__schema_decl = ctx.schema_decl
2188
+
2189
+ schemas = visit_if_map(ctx__schema_decl)
2190
+
2191
+ Model::Repository.new({
2192
+ schemas: schemas
2193
+ })
2194
+ end
2195
+
2196
+ def visit_term(ctx)
2197
+ ctx__factor = ctx.factor
2198
+ ctx__multiplication_like_op = ctx.multiplication_like_op
2199
+
2200
+ if ctx__factor
2201
+ if ctx__factor.length >= 2
2202
+ if ctx__multiplication_like_op and ctx__multiplication_like_op.length == ctx__factor.length - 1
2203
+ operands = ctx__factor.map(&self.method(:visit))
2204
+ operators = ctx__multiplication_like_op.map(&self.method(:visit))
2205
+
2206
+ handle_binary_expression(operands, operators)
2207
+ else
2208
+ raise 'Invalid state'
2209
+ end
2210
+ elsif ctx__factor.length == 1
2211
+ visit(ctx__factor[0])
2212
+ else
2213
+ raise 'Invalid state'
2214
+ end
2215
+ end
2216
+ end
2217
+
2218
+ def visit_total_over(ctx)
2219
+ ctx__entity_ref = ctx.entity_ref
2220
+
2221
+ visit_if_map(ctx__entity_ref)
2222
+ end
2223
+
2224
+ def visit_type_decl(ctx)
2225
+ ctx__type_id = ctx.type_id
2226
+ ctx__underlying_type = ctx.underlying_type
2227
+ ctx__where_clause = ctx.where_clause
2228
+
2229
+ id = visit_if(ctx__type_id)
2230
+ type = visit_if(ctx__underlying_type)
2231
+ where = visit_if(ctx__where_clause)
2232
+
2233
+ Model::Type.new({
2234
+ id: id,
2235
+ type: type,
2236
+ where: where
2237
+ })
2238
+ end
2239
+
2240
+ def visit_type_id(ctx)
2241
+ ctx__SimpleId = ctx.SimpleId
2242
+
2243
+ handle_simple_id(ctx__SimpleId)
2244
+ end
2245
+
2246
+ def visit_type_label(ctx)
2247
+ ctx__type_label_id = ctx.type_label_id
2248
+ ctx__type_label_ref = ctx.type_label_ref
2249
+
2250
+ visit_if(ctx__type_label_id || ctx__type_label_ref)
2251
+ end
2252
+
2253
+ def visit_type_label_id(ctx)
2254
+ ctx__SimpleId = ctx.SimpleId
2255
+
2256
+ handle_simple_id(ctx__SimpleId)
2257
+ end
2258
+
2259
+ def visit_unary_op(ctx)
2260
+ ctx__text = ctx.text
2261
+ ctx__PLUS = ctx__text == '+'
2262
+ ctx__MINUS = ctx__text == '-'
2263
+ ctx__NOT = ctx.NOT
2264
+
2265
+ if ctx__PLUS
2266
+ Model::Expressions::UnaryExpression::PLUS
2267
+ elsif ctx__MINUS
2268
+ Model::Expressions::UnaryExpression::MINUS
2269
+ elsif ctx__NOT
2270
+ Model::Expressions::UnaryExpression::NOT
2271
+ else
2272
+ raise 'Invalid state'
2273
+ end
2274
+ end
2275
+
2276
+ def visit_underlying_type(ctx)
2277
+ ctx__concrete_types = ctx.concrete_types
2278
+ ctx__constructed_types = ctx.constructed_types
2279
+
2280
+ visit_if(ctx__concrete_types || ctx__constructed_types)
2281
+ end
2282
+
2283
+ def visit_unique_clause(ctx)
2284
+ ctx__unique_rule = ctx.unique_rule
2285
+
2286
+ visit_if_map(ctx__unique_rule)
2287
+ end
2288
+
2289
+ def visit_unique_rule(ctx)
2290
+ ctx__rule_label_id = ctx.rule_label_id
2291
+ ctx__referenced_attribute = ctx.referenced_attribute
2292
+
2293
+ id = visit_if(ctx__rule_label_id)
2294
+ attributes = visit_if_map(ctx__referenced_attribute)
2295
+
2296
+ Model::Unique.new({
2297
+ id: id,
2298
+ attributes: attributes
2299
+ })
2300
+ end
2301
+
2302
+ def visit_until_control(ctx)
2303
+ ctx__logical_expression = ctx.logical_expression
2304
+
2305
+ visit_if(ctx__logical_expression)
2306
+ end
2307
+
2308
+ def visit_use_clause(ctx)
2309
+ ctx__schema_ref = ctx.schema_ref
2310
+ ctx__named_type_or_rename = ctx.named_type_or_rename
2311
+
2312
+ schema = visit_if(ctx__schema_ref)
2313
+ items = visit_if_map(ctx__named_type_or_rename)
2314
+
2315
+ Model::Interface.new({
2316
+ kind: Model::Interface::USE,
2317
+ schema: schema,
2318
+ items: items
2319
+ })
2320
+ end
2321
+
2322
+ def visit_variable_id(ctx)
2323
+ ctx__SimpleId = ctx.SimpleId
2324
+
2325
+ handle_simple_id(ctx__SimpleId)
2326
+ end
2327
+
2328
+ def visit_where_clause(ctx)
2329
+ ctx__domain_rule = ctx.domain_rule
2330
+
2331
+ visit_if_map(ctx__domain_rule)
2332
+ end
2333
+
2334
+ def visit_while_control(ctx)
2335
+ ctx__logical_expression = ctx.logical_expression
2336
+
2337
+ visit_if(ctx__logical_expression)
2338
+ end
2339
+
2340
+ def visit_width(ctx)
2341
+ ctx__numeric_expression = ctx.numeric_expression
2342
+
2343
+ visit_if(ctx__numeric_expression)
2344
+ end
2345
+
2346
+ def visit_width_spec(ctx)
2347
+ raise 'Invalid state'
2348
+ end
2349
+
2350
+ private
2351
+
2352
+ def handle_binary_expression(operands, operators)
2353
+ if operands.length != operators.length + 1
2354
+ raise 'Invalid state'
2355
+ end
2356
+
2357
+ expression = Model::Expressions::BinaryExpression.new({
2358
+ operator: operators[0],
2359
+ operand1: operands[0],
2360
+ operand2: operands[1]
2361
+ })
2362
+ operators[1..(operators.length - 1)].each_with_index do |operator, i|
2363
+ expression = Model::Expressions::BinaryExpression.new({
2364
+ operator: operator,
2365
+ operand1: expression,
2366
+ operand2: operands[i + 2]
2367
+ })
2368
+ end
2369
+ expression
2370
+ end
2371
+
2372
+ def handle_qualified_ref(ref, qualifiers)
2373
+ qualifiers.reduce(ref) do |ref, ctx|
2374
+ ctx__attribute_qualifier = ctx.attribute_qualifier
2375
+ ctx__group_qualifier = ctx.group_qualifier
2376
+ ctx__index_qualifier = ctx.index_qualifier
2377
+
2378
+ if ctx__attribute_qualifier
2379
+ attribute_reference = visit_if(ctx__attribute_qualifier)
2380
+
2381
+ Model::Expressions::AttributeReference.new({
2382
+ ref: ref,
2383
+ attribute: attribute_reference.attribute
2384
+ })
2385
+ elsif ctx__group_qualifier
2386
+ group_reference = visit_if(ctx__group_qualifier)
2387
+
2388
+ Model::Expressions::GroupReference.new({
2389
+ ref: ref,
2390
+ entity: group_reference.entity
2391
+ })
2392
+ elsif ctx__index_qualifier
2393
+ index_reference = visit_if(ctx__index_qualifier)
2394
+
2395
+ Model::Expressions::IndexReference.new({
2396
+ ref: ref,
2397
+ index1: index_reference.index1,
2398
+ index2: index_reference.index2
2399
+ })
2400
+ else
2401
+ raise 'Invalid state'
2402
+ end
2403
+ end
2404
+ end
2405
+
2406
+ def handle_binary_literal(ctx)
2407
+ ctx__text = ctx.text
2408
+
2409
+ value = ctx__text[1..(ctx__text.length - 1)]
2410
+
2411
+ Model::Literals::Binary.new({
2412
+ value: value
2413
+ })
2414
+ end
2415
+
2416
+ def handle_integer_literal(ctx)
2417
+ ctx__text = ctx.text
2418
+
2419
+ value = ctx__text
2420
+
2421
+ Model::Literals::Integer.new({
2422
+ value: value
2423
+ })
2424
+ end
2425
+
2426
+ def handle_real_literal(ctx)
2427
+ ctx__text = ctx.text
2428
+
2429
+ value = ctx__text
2430
+
2431
+ Model::Literals::Real.new({
2432
+ value: value
2433
+ })
2434
+ end
2435
+
2436
+ def handle_simple_id(ctx)
2437
+ ctx__text = ctx.text
2438
+
2439
+ ctx__text
2440
+ end
2441
+
2442
+ def handle_simple_string_literal(ctx)
2443
+ ctx__text = ctx.text
2444
+
2445
+ value = ctx__text[1..(ctx__text.length - 2)].force_encoding('UTF-8')
2446
+
2447
+ Model::Literals::String.new({
2448
+ value: value
2449
+ })
2450
+ end
2451
+
2452
+ def handle_encoded_string_literal(ctx)
2453
+ ctx__text = ctx.text
2454
+
2455
+ value = ctx__text[1..(ctx__text.length - 2)].force_encoding('UTF-8')
2456
+
2457
+ Model::Literals::String.new({
2458
+ value: value,
2459
+ encoded: true
2460
+ })
2461
+ end
2462
+ end
2463
+ end
2464
+ end