expressir 2.1.31 → 2.2.0

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