expressir 1.2.3-aarch64-linux

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