expressir 0.2.3 → 0.2.4

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