expressir 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -13
- data/.rubocop_todo.yml +69 -6
- data/Gemfile +1 -1
- data/README.adoc +46 -0
- data/exe/expressir-format-test +2 -1
- data/expressir.gemspec +2 -3
- data/lib/expressir/express/cache.rb +6 -6
- data/lib/expressir/express/formatter.rb +754 -741
- data/lib/expressir/express/hyperlink_formatter.rb +2 -2
- data/lib/expressir/express/model_visitor.rb +1 -1
- data/lib/expressir/express/parser.rb +224 -100
- data/lib/expressir/express/resolve_references_model_visitor.rb +6 -6
- data/lib/expressir/express/schema_head_formatter.rb +3 -3
- data/lib/expressir/express/visitor.rb +353 -344
- data/lib/expressir/model/cache.rb +3 -3
- data/lib/expressir/model/data_type.rb +1 -1
- data/lib/expressir/model/data_types/aggregate.rb +3 -3
- data/lib/expressir/model/data_types/array.rb +6 -6
- data/lib/expressir/model/data_types/bag.rb +4 -4
- data/lib/expressir/model/data_types/binary.rb +3 -3
- data/lib/expressir/model/data_types/boolean.rb +1 -1
- data/lib/expressir/model/data_types/enumeration.rb +4 -4
- data/lib/expressir/model/data_types/enumeration_item.rb +2 -2
- data/lib/expressir/model/data_types/generic.rb +2 -2
- data/lib/expressir/model/data_types/generic_entity.rb +2 -2
- data/lib/expressir/model/data_types/integer.rb +1 -1
- data/lib/expressir/model/data_types/list.rb +5 -5
- data/lib/expressir/model/data_types/logical.rb +1 -1
- data/lib/expressir/model/data_types/number.rb +1 -1
- data/lib/expressir/model/data_types/real.rb +2 -2
- data/lib/expressir/model/data_types/select.rb +5 -5
- data/lib/expressir/model/data_types/set.rb +4 -4
- data/lib/expressir/model/data_types/string.rb +3 -3
- data/lib/expressir/model/declaration.rb +1 -1
- data/lib/expressir/model/declarations/attribute.rb +7 -7
- data/lib/expressir/model/declarations/constant.rb +4 -4
- data/lib/expressir/model/declarations/entity.rb +9 -9
- data/lib/expressir/model/declarations/function.rb +13 -13
- data/lib/expressir/model/declarations/interface.rb +4 -4
- data/lib/expressir/model/declarations/interface_item.rb +3 -3
- data/lib/expressir/model/declarations/interfaced_item.rb +6 -6
- data/lib/expressir/model/declarations/parameter.rb +4 -4
- data/lib/expressir/model/declarations/procedure.rb +12 -12
- data/lib/expressir/model/declarations/remark_item.rb +3 -3
- data/lib/expressir/model/declarations/rule.rb +14 -14
- data/lib/expressir/model/declarations/schema.rb +18 -18
- data/lib/expressir/model/declarations/schema_version.rb +3 -3
- data/lib/expressir/model/declarations/schema_version_item.rb +3 -3
- data/lib/expressir/model/declarations/subtype_constraint.rb +6 -6
- data/lib/expressir/model/declarations/type.rb +5 -5
- data/lib/expressir/model/declarations/unique_rule.rb +3 -3
- data/lib/expressir/model/declarations/variable.rb +4 -4
- data/lib/expressir/model/declarations/where_rule.rb +3 -3
- data/lib/expressir/model/expression.rb +1 -1
- data/lib/expressir/model/expressions/aggregate_initializer.rb +2 -2
- data/lib/expressir/model/expressions/aggregate_initializer_item.rb +3 -3
- data/lib/expressir/model/expressions/binary_expression.rb +12 -5
- data/lib/expressir/model/expressions/entity_constructor.rb +3 -3
- data/lib/expressir/model/expressions/function_call.rb +3 -3
- data/lib/expressir/model/expressions/interval.rb +6 -6
- data/lib/expressir/model/expressions/query_expression.rb +4 -4
- data/lib/expressir/model/expressions/unary_expression.rb +3 -3
- data/lib/expressir/model/identifier.rb +5 -5
- data/lib/expressir/model/literal.rb +1 -1
- data/lib/expressir/model/literals/binary.rb +2 -2
- data/lib/expressir/model/literals/integer.rb +2 -2
- data/lib/expressir/model/literals/logical.rb +2 -2
- data/lib/expressir/model/literals/real.rb +2 -2
- data/lib/expressir/model/literals/string.rb +3 -3
- data/lib/expressir/model/model_element.rb +35 -41
- data/lib/expressir/model/reference.rb +1 -1
- data/lib/expressir/model/references/attribute_reference.rb +3 -3
- data/lib/expressir/model/references/group_reference.rb +3 -3
- data/lib/expressir/model/references/index_reference.rb +4 -4
- data/lib/expressir/model/references/simple_reference.rb +3 -3
- data/lib/expressir/model/repository.rb +3 -4
- data/lib/expressir/model/statement.rb +1 -1
- data/lib/expressir/model/statements/alias.rb +4 -4
- data/lib/expressir/model/statements/assignment.rb +3 -3
- data/lib/expressir/model/statements/case.rb +4 -4
- data/lib/expressir/model/statements/case_action.rb +3 -3
- data/lib/expressir/model/statements/compound.rb +2 -2
- data/lib/expressir/model/statements/escape.rb +1 -1
- data/lib/expressir/model/statements/if.rb +4 -4
- data/lib/expressir/model/statements/null.rb +1 -1
- data/lib/expressir/model/statements/procedure_call.rb +3 -3
- data/lib/expressir/model/statements/repeat.rb +8 -8
- data/lib/expressir/model/statements/return.rb +2 -2
- data/lib/expressir/model/statements/skip.rb +1 -1
- data/lib/expressir/model/supertype_expression.rb +1 -1
- data/lib/expressir/model/supertype_expressions/binary_supertype_expression.rb +4 -4
- data/lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb +2 -2
- data/lib/expressir/version.rb +1 -1
- metadata +12 -12
@@ -25,16 +25,16 @@ require "set"
|
|
25
25
|
# - prevents segfault in ANTLR4 C++ runtime, not sure why they are caused
|
26
26
|
# - e.g. see visit_schema_decl
|
27
27
|
|
28
|
-
require
|
28
|
+
require "objspace"
|
29
29
|
|
30
30
|
module Expressir
|
31
31
|
module Express
|
32
32
|
class Visitor
|
33
33
|
class Ctx
|
34
|
-
attr_reader :name
|
35
|
-
attr_reader :data
|
34
|
+
attr_reader :name, :data
|
36
35
|
attr_accessor :source_pos
|
37
|
-
|
36
|
+
|
37
|
+
def initialize(data, name)
|
38
38
|
@data = data
|
39
39
|
@name = name
|
40
40
|
end
|
@@ -43,10 +43,10 @@ module Expressir
|
|
43
43
|
str.data.to_s
|
44
44
|
end
|
45
45
|
|
46
|
-
def method_missing(name
|
47
|
-
rulename = name.to_s.sub(/^visit_/,"").gsub(/_([a-z])/) { |m| m[1].upcase }.to_sym
|
46
|
+
def method_missing(name, *args)
|
47
|
+
rulename = name.to_s.sub(/^visit_/, "").gsub(/_([a-z])/) { |m| m[1].upcase }.to_sym
|
48
48
|
self.class.define_method(name) { @data[rulename] }
|
49
|
-
|
49
|
+
send name, *args
|
50
50
|
end
|
51
51
|
|
52
52
|
def keys
|
@@ -63,9 +63,9 @@ module Expressir
|
|
63
63
|
end
|
64
64
|
|
65
65
|
class SimpleCtx
|
66
|
-
attr_reader :name
|
67
|
-
|
68
|
-
def initialize(data,name)
|
66
|
+
attr_reader :name, :data
|
67
|
+
|
68
|
+
def initialize(data, name)
|
69
69
|
@data = data
|
70
70
|
@name = name
|
71
71
|
end
|
@@ -88,68 +88,69 @@ module Expressir
|
|
88
88
|
@attached_remark_tokens = Set.new
|
89
89
|
|
90
90
|
@visit_methods = Hash[
|
91
|
-
private_methods.grep(/^visit_/).map
|
92
|
-
rulename = name.to_s.sub(/^visit_/,"").gsub(/_([a-z])/) { $1.upcase }
|
93
|
-
[rulename.to_sym,name.to_sym]
|
94
|
-
|
91
|
+
private_methods.grep(/^visit_/).map do |name|
|
92
|
+
rulename = name.to_s.sub(/^visit_/, "").gsub(/_([a-z])/) { $1.upcase }
|
93
|
+
[rulename.to_sym, name.to_sym]
|
94
|
+
end
|
95
95
|
]
|
96
96
|
end
|
97
97
|
|
98
|
-
def to_ctx(ast,name
|
98
|
+
def to_ctx(ast, name = :unnamed)
|
99
99
|
case ast
|
100
100
|
when Hash
|
101
101
|
nodes = Hash[
|
102
|
-
ast.map
|
103
|
-
if k
|
102
|
+
ast.map do |k, v|
|
103
|
+
if k =~ /^listOf_(.*)$/
|
104
104
|
itemkey = $1.to_sym
|
105
|
-
ary =
|
106
|
-
[
|
105
|
+
ary = Array === v ? v : [v]
|
106
|
+
[itemkey, to_ctx(ary.select { |v| v[itemkey] }.map { |v| v.slice(itemkey) })]
|
107
107
|
else
|
108
|
-
[
|
108
|
+
[k, to_ctx(v, k)]
|
109
109
|
end
|
110
|
-
|
110
|
+
end
|
111
111
|
]
|
112
|
-
Ctx.new nodes,name
|
112
|
+
Ctx.new nodes, name
|
113
113
|
when Array
|
114
|
-
ast.map
|
114
|
+
ast.map do |v|
|
115
115
|
v.length == 1 or raise "element of array invalid (#{v.keys})"
|
116
|
-
to_ctx(v.values[0],v.keys[0])
|
117
|
-
|
116
|
+
to_ctx(v.values[0], v.keys[0])
|
117
|
+
end
|
118
118
|
when nil
|
119
119
|
nil
|
120
120
|
else
|
121
|
-
SimpleCtx.new ast,name
|
121
|
+
SimpleCtx.new ast, name
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
125
|
def get_source_pos(ctx)
|
126
|
-
|
126
|
+
nil
|
127
127
|
ranges = case ctx
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
128
|
+
when Ctx
|
129
|
+
ctx.source_pos and return ctx.source_pos # cache
|
130
|
+
ctx.values.map { |item| get_source_pos(item) }
|
131
|
+
when SimpleCtx
|
132
|
+
return nil unless ctx.data.respond_to? :offset
|
133
|
+
|
134
|
+
[[ctx.data.offset, ctx.data.offset + ctx.data.length]]
|
135
|
+
when Array
|
136
|
+
ctx.map { |item| get_source_pos(item) }
|
137
|
+
else
|
138
|
+
raise "unknown type in Ctx tree: #{ctx}"
|
139
|
+
end
|
140
|
+
source_pos = ranges.compact.reduce do |item, acc|
|
141
|
+
[[item[0], acc[0]].min, [item[1], acc[1]].max]
|
138
142
|
end
|
139
|
-
source_pos = ranges.compact.reduce { |item,acc|
|
140
|
-
[ [item[0],acc[0]].min, [item[1],acc[1]].max ]
|
141
|
-
}
|
142
143
|
Ctx === ctx and ctx.source_pos = source_pos
|
143
144
|
source_pos
|
144
145
|
end
|
145
146
|
|
146
147
|
def get_source(ctx)
|
147
|
-
a,b = get_source_pos ctx
|
148
|
-
@source[a..b-1].strip
|
148
|
+
a, b = get_source_pos ctx
|
149
|
+
@source[a..b - 1].strip
|
149
150
|
end
|
150
151
|
|
151
|
-
def visit_ast(ast,name)
|
152
|
-
ctx = to_ctx(ast,name)
|
152
|
+
def visit_ast(ast, name)
|
153
|
+
ctx = to_ctx(ast, name)
|
153
154
|
|
154
155
|
visit ctx
|
155
156
|
end
|
@@ -161,7 +162,7 @@ module Expressir
|
|
161
162
|
|
162
163
|
node = ctx
|
163
164
|
if @visit_methods[ctx.name]
|
164
|
-
node = send(@visit_methods[ctx.name],ctx)
|
165
|
+
node = send(@visit_methods[ctx.name], ctx)
|
165
166
|
if @include_source && node.respond_to?(:source)
|
166
167
|
node.source = get_source ctx
|
167
168
|
end
|
@@ -171,7 +172,7 @@ module Expressir
|
|
171
172
|
node
|
172
173
|
end
|
173
174
|
|
174
|
-
|
175
|
+
# ###########################################3
|
175
176
|
private
|
176
177
|
|
177
178
|
def visit_top(ctx)
|
@@ -188,7 +189,7 @@ module Expressir
|
|
188
189
|
|
189
190
|
def visit_if_map(ctx)
|
190
191
|
if ctx
|
191
|
-
ctx.map{|ctx2| visit(ctx2)}
|
192
|
+
ctx.map { |ctx2| visit(ctx2) }
|
192
193
|
else
|
193
194
|
[]
|
194
195
|
end
|
@@ -196,7 +197,7 @@ module Expressir
|
|
196
197
|
|
197
198
|
def visit_if_map_flatten(ctx)
|
198
199
|
if ctx
|
199
|
-
ctx.map{|ctx2| visit(ctx2)}.flatten
|
200
|
+
ctx.map { |ctx2| visit(ctx2) }.flatten
|
200
201
|
else
|
201
202
|
[]
|
202
203
|
end
|
@@ -204,11 +205,10 @@ module Expressir
|
|
204
205
|
|
205
206
|
def node_find(node, path)
|
206
207
|
if node.is_a?(Enumerable)
|
207
|
-
|
208
|
+
node.find { |item| item.find(path) }
|
208
209
|
else
|
209
|
-
|
210
|
+
node.find(path)
|
210
211
|
end
|
211
|
-
target_node
|
212
212
|
end
|
213
213
|
|
214
214
|
def find_remark_target(node, path)
|
@@ -221,15 +221,15 @@ module Expressir
|
|
221
221
|
rest, _, current_path = path.rpartition(".") # get last path part
|
222
222
|
_, _, current_path = current_path.rpartition(":") # ignore prefix
|
223
223
|
parent_node = node_find(node, rest)
|
224
|
-
if parent_node
|
224
|
+
if parent_node&.class&.method_defined?(:remark_items)
|
225
225
|
remark_item = Model::Declarations::RemarkItem.new(
|
226
|
-
id: current_path
|
226
|
+
id: current_path,
|
227
227
|
)
|
228
228
|
remark_item.parent = parent_node
|
229
229
|
|
230
230
|
# check if path can create implicit informal proposition
|
231
231
|
# see https://github.com/lutaml/expressir/issues/50
|
232
|
-
if parent_node.class.method_defined?
|
232
|
+
if parent_node.class.method_defined?(:informal_propositions) && current_path.match(/^IP\d+$/)
|
233
233
|
parent_node.informal_propositions << remark_item
|
234
234
|
else
|
235
235
|
parent_node.remark_items << remark_item
|
@@ -240,16 +240,16 @@ module Expressir
|
|
240
240
|
end
|
241
241
|
end
|
242
242
|
|
243
|
-
def get_remarks(ctx,indent="")
|
243
|
+
def get_remarks(ctx, indent = "")
|
244
244
|
case ctx
|
245
245
|
when Ctx
|
246
|
-
ctx.values.map { |item| get_remarks(item,indent
|
246
|
+
ctx.values.map { |item| get_remarks(item, "#{indent} ") }.inject([], :+)
|
247
247
|
when Array
|
248
|
-
|
249
|
-
|
248
|
+
ctx.map { |item| get_remarks(item, "#{indent} ") }.inject([], :+)
|
249
|
+
|
250
250
|
else
|
251
|
-
if [
|
252
|
-
[
|
251
|
+
if %i[tailRemark embeddedRemark].include?(ctx.name)
|
252
|
+
[get_source_pos(ctx)]
|
253
253
|
else
|
254
254
|
[]
|
255
255
|
end
|
@@ -257,30 +257,29 @@ module Expressir
|
|
257
257
|
end
|
258
258
|
|
259
259
|
def attach_remarks(ctx, node)
|
260
|
-
|
261
260
|
remark_tokens = get_remarks ctx
|
262
261
|
|
263
262
|
# skip already attached remarks
|
264
|
-
remark_tokens = remark_tokens.
|
263
|
+
remark_tokens = remark_tokens.reject { |x| @attached_remark_tokens.include?(x) }
|
265
264
|
|
266
265
|
# parse remarks, find remark targets
|
267
266
|
tagged_remark_tokens = remark_tokens.map do |span|
|
268
|
-
text = @source[span[0]..span[1]-1]
|
269
|
-
_, remark_tag, remark_text = if text.start_with?(
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
267
|
+
text = @source[span[0]..span[1] - 1]
|
268
|
+
_, remark_tag, remark_text = if text.start_with?("--")
|
269
|
+
text.match(/^--"([^"]*)"(.*)$/).to_a
|
270
|
+
else
|
271
|
+
text.match(/^\(\*"([^"]*)"(.*)\*\)$/m).to_a
|
272
|
+
end
|
274
273
|
|
275
274
|
if remark_tag
|
276
275
|
remark_target = find_remark_target(node, remark_tag)
|
277
276
|
end
|
278
277
|
if remark_text
|
279
|
-
remark_text = remark_text.strip.force_encoding(
|
278
|
+
remark_text = remark_text.strip.force_encoding("UTF-8")
|
280
279
|
end
|
281
280
|
|
282
281
|
[span, remark_target, remark_text]
|
283
|
-
end.select{|x| x[1]}
|
282
|
+
end.select { |x| x[1] }
|
284
283
|
|
285
284
|
tagged_remark_tokens.each do |span, remark_target, remark_text|
|
286
285
|
# attach remark
|
@@ -298,7 +297,7 @@ module Expressir
|
|
298
297
|
id = visit_if(ctx__attribute_id)
|
299
298
|
|
300
299
|
Model::References::SimpleReference.new(
|
301
|
-
id: id
|
300
|
+
id: id,
|
302
301
|
)
|
303
302
|
end
|
304
303
|
|
@@ -308,7 +307,7 @@ module Expressir
|
|
308
307
|
id = visit_if(ctx__constant_id)
|
309
308
|
|
310
309
|
Model::References::SimpleReference.new(
|
311
|
-
id: id
|
310
|
+
id: id,
|
312
311
|
)
|
313
312
|
end
|
314
313
|
|
@@ -318,7 +317,7 @@ module Expressir
|
|
318
317
|
id = visit_if(ctx__entity_id)
|
319
318
|
|
320
319
|
Model::References::SimpleReference.new(
|
321
|
-
id: id
|
320
|
+
id: id,
|
322
321
|
)
|
323
322
|
end
|
324
323
|
|
@@ -328,7 +327,7 @@ module Expressir
|
|
328
327
|
id = visit_if(ctx__enumeration_id)
|
329
328
|
|
330
329
|
Model::References::SimpleReference.new(
|
331
|
-
id: id
|
330
|
+
id: id,
|
332
331
|
)
|
333
332
|
end
|
334
333
|
|
@@ -338,7 +337,7 @@ module Expressir
|
|
338
337
|
id = visit_if(ctx__function_id)
|
339
338
|
|
340
339
|
Model::References::SimpleReference.new(
|
341
|
-
id: id
|
340
|
+
id: id,
|
342
341
|
)
|
343
342
|
end
|
344
343
|
|
@@ -348,7 +347,7 @@ module Expressir
|
|
348
347
|
id = visit_if(ctx__parameter_id)
|
349
348
|
|
350
349
|
Model::References::SimpleReference.new(
|
351
|
-
id: id
|
350
|
+
id: id,
|
352
351
|
)
|
353
352
|
end
|
354
353
|
|
@@ -358,7 +357,7 @@ module Expressir
|
|
358
357
|
id = visit_if(ctx__procedure_id)
|
359
358
|
|
360
359
|
Model::References::SimpleReference.new(
|
361
|
-
id: id
|
360
|
+
id: id,
|
362
361
|
)
|
363
362
|
end
|
364
363
|
|
@@ -368,7 +367,7 @@ module Expressir
|
|
368
367
|
id = visit_if(ctx__rule_label_id)
|
369
368
|
|
370
369
|
Model::References::SimpleReference.new(
|
371
|
-
id: id
|
370
|
+
id: id,
|
372
371
|
)
|
373
372
|
end
|
374
373
|
|
@@ -378,7 +377,7 @@ module Expressir
|
|
378
377
|
id = visit_if(ctx__rule_id)
|
379
378
|
|
380
379
|
Model::References::SimpleReference.new(
|
381
|
-
id: id
|
380
|
+
id: id,
|
382
381
|
)
|
383
382
|
end
|
384
383
|
|
@@ -388,7 +387,7 @@ module Expressir
|
|
388
387
|
id = visit_if(ctx__schema_id)
|
389
388
|
|
390
389
|
Model::References::SimpleReference.new(
|
391
|
-
id: id
|
390
|
+
id: id,
|
392
391
|
)
|
393
392
|
end
|
394
393
|
|
@@ -398,7 +397,7 @@ module Expressir
|
|
398
397
|
id = visit_if(ctx__subtype_constraint_id)
|
399
398
|
|
400
399
|
Model::References::SimpleReference.new(
|
401
|
-
id: id
|
400
|
+
id: id,
|
402
401
|
)
|
403
402
|
end
|
404
403
|
|
@@ -408,7 +407,7 @@ module Expressir
|
|
408
407
|
id = visit_if(ctx__type_label_id)
|
409
408
|
|
410
409
|
Model::References::SimpleReference.new(
|
411
|
-
id: id
|
410
|
+
id: id,
|
412
411
|
)
|
413
412
|
end
|
414
413
|
|
@@ -418,7 +417,7 @@ module Expressir
|
|
418
417
|
id = visit_if(ctx__type_id)
|
419
418
|
|
420
419
|
Model::References::SimpleReference.new(
|
421
|
-
id: id
|
420
|
+
id: id,
|
422
421
|
)
|
423
422
|
end
|
424
423
|
|
@@ -428,16 +427,16 @@ module Expressir
|
|
428
427
|
id = visit_if(ctx__variable_id)
|
429
428
|
|
430
429
|
Model::References::SimpleReference.new(
|
431
|
-
id: id
|
430
|
+
id: id,
|
432
431
|
)
|
433
432
|
end
|
434
433
|
|
435
|
-
def visit_abstract_entity_declaration(
|
436
|
-
raise
|
434
|
+
def visit_abstract_entity_declaration(_ctx)
|
435
|
+
raise "Invalid state"
|
437
436
|
end
|
438
437
|
|
439
|
-
def visit_abstract_supertype(
|
440
|
-
raise
|
438
|
+
def visit_abstract_supertype(_ctx)
|
439
|
+
raise "Invalid state"
|
441
440
|
end
|
442
441
|
|
443
442
|
def visit_abstract_supertype_declaration(ctx)
|
@@ -454,8 +453,8 @@ module Expressir
|
|
454
453
|
|
455
454
|
def visit_add_like_op(ctx)
|
456
455
|
ctx__text = ctx.values[0].text
|
457
|
-
ctx__ADDITION = ctx__text ==
|
458
|
-
ctx__SUBTRACTION = ctx__text ==
|
456
|
+
ctx__ADDITION = ctx__text == "+"
|
457
|
+
ctx__SUBTRACTION = ctx__text == "-"
|
459
458
|
ctx__OR = ctx.tOR
|
460
459
|
ctx__XOR = ctx.tXOR
|
461
460
|
|
@@ -468,7 +467,7 @@ module Expressir
|
|
468
467
|
elsif ctx__XOR
|
469
468
|
Model::Expressions::BinaryExpression::XOR
|
470
469
|
else
|
471
|
-
raise
|
470
|
+
raise "Invalid state"
|
472
471
|
end
|
473
472
|
end
|
474
473
|
|
@@ -478,7 +477,7 @@ module Expressir
|
|
478
477
|
items = visit_if_map(ctx__element)
|
479
478
|
|
480
479
|
Model::Expressions::AggregateInitializer.new(
|
481
|
-
items: items
|
480
|
+
items: items,
|
482
481
|
)
|
483
482
|
end
|
484
483
|
|
@@ -497,7 +496,7 @@ module Expressir
|
|
497
496
|
|
498
497
|
Model::DataTypes::Aggregate.new(
|
499
498
|
id: id,
|
500
|
-
base_type: base_type
|
499
|
+
base_type: base_type,
|
501
500
|
)
|
502
501
|
end
|
503
502
|
|
@@ -510,8 +509,8 @@ module Expressir
|
|
510
509
|
visit_if(ctx__array_type || ctx__bag_type || ctx__list_type || ctx__set_type)
|
511
510
|
end
|
512
511
|
|
513
|
-
def visit_algorithm_head(
|
514
|
-
raise
|
512
|
+
def visit_algorithm_head(_ctx)
|
513
|
+
raise "Invalid state"
|
515
514
|
end
|
516
515
|
|
517
516
|
def visit_alias_stmt(ctx)
|
@@ -527,7 +526,7 @@ module Expressir
|
|
527
526
|
Model::Statements::Alias.new(
|
528
527
|
id: id,
|
529
528
|
expression: expression,
|
530
|
-
statements: statements
|
529
|
+
statements: statements,
|
531
530
|
)
|
532
531
|
end
|
533
532
|
|
@@ -550,7 +549,7 @@ module Expressir
|
|
550
549
|
bound2: bound2,
|
551
550
|
optional: optional,
|
552
551
|
unique: unique,
|
553
|
-
base_type: base_type
|
552
|
+
base_type: base_type,
|
554
553
|
)
|
555
554
|
end
|
556
555
|
|
@@ -564,7 +563,7 @@ module Expressir
|
|
564
563
|
|
565
564
|
Model::Statements::Assignment.new(
|
566
565
|
ref: ref,
|
567
|
-
expression: expression
|
566
|
+
expression: expression,
|
568
567
|
)
|
569
568
|
end
|
570
569
|
|
@@ -579,7 +578,7 @@ module Expressir
|
|
579
578
|
|
580
579
|
Model::Declarations::Attribute.new(
|
581
580
|
id: id,
|
582
|
-
supertype_attribute: supertype_attribute
|
581
|
+
supertype_attribute: supertype_attribute,
|
583
582
|
)
|
584
583
|
end
|
585
584
|
|
@@ -595,12 +594,12 @@ module Expressir
|
|
595
594
|
attribute = visit_if(ctx__attribute_ref)
|
596
595
|
|
597
596
|
Model::References::AttributeReference.new(
|
598
|
-
attribute: attribute
|
597
|
+
attribute: attribute,
|
599
598
|
)
|
600
599
|
end
|
601
600
|
|
602
|
-
def visit_attribute_reference(
|
603
|
-
raise
|
601
|
+
def visit_attribute_reference(_ctx)
|
602
|
+
raise "Invalid state"
|
604
603
|
end
|
605
604
|
|
606
605
|
def visit_bag_type(ctx)
|
@@ -616,7 +615,7 @@ module Expressir
|
|
616
615
|
Model::DataTypes::Bag.new(
|
617
616
|
bound1: bound1,
|
618
617
|
bound2: bound2,
|
619
|
-
base_type: base_type
|
618
|
+
base_type: base_type,
|
620
619
|
)
|
621
620
|
end
|
622
621
|
|
@@ -630,11 +629,11 @@ module Expressir
|
|
630
629
|
|
631
630
|
Model::DataTypes::Binary.new(
|
632
631
|
width: width,
|
633
|
-
fixed: fixed
|
632
|
+
fixed: fixed,
|
634
633
|
)
|
635
634
|
end
|
636
635
|
|
637
|
-
def visit_boolean_type(
|
636
|
+
def visit_boolean_type(_ctx)
|
638
637
|
Model::DataTypes::Boolean.new
|
639
638
|
end
|
640
639
|
|
@@ -650,8 +649,8 @@ module Expressir
|
|
650
649
|
visit_if(ctx__numeric_expression)
|
651
650
|
end
|
652
651
|
|
653
|
-
def visit_bound_spec(
|
654
|
-
raise
|
652
|
+
def visit_bound_spec(_ctx)
|
653
|
+
raise "Invalid state"
|
655
654
|
end
|
656
655
|
|
657
656
|
def visit_built_in_constant(ctx)
|
@@ -660,7 +659,7 @@ module Expressir
|
|
660
659
|
id = ctx__text
|
661
660
|
|
662
661
|
Model::References::SimpleReference.new(
|
663
|
-
id: id
|
662
|
+
id: id,
|
664
663
|
)
|
665
664
|
end
|
666
665
|
|
@@ -670,7 +669,7 @@ module Expressir
|
|
670
669
|
id = ctx__text
|
671
670
|
|
672
671
|
Model::References::SimpleReference.new(
|
673
|
-
id: id
|
672
|
+
id: id,
|
674
673
|
)
|
675
674
|
end
|
676
675
|
|
@@ -680,7 +679,7 @@ module Expressir
|
|
680
679
|
id = ctx__text
|
681
680
|
|
682
681
|
Model::References::SimpleReference.new(
|
683
|
-
id: id
|
682
|
+
id: id,
|
684
683
|
)
|
685
684
|
end
|
686
685
|
|
@@ -693,7 +692,7 @@ module Expressir
|
|
693
692
|
|
694
693
|
Model::Statements::CaseAction.new(
|
695
694
|
labels: labels,
|
696
|
-
statement: statement
|
695
|
+
statement: statement,
|
697
696
|
)
|
698
697
|
end
|
699
698
|
|
@@ -716,7 +715,7 @@ module Expressir
|
|
716
715
|
Model::Statements::Case.new(
|
717
716
|
expression: expression,
|
718
717
|
actions: actions,
|
719
|
-
otherwise_statement: otherwise_statement
|
718
|
+
otherwise_statement: otherwise_statement,
|
720
719
|
)
|
721
720
|
end
|
722
721
|
|
@@ -726,7 +725,7 @@ module Expressir
|
|
726
725
|
statements = visit_if_map(ctx__stmt)
|
727
726
|
|
728
727
|
Model::Statements::Compound.new(
|
729
|
-
statements: statements
|
728
|
+
statements: statements,
|
730
729
|
)
|
731
730
|
end
|
732
731
|
|
@@ -750,7 +749,7 @@ module Expressir
|
|
750
749
|
Model::Declarations::Constant.new(
|
751
750
|
id: id,
|
752
751
|
type: type,
|
753
|
-
expression: expression
|
752
|
+
expression: expression,
|
754
753
|
)
|
755
754
|
end
|
756
755
|
|
@@ -804,7 +803,7 @@ module Expressir
|
|
804
803
|
kind: Model::Declarations::Attribute::DERIVED,
|
805
804
|
supertype_attribute: attribute.supertype_attribute, # reuse
|
806
805
|
type: type,
|
807
|
-
expression: expression
|
806
|
+
expression: expression,
|
808
807
|
)
|
809
808
|
end
|
810
809
|
|
@@ -823,7 +822,7 @@ module Expressir
|
|
823
822
|
|
824
823
|
Model::Declarations::WhereRule.new(
|
825
824
|
id: id,
|
826
|
-
expression: expression
|
825
|
+
expression: expression,
|
827
826
|
)
|
828
827
|
end
|
829
828
|
|
@@ -837,15 +836,15 @@ module Expressir
|
|
837
836
|
|
838
837
|
Model::Expressions::AggregateInitializerItem.new(
|
839
838
|
expression: expression,
|
840
|
-
repetition: repetition
|
839
|
+
repetition: repetition,
|
841
840
|
)
|
842
841
|
else
|
843
842
|
visit_if(ctx__expression)
|
844
843
|
end
|
845
844
|
end
|
846
845
|
|
847
|
-
def visit_entity_body(
|
848
|
-
raise
|
846
|
+
def visit_entity_body(_ctx)
|
847
|
+
raise "Invalid state"
|
849
848
|
end
|
850
849
|
|
851
850
|
def visit_entity_constructor(ctx)
|
@@ -861,7 +860,7 @@ module Expressir
|
|
861
860
|
# )
|
862
861
|
Model::Expressions::FunctionCall.new(
|
863
862
|
function: entity,
|
864
|
-
parameters: parameters
|
863
|
+
parameters: parameters,
|
865
864
|
)
|
866
865
|
end
|
867
866
|
|
@@ -871,8 +870,10 @@ module Expressir
|
|
871
870
|
ctx__entity_head__entity_id = ctx__entity_head&.entity_id
|
872
871
|
ctx__entity_head__subsuper = visit_if ctx__entity_head&.subsuper
|
873
872
|
ctx__entity_head__subsuper__supertype_constraint = ctx__entity_head__subsuper&.supertype_constraint
|
874
|
-
ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration =
|
875
|
-
|
873
|
+
ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration =
|
874
|
+
ctx__entity_head__subsuper__supertype_constraint&.abstract_entity_declaration
|
875
|
+
ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration =
|
876
|
+
ctx__entity_head__subsuper__supertype_constraint&.abstract_supertype_declaration
|
876
877
|
ctx__entity_head__subsuper__supertype_constraint__supertype_rule = ctx__entity_head__subsuper__supertype_constraint&.supertype_rule
|
877
878
|
ctx__entity_head__subsuper__subtype_declaration = ctx__entity_head__subsuper&.subtype_declaration
|
878
879
|
ctx__entity_body__explicit_attr = ctx__entity_body&.explicit_attr
|
@@ -882,13 +883,15 @@ module Expressir
|
|
882
883
|
ctx__entity_body__where_clause = ctx__entity_body&.where_clause
|
883
884
|
|
884
885
|
id = visit_if(ctx__entity_head__entity_id)
|
885
|
-
abstract = (ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration ||
|
886
|
-
|
886
|
+
abstract = (ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration ||
|
887
|
+
ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration) && true
|
888
|
+
supertype_expression = visit_if(ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration ||
|
889
|
+
ctx__entity_head__subsuper__supertype_constraint__supertype_rule)
|
887
890
|
subtype_of = visit_if(ctx__entity_head__subsuper__subtype_declaration, [])
|
888
891
|
attributes = [
|
889
892
|
*visit_if_map_flatten(ctx__entity_body__explicit_attr),
|
890
893
|
*visit_if(ctx__entity_body__derive_clause),
|
891
|
-
*visit_if(ctx__entity_body__inverse_clause)
|
894
|
+
*visit_if(ctx__entity_body__inverse_clause),
|
892
895
|
]
|
893
896
|
unique_rules = visit_if(ctx__entity_body__unique_clause, [])
|
894
897
|
where_rules = visit_if(ctx__entity_body__where_clause, [])
|
@@ -900,12 +903,12 @@ module Expressir
|
|
900
903
|
subtype_of: subtype_of,
|
901
904
|
attributes: attributes,
|
902
905
|
unique_rules: unique_rules,
|
903
|
-
where_rules: where_rules
|
906
|
+
where_rules: where_rules,
|
904
907
|
)
|
905
908
|
end
|
906
909
|
|
907
|
-
def visit_entity_head(
|
908
|
-
raise
|
910
|
+
def visit_entity_head(_ctx)
|
911
|
+
raise "Invalid state"
|
909
912
|
end
|
910
913
|
|
911
914
|
def visit_entity_id(ctx)
|
@@ -914,8 +917,8 @@ module Expressir
|
|
914
917
|
handle_simple_id(ctx__SimpleId)
|
915
918
|
end
|
916
919
|
|
917
|
-
def visit_enumeration_extension(
|
918
|
-
raise
|
920
|
+
def visit_enumeration_extension(_ctx)
|
921
|
+
raise "Invalid state"
|
919
922
|
end
|
920
923
|
|
921
924
|
def visit_enumeration_id(ctx)
|
@@ -936,7 +939,7 @@ module Expressir
|
|
936
939
|
id = visit_if(ctx__enumeration_id)
|
937
940
|
|
938
941
|
Model::DataTypes::EnumerationItem.new(
|
939
|
-
id: id
|
942
|
+
id: id,
|
940
943
|
)
|
941
944
|
end
|
942
945
|
|
@@ -950,7 +953,7 @@ module Expressir
|
|
950
953
|
|
951
954
|
Model::References::AttributeReference.new(
|
952
955
|
ref: ref,
|
953
|
-
attribute: attribute
|
956
|
+
attribute: attribute,
|
954
957
|
)
|
955
958
|
else
|
956
959
|
visit_if(ctx__enumeration_ref)
|
@@ -971,11 +974,11 @@ module Expressir
|
|
971
974
|
Model::DataTypes::Enumeration.new(
|
972
975
|
extensible: extensible,
|
973
976
|
based_on: based_on,
|
974
|
-
items: items
|
977
|
+
items: items,
|
975
978
|
)
|
976
979
|
end
|
977
980
|
|
978
|
-
def visit_escape_stmt(
|
981
|
+
def visit_escape_stmt(_ctx)
|
979
982
|
Model::Statements::Escape.new
|
980
983
|
end
|
981
984
|
|
@@ -994,7 +997,7 @@ module Expressir
|
|
994
997
|
kind: Model::Declarations::Attribute::EXPLICIT,
|
995
998
|
supertype_attribute: attribute.supertype_attribute, # reuse
|
996
999
|
optional: optional,
|
997
|
-
type: type
|
1000
|
+
type: type,
|
998
1001
|
)
|
999
1002
|
end
|
1000
1003
|
end
|
@@ -1012,7 +1015,7 @@ module Expressir
|
|
1012
1015
|
Model::Expressions::BinaryExpression.new(
|
1013
1016
|
operator: operator,
|
1014
1017
|
operand1: operand1,
|
1015
|
-
operand2: operand2
|
1018
|
+
operand2: operand2,
|
1016
1019
|
)
|
1017
1020
|
else
|
1018
1021
|
visit_if(ctx__simple_expression)
|
@@ -1031,7 +1034,7 @@ module Expressir
|
|
1031
1034
|
Model::Expressions::BinaryExpression.new(
|
1032
1035
|
operator: operator,
|
1033
1036
|
operand1: operand1,
|
1034
|
-
operand2: operand2
|
1037
|
+
operand2: operand2,
|
1035
1038
|
)
|
1036
1039
|
else
|
1037
1040
|
visit_if(ctx__simple_factor)
|
@@ -1048,7 +1051,7 @@ module Expressir
|
|
1048
1051
|
ids.map do |id|
|
1049
1052
|
Model::Declarations::Parameter.new(
|
1050
1053
|
id: id,
|
1051
|
-
type: type
|
1054
|
+
type: type,
|
1052
1055
|
)
|
1053
1056
|
end
|
1054
1057
|
end
|
@@ -1063,7 +1066,7 @@ module Expressir
|
|
1063
1066
|
|
1064
1067
|
Model::Expressions::FunctionCall.new(
|
1065
1068
|
function: function,
|
1066
|
-
parameters: parameters
|
1069
|
+
parameters: parameters,
|
1067
1070
|
)
|
1068
1071
|
end
|
1069
1072
|
|
@@ -1082,11 +1085,11 @@ module Expressir
|
|
1082
1085
|
parameters = visit_if_map_flatten(ctx__function_head__formal_parameter)
|
1083
1086
|
return_type = visit_if(ctx__function_head__parameter_type)
|
1084
1087
|
declarations = visit_if_map(ctx__algorithm_head__declaration)
|
1085
|
-
types = declarations.select{|x| x.is_a? Model::Declarations::Type}
|
1086
|
-
entities = declarations.select{|x| x.is_a? Model::Declarations::Entity}
|
1087
|
-
subtype_constraints = declarations.select{|x| x.is_a? Model::Declarations::SubtypeConstraint}
|
1088
|
-
functions = declarations.select{|x| x.is_a? Model::Declarations::Function}
|
1089
|
-
procedures = declarations.select{|x| x.is_a? Model::Declarations::Procedure}
|
1088
|
+
types = declarations.select { |x| x.is_a? Model::Declarations::Type }
|
1089
|
+
entities = declarations.select { |x| x.is_a? Model::Declarations::Entity }
|
1090
|
+
subtype_constraints = declarations.select { |x| x.is_a? Model::Declarations::SubtypeConstraint }
|
1091
|
+
functions = declarations.select { |x| x.is_a? Model::Declarations::Function }
|
1092
|
+
procedures = declarations.select { |x| x.is_a? Model::Declarations::Procedure }
|
1090
1093
|
constants = visit_if(ctx__algorithm_head__constant_decl, [])
|
1091
1094
|
variables = visit_if(ctx__algorithm_head__local_decl, [])
|
1092
1095
|
statements = visit_if_map(ctx__stmt)
|
@@ -1102,12 +1105,12 @@ module Expressir
|
|
1102
1105
|
procedures: procedures,
|
1103
1106
|
constants: constants,
|
1104
1107
|
variables: variables,
|
1105
|
-
statements: statements
|
1108
|
+
statements: statements,
|
1106
1109
|
)
|
1107
1110
|
end
|
1108
1111
|
|
1109
|
-
def visit_function_head(
|
1110
|
-
raise
|
1112
|
+
def visit_function_head(_ctx)
|
1113
|
+
raise "Invalid state"
|
1111
1114
|
end
|
1112
1115
|
|
1113
1116
|
def visit_function_id(ctx)
|
@@ -1153,7 +1156,7 @@ module Expressir
|
|
1153
1156
|
bound2: bound2,
|
1154
1157
|
optional: optional,
|
1155
1158
|
unique: unique,
|
1156
|
-
base_type: base_type
|
1159
|
+
base_type: base_type,
|
1157
1160
|
)
|
1158
1161
|
end
|
1159
1162
|
|
@@ -1170,7 +1173,7 @@ module Expressir
|
|
1170
1173
|
Model::DataTypes::Bag.new(
|
1171
1174
|
bound1: bound1,
|
1172
1175
|
bound2: bound2,
|
1173
|
-
base_type: base_type
|
1176
|
+
base_type: base_type,
|
1174
1177
|
)
|
1175
1178
|
end
|
1176
1179
|
|
@@ -1190,7 +1193,7 @@ module Expressir
|
|
1190
1193
|
bound1: bound1,
|
1191
1194
|
bound2: bound2,
|
1192
1195
|
unique: unique,
|
1193
|
-
base_type: base_type
|
1196
|
+
base_type: base_type,
|
1194
1197
|
)
|
1195
1198
|
end
|
1196
1199
|
|
@@ -1214,7 +1217,7 @@ module Expressir
|
|
1214
1217
|
Model::DataTypes::Set.new(
|
1215
1218
|
bound1: bound1,
|
1216
1219
|
bound2: bound2,
|
1217
|
-
base_type: base_type
|
1220
|
+
base_type: base_type,
|
1218
1221
|
)
|
1219
1222
|
end
|
1220
1223
|
|
@@ -1224,7 +1227,7 @@ module Expressir
|
|
1224
1227
|
id = visit_if(ctx__type_label)
|
1225
1228
|
|
1226
1229
|
Model::DataTypes::GenericEntity.new(
|
1227
|
-
id: id
|
1230
|
+
id: id,
|
1228
1231
|
)
|
1229
1232
|
end
|
1230
1233
|
|
@@ -1234,7 +1237,7 @@ module Expressir
|
|
1234
1237
|
id = visit_if(ctx__type_label)
|
1235
1238
|
|
1236
1239
|
Model::DataTypes::Generic.new(
|
1237
|
-
id: id
|
1240
|
+
id: id,
|
1238
1241
|
)
|
1239
1242
|
end
|
1240
1243
|
|
@@ -1244,12 +1247,12 @@ module Expressir
|
|
1244
1247
|
entity = visit_if(ctx__entity_ref)
|
1245
1248
|
|
1246
1249
|
Model::References::GroupReference.new(
|
1247
|
-
entity: entity
|
1250
|
+
entity: entity,
|
1248
1251
|
)
|
1249
1252
|
end
|
1250
1253
|
|
1251
|
-
def visit_group_reference(
|
1252
|
-
raise
|
1254
|
+
def visit_group_reference(_ctx)
|
1255
|
+
raise "Invalid state"
|
1253
1256
|
end
|
1254
1257
|
|
1255
1258
|
def visit_if_stmt(ctx)
|
@@ -1264,7 +1267,7 @@ module Expressir
|
|
1264
1267
|
Model::Statements::If.new(
|
1265
1268
|
expression: expression,
|
1266
1269
|
statements: statements,
|
1267
|
-
else_statements: else_statements
|
1270
|
+
else_statements: else_statements,
|
1268
1271
|
)
|
1269
1272
|
end
|
1270
1273
|
|
@@ -1286,8 +1289,8 @@ module Expressir
|
|
1286
1289
|
visit_if(ctx__numeric_expression)
|
1287
1290
|
end
|
1288
1291
|
|
1289
|
-
def visit_increment_control(
|
1290
|
-
raise
|
1292
|
+
def visit_increment_control(_ctx)
|
1293
|
+
raise "Invalid state"
|
1291
1294
|
end
|
1292
1295
|
|
1293
1296
|
def visit_index(ctx)
|
@@ -1317,12 +1320,12 @@ module Expressir
|
|
1317
1320
|
|
1318
1321
|
Model::References::IndexReference.new(
|
1319
1322
|
index1: index1,
|
1320
|
-
index2: index2
|
1323
|
+
index2: index2,
|
1321
1324
|
)
|
1322
1325
|
end
|
1323
1326
|
|
1324
|
-
def visit_index_reference(
|
1325
|
-
raise
|
1327
|
+
def visit_index_reference(_ctx)
|
1328
|
+
raise "Invalid state"
|
1326
1329
|
end
|
1327
1330
|
|
1328
1331
|
def visit_instantiable_type(ctx)
|
@@ -1332,7 +1335,7 @@ module Expressir
|
|
1332
1335
|
visit_if(ctx__concrete_types || ctx__entity_ref)
|
1333
1336
|
end
|
1334
1337
|
|
1335
|
-
def visit_integer_type(
|
1338
|
+
def visit_integer_type(_ctx)
|
1336
1339
|
Model::DataTypes::Integer.new
|
1337
1340
|
end
|
1338
1341
|
|
@@ -1361,7 +1364,7 @@ module Expressir
|
|
1361
1364
|
operator1: operator1,
|
1362
1365
|
item: item,
|
1363
1366
|
operator2: operator2,
|
1364
|
-
high: high
|
1367
|
+
high: high,
|
1365
1368
|
)
|
1366
1369
|
end
|
1367
1370
|
|
@@ -1385,15 +1388,15 @@ module Expressir
|
|
1385
1388
|
|
1386
1389
|
def visit_interval_op(ctx)
|
1387
1390
|
ctx__text = ctx.values[0].text
|
1388
|
-
ctx__LESS_THAN = ctx__text ==
|
1389
|
-
ctx__LESS_THAN_OR_EQUAL = ctx__text ==
|
1391
|
+
ctx__LESS_THAN = ctx__text == "<"
|
1392
|
+
ctx__LESS_THAN_OR_EQUAL = ctx__text == "<="
|
1390
1393
|
|
1391
1394
|
if ctx__LESS_THAN
|
1392
1395
|
Model::Expressions::Interval::LESS_THAN
|
1393
1396
|
elsif ctx__LESS_THAN_OR_EQUAL
|
1394
1397
|
Model::Expressions::Interval::LESS_THAN_OR_EQUAL
|
1395
1398
|
else
|
1396
|
-
raise
|
1399
|
+
raise "Invalid state"
|
1397
1400
|
end
|
1398
1401
|
end
|
1399
1402
|
|
@@ -1406,23 +1409,23 @@ module Expressir
|
|
1406
1409
|
attribute = visit_if(ctx__attribute_decl)
|
1407
1410
|
type = visit_if(ctx__inverse_attr_type)
|
1408
1411
|
expression = if ctx__entity_ref
|
1409
|
-
|
1410
|
-
|
1412
|
+
ref = visit(ctx__entity_ref)
|
1413
|
+
attribute_ref = visit(ctx__attribute_ref)
|
1411
1414
|
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1415
|
+
Model::References::AttributeReference.new(
|
1416
|
+
ref: ref,
|
1417
|
+
attribute: attribute_ref,
|
1418
|
+
)
|
1419
|
+
else
|
1420
|
+
visit(ctx__attribute_ref)
|
1421
|
+
end
|
1419
1422
|
|
1420
1423
|
Model::Declarations::Attribute.new(
|
1421
1424
|
id: attribute.id, # reuse
|
1422
1425
|
kind: Model::Declarations::Attribute::INVERSE,
|
1423
1426
|
supertype_attribute: attribute.supertype_attribute, # reuse
|
1424
1427
|
type: type,
|
1425
|
-
expression: expression
|
1428
|
+
expression: expression,
|
1426
1429
|
)
|
1427
1430
|
end
|
1428
1431
|
|
@@ -1442,7 +1445,7 @@ module Expressir
|
|
1442
1445
|
Model::DataTypes::Set.new(
|
1443
1446
|
bound1: bound1,
|
1444
1447
|
bound2: bound2,
|
1445
|
-
base_type: base_type
|
1448
|
+
base_type: base_type,
|
1446
1449
|
)
|
1447
1450
|
elsif ctx__BAG
|
1448
1451
|
bound1 = visit_if(ctx__bound_spec__bound1)
|
@@ -1452,7 +1455,7 @@ module Expressir
|
|
1452
1455
|
Model::DataTypes::Bag.new(
|
1453
1456
|
bound1: bound1,
|
1454
1457
|
bound2: bound2,
|
1455
|
-
base_type: base_type
|
1458
|
+
base_type: base_type,
|
1456
1459
|
)
|
1457
1460
|
else
|
1458
1461
|
visit_if(ctx__entity_ref)
|
@@ -1481,7 +1484,7 @@ module Expressir
|
|
1481
1484
|
bound1: bound1,
|
1482
1485
|
bound2: bound2,
|
1483
1486
|
unique: unique,
|
1484
|
-
base_type: base_type
|
1487
|
+
base_type: base_type,
|
1485
1488
|
)
|
1486
1489
|
end
|
1487
1490
|
|
@@ -1503,7 +1506,7 @@ module Expressir
|
|
1503
1506
|
elsif ctx__string_literal
|
1504
1507
|
visit(ctx__string_literal)
|
1505
1508
|
else
|
1506
|
-
raise
|
1509
|
+
raise "Invalid state"
|
1507
1510
|
end
|
1508
1511
|
end
|
1509
1512
|
|
@@ -1526,7 +1529,7 @@ module Expressir
|
|
1526
1529
|
Model::Declarations::Variable.new(
|
1527
1530
|
id: id,
|
1528
1531
|
type: type,
|
1529
|
-
expression: expression
|
1532
|
+
expression: expression,
|
1530
1533
|
)
|
1531
1534
|
end
|
1532
1535
|
end
|
@@ -1543,32 +1546,32 @@ module Expressir
|
|
1543
1546
|
ctx__UNKNOWN = ctx.tUNKNOWN
|
1544
1547
|
|
1545
1548
|
value = if ctx__TRUE
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1549
|
+
Model::Literals::Logical::TRUE
|
1550
|
+
elsif ctx__FALSE
|
1551
|
+
Model::Literals::Logical::FALSE
|
1552
|
+
elsif ctx__UNKNOWN
|
1553
|
+
Model::Literals::Logical::UNKNOWN
|
1554
|
+
else
|
1555
|
+
raise "Invalid state"
|
1556
|
+
end
|
1554
1557
|
|
1555
1558
|
Model::Literals::Logical.new(
|
1556
|
-
value: value
|
1559
|
+
value: value,
|
1557
1560
|
)
|
1558
1561
|
end
|
1559
1562
|
|
1560
|
-
def visit_logical_type(
|
1563
|
+
def visit_logical_type(_ctx)
|
1561
1564
|
Model::DataTypes::Logical.new
|
1562
1565
|
end
|
1563
1566
|
|
1564
1567
|
def visit_multiplication_like_op(ctx)
|
1565
1568
|
ctx__text = ctx.values[0].text
|
1566
|
-
ctx__MULTIPLICATION = ctx__text ==
|
1567
|
-
ctx__REAL_DIVISION = ctx__text ==
|
1569
|
+
ctx__MULTIPLICATION = ctx__text == "*"
|
1570
|
+
ctx__REAL_DIVISION = ctx__text == "/"
|
1568
1571
|
ctx__INTEGER_DIVISION = ctx.tDIV
|
1569
1572
|
ctx__MODULO = ctx.tMOD
|
1570
1573
|
ctx__AND = ctx.tAND
|
1571
|
-
ctx__COMBINE = ctx__text ==
|
1574
|
+
ctx__COMBINE = ctx__text == "||"
|
1572
1575
|
|
1573
1576
|
if ctx__MULTIPLICATION
|
1574
1577
|
Model::Expressions::BinaryExpression::MULTIPLICATION
|
@@ -1583,7 +1586,7 @@ module Expressir
|
|
1583
1586
|
elsif ctx__COMBINE
|
1584
1587
|
Model::Expressions::BinaryExpression::COMBINE
|
1585
1588
|
else
|
1586
|
-
raise
|
1589
|
+
raise "Invalid state"
|
1587
1590
|
end
|
1588
1591
|
end
|
1589
1592
|
|
@@ -1604,15 +1607,15 @@ module Expressir
|
|
1604
1607
|
|
1605
1608
|
Model::Declarations::InterfaceItem.new(
|
1606
1609
|
ref: ref,
|
1607
|
-
id: id
|
1610
|
+
id: id,
|
1608
1611
|
)
|
1609
1612
|
end
|
1610
1613
|
|
1611
|
-
def visit_null_stmt(
|
1614
|
+
def visit_null_stmt(_ctx)
|
1612
1615
|
Model::Statements::Null.new
|
1613
1616
|
end
|
1614
1617
|
|
1615
|
-
def visit_number_type(
|
1618
|
+
def visit_number_type(_ctx)
|
1616
1619
|
Model::DataTypes::Number.new
|
1617
1620
|
end
|
1618
1621
|
|
@@ -1628,7 +1631,7 @@ module Expressir
|
|
1628
1631
|
operands = visit_if_map(ctx__supertype_expression)
|
1629
1632
|
|
1630
1633
|
Model::SupertypeExpressions::OneofSupertypeExpression.new(
|
1631
|
-
operands: operands
|
1634
|
+
operands: operands,
|
1632
1635
|
)
|
1633
1636
|
end
|
1634
1637
|
|
@@ -1674,7 +1677,7 @@ module Expressir
|
|
1674
1677
|
elsif ctx__qualifiable_factor
|
1675
1678
|
handle_qualified_ref(visit(ctx__qualifiable_factor), ctx__qualifier)
|
1676
1679
|
else
|
1677
|
-
raise
|
1680
|
+
raise "Invalid state"
|
1678
1681
|
end
|
1679
1682
|
end
|
1680
1683
|
|
@@ -1688,7 +1691,7 @@ module Expressir
|
|
1688
1691
|
|
1689
1692
|
Model::Statements::ProcedureCall.new(
|
1690
1693
|
procedure: procedure,
|
1691
|
-
parameters: parameters
|
1694
|
+
parameters: parameters,
|
1692
1695
|
)
|
1693
1696
|
end
|
1694
1697
|
|
@@ -1705,11 +1708,11 @@ module Expressir
|
|
1705
1708
|
id = visit_if(ctx__procedure_head__procedure_id)
|
1706
1709
|
parameters = visit_if_map_flatten(ctx__procedure_head__procedure_head_parameter)
|
1707
1710
|
declarations = visit_if_map(ctx__algorithm_head__declaration)
|
1708
|
-
types = declarations.select{|x| x.is_a? Model::Declarations::Type}
|
1709
|
-
entities = declarations.select{|x| x.is_a? Model::Declarations::Entity}
|
1710
|
-
subtype_constraints = declarations.select{|x| x.is_a? Model::Declarations::SubtypeConstraint}
|
1711
|
-
functions = declarations.select{|x| x.is_a? Model::Declarations::Function}
|
1712
|
-
procedures = declarations.select{|x| x.is_a? Model::Declarations::Procedure}
|
1711
|
+
types = declarations.select { |x| x.is_a? Model::Declarations::Type }
|
1712
|
+
entities = declarations.select { |x| x.is_a? Model::Declarations::Entity }
|
1713
|
+
subtype_constraints = declarations.select { |x| x.is_a? Model::Declarations::SubtypeConstraint }
|
1714
|
+
functions = declarations.select { |x| x.is_a? Model::Declarations::Function }
|
1715
|
+
procedures = declarations.select { |x| x.is_a? Model::Declarations::Procedure }
|
1713
1716
|
constants = visit_if(ctx__algorithm_head__constant_decl, [])
|
1714
1717
|
variables = visit_if(ctx__algorithm_head__local_decl, [])
|
1715
1718
|
statements = visit_if_map(ctx__stmt)
|
@@ -1724,17 +1727,17 @@ module Expressir
|
|
1724
1727
|
procedures: procedures,
|
1725
1728
|
constants: constants,
|
1726
1729
|
variables: variables,
|
1727
|
-
statements: statements
|
1730
|
+
statements: statements,
|
1728
1731
|
)
|
1729
1732
|
end
|
1730
1733
|
|
1731
|
-
def visit_procedure_head(
|
1732
|
-
raise
|
1734
|
+
def visit_procedure_head(_ctx)
|
1735
|
+
raise "Invalid state"
|
1733
1736
|
end
|
1734
1737
|
|
1735
1738
|
def visit_procedure_head_parameter(ctx)
|
1736
1739
|
ctx__formal_parameter = ctx.formal_parameter
|
1737
|
-
|
1740
|
+
ctx.tVAR
|
1738
1741
|
|
1739
1742
|
parameters = visit(ctx__formal_parameter)
|
1740
1743
|
|
@@ -1743,7 +1746,7 @@ module Expressir
|
|
1743
1746
|
Model::Declarations::Parameter.new(
|
1744
1747
|
id: parameter.id,
|
1745
1748
|
var: true,
|
1746
|
-
type: parameter.type
|
1749
|
+
type: parameter.type,
|
1747
1750
|
)
|
1748
1751
|
end
|
1749
1752
|
else
|
@@ -1771,18 +1774,18 @@ module Expressir
|
|
1771
1774
|
ctx__group_qualifier = ctx.group_qualifier
|
1772
1775
|
ctx__attribute_qualifier = ctx.attribute_qualifier
|
1773
1776
|
|
1774
|
-
id =
|
1777
|
+
id = "SELF"
|
1775
1778
|
group_reference = visit_if(ctx__group_qualifier)
|
1776
1779
|
attribute_reference = visit_if(ctx__attribute_qualifier)
|
1777
1780
|
|
1778
1781
|
Model::References::AttributeReference.new(
|
1779
1782
|
ref: Model::References::GroupReference.new(
|
1780
1783
|
ref: Model::References::SimpleReference.new(
|
1781
|
-
id: id
|
1784
|
+
id: id,
|
1782
1785
|
),
|
1783
|
-
entity: group_reference.entity # reuse
|
1786
|
+
entity: group_reference.entity, # reuse
|
1784
1787
|
),
|
1785
|
-
attribute: attribute_reference.attribute # reuse
|
1788
|
+
attribute: attribute_reference.attribute, # reuse
|
1786
1789
|
)
|
1787
1790
|
end
|
1788
1791
|
|
@@ -1806,7 +1809,7 @@ module Expressir
|
|
1806
1809
|
Model::Expressions::QueryExpression.new(
|
1807
1810
|
id: id,
|
1808
1811
|
aggregate_source: aggregate_source,
|
1809
|
-
expression: expression
|
1812
|
+
expression: expression,
|
1810
1813
|
)
|
1811
1814
|
end
|
1812
1815
|
|
@@ -1816,12 +1819,12 @@ module Expressir
|
|
1816
1819
|
precision = visit_if(ctx__precision_spec)
|
1817
1820
|
|
1818
1821
|
Model::DataTypes::Real.new(
|
1819
|
-
precision: precision
|
1822
|
+
precision: precision,
|
1820
1823
|
)
|
1821
1824
|
end
|
1822
1825
|
|
1823
|
-
def visit_redeclared_attribute(
|
1824
|
-
raise
|
1826
|
+
def visit_redeclared_attribute(_ctx)
|
1827
|
+
raise "Invalid state"
|
1825
1828
|
end
|
1826
1829
|
|
1827
1830
|
def visit_referenced_attribute(ctx)
|
@@ -1841,20 +1844,20 @@ module Expressir
|
|
1841
1844
|
Model::Declarations::Interface.new(
|
1842
1845
|
kind: Model::Declarations::Interface::REFERENCE,
|
1843
1846
|
schema: schema,
|
1844
|
-
items: items
|
1847
|
+
items: items,
|
1845
1848
|
)
|
1846
1849
|
end
|
1847
1850
|
|
1848
1851
|
def visit_rel_op(ctx)
|
1849
1852
|
ctx__text = ctx.values[0].text
|
1850
|
-
ctx__LESS_THAN = ctx__text ==
|
1851
|
-
ctx__GREATER_THAN = ctx__text ==
|
1852
|
-
ctx__LESS_THAN_OR_EQUAL = ctx__text ==
|
1853
|
-
ctx__GREATER_THAN_OR_EQUAL = ctx__text ==
|
1854
|
-
ctx__NOT_EQUAL = ctx__text ==
|
1855
|
-
ctx__EQUAL = ctx__text ==
|
1856
|
-
ctx__INSTANCE_NOT_EQUAL = ctx__text ==
|
1857
|
-
ctx__INSTANCE_EQUAL = ctx__text ==
|
1853
|
+
ctx__LESS_THAN = ctx__text == "<"
|
1854
|
+
ctx__GREATER_THAN = ctx__text == ">"
|
1855
|
+
ctx__LESS_THAN_OR_EQUAL = ctx__text == "<="
|
1856
|
+
ctx__GREATER_THAN_OR_EQUAL = ctx__text == ">="
|
1857
|
+
ctx__NOT_EQUAL = ctx__text == "<>"
|
1858
|
+
ctx__EQUAL = ctx__text == "="
|
1859
|
+
ctx__INSTANCE_NOT_EQUAL = ctx__text == ":<>:"
|
1860
|
+
ctx__INSTANCE_EQUAL = ctx__text == ":=:"
|
1858
1861
|
|
1859
1862
|
if ctx__LESS_THAN
|
1860
1863
|
Model::Expressions::BinaryExpression::LESS_THAN
|
@@ -1873,7 +1876,7 @@ module Expressir
|
|
1873
1876
|
elsif ctx__INSTANCE_EQUAL
|
1874
1877
|
Model::Expressions::BinaryExpression::INSTANCE_EQUAL
|
1875
1878
|
else
|
1876
|
-
raise
|
1879
|
+
raise "Invalid state"
|
1877
1880
|
end
|
1878
1881
|
end
|
1879
1882
|
|
@@ -1889,7 +1892,7 @@ module Expressir
|
|
1889
1892
|
elsif ctx__LIKE
|
1890
1893
|
Model::Expressions::BinaryExpression::LIKE
|
1891
1894
|
else
|
1892
|
-
raise
|
1895
|
+
raise "Invalid state"
|
1893
1896
|
end
|
1894
1897
|
end
|
1895
1898
|
|
@@ -1904,7 +1907,7 @@ module Expressir
|
|
1904
1907
|
end
|
1905
1908
|
|
1906
1909
|
def visit_repeat_control(ctx)
|
1907
|
-
|
1910
|
+
SimpleCtx === ctx ? to_ctx({}, :repeatControl) : ctx
|
1908
1911
|
end
|
1909
1912
|
|
1910
1913
|
def visit_repeat_stmt(ctx)
|
@@ -1933,7 +1936,7 @@ module Expressir
|
|
1933
1936
|
increment: increment,
|
1934
1937
|
while_expression: while_expression,
|
1935
1938
|
until_expression: until_expression,
|
1936
|
-
statements: statements
|
1939
|
+
statements: statements,
|
1937
1940
|
)
|
1938
1941
|
end
|
1939
1942
|
|
@@ -1952,7 +1955,7 @@ module Expressir
|
|
1952
1955
|
|
1953
1956
|
Model::Declarations::InterfaceItem.new(
|
1954
1957
|
ref: ref,
|
1955
|
-
id: id
|
1958
|
+
id: id,
|
1956
1959
|
)
|
1957
1960
|
end
|
1958
1961
|
|
@@ -1972,7 +1975,7 @@ module Expressir
|
|
1972
1975
|
expression = visit_if(ctx__expression)
|
1973
1976
|
|
1974
1977
|
Model::Statements::Return.new(
|
1975
|
-
expression: expression
|
1978
|
+
expression: expression,
|
1976
1979
|
)
|
1977
1980
|
end
|
1978
1981
|
|
@@ -1990,11 +1993,11 @@ module Expressir
|
|
1990
1993
|
id = visit_if(ctx__rule_head__rule_id)
|
1991
1994
|
applies_to = visit_if_map(ctx__rule_head__entity_ref)
|
1992
1995
|
declarations = visit_if_map(ctx__algorithm_head__declaration)
|
1993
|
-
types = declarations.select{|x| x.is_a? Model::Declarations::Type}
|
1994
|
-
entities = declarations.select{|x| x.is_a? Model::Declarations::Entity}
|
1995
|
-
subtype_constraints = declarations.select{|x| x.is_a? Model::Declarations::SubtypeConstraint}
|
1996
|
-
functions = declarations.select{|x| x.is_a? Model::Declarations::Function}
|
1997
|
-
procedures = declarations.select{|x| x.is_a? Model::Declarations::Procedure}
|
1996
|
+
types = declarations.select { |x| x.is_a? Model::Declarations::Type }
|
1997
|
+
entities = declarations.select { |x| x.is_a? Model::Declarations::Entity }
|
1998
|
+
subtype_constraints = declarations.select { |x| x.is_a? Model::Declarations::SubtypeConstraint }
|
1999
|
+
functions = declarations.select { |x| x.is_a? Model::Declarations::Function }
|
2000
|
+
procedures = declarations.select { |x| x.is_a? Model::Declarations::Procedure }
|
1998
2001
|
constants = visit_if(ctx__algorithm_head__constant_decl, [])
|
1999
2002
|
variables = visit_if(ctx__algorithm_head__local_decl, [])
|
2000
2003
|
statements = visit_if_map(ctx__stmt)
|
@@ -2011,12 +2014,12 @@ module Expressir
|
|
2011
2014
|
constants: constants,
|
2012
2015
|
variables: variables,
|
2013
2016
|
statements: statements,
|
2014
|
-
where_rules: where_rules
|
2017
|
+
where_rules: where_rules,
|
2015
2018
|
)
|
2016
2019
|
end
|
2017
2020
|
|
2018
|
-
def visit_rule_head(
|
2019
|
-
raise
|
2021
|
+
def visit_rule_head(_ctx)
|
2022
|
+
raise "Invalid state"
|
2020
2023
|
end
|
2021
2024
|
|
2022
2025
|
def visit_rule_id(ctx)
|
@@ -2031,8 +2034,8 @@ module Expressir
|
|
2031
2034
|
handle_simple_id(ctx__SimpleId)
|
2032
2035
|
end
|
2033
2036
|
|
2034
|
-
def visit_schema_body(
|
2035
|
-
raise
|
2037
|
+
def visit_schema_body(_ctx)
|
2038
|
+
raise "Invalid state"
|
2036
2039
|
end
|
2037
2040
|
|
2038
2041
|
def visit_schema_body_declaration(ctx)
|
@@ -2055,12 +2058,12 @@ module Expressir
|
|
2055
2058
|
interfaces = visit_if_map(ctx__schema_body__interface_specification)
|
2056
2059
|
constants = visit_if(ctx__schema_body__constant_decl, [])
|
2057
2060
|
declarations = visit_if_map(ctx__schema_body__schema_body_declaration)
|
2058
|
-
types = declarations.select{|x| x.is_a? Model::Declarations::Type}
|
2059
|
-
entities = declarations.select{|x| x.is_a? Model::Declarations::Entity}
|
2060
|
-
subtype_constraints = declarations.select{|x| x.is_a? Model::Declarations::SubtypeConstraint}
|
2061
|
-
functions = declarations.select{|x| x.is_a? Model::Declarations::Function}
|
2062
|
-
rules = declarations.select{|x| x.is_a? Model::Declarations::Rule}
|
2063
|
-
procedures = declarations.select{|x| x.is_a? Model::Declarations::Procedure}
|
2061
|
+
types = declarations.select { |x| x.is_a? Model::Declarations::Type }
|
2062
|
+
entities = declarations.select { |x| x.is_a? Model::Declarations::Entity }
|
2063
|
+
subtype_constraints = declarations.select { |x| x.is_a? Model::Declarations::SubtypeConstraint }
|
2064
|
+
functions = declarations.select { |x| x.is_a? Model::Declarations::Function }
|
2065
|
+
rules = declarations.select { |x| x.is_a? Model::Declarations::Rule }
|
2066
|
+
procedures = declarations.select { |x| x.is_a? Model::Declarations::Procedure }
|
2064
2067
|
|
2065
2068
|
Model::Declarations::Schema.new(
|
2066
2069
|
id: id,
|
@@ -2072,7 +2075,7 @@ module Expressir
|
|
2072
2075
|
subtype_constraints: subtype_constraints,
|
2073
2076
|
functions: functions,
|
2074
2077
|
rules: rules,
|
2075
|
-
procedures: procedures
|
2078
|
+
procedures: procedures,
|
2076
2079
|
)
|
2077
2080
|
end
|
2078
2081
|
|
@@ -2088,34 +2091,34 @@ module Expressir
|
|
2088
2091
|
value = visit_if(ctx__string_literal)
|
2089
2092
|
value = value.value
|
2090
2093
|
|
2091
|
-
items = if value.start_with?(
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
|
2094
|
+
items = if value.start_with?("{") && value.end_with?("}")
|
2095
|
+
parts = value.sub(/^\{/, "").sub(/\}$/, "").split(" ")
|
2096
|
+
parts.map do |part|
|
2097
|
+
if match = part.match(/^(.+)\((\d+)\)$/)
|
2098
|
+
Model::Declarations::SchemaVersionItem.new(
|
2099
|
+
name: match[1],
|
2100
|
+
value: match[2],
|
2101
|
+
)
|
2102
|
+
elsif /^\d+$/.match?(part)
|
2103
|
+
Model::Declarations::SchemaVersionItem.new(
|
2104
|
+
value: part,
|
2105
|
+
)
|
2106
|
+
else
|
2107
|
+
Model::Declarations::SchemaVersionItem.new(
|
2108
|
+
name: part,
|
2109
|
+
)
|
2110
|
+
end
|
2111
|
+
end
|
2112
|
+
end
|
2110
2113
|
|
2111
2114
|
Model::Declarations::SchemaVersion.new(
|
2112
2115
|
value: value,
|
2113
|
-
items: items
|
2116
|
+
items: items,
|
2114
2117
|
)
|
2115
2118
|
end
|
2116
2119
|
|
2117
|
-
def visit_selector(
|
2118
|
-
raise
|
2120
|
+
def visit_selector(_ctx)
|
2121
|
+
raise "Invalid state"
|
2119
2122
|
end
|
2120
2123
|
|
2121
2124
|
def visit_select_extension(ctx)
|
@@ -2147,7 +2150,7 @@ module Expressir
|
|
2147
2150
|
extensible: extensible,
|
2148
2151
|
generic_entity: generic_entity,
|
2149
2152
|
based_on: based_on,
|
2150
|
-
items: items
|
2153
|
+
items: items,
|
2151
2154
|
)
|
2152
2155
|
end
|
2153
2156
|
|
@@ -2164,28 +2167,28 @@ module Expressir
|
|
2164
2167
|
Model::DataTypes::Set.new(
|
2165
2168
|
bound1: bound1,
|
2166
2169
|
bound2: bound2,
|
2167
|
-
base_type: base_type
|
2170
|
+
base_type: base_type,
|
2168
2171
|
)
|
2169
2172
|
end
|
2170
2173
|
|
2171
2174
|
def visit_simple_expression(ctx)
|
2172
|
-
ctx__term = [ctx.term] + ctx.rhs.map
|
2175
|
+
ctx__term = [ctx.term] + ctx.rhs.map(&:term)
|
2173
2176
|
ctx__add_like_op = ctx.rhs.map { |item| item.operator.values[0] }
|
2174
2177
|
|
2175
2178
|
if ctx__term
|
2176
2179
|
if ctx__term.length >= 2
|
2177
|
-
if ctx__add_like_op
|
2178
|
-
operands = ctx__term.map(&
|
2179
|
-
operators = ctx__add_like_op.map(&
|
2180
|
+
if ctx__add_like_op && (ctx__add_like_op.length == ctx__term.length - 1)
|
2181
|
+
operands = ctx__term.map(&method(:visit))
|
2182
|
+
operators = ctx__add_like_op.map(&method(:visit))
|
2180
2183
|
|
2181
2184
|
handle_binary_expression(operands, operators)
|
2182
2185
|
else
|
2183
|
-
raise
|
2186
|
+
raise "Invalid state"
|
2184
2187
|
end
|
2185
2188
|
elsif ctx__term.length == 1
|
2186
2189
|
visit(ctx__term[0])
|
2187
2190
|
else
|
2188
|
-
raise
|
2191
|
+
raise "Invalid state"
|
2189
2192
|
end
|
2190
2193
|
end
|
2191
2194
|
end
|
@@ -2199,7 +2202,10 @@ module Expressir
|
|
2199
2202
|
ctx__simple_factor_expression = ctx.simple_factor_expression
|
2200
2203
|
ctx__simple_factor_unary_expression = ctx.simple_factor_unary_expression
|
2201
2204
|
|
2202
|
-
visit_if(ctx__aggregate_initializer || ctx__entity_constructor ||
|
2205
|
+
visit_if(ctx__aggregate_initializer || ctx__entity_constructor ||
|
2206
|
+
ctx__enumeration_reference || ctx__interval ||
|
2207
|
+
ctx__query_expression || ctx__simple_factor_expression ||
|
2208
|
+
ctx__simple_factor_unary_expression)
|
2203
2209
|
end
|
2204
2210
|
|
2205
2211
|
def visit_simple_factor_expression(ctx)
|
@@ -2218,7 +2224,7 @@ module Expressir
|
|
2218
2224
|
|
2219
2225
|
Model::Expressions::UnaryExpression.new(
|
2220
2226
|
operator: operator,
|
2221
|
-
operand: operand
|
2227
|
+
operand: operand,
|
2222
2228
|
)
|
2223
2229
|
end
|
2224
2230
|
|
@@ -2231,10 +2237,12 @@ module Expressir
|
|
2231
2237
|
ctx__real_type = ctx.real_type
|
2232
2238
|
ctx__string_type = ctx.string_type
|
2233
2239
|
|
2234
|
-
visit_if(ctx__binary_type || ctx__boolean_type || ctx__integer_type ||
|
2240
|
+
visit_if(ctx__binary_type || ctx__boolean_type || ctx__integer_type ||
|
2241
|
+
ctx__logical_type || ctx__number_type || ctx__real_type ||
|
2242
|
+
ctx__string_type)
|
2235
2243
|
end
|
2236
2244
|
|
2237
|
-
def visit_skip_stmt(
|
2245
|
+
def visit_skip_stmt(_ctx)
|
2238
2246
|
Model::Statements::Skip.new
|
2239
2247
|
end
|
2240
2248
|
|
@@ -2251,7 +2259,10 @@ module Expressir
|
|
2251
2259
|
ctx__return_stmt = ctx.return_stmt
|
2252
2260
|
ctx__skip_stmt = ctx.skip_stmt
|
2253
2261
|
|
2254
|
-
visit_if(ctx__alias_stmt || ctx__assignment_stmt || ctx__case_stmt ||
|
2262
|
+
visit_if(ctx__alias_stmt || ctx__assignment_stmt || ctx__case_stmt ||
|
2263
|
+
ctx__compound_stmt || ctx__escape_stmt || ctx__if_stmt ||
|
2264
|
+
ctx__null_stmt || ctx__procedure_call_stmt ||
|
2265
|
+
ctx__repeat_stmt || ctx__return_stmt || ctx__skip_stmt)
|
2255
2266
|
end
|
2256
2267
|
|
2257
2268
|
def visit_string_literal(ctx)
|
@@ -2263,7 +2274,7 @@ module Expressir
|
|
2263
2274
|
elsif ctx__EncodedStringLiteral
|
2264
2275
|
handle_encoded_string_literal(ctx__EncodedStringLiteral)
|
2265
2276
|
else
|
2266
|
-
raise
|
2277
|
+
raise "Invalid state"
|
2267
2278
|
end
|
2268
2279
|
end
|
2269
2280
|
|
@@ -2277,12 +2288,12 @@ module Expressir
|
|
2277
2288
|
|
2278
2289
|
Model::DataTypes::String.new(
|
2279
2290
|
width: width,
|
2280
|
-
fixed: fixed
|
2291
|
+
fixed: fixed,
|
2281
2292
|
)
|
2282
2293
|
end
|
2283
2294
|
|
2284
2295
|
def visit_subsuper(ctx)
|
2285
|
-
|
2296
|
+
SimpleCtx === ctx ? to_ctx({}, :subsuper) : ctx
|
2286
2297
|
end
|
2287
2298
|
|
2288
2299
|
def visit_subtype_constraint(ctx)
|
@@ -2292,7 +2303,7 @@ module Expressir
|
|
2292
2303
|
end
|
2293
2304
|
|
2294
2305
|
def visit_subtype_constraint_body(ctx)
|
2295
|
-
|
2306
|
+
SimpleCtx === ctx ? to_ctx({}, :subtypeConstraintBody) : ctx
|
2296
2307
|
end
|
2297
2308
|
|
2298
2309
|
def visit_subtype_constraint_decl(ctx)
|
@@ -2315,12 +2326,12 @@ module Expressir
|
|
2315
2326
|
applies_to: applies_to,
|
2316
2327
|
abstract: abstract,
|
2317
2328
|
total_over: total_over,
|
2318
|
-
supertype_expression: supertype_expression
|
2329
|
+
supertype_expression: supertype_expression,
|
2319
2330
|
)
|
2320
2331
|
end
|
2321
2332
|
|
2322
|
-
def visit_subtype_constraint_head(
|
2323
|
-
raise
|
2333
|
+
def visit_subtype_constraint_head(_ctx)
|
2334
|
+
raise "Invalid state"
|
2324
2335
|
end
|
2325
2336
|
|
2326
2337
|
def visit_subtype_constraint_id(ctx)
|
@@ -2335,50 +2346,50 @@ module Expressir
|
|
2335
2346
|
visit_if_map(ctx__entity_ref)
|
2336
2347
|
end
|
2337
2348
|
|
2338
|
-
def visit_supertype_constraint(
|
2339
|
-
raise
|
2349
|
+
def visit_supertype_constraint(_ctx)
|
2350
|
+
raise "Invalid state"
|
2340
2351
|
end
|
2341
2352
|
|
2342
2353
|
def visit_supertype_expression(ctx)
|
2343
|
-
ctx__supertype_factor = [ctx.supertype_factor]+ctx.rhs.map
|
2354
|
+
ctx__supertype_factor = [ctx.supertype_factor] + ctx.rhs.map(&:supertype_factor)
|
2344
2355
|
ctx__ANDOR = ctx.rhs.map { |item| item.operator.values[0] }
|
2345
2356
|
|
2346
2357
|
if ctx__supertype_factor
|
2347
2358
|
if ctx__supertype_factor.length >= 2
|
2348
|
-
if ctx__ANDOR
|
2349
|
-
operands = ctx__supertype_factor.map(&
|
2350
|
-
operators = ctx__ANDOR.map{Model::SupertypeExpressions::BinarySupertypeExpression::ANDOR}
|
2359
|
+
if ctx__ANDOR && (ctx__ANDOR.length == ctx__supertype_factor.length - 1)
|
2360
|
+
operands = ctx__supertype_factor.map(&method(:visit))
|
2361
|
+
operators = ctx__ANDOR.map { Model::SupertypeExpressions::BinarySupertypeExpression::ANDOR }
|
2351
2362
|
|
2352
2363
|
handle_binary_supertype_expression(operands, operators)
|
2353
2364
|
else
|
2354
|
-
raise
|
2365
|
+
raise "Invalid state"
|
2355
2366
|
end
|
2356
2367
|
elsif ctx__supertype_factor.length == 1
|
2357
2368
|
visit(ctx__supertype_factor[0])
|
2358
2369
|
else
|
2359
|
-
raise
|
2370
|
+
raise "Invalid state"
|
2360
2371
|
end
|
2361
2372
|
end
|
2362
2373
|
end
|
2363
2374
|
|
2364
2375
|
def visit_supertype_factor(ctx)
|
2365
|
-
ctx__supertype_term = [ctx.supertype_term] + ctx.rhs.map
|
2376
|
+
ctx__supertype_term = [ctx.supertype_term] + ctx.rhs.map(&:supertype_term)
|
2366
2377
|
ctx__AND = ctx.rhs.map { |item| item.operator.values[0] }
|
2367
2378
|
|
2368
2379
|
if ctx__supertype_term
|
2369
2380
|
if ctx__supertype_term.length >= 2
|
2370
|
-
if ctx__AND
|
2371
|
-
operands = ctx__supertype_term.map(&
|
2372
|
-
operators = ctx__AND.map{Model::SupertypeExpressions::BinarySupertypeExpression::AND}
|
2381
|
+
if ctx__AND && (ctx__AND.length == ctx__supertype_term.length - 1)
|
2382
|
+
operands = ctx__supertype_term.map(&method(:visit))
|
2383
|
+
operators = ctx__AND.map { Model::SupertypeExpressions::BinarySupertypeExpression::AND }
|
2373
2384
|
|
2374
2385
|
handle_binary_supertype_expression(operands, operators)
|
2375
2386
|
else
|
2376
|
-
raise
|
2387
|
+
raise "Invalid state"
|
2377
2388
|
end
|
2378
2389
|
elsif ctx__supertype_term.length == 1
|
2379
2390
|
visit(ctx__supertype_term[0])
|
2380
2391
|
else
|
2381
|
-
raise
|
2392
|
+
raise "Invalid state"
|
2382
2393
|
end
|
2383
2394
|
end
|
2384
2395
|
end
|
@@ -2403,28 +2414,28 @@ module Expressir
|
|
2403
2414
|
schemas = visit_if_map(ctx__schema_decl)
|
2404
2415
|
|
2405
2416
|
Model::Repository.new(
|
2406
|
-
schemas: schemas
|
2417
|
+
schemas: schemas,
|
2407
2418
|
)
|
2408
2419
|
end
|
2409
2420
|
|
2410
2421
|
def visit_term(ctx)
|
2411
|
-
ctx__factor = [ctx.factor] + ctx.rhs.map
|
2412
|
-
ctx__multiplication_like_op = ctx.rhs.map
|
2422
|
+
ctx__factor = [ctx.factor] + ctx.rhs.map(&:factor)
|
2423
|
+
ctx__multiplication_like_op = ctx.rhs.map(&:multiplication_like_op)
|
2413
2424
|
|
2414
2425
|
if ctx__factor
|
2415
2426
|
if ctx__factor.length >= 2
|
2416
|
-
if ctx__multiplication_like_op
|
2417
|
-
operands = ctx__factor.map(&
|
2418
|
-
operators = ctx__multiplication_like_op.map(&
|
2427
|
+
if ctx__multiplication_like_op && (ctx__multiplication_like_op.length == ctx__factor.length - 1)
|
2428
|
+
operands = ctx__factor.map(&method(:visit))
|
2429
|
+
operators = ctx__multiplication_like_op.map(&method(:visit))
|
2419
2430
|
|
2420
2431
|
handle_binary_expression(operands, operators)
|
2421
2432
|
else
|
2422
|
-
raise
|
2433
|
+
raise "Invalid state"
|
2423
2434
|
end
|
2424
2435
|
elsif ctx__factor.length == 1
|
2425
2436
|
visit(ctx__factor[0])
|
2426
2437
|
else
|
2427
|
-
raise
|
2438
|
+
raise "Invalid state"
|
2428
2439
|
end
|
2429
2440
|
end
|
2430
2441
|
end
|
@@ -2447,7 +2458,7 @@ module Expressir
|
|
2447
2458
|
Model::Declarations::Type.new(
|
2448
2459
|
id: id,
|
2449
2460
|
underlying_type: underlying_type,
|
2450
|
-
where_rules: where_rules
|
2461
|
+
where_rules: where_rules,
|
2451
2462
|
)
|
2452
2463
|
end
|
2453
2464
|
|
@@ -2472,8 +2483,8 @@ module Expressir
|
|
2472
2483
|
|
2473
2484
|
def visit_unary_op(ctx)
|
2474
2485
|
ctx__text = ctx.values[0].text
|
2475
|
-
ctx__PLUS = ctx__text ==
|
2476
|
-
ctx__MINUS = ctx__text ==
|
2486
|
+
ctx__PLUS = ctx__text == "+"
|
2487
|
+
ctx__MINUS = ctx__text == "-"
|
2477
2488
|
ctx__NOT = ctx.tNOT
|
2478
2489
|
|
2479
2490
|
if ctx__PLUS
|
@@ -2483,7 +2494,7 @@ module Expressir
|
|
2483
2494
|
elsif ctx__NOT
|
2484
2495
|
Model::Expressions::UnaryExpression::NOT
|
2485
2496
|
else
|
2486
|
-
raise
|
2497
|
+
raise "Invalid state"
|
2487
2498
|
end
|
2488
2499
|
end
|
2489
2500
|
|
@@ -2509,7 +2520,7 @@ module Expressir
|
|
2509
2520
|
|
2510
2521
|
Model::Declarations::UniqueRule.new(
|
2511
2522
|
id: id,
|
2512
|
-
attributes: attributes
|
2523
|
+
attributes: attributes,
|
2513
2524
|
)
|
2514
2525
|
end
|
2515
2526
|
|
@@ -2529,7 +2540,7 @@ module Expressir
|
|
2529
2540
|
Model::Declarations::Interface.new(
|
2530
2541
|
kind: Model::Declarations::Interface::USE,
|
2531
2542
|
schema: schema,
|
2532
|
-
items: items
|
2543
|
+
items: items,
|
2533
2544
|
)
|
2534
2545
|
end
|
2535
2546
|
|
@@ -2557,25 +2568,25 @@ module Expressir
|
|
2557
2568
|
visit_if(ctx__numeric_expression)
|
2558
2569
|
end
|
2559
2570
|
|
2560
|
-
def visit_width_spec(
|
2561
|
-
raise
|
2571
|
+
def visit_width_spec(_ctx)
|
2572
|
+
raise "Invalid state"
|
2562
2573
|
end
|
2563
2574
|
|
2564
2575
|
def handle_binary_expression(operands, operators)
|
2565
2576
|
if operands.length != operators.length + 1
|
2566
|
-
raise
|
2577
|
+
raise "Invalid state"
|
2567
2578
|
end
|
2568
2579
|
|
2569
2580
|
expression = Model::Expressions::BinaryExpression.new(
|
2570
2581
|
operator: operators[0],
|
2571
2582
|
operand1: operands[0],
|
2572
|
-
operand2: operands[1]
|
2583
|
+
operand2: operands[1],
|
2573
2584
|
)
|
2574
2585
|
operators[1..(operators.length - 1)].each_with_index do |operator, i|
|
2575
2586
|
expression = Model::Expressions::BinaryExpression.new(
|
2576
2587
|
operator: operator,
|
2577
2588
|
operand1: expression,
|
2578
|
-
operand2: operands[i + 2]
|
2589
|
+
operand2: operands[i + 2],
|
2579
2590
|
)
|
2580
2591
|
end
|
2581
2592
|
expression
|
@@ -2583,19 +2594,19 @@ module Expressir
|
|
2583
2594
|
|
2584
2595
|
def handle_binary_supertype_expression(operands, operators)
|
2585
2596
|
if operands.length != operators.length + 1
|
2586
|
-
raise
|
2597
|
+
raise "Invalid state"
|
2587
2598
|
end
|
2588
2599
|
|
2589
2600
|
expression = Model::SupertypeExpressions::BinarySupertypeExpression.new(
|
2590
2601
|
operator: operators[0],
|
2591
2602
|
operand1: operands[0],
|
2592
|
-
operand2: operands[1]
|
2603
|
+
operand2: operands[1],
|
2593
2604
|
)
|
2594
2605
|
operators[1..(operators.length - 1)].each_with_index do |operator, i|
|
2595
2606
|
expression = Model::SupertypeExpressions::BinarySupertypeExpression.new(
|
2596
2607
|
operator: operator,
|
2597
2608
|
operand1: expression,
|
2598
|
-
operand2: operands[i + 2]
|
2609
|
+
operand2: operands[i + 2],
|
2599
2610
|
)
|
2600
2611
|
end
|
2601
2612
|
expression
|
@@ -2612,14 +2623,14 @@ module Expressir
|
|
2612
2623
|
|
2613
2624
|
Model::References::AttributeReference.new(
|
2614
2625
|
ref: ref,
|
2615
|
-
attribute: attribute_reference.attribute
|
2626
|
+
attribute: attribute_reference.attribute,
|
2616
2627
|
)
|
2617
2628
|
elsif ctx__group_qualifier
|
2618
2629
|
group_reference = visit_if(ctx__group_qualifier)
|
2619
2630
|
|
2620
2631
|
Model::References::GroupReference.new(
|
2621
2632
|
ref: ref,
|
2622
|
-
entity: group_reference.entity
|
2633
|
+
entity: group_reference.entity,
|
2623
2634
|
)
|
2624
2635
|
elsif ctx__index_qualifier
|
2625
2636
|
index_reference = visit_if(ctx__index_qualifier)
|
@@ -2627,10 +2638,10 @@ module Expressir
|
|
2627
2638
|
Model::References::IndexReference.new(
|
2628
2639
|
ref: ref,
|
2629
2640
|
index1: index_reference.index1,
|
2630
|
-
index2: index_reference.index2
|
2641
|
+
index2: index_reference.index2,
|
2631
2642
|
)
|
2632
2643
|
else
|
2633
|
-
raise
|
2644
|
+
raise "Invalid state"
|
2634
2645
|
end
|
2635
2646
|
end
|
2636
2647
|
end
|
@@ -2641,7 +2652,7 @@ module Expressir
|
|
2641
2652
|
value = ctx__text[1..(ctx__text.length - 1)]
|
2642
2653
|
|
2643
2654
|
Model::Literals::Binary.new(
|
2644
|
-
value: value
|
2655
|
+
value: value,
|
2645
2656
|
)
|
2646
2657
|
end
|
2647
2658
|
|
@@ -2651,7 +2662,7 @@ module Expressir
|
|
2651
2662
|
value = ctx__text
|
2652
2663
|
|
2653
2664
|
Model::Literals::Integer.new(
|
2654
|
-
value: value
|
2665
|
+
value: value,
|
2655
2666
|
)
|
2656
2667
|
end
|
2657
2668
|
|
@@ -2661,34 +2672,32 @@ module Expressir
|
|
2661
2672
|
value = ctx__text
|
2662
2673
|
|
2663
2674
|
Model::Literals::Real.new(
|
2664
|
-
value: value
|
2675
|
+
value: value,
|
2665
2676
|
)
|
2666
2677
|
end
|
2667
2678
|
|
2668
2679
|
def handle_simple_id(ctx)
|
2669
|
-
|
2670
|
-
|
2671
|
-
ctx__text
|
2680
|
+
ctx.text
|
2672
2681
|
end
|
2673
2682
|
|
2674
2683
|
def handle_simple_string_literal(ctx)
|
2675
2684
|
ctx__text = ctx.text
|
2676
2685
|
|
2677
|
-
value = ctx__text[1..(ctx__text.length - 2)].force_encoding(
|
2686
|
+
value = ctx__text[1..(ctx__text.length - 2)].force_encoding("UTF-8")
|
2678
2687
|
|
2679
2688
|
Model::Literals::String.new(
|
2680
|
-
value: value
|
2689
|
+
value: value,
|
2681
2690
|
)
|
2682
2691
|
end
|
2683
2692
|
|
2684
2693
|
def handle_encoded_string_literal(ctx)
|
2685
2694
|
ctx__text = ctx.text
|
2686
2695
|
|
2687
|
-
value = ctx__text[1..(ctx__text.length - 2)].force_encoding(
|
2696
|
+
value = ctx__text[1..(ctx__text.length - 2)].force_encoding("UTF-8")
|
2688
2697
|
|
2689
2698
|
Model::Literals::String.new(
|
2690
2699
|
value: value,
|
2691
|
-
encoded: true
|
2700
|
+
encoded: true,
|
2692
2701
|
)
|
2693
2702
|
end
|
2694
2703
|
end
|