expressir 1.3.0-aarch64-linux-gnu

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