expressir 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/expressir/express_exp/formatter.rb +1444 -0
- data/lib/expressir/express_exp/visitor.rb +288 -280
- data/lib/expressir/model.rb +13 -42
- data/lib/expressir/model/{derived.rb → attribute.rb} +13 -4
- data/lib/expressir/model/constant.rb +2 -1
- data/lib/expressir/model/entity.rb +22 -17
- data/lib/expressir/model/enumeration_item.rb +2 -1
- data/lib/expressir/model/expressions/aggregate_initializer.rb +9 -9
- data/lib/expressir/model/expressions/aggregate_item.rb +15 -0
- data/lib/expressir/model/expressions/{attribute_qualifier.rb → attribute_reference.rb} +3 -1
- data/lib/expressir/model/expressions/binary_expression.rb +40 -0
- data/lib/expressir/model/expressions/{function_call.rb → call.rb} +3 -3
- data/lib/expressir/model/expressions/entity_constructor.rb +11 -11
- data/lib/expressir/model/expressions/{group_qualifier.rb → group_reference.rb} +3 -1
- data/lib/expressir/model/expressions/{index_qualifier.rb → index_reference.rb} +3 -1
- data/lib/expressir/model/expressions/interval.rb +17 -17
- data/lib/expressir/model/expressions/query_expression.rb +26 -0
- data/lib/expressir/model/expressions/simple_reference.rb +13 -0
- data/lib/expressir/model/expressions/{expression.rb → unary_expression.rb} +7 -3
- data/lib/expressir/model/function.rb +14 -6
- data/lib/expressir/model/{reference.rb → interface.rb} +6 -1
- data/lib/expressir/model/literals/logical.rb +4 -0
- data/lib/expressir/model/parameter.rb +4 -3
- data/lib/expressir/model/procedure.rb +14 -6
- data/lib/expressir/model/repository.rb +1 -1
- data/lib/expressir/model/rule.rb +16 -8
- data/lib/expressir/model/schema.rb +22 -6
- data/lib/expressir/model/statements/alias.rb +3 -2
- data/lib/expressir/model/statements/{procedure_call.rb → call.rb} +3 -3
- data/lib/expressir/model/statements/case.rb +2 -2
- data/lib/expressir/model/statements/case_action.rb +2 -2
- data/lib/expressir/model/statements/repeat.rb +3 -2
- data/lib/expressir/model/subtype_constraint.rb +6 -5
- data/lib/expressir/model/type.rb +3 -2
- data/lib/expressir/model/types/aggregate.rb +2 -1
- data/lib/expressir/model/types/generic.rb +2 -1
- data/lib/expressir/model/types/generic_entity.rb +2 -1
- data/lib/expressir/model/unique.rb +2 -1
- data/lib/expressir/model/{local.rb → variable.rb} +3 -2
- data/lib/expressir/model/where.rb +2 -1
- data/lib/expressir/version.rb +1 -1
- data/original/examples/syntax/remark.exp +126 -108
- data/original/examples/syntax/remark_formatted.exp +172 -0
- data/original/examples/syntax/syntax.exp +287 -277
- data/original/examples/syntax/syntax_formatted.exp +1176 -0
- data/spec/expressir/express_exp/format_remark_spec.rb +28 -0
- data/spec/expressir/express_exp/format_syntax_spec.rb +28 -0
- data/spec/expressir/express_exp/{remark_spec.rb → parse_remark_spec.rb} +80 -36
- data/spec/expressir/express_exp/parse_syntax_spec.rb +2998 -0
- metadata +22 -46
- data/lib/expressir/model/explicit.rb +0 -19
- data/lib/expressir/model/expressions/aggregate_element.rb +0 -15
- data/lib/expressir/model/expressions/qualified_ref.rb +0 -15
- data/lib/expressir/model/expressions/query.rb +0 -25
- data/lib/expressir/model/inverse.rb +0 -19
- data/lib/expressir/model/operators/addition.rb +0 -8
- data/lib/expressir/model/operators/and.rb +0 -8
- data/lib/expressir/model/operators/andor.rb +0 -8
- data/lib/expressir/model/operators/combine.rb +0 -8
- data/lib/expressir/model/operators/equal.rb +0 -8
- data/lib/expressir/model/operators/exponentiation.rb +0 -8
- data/lib/expressir/model/operators/greater_than.rb +0 -8
- data/lib/expressir/model/operators/greater_than_or_equal.rb +0 -8
- data/lib/expressir/model/operators/in.rb +0 -8
- data/lib/expressir/model/operators/instance_equal.rb +0 -8
- data/lib/expressir/model/operators/instance_not_equal.rb +0 -8
- data/lib/expressir/model/operators/integer_division.rb +0 -8
- data/lib/expressir/model/operators/less_than.rb +0 -8
- data/lib/expressir/model/operators/less_than_or_equal.rb +0 -8
- data/lib/expressir/model/operators/like.rb +0 -8
- data/lib/expressir/model/operators/modulo.rb +0 -8
- data/lib/expressir/model/operators/multiplication.rb +0 -8
- data/lib/expressir/model/operators/not.rb +0 -8
- data/lib/expressir/model/operators/not_equal.rb +0 -8
- data/lib/expressir/model/operators/oneof.rb +0 -8
- data/lib/expressir/model/operators/or.rb +0 -8
- data/lib/expressir/model/operators/real_division.rb +0 -8
- data/lib/expressir/model/operators/subtraction.rb +0 -8
- data/lib/expressir/model/operators/unary_minus.rb +0 -8
- data/lib/expressir/model/operators/unary_plus.rb +0 -8
- data/lib/expressir/model/operators/xor.rb +0 -8
- data/lib/expressir/model/ref.rb +0 -11
- data/lib/expressir/model/use.rb +0 -13
- data/spec/expressir/express_exp/syntax_spec.rb +0 -2992
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'expressir/express_exp/generated/ExpressBaseVisitor'
|
2
2
|
require 'expressir/model'
|
3
3
|
|
4
|
-
#
|
4
|
+
# static shorthands are unwrapped
|
5
|
+
# - entity attributes, function/procedure parameters, local variables
|
5
6
|
#
|
6
7
|
# reference type is not recognized
|
7
8
|
# see note in A.1.5 Interpreted identifiers
|
@@ -11,8 +12,8 @@ require 'expressir/model'
|
|
11
12
|
# > declarations, so that subsequent passes are then able to distinguish a veriable_ref from a function_ref,
|
12
13
|
# > for example.
|
13
14
|
#
|
14
|
-
# - xxxRef - merged to
|
15
|
-
# - entityConstructor, functionCall
|
15
|
+
# - xxxRef - merged to SimpleReference
|
16
|
+
# - entityConstructor, functionCall - merged to Call
|
16
17
|
#
|
17
18
|
# difference between generalized and instantiable types is not recognized
|
18
19
|
# see note in 8.6.2 Parameter data types
|
@@ -32,11 +33,22 @@ module Expressir
|
|
32
33
|
|
33
34
|
def visit(ctx)
|
34
35
|
result = super(ctx)
|
36
|
+
attach_parent(ctx, result)
|
35
37
|
attach_remarks(ctx, result)
|
36
38
|
result
|
37
39
|
end
|
38
40
|
|
39
|
-
def
|
41
|
+
def attach_parent(ctx, node)
|
42
|
+
if node.class.method_defined? :children
|
43
|
+
node.children.each do |child_node|
|
44
|
+
if child_node.class.method_defined? :parent
|
45
|
+
child_node.parent = node
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def attach_remarks(ctx, node)
|
40
52
|
# get remark tokens
|
41
53
|
start_index, stop_index = if ctx.instance_of? Generated::ExpressParser::SyntaxContext
|
42
54
|
[0, @tokens.size - 1]
|
@@ -66,16 +78,16 @@ module Expressir
|
|
66
78
|
end
|
67
79
|
|
68
80
|
# attach tagged remark
|
69
|
-
remark_tag = match[1]
|
81
|
+
remark_tag = match[1].downcase
|
70
82
|
remark_content = match[2].strip
|
71
83
|
|
72
|
-
|
84
|
+
current_node = node
|
73
85
|
remark_tag.split('.').each do |id|
|
74
|
-
if
|
75
|
-
if
|
76
|
-
|
86
|
+
if current_node
|
87
|
+
if current_node.class.method_defined? :children
|
88
|
+
current_node = current_node.children.find{|x| x.id.downcase == id}
|
77
89
|
else
|
78
|
-
|
90
|
+
current_node = nil
|
79
91
|
break
|
80
92
|
end
|
81
93
|
else
|
@@ -83,9 +95,9 @@ module Expressir
|
|
83
95
|
end
|
84
96
|
end
|
85
97
|
|
86
|
-
if
|
87
|
-
|
88
|
-
|
98
|
+
if current_node
|
99
|
+
current_node.remarks ||= []
|
100
|
+
current_node.remarks << remark_content
|
89
101
|
|
90
102
|
# mark remark as attached, so that it is not attached again at higher nesting level
|
91
103
|
@attached_remarks << remark_token
|
@@ -97,7 +109,7 @@ module Expressir
|
|
97
109
|
def visitAttributeRef(ctx)
|
98
110
|
id = visit(ctx.attributeId())
|
99
111
|
|
100
|
-
Model::
|
112
|
+
Model::Expressions::SimpleReference.new({
|
101
113
|
id: id
|
102
114
|
})
|
103
115
|
end
|
@@ -105,7 +117,7 @@ module Expressir
|
|
105
117
|
def visitConstantRef(ctx)
|
106
118
|
id = visit(ctx.constantId())
|
107
119
|
|
108
|
-
Model::
|
120
|
+
Model::Expressions::SimpleReference.new({
|
109
121
|
id: id
|
110
122
|
})
|
111
123
|
end
|
@@ -113,7 +125,7 @@ module Expressir
|
|
113
125
|
def visitEntityRef(ctx)
|
114
126
|
id = visit(ctx.entityId())
|
115
127
|
|
116
|
-
Model::
|
128
|
+
Model::Expressions::SimpleReference.new({
|
117
129
|
id: id
|
118
130
|
})
|
119
131
|
end
|
@@ -121,7 +133,7 @@ module Expressir
|
|
121
133
|
def visitEnumerationRef(ctx)
|
122
134
|
id = visit(ctx.enumerationId())
|
123
135
|
|
124
|
-
Model::
|
136
|
+
Model::Expressions::SimpleReference.new({
|
125
137
|
id: id
|
126
138
|
})
|
127
139
|
end
|
@@ -129,7 +141,7 @@ module Expressir
|
|
129
141
|
def visitFunctionRef(ctx)
|
130
142
|
id = visit(ctx.functionId())
|
131
143
|
|
132
|
-
Model::
|
144
|
+
Model::Expressions::SimpleReference.new({
|
133
145
|
id: id
|
134
146
|
})
|
135
147
|
end
|
@@ -137,7 +149,7 @@ module Expressir
|
|
137
149
|
def visitParameterRef(ctx)
|
138
150
|
id = visit(ctx.parameterId())
|
139
151
|
|
140
|
-
Model::
|
152
|
+
Model::Expressions::SimpleReference.new({
|
141
153
|
id: id
|
142
154
|
})
|
143
155
|
end
|
@@ -145,7 +157,7 @@ module Expressir
|
|
145
157
|
def visitProcedureRef(ctx)
|
146
158
|
id = visit(ctx.procedureId())
|
147
159
|
|
148
|
-
Model::
|
160
|
+
Model::Expressions::SimpleReference.new({
|
149
161
|
id: id
|
150
162
|
})
|
151
163
|
end
|
@@ -153,7 +165,7 @@ module Expressir
|
|
153
165
|
def visitRuleLabelRef(ctx)
|
154
166
|
id = visit(ctx.ruleLabelId())
|
155
167
|
|
156
|
-
Model::
|
168
|
+
Model::Expressions::SimpleReference.new({
|
157
169
|
id: id
|
158
170
|
})
|
159
171
|
end
|
@@ -161,7 +173,7 @@ module Expressir
|
|
161
173
|
def visitRuleRef(ctx)
|
162
174
|
id = visit(ctx.ruleId())
|
163
175
|
|
164
|
-
Model::
|
176
|
+
Model::Expressions::SimpleReference.new({
|
165
177
|
id: id
|
166
178
|
})
|
167
179
|
end
|
@@ -169,7 +181,7 @@ module Expressir
|
|
169
181
|
def visitSchemaRef(ctx)
|
170
182
|
id = visit(ctx.schemaId())
|
171
183
|
|
172
|
-
Model::
|
184
|
+
Model::Expressions::SimpleReference.new({
|
173
185
|
id: id
|
174
186
|
})
|
175
187
|
end
|
@@ -177,7 +189,7 @@ module Expressir
|
|
177
189
|
def visitSubtypeConstraintRef(ctx)
|
178
190
|
id = visit(ctx.subtypeConstraintId())
|
179
191
|
|
180
|
-
Model::
|
192
|
+
Model::Expressions::SimpleReference.new({
|
181
193
|
id: id
|
182
194
|
})
|
183
195
|
end
|
@@ -185,7 +197,7 @@ module Expressir
|
|
185
197
|
def visitTypeLabelRef(ctx)
|
186
198
|
id = visit(ctx.typeLabelId())
|
187
199
|
|
188
|
-
Model::
|
200
|
+
Model::Expressions::SimpleReference.new({
|
189
201
|
id: id
|
190
202
|
})
|
191
203
|
end
|
@@ -193,7 +205,7 @@ module Expressir
|
|
193
205
|
def visitTypeRef(ctx)
|
194
206
|
id = visit(ctx.typeId())
|
195
207
|
|
196
|
-
Model::
|
208
|
+
Model::Expressions::SimpleReference.new({
|
197
209
|
id: id
|
198
210
|
})
|
199
211
|
end
|
@@ -201,7 +213,7 @@ module Expressir
|
|
201
213
|
def visitVariableRef(ctx)
|
202
214
|
id = visit(ctx.variableId())
|
203
215
|
|
204
|
-
Model::
|
216
|
+
Model::Expressions::SimpleReference.new({
|
205
217
|
id: id
|
206
218
|
})
|
207
219
|
end
|
@@ -224,13 +236,13 @@ module Expressir
|
|
224
236
|
|
225
237
|
def visitAddLikeOp(ctx)
|
226
238
|
if ctx.text == '+'
|
227
|
-
Model::
|
239
|
+
Model::Expressions::BinaryExpression::ADDITION
|
228
240
|
elsif ctx.text == '-'
|
229
|
-
Model::
|
241
|
+
Model::Expressions::BinaryExpression::SUBTRACTION
|
230
242
|
elsif ctx.OR()
|
231
|
-
Model::
|
243
|
+
Model::Expressions::BinaryExpression::OR
|
232
244
|
elsif ctx.XOR()
|
233
|
-
Model::
|
245
|
+
Model::Expressions::BinaryExpression::XOR
|
234
246
|
else
|
235
247
|
raise 'Invalid state'
|
236
248
|
end
|
@@ -280,17 +292,7 @@ module Expressir
|
|
280
292
|
|
281
293
|
def visitAliasStmt(ctx)
|
282
294
|
id = visit(ctx.variableId())
|
283
|
-
expression =
|
284
|
-
ref = visit(ctx.generalRef())
|
285
|
-
qualifiers = ctx.qualifier().map{|ctx| visit(ctx)}
|
286
|
-
|
287
|
-
Model::Expressions::QualifiedRef.new({
|
288
|
-
ref: ref,
|
289
|
-
qualifiers: qualifiers
|
290
|
-
})
|
291
|
-
else
|
292
|
-
visit(ctx.generalRef())
|
293
|
-
end
|
295
|
+
expression = handleQualifiedRef(visit(ctx.generalRef()), ctx.qualifier())
|
294
296
|
statements = ctx.stmt().map{|ctx| visit(ctx)}
|
295
297
|
|
296
298
|
Model::Statements::Alias.new({
|
@@ -317,20 +319,9 @@ module Expressir
|
|
317
319
|
end
|
318
320
|
|
319
321
|
def visitAssignmentStmt(ctx)
|
322
|
+
ref = handleQualifiedRef(visit(ctx.generalRef()), ctx.qualifier())
|
320
323
|
expression = visit(ctx.expression())
|
321
324
|
|
322
|
-
ref = if ctx.qualifier().length > 0
|
323
|
-
ref = visit(ctx.generalRef())
|
324
|
-
qualifiers = ctx.qualifier().map{|ctx| visit(ctx)}
|
325
|
-
|
326
|
-
Model::Expressions::QualifiedRef.new({
|
327
|
-
ref: ref,
|
328
|
-
qualifiers: qualifiers
|
329
|
-
})
|
330
|
-
else
|
331
|
-
visit(ctx.generalRef())
|
332
|
-
end
|
333
|
-
|
334
325
|
Model::Statements::Assignment.new({
|
335
326
|
ref: ref,
|
336
327
|
expression: expression
|
@@ -345,20 +336,16 @@ module Expressir
|
|
345
336
|
handleSimpleId(ctx.SimpleId())
|
346
337
|
end
|
347
338
|
|
348
|
-
def
|
349
|
-
|
350
|
-
|
351
|
-
Model::Expressions::AttributeQualifier.new({
|
352
|
-
attribute: attribute
|
353
|
-
})
|
339
|
+
def visitAttributeReference(ctx)
|
340
|
+
raise 'Invalid state'
|
354
341
|
end
|
355
342
|
|
356
343
|
def visitBagType(ctx)
|
357
|
-
bound1
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
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())
|
362
349
|
end
|
363
350
|
base_type = visit(ctx.instantiableType())
|
364
351
|
|
@@ -402,7 +389,7 @@ module Expressir
|
|
402
389
|
def visitBuiltInConstant(ctx)
|
403
390
|
id = ctx.text
|
404
391
|
|
405
|
-
Model::
|
392
|
+
Model::Expressions::SimpleReference.new({
|
406
393
|
id: id
|
407
394
|
})
|
408
395
|
end
|
@@ -410,7 +397,7 @@ module Expressir
|
|
410
397
|
def visitBuiltInFunction(ctx)
|
411
398
|
id = ctx.text
|
412
399
|
|
413
|
-
Model::
|
400
|
+
Model::Expressions::SimpleReference.new({
|
414
401
|
id: id
|
415
402
|
})
|
416
403
|
end
|
@@ -418,21 +405,19 @@ module Expressir
|
|
418
405
|
def visitBuiltInProcedure(ctx)
|
419
406
|
id = ctx.text
|
420
407
|
|
421
|
-
Model::
|
408
|
+
Model::Expressions::SimpleReference.new({
|
422
409
|
id: id
|
423
410
|
})
|
424
411
|
end
|
425
412
|
|
426
413
|
def visitCaseAction(ctx)
|
427
|
-
|
414
|
+
labels = ctx.caseLabel().map{|ctx| visit(ctx.expression())}
|
428
415
|
statement = visit(ctx.stmt())
|
429
416
|
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
})
|
435
|
-
end
|
417
|
+
Model::Statements::CaseAction.new({
|
418
|
+
labels: labels,
|
419
|
+
statement: statement
|
420
|
+
})
|
436
421
|
end
|
437
422
|
|
438
423
|
def visitCaseLabel(ctx)
|
@@ -440,14 +425,14 @@ module Expressir
|
|
440
425
|
end
|
441
426
|
|
442
427
|
def visitCaseStmt(ctx)
|
443
|
-
|
428
|
+
expression = visit(ctx.selector().expression())
|
444
429
|
actions = ctx.caseAction().map{|ctx| visit(ctx)}.flatten
|
445
430
|
otherwise_statement = if ctx.stmt()
|
446
431
|
visit(ctx.stmt())
|
447
432
|
end
|
448
433
|
|
449
434
|
Model::Statements::Case.new({
|
450
|
-
|
435
|
+
expression: expression,
|
451
436
|
actions: actions,
|
452
437
|
otherwise_statement: otherwise_statement
|
453
438
|
})
|
@@ -530,20 +515,21 @@ module Expressir
|
|
530
515
|
end
|
531
516
|
|
532
517
|
def visitDerivedAttr(ctx)
|
518
|
+
supertype_attribute = if ctx.attributeDecl().redeclaredAttribute() && ctx.attributeDecl().redeclaredAttribute().qualifiedAttribute()
|
519
|
+
visit(ctx.attributeDecl().redeclaredAttribute().qualifiedAttribute())
|
520
|
+
end
|
533
521
|
id = if ctx.attributeDecl().attributeId()
|
534
522
|
visit(ctx.attributeDecl().attributeId())
|
535
523
|
elsif ctx.attributeDecl().redeclaredAttribute() && ctx.attributeDecl().redeclaredAttribute().attributeId()
|
536
524
|
visit(ctx.attributeDecl().redeclaredAttribute().attributeId())
|
537
525
|
end
|
538
|
-
supertype_attribute = if ctx.attributeDecl().redeclaredAttribute() && ctx.attributeDecl().redeclaredAttribute().qualifiedAttribute()
|
539
|
-
visit(ctx.attributeDecl().redeclaredAttribute().qualifiedAttribute())
|
540
|
-
end
|
541
526
|
type = visit(ctx.parameterType())
|
542
527
|
expression = visit(ctx.expression())
|
543
528
|
|
544
|
-
Model::
|
545
|
-
|
529
|
+
Model::Attribute.new({
|
530
|
+
kind: Model::Attribute::DERIVED,
|
546
531
|
supertype_attribute: supertype_attribute,
|
532
|
+
id: id,
|
547
533
|
type: type,
|
548
534
|
expression: expression
|
549
535
|
})
|
@@ -570,7 +556,7 @@ module Expressir
|
|
570
556
|
expression = visit(ctx.expression())
|
571
557
|
repetition = visit(ctx.repetition().numericExpression().simpleExpression())
|
572
558
|
|
573
|
-
Model::Expressions::
|
559
|
+
Model::Expressions::AggregateItem.new({
|
574
560
|
expression: expression,
|
575
561
|
repetition: repetition
|
576
562
|
})
|
@@ -584,11 +570,11 @@ module Expressir
|
|
584
570
|
end
|
585
571
|
|
586
572
|
def visitEntityConstructor(ctx)
|
587
|
-
|
573
|
+
ref = visit(ctx.entityRef())
|
588
574
|
parameters = ctx.expression().map{|ctx| visit(ctx)}
|
589
575
|
|
590
|
-
Model::Expressions::
|
591
|
-
|
576
|
+
Model::Expressions::Call.new({
|
577
|
+
ref: ref,
|
592
578
|
parameters: parameters
|
593
579
|
})
|
594
580
|
end
|
@@ -596,26 +582,25 @@ module Expressir
|
|
596
582
|
def visitEntityDecl(ctx)
|
597
583
|
id = visit(ctx.entityHead().entityId())
|
598
584
|
abstract = if ctx.entityHead().subsuper().supertypeConstraint()
|
599
|
-
!!ctx.entityHead().subsuper().supertypeConstraint().abstractEntityDeclaration()
|
600
|
-
end
|
601
|
-
abstract_supertype = if ctx.entityHead().subsuper().supertypeConstraint()
|
602
|
-
!!ctx.entityHead().subsuper().supertypeConstraint().abstractSupertypeDeclaration()
|
585
|
+
!!ctx.entityHead().subsuper().supertypeConstraint().abstractEntityDeclaration() || !!ctx.entityHead().subsuper().supertypeConstraint().abstractSupertypeDeclaration()
|
603
586
|
end
|
604
|
-
|
605
|
-
ctx.entityHead().subsuper().subtypeDeclaration().entityRef().map{|ctx| visit(ctx)}
|
606
|
-
end
|
607
|
-
subtype_expression = if ctx.entityHead().subsuper().supertypeConstraint() && ctx.entityHead().subsuper().supertypeConstraint().abstractSupertypeDeclaration() && ctx.entityHead().subsuper().supertypeConstraint().abstractSupertypeDeclaration().subtypeConstraint()
|
587
|
+
supertype_expression = if ctx.entityHead().subsuper().supertypeConstraint() && ctx.entityHead().subsuper().supertypeConstraint().abstractSupertypeDeclaration() && ctx.entityHead().subsuper().supertypeConstraint().abstractSupertypeDeclaration().subtypeConstraint()
|
608
588
|
visit(ctx.entityHead().subsuper().supertypeConstraint().abstractSupertypeDeclaration().subtypeConstraint().supertypeExpression())
|
609
589
|
elsif ctx.entityHead().subsuper().supertypeConstraint() && ctx.entityHead().subsuper().supertypeConstraint().supertypeRule()
|
610
590
|
visit(ctx.entityHead().subsuper().supertypeConstraint().supertypeRule().subtypeConstraint().supertypeExpression())
|
611
591
|
end
|
612
|
-
|
613
|
-
|
614
|
-
ctx.entityBody().deriveClause().derivedAttr().map{|ctx| visit(ctx)}
|
615
|
-
end
|
616
|
-
inverse = if ctx.entityBody().inverseClause()
|
617
|
-
ctx.entityBody().inverseClause().inverseAttr().map{|ctx| visit(ctx)}
|
592
|
+
subtype_of = if ctx.entityHead().subsuper().subtypeDeclaration()
|
593
|
+
ctx.entityHead().subsuper().subtypeDeclaration().entityRef().map{|ctx| visit(ctx)}
|
618
594
|
end
|
595
|
+
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
|
603
|
+
]
|
619
604
|
unique = if ctx.entityBody().uniqueClause()
|
620
605
|
ctx.entityBody().uniqueClause().uniqueRule().map{|ctx| visit(ctx)}
|
621
606
|
end
|
@@ -626,12 +611,9 @@ module Expressir
|
|
626
611
|
Model::Entity.new({
|
627
612
|
id: id,
|
628
613
|
abstract: abstract,
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
explicit: explicit,
|
633
|
-
derived: derived,
|
634
|
-
inverse: inverse,
|
614
|
+
supertype_expression: supertype_expression,
|
615
|
+
subtype_of: subtype_of,
|
616
|
+
attributes: attributes,
|
635
617
|
unique: unique,
|
636
618
|
where: where
|
637
619
|
})
|
@@ -661,14 +643,10 @@ module Expressir
|
|
661
643
|
if ctx.typeRef()
|
662
644
|
ref = visit(ctx.typeRef())
|
663
645
|
attribute = visit(ctx.enumerationRef())
|
664
|
-
attribute_qualifier = Model::Expressions::AttributeQualifier.new({
|
665
|
-
attribute: attribute
|
666
|
-
})
|
667
|
-
qualifiers = [attribute_qualifier]
|
668
646
|
|
669
|
-
Model::Expressions::
|
647
|
+
Model::Expressions::AttributeReference.new({
|
670
648
|
ref: ref,
|
671
|
-
|
649
|
+
attribute: attribute
|
672
650
|
})
|
673
651
|
else
|
674
652
|
visit(ctx.enumerationRef())
|
@@ -705,17 +683,19 @@ module Expressir
|
|
705
683
|
type = visit(ctx.parameterType())
|
706
684
|
|
707
685
|
decls.map do |decl|
|
686
|
+
supertype_attribute = if decl.redeclaredAttribute() && decl.redeclaredAttribute().qualifiedAttribute()
|
687
|
+
visit(decl.redeclaredAttribute().qualifiedAttribute())
|
688
|
+
end
|
708
689
|
id = if decl.attributeId()
|
709
690
|
visit(decl.attributeId())
|
710
691
|
elsif decl.redeclaredAttribute() && decl.redeclaredAttribute().attributeId()
|
711
692
|
visit(decl.redeclaredAttribute().attributeId())
|
712
693
|
end
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
Model::Explicit.new({
|
717
|
-
id: id,
|
694
|
+
|
695
|
+
Model::Attribute.new({
|
696
|
+
kind: Model::Attribute::EXPLICIT,
|
718
697
|
supertype_attribute: supertype_attribute,
|
698
|
+
id: id,
|
719
699
|
optional: optional,
|
720
700
|
type: type
|
721
701
|
})
|
@@ -725,11 +705,13 @@ module Expressir
|
|
725
705
|
def visitExpression(ctx)
|
726
706
|
if ctx.relOpExtended()
|
727
707
|
operator = visit(ctx.relOpExtended())
|
728
|
-
|
708
|
+
operand1 = visit(ctx.simpleExpression()[0])
|
709
|
+
operand2 = visit(ctx.simpleExpression()[1])
|
729
710
|
|
730
|
-
Model::Expressions::
|
711
|
+
Model::Expressions::BinaryExpression.new({
|
731
712
|
operator: operator,
|
732
|
-
|
713
|
+
operand1: operand1,
|
714
|
+
operand2: operand2
|
733
715
|
})
|
734
716
|
else
|
735
717
|
visit(ctx.simpleExpression()[0])
|
@@ -738,12 +720,14 @@ module Expressir
|
|
738
720
|
|
739
721
|
def visitFactor(ctx)
|
740
722
|
if ctx.child_at(1) && ctx.child_at(1).text == '**'
|
741
|
-
operator = Model::
|
742
|
-
|
723
|
+
operator = Model::Expressions::BinaryExpression::EXPONENTIATION
|
724
|
+
operand1 = visit(ctx.simpleFactor()[0])
|
725
|
+
operand2 = visit(ctx.simpleFactor()[1])
|
743
726
|
|
744
|
-
Model::Expressions::
|
727
|
+
Model::Expressions::BinaryExpression.new({
|
745
728
|
operator: operator,
|
746
|
-
|
729
|
+
operand1: operand1,
|
730
|
+
operand2: operand2
|
747
731
|
})
|
748
732
|
else
|
749
733
|
visit(ctx.simpleFactor()[0])
|
@@ -763,7 +747,7 @@ module Expressir
|
|
763
747
|
end
|
764
748
|
|
765
749
|
def visitFunctionCall(ctx)
|
766
|
-
|
750
|
+
ref = if ctx.builtInFunction()
|
767
751
|
visit(ctx.builtInFunction())
|
768
752
|
elsif ctx.functionRef()
|
769
753
|
visit(ctx.functionRef())
|
@@ -774,8 +758,8 @@ module Expressir
|
|
774
758
|
ctx.actualParameterList().parameter().map{|ctx| visit(ctx.expression)}
|
775
759
|
end
|
776
760
|
|
777
|
-
Model::Expressions::
|
778
|
-
|
761
|
+
Model::Expressions::Call.new({
|
762
|
+
ref: ref,
|
779
763
|
parameters: parameters
|
780
764
|
})
|
781
765
|
end
|
@@ -788,7 +772,7 @@ module Expressir
|
|
788
772
|
constants = if ctx.algorithmHead().constantDecl()
|
789
773
|
ctx.algorithmHead().constantDecl().constantBody().map{|ctx| visit(ctx)}
|
790
774
|
end
|
791
|
-
|
775
|
+
variables = if ctx.algorithmHead().localDecl()
|
792
776
|
ctx.algorithmHead().localDecl().localVariable().map{|ctx| visit(ctx)}.flatten
|
793
777
|
end
|
794
778
|
declarations = ctx.algorithmHead().declaration().map{|ctx| visit(ctx)}
|
@@ -800,7 +784,7 @@ module Expressir
|
|
800
784
|
return_type: return_type,
|
801
785
|
declarations: declarations,
|
802
786
|
constants: constants,
|
803
|
-
|
787
|
+
variables: variables,
|
804
788
|
statements: statements
|
805
789
|
})
|
806
790
|
end
|
@@ -842,11 +826,11 @@ module Expressir
|
|
842
826
|
end
|
843
827
|
|
844
828
|
def visitGeneralArrayType(ctx)
|
845
|
-
bound1
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
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())
|
850
834
|
end
|
851
835
|
optional = !!ctx.OPTIONAL()
|
852
836
|
unique = !!ctx.UNIQUE()
|
@@ -862,11 +846,11 @@ module Expressir
|
|
862
846
|
end
|
863
847
|
|
864
848
|
def visitGeneralBagType(ctx)
|
865
|
-
bound1
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
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())
|
870
854
|
end
|
871
855
|
base_type = visit(ctx.parameterType())
|
872
856
|
|
@@ -878,11 +862,11 @@ module Expressir
|
|
878
862
|
end
|
879
863
|
|
880
864
|
def visitGeneralListType(ctx)
|
881
|
-
bound1
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
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())
|
886
870
|
end
|
887
871
|
unique = !!ctx.UNIQUE()
|
888
872
|
base_type = visit(ctx.parameterType())
|
@@ -906,11 +890,11 @@ module Expressir
|
|
906
890
|
end
|
907
891
|
|
908
892
|
def visitGeneralSetType(ctx)
|
909
|
-
bound1
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
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())
|
914
898
|
end
|
915
899
|
base_type = visit(ctx.parameterType())
|
916
900
|
|
@@ -941,12 +925,8 @@ module Expressir
|
|
941
925
|
})
|
942
926
|
end
|
943
927
|
|
944
|
-
def
|
945
|
-
|
946
|
-
|
947
|
-
Model::Expressions::GroupQualifier.new({
|
948
|
-
entity: entity
|
949
|
-
})
|
928
|
+
def visitGroupReference(ctx)
|
929
|
+
raise 'Invalid state'
|
950
930
|
end
|
951
931
|
|
952
932
|
def visitIfStmt(ctx)
|
@@ -993,16 +973,8 @@ module Expressir
|
|
993
973
|
raise 'Invalid state'
|
994
974
|
end
|
995
975
|
|
996
|
-
def
|
997
|
-
|
998
|
-
index2 = if ctx.index2()
|
999
|
-
visit(ctx.index2().index().numericExpression().simpleExpression())
|
1000
|
-
end
|
1001
|
-
|
1002
|
-
Model::Expressions::IndexQualifier.new({
|
1003
|
-
index1: index1,
|
1004
|
-
index2: index2
|
1005
|
-
})
|
976
|
+
def visitIndexReference(ctx)
|
977
|
+
raise 'Invalid state'
|
1006
978
|
end
|
1007
979
|
|
1008
980
|
def visitInstantiableType(ctx)
|
@@ -1059,29 +1031,29 @@ module Expressir
|
|
1059
1031
|
|
1060
1032
|
def visitIntervalOp(ctx)
|
1061
1033
|
if ctx.text == '<'
|
1062
|
-
Model::
|
1034
|
+
Model::Expressions::BinaryExpression::LESS_THAN
|
1063
1035
|
elsif ctx.text == '<='
|
1064
|
-
Model::
|
1036
|
+
Model::Expressions::BinaryExpression::LESS_THAN_OR_EQUAL
|
1065
1037
|
else
|
1066
1038
|
raise 'Invalid state'
|
1067
1039
|
end
|
1068
1040
|
end
|
1069
1041
|
|
1070
1042
|
def visitInverseAttr(ctx)
|
1043
|
+
supertype_attribute = if ctx.attributeDecl().redeclaredAttribute() && ctx.attributeDecl().redeclaredAttribute().qualifiedAttribute()
|
1044
|
+
visit(ctx.attributeDecl().redeclaredAttribute().qualifiedAttribute())
|
1045
|
+
end
|
1071
1046
|
id = if ctx.attributeDecl().attributeId()
|
1072
1047
|
visit(ctx.attributeDecl().attributeId())
|
1073
1048
|
elsif ctx.attributeDecl().redeclaredAttribute() && ctx.attributeDecl().redeclaredAttribute().attributeId()
|
1074
1049
|
visit(ctx.attributeDecl().redeclaredAttribute().attributeId())
|
1075
1050
|
end
|
1076
|
-
supertype_attribute = if ctx.attributeDecl().redeclaredAttribute() && ctx.attributeDecl().redeclaredAttribute().qualifiedAttribute()
|
1077
|
-
visit(ctx.attributeDecl().redeclaredAttribute().qualifiedAttribute())
|
1078
|
-
end
|
1079
1051
|
type = if ctx.SET()
|
1080
|
-
bound1
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
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())
|
1085
1057
|
end
|
1086
1058
|
base_type = visit(ctx.entityRef()[0])
|
1087
1059
|
|
@@ -1091,11 +1063,11 @@ module Expressir
|
|
1091
1063
|
base_type: base_type
|
1092
1064
|
})
|
1093
1065
|
elsif ctx.BAG()
|
1094
|
-
bound1
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
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())
|
1099
1071
|
end
|
1100
1072
|
base_type = visit(ctx.entityRef()[0])
|
1101
1073
|
|
@@ -1107,27 +1079,24 @@ module Expressir
|
|
1107
1079
|
else
|
1108
1080
|
visit(ctx.entityRef()[0])
|
1109
1081
|
end
|
1110
|
-
|
1082
|
+
expression = if ctx.entityRef()[1]
|
1111
1083
|
ref = visit(ctx.entityRef()[1])
|
1112
1084
|
attribute = visit(ctx.attributeRef())
|
1113
|
-
attribute_qualifier = Model::Expressions::AttributeQualifier.new({
|
1114
|
-
attribute: attribute
|
1115
|
-
})
|
1116
|
-
qualifiers = [attribute_qualifier]
|
1117
1085
|
|
1118
|
-
Model::Expressions::
|
1086
|
+
Model::Expressions::AttributeReference.new({
|
1119
1087
|
ref: ref,
|
1120
|
-
|
1088
|
+
attribute: attribute
|
1121
1089
|
})
|
1122
1090
|
else
|
1123
1091
|
visit(ctx.attributeRef())
|
1124
1092
|
end
|
1125
1093
|
|
1126
|
-
Model::
|
1127
|
-
|
1094
|
+
Model::Attribute.new({
|
1095
|
+
kind: Model::Attribute::INVERSE,
|
1128
1096
|
supertype_attribute: supertype_attribute,
|
1097
|
+
id: id,
|
1129
1098
|
type: type,
|
1130
|
-
|
1099
|
+
expression: expression
|
1131
1100
|
})
|
1132
1101
|
end
|
1133
1102
|
|
@@ -1136,11 +1105,11 @@ module Expressir
|
|
1136
1105
|
end
|
1137
1106
|
|
1138
1107
|
def visitListType(ctx)
|
1139
|
-
bound1
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
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())
|
1144
1113
|
end
|
1145
1114
|
unique = !!ctx.UNIQUE()
|
1146
1115
|
base_type = visit(ctx.instantiableType())
|
@@ -1181,7 +1150,7 @@ module Expressir
|
|
1181
1150
|
end
|
1182
1151
|
|
1183
1152
|
ids.map do |id|
|
1184
|
-
Model::
|
1153
|
+
Model::Variable.new({
|
1185
1154
|
id: id,
|
1186
1155
|
type: type,
|
1187
1156
|
expression: expression
|
@@ -1195,11 +1164,11 @@ module Expressir
|
|
1195
1164
|
|
1196
1165
|
def visitLogicalLiteral(ctx)
|
1197
1166
|
value = if ctx.TRUE()
|
1198
|
-
|
1167
|
+
Model::Literals::Logical::TRUE
|
1199
1168
|
elsif ctx.FALSE()
|
1200
|
-
|
1169
|
+
Model::Literals::Logical::FALSE
|
1201
1170
|
elsif ctx.UNKNOWN()
|
1202
|
-
|
1171
|
+
Model::Literals::Logical::UNKNOWN
|
1203
1172
|
else
|
1204
1173
|
raise 'Invalid state'
|
1205
1174
|
end
|
@@ -1215,17 +1184,17 @@ module Expressir
|
|
1215
1184
|
|
1216
1185
|
def visitMultiplicationLikeOp(ctx)
|
1217
1186
|
if ctx.text == '*'
|
1218
|
-
Model::
|
1187
|
+
Model::Expressions::BinaryExpression::MULTIPLICATION
|
1219
1188
|
elsif ctx.text == '/'
|
1220
|
-
Model::
|
1189
|
+
Model::Expressions::BinaryExpression::REAL_DIVISION
|
1221
1190
|
elsif ctx.DIV()
|
1222
|
-
Model::
|
1191
|
+
Model::Expressions::BinaryExpression::INTEGER_DIVISION
|
1223
1192
|
elsif ctx.MOD()
|
1224
|
-
Model::
|
1193
|
+
Model::Expressions::BinaryExpression::MODULO
|
1225
1194
|
elsif ctx.AND()
|
1226
|
-
Model::
|
1195
|
+
Model::Expressions::BinaryExpression::AND
|
1227
1196
|
elsif ctx.text == '||'
|
1228
|
-
Model::
|
1197
|
+
Model::Expressions::BinaryExpression::COMBINE
|
1229
1198
|
else
|
1230
1199
|
raise 'Invalid state'
|
1231
1200
|
end
|
@@ -1272,12 +1241,12 @@ module Expressir
|
|
1272
1241
|
end
|
1273
1242
|
|
1274
1243
|
def visitOneOf(ctx)
|
1275
|
-
|
1276
|
-
|
1244
|
+
ref = Model::Expressions::SimpleReference.new({ id: 'ONEOF' })
|
1245
|
+
parameters = ctx.supertypeExpression().map{|ctx| visit(ctx)}
|
1277
1246
|
|
1278
|
-
Model::Expressions::
|
1279
|
-
|
1280
|
-
|
1247
|
+
Model::Expressions::Call.new({
|
1248
|
+
ref: ref,
|
1249
|
+
parameters: parameters
|
1281
1250
|
})
|
1282
1251
|
end
|
1283
1252
|
|
@@ -1313,14 +1282,14 @@ module Expressir
|
|
1313
1282
|
if ctx.literal()
|
1314
1283
|
visit(ctx.literal())
|
1315
1284
|
elsif ctx.qualifiableFactor()
|
1316
|
-
visit(ctx.qualifiableFactor())
|
1285
|
+
handleQualifiedRef(visit(ctx.qualifiableFactor()), ctx.qualifier())
|
1317
1286
|
else
|
1318
1287
|
raise 'Invalid state'
|
1319
1288
|
end
|
1320
1289
|
end
|
1321
1290
|
|
1322
1291
|
def visitProcedureCallStmt(ctx)
|
1323
|
-
|
1292
|
+
ref = if ctx.builtInProcedure()
|
1324
1293
|
visit(ctx.builtInProcedure())
|
1325
1294
|
elsif ctx.procedureRef()
|
1326
1295
|
visit(ctx.procedureRef())
|
@@ -1331,8 +1300,8 @@ module Expressir
|
|
1331
1300
|
ctx.actualParameterList().parameter().map{|ctx| visit(ctx.expression)}
|
1332
1301
|
end
|
1333
1302
|
|
1334
|
-
Model::Statements::
|
1335
|
-
|
1303
|
+
Model::Statements::Call.new({
|
1304
|
+
ref: ref,
|
1336
1305
|
parameters: parameters
|
1337
1306
|
})
|
1338
1307
|
end
|
@@ -1346,9 +1315,9 @@ module Expressir
|
|
1346
1315
|
if var.text == 'VAR'
|
1347
1316
|
parameters.map do |parameter|
|
1348
1317
|
Model::Parameter.new({
|
1318
|
+
var: true,
|
1349
1319
|
id: parameter.id,
|
1350
|
-
type: parameter.type
|
1351
|
-
var: true
|
1320
|
+
type: parameter.type
|
1352
1321
|
})
|
1353
1322
|
end
|
1354
1323
|
else
|
@@ -1359,7 +1328,7 @@ module Expressir
|
|
1359
1328
|
constants = if ctx.algorithmHead().constantDecl()
|
1360
1329
|
ctx.algorithmHead().constantDecl().constantBody().map{|ctx| visit(ctx)}
|
1361
1330
|
end
|
1362
|
-
|
1331
|
+
variables = if ctx.algorithmHead().localDecl()
|
1363
1332
|
ctx.algorithmHead().localDecl().localVariable().map{|ctx| visit(ctx)}.flatten
|
1364
1333
|
end
|
1365
1334
|
statements = ctx.stmt().map{|ctx| visit(ctx)}
|
@@ -1369,7 +1338,7 @@ module Expressir
|
|
1369
1338
|
parameters: parameters,
|
1370
1339
|
declarations: declarations,
|
1371
1340
|
constants: constants,
|
1372
|
-
|
1341
|
+
variables: variables,
|
1373
1342
|
statements: statements
|
1374
1343
|
})
|
1375
1344
|
end
|
@@ -1400,18 +1369,17 @@ module Expressir
|
|
1400
1369
|
|
1401
1370
|
def visitQualifiedAttribute(ctx)
|
1402
1371
|
id = ctx.SELF().text
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
qualifiers: qualifiers
|
1372
|
+
entity = visit(ctx.groupQualifier().entityRef())
|
1373
|
+
attribute = visit(ctx.attributeQualifier().attributeRef())
|
1374
|
+
|
1375
|
+
Model::Expressions::AttributeReference.new({
|
1376
|
+
ref: Model::Expressions::GroupReference.new({
|
1377
|
+
ref: Model::Expressions::SimpleReference.new({
|
1378
|
+
id: id
|
1379
|
+
}),
|
1380
|
+
entity: entity
|
1381
|
+
}),
|
1382
|
+
attribute: attribute
|
1415
1383
|
})
|
1416
1384
|
end
|
1417
1385
|
|
@@ -1432,7 +1400,7 @@ module Expressir
|
|
1432
1400
|
source = visit(ctx.aggregateSource().simpleExpression())
|
1433
1401
|
expression = visit(ctx.logicalExpression().expression())
|
1434
1402
|
|
1435
|
-
Model::Expressions::
|
1403
|
+
Model::Expressions::QueryExpression.new({
|
1436
1404
|
id: id,
|
1437
1405
|
source: source,
|
1438
1406
|
expression: expression
|
@@ -1467,7 +1435,8 @@ module Expressir
|
|
1467
1435
|
schema = visit(ctx.schemaRef())
|
1468
1436
|
items = ctx.resourceOrRename().map{|ctx| visit(ctx)}
|
1469
1437
|
|
1470
|
-
Model::
|
1438
|
+
Model::Interface.new({
|
1439
|
+
kind: Model::Interface::REFERENCE,
|
1471
1440
|
schema: schema,
|
1472
1441
|
items: items
|
1473
1442
|
})
|
@@ -1475,21 +1444,21 @@ module Expressir
|
|
1475
1444
|
|
1476
1445
|
def visitRelOp(ctx)
|
1477
1446
|
if ctx.text == '<'
|
1478
|
-
Model::
|
1447
|
+
Model::Expressions::BinaryExpression::LESS_THAN
|
1479
1448
|
elsif ctx.text == '>'
|
1480
|
-
Model::
|
1449
|
+
Model::Expressions::BinaryExpression::GREATER_THAN
|
1481
1450
|
elsif ctx.text == '<='
|
1482
|
-
Model::
|
1451
|
+
Model::Expressions::BinaryExpression::LESS_THAN_OR_EQUAL
|
1483
1452
|
elsif ctx.text == '>='
|
1484
|
-
Model::
|
1453
|
+
Model::Expressions::BinaryExpression::GREATER_THAN_OR_EQUAL
|
1485
1454
|
elsif ctx.text == '<>'
|
1486
|
-
Model::
|
1455
|
+
Model::Expressions::BinaryExpression::NOT_EQUAL
|
1487
1456
|
elsif ctx.text == '='
|
1488
|
-
Model::
|
1457
|
+
Model::Expressions::BinaryExpression::EQUAL
|
1489
1458
|
elsif ctx.text == ':<>:'
|
1490
|
-
Model::
|
1459
|
+
Model::Expressions::BinaryExpression::INSTANCE_NOT_EQUAL
|
1491
1460
|
elsif ctx.text == ':=:'
|
1492
|
-
Model::
|
1461
|
+
Model::Expressions::BinaryExpression::INSTANCE_EQUAL
|
1493
1462
|
else
|
1494
1463
|
raise 'Invalid state'
|
1495
1464
|
end
|
@@ -1499,9 +1468,9 @@ module Expressir
|
|
1499
1468
|
if ctx.relOp()
|
1500
1469
|
visit(ctx.relOp())
|
1501
1470
|
elsif ctx.IN()
|
1502
|
-
Model::
|
1471
|
+
Model::Expressions::BinaryExpression::IN
|
1503
1472
|
elsif ctx.LIKE()
|
1504
|
-
Model::
|
1473
|
+
Model::Expressions::BinaryExpression::LIKE
|
1505
1474
|
else
|
1506
1475
|
raise 'Invalid state'
|
1507
1476
|
end
|
@@ -1531,11 +1500,11 @@ module Expressir
|
|
1531
1500
|
id = if ctx.repeatControl().incrementControl()
|
1532
1501
|
visit(ctx.repeatControl().incrementControl().variableId())
|
1533
1502
|
end
|
1534
|
-
bound1
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
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())
|
1539
1508
|
end
|
1540
1509
|
increment = if ctx.repeatControl().incrementControl() && ctx.repeatControl().incrementControl().increment()
|
1541
1510
|
visit(ctx.repeatControl().incrementControl().increment().numericExpression().simpleExpression())
|
@@ -1594,7 +1563,9 @@ module Expressir
|
|
1594
1563
|
end
|
1595
1564
|
|
1596
1565
|
def visitReturnStmt(ctx)
|
1597
|
-
expression =
|
1566
|
+
expression = if ctx.expression()
|
1567
|
+
visit(ctx.expression())
|
1568
|
+
end
|
1598
1569
|
|
1599
1570
|
Model::Statements::Return.new({
|
1600
1571
|
expression: expression
|
@@ -1608,20 +1579,20 @@ module Expressir
|
|
1608
1579
|
constants = if ctx.algorithmHead().constantDecl()
|
1609
1580
|
ctx.algorithmHead().constantDecl().constantBody().map{|ctx| visit(ctx)}
|
1610
1581
|
end
|
1611
|
-
|
1582
|
+
variables = if ctx.algorithmHead().localDecl()
|
1612
1583
|
ctx.algorithmHead().localDecl().localVariable().map{|ctx| visit(ctx)}.flatten
|
1613
1584
|
end
|
1614
|
-
where = ctx.whereClause().domainRule().map{|ctx| visit(ctx)}
|
1615
1585
|
statements = ctx.stmt().map{|ctx| visit(ctx)}
|
1586
|
+
where = ctx.whereClause().domainRule().map{|ctx| visit(ctx)}
|
1616
1587
|
|
1617
1588
|
Model::Rule.new({
|
1618
1589
|
id: id,
|
1619
1590
|
applies_to: applies_to,
|
1620
1591
|
declarations: declarations,
|
1621
1592
|
constants: constants,
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1593
|
+
variables: variables,
|
1594
|
+
statements: statements,
|
1595
|
+
where: where
|
1625
1596
|
})
|
1626
1597
|
end
|
1627
1598
|
|
@@ -1650,16 +1621,17 @@ module Expressir
|
|
1650
1621
|
constants = if ctx.schemaBody().constantDecl()
|
1651
1622
|
ctx.schemaBody().constantDecl().constantBody().map{|ctx| visit(ctx)}
|
1652
1623
|
end
|
1653
|
-
declarations =
|
1654
|
-
|
1624
|
+
declarations = [
|
1625
|
+
*ctx.schemaBody().declaration().map{|ctx| visit(ctx)},
|
1626
|
+
*ctx.schemaBody().ruleDecl().map{|ctx| visit(ctx)}
|
1627
|
+
]
|
1655
1628
|
|
1656
1629
|
Model::Schema.new({
|
1657
1630
|
id: id,
|
1658
1631
|
version: version,
|
1659
1632
|
interfaces: interfaces,
|
1660
1633
|
constants: constants,
|
1661
|
-
declarations: declarations
|
1662
|
-
rules: rules
|
1634
|
+
declarations: declarations
|
1663
1635
|
})
|
1664
1636
|
end
|
1665
1637
|
|
@@ -1706,11 +1678,11 @@ module Expressir
|
|
1706
1678
|
end
|
1707
1679
|
|
1708
1680
|
def visitSetType(ctx)
|
1709
|
-
bound1
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
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())
|
1714
1686
|
end
|
1715
1687
|
base_type = visit(ctx.instantiableType())
|
1716
1688
|
|
@@ -1751,17 +1723,17 @@ module Expressir
|
|
1751
1723
|
operator = visit(ctx.unaryOp())
|
1752
1724
|
operand = visit(ctx.expression())
|
1753
1725
|
|
1754
|
-
Model::Expressions::
|
1726
|
+
Model::Expressions::UnaryExpression.new({
|
1755
1727
|
operator: operator,
|
1756
|
-
|
1728
|
+
operand: operand
|
1757
1729
|
})
|
1758
1730
|
elsif ctx.unaryOp() && ctx.primary()
|
1759
1731
|
operator = visit(ctx.unaryOp())
|
1760
1732
|
operand = visit(ctx.primary())
|
1761
1733
|
|
1762
|
-
Model::Expressions::
|
1734
|
+
Model::Expressions::UnaryExpression.new({
|
1763
1735
|
operator: operator,
|
1764
|
-
|
1736
|
+
operand: operand
|
1765
1737
|
})
|
1766
1738
|
else
|
1767
1739
|
raise 'Invalid state'
|
@@ -1859,20 +1831,20 @@ module Expressir
|
|
1859
1831
|
def visitSubtypeConstraintDecl(ctx)
|
1860
1832
|
id = visit(ctx.subtypeConstraintHead().subtypeConstraintId())
|
1861
1833
|
applies_to = visit(ctx.subtypeConstraintHead().entityRef())
|
1862
|
-
|
1834
|
+
abstract = !!ctx.subtypeConstraintBody().abstractSupertype()
|
1863
1835
|
total_over = if ctx.subtypeConstraintBody().totalOver()
|
1864
1836
|
ctx.subtypeConstraintBody().totalOver().entityRef().map{|ctx| visit(ctx)}
|
1865
1837
|
end
|
1866
|
-
|
1838
|
+
supertype_expression = if ctx.subtypeConstraintBody().supertypeExpression()
|
1867
1839
|
visit(ctx.subtypeConstraintBody().supertypeExpression())
|
1868
1840
|
end
|
1869
1841
|
|
1870
1842
|
Model::SubtypeConstraint.new({
|
1871
1843
|
id: id,
|
1872
1844
|
applies_to: applies_to,
|
1873
|
-
|
1845
|
+
abstract: abstract,
|
1874
1846
|
total_over: total_over,
|
1875
|
-
|
1847
|
+
supertype_expression: supertype_expression
|
1876
1848
|
})
|
1877
1849
|
end
|
1878
1850
|
|
@@ -1895,7 +1867,7 @@ module Expressir
|
|
1895
1867
|
def visitSupertypeExpression(ctx)
|
1896
1868
|
if ctx.supertypeFactor().length >= 2
|
1897
1869
|
operands = ctx.supertypeFactor().map{|ctx| visit(ctx)}
|
1898
|
-
operators = ctx.ANDOR().map{|ctx| Model::
|
1870
|
+
operators = ctx.ANDOR().map{|ctx| Model::Expressions::BinaryExpression::ANDOR}
|
1899
1871
|
|
1900
1872
|
handleBinaryExpression(operands, operators)
|
1901
1873
|
else
|
@@ -1906,7 +1878,7 @@ module Expressir
|
|
1906
1878
|
def visitSupertypeFactor(ctx)
|
1907
1879
|
if ctx.supertypeTerm().length >= 2
|
1908
1880
|
operands = ctx.supertypeTerm().map{|ctx| visit(ctx)}
|
1909
|
-
operators = ctx.AND().map{|ctx| Model::
|
1881
|
+
operators = ctx.AND().map{|ctx| Model::Expressions::BinaryExpression::AND}
|
1910
1882
|
|
1911
1883
|
handleBinaryExpression(operands, operators)
|
1912
1884
|
else
|
@@ -1987,11 +1959,11 @@ module Expressir
|
|
1987
1959
|
|
1988
1960
|
def visitUnaryOp(ctx)
|
1989
1961
|
if ctx.text == '+'
|
1990
|
-
Model::
|
1962
|
+
Model::Expressions::UnaryExpression::PLUS
|
1991
1963
|
elsif ctx.text == '-'
|
1992
|
-
Model::
|
1964
|
+
Model::Expressions::UnaryExpression::MINUS
|
1993
1965
|
elsif ctx.NOT()
|
1994
|
-
Model::
|
1966
|
+
Model::Expressions::UnaryExpression::NOT
|
1995
1967
|
else
|
1996
1968
|
raise 'Invalid state'
|
1997
1969
|
end
|
@@ -2031,7 +2003,8 @@ module Expressir
|
|
2031
2003
|
schema = visit(ctx.schemaRef())
|
2032
2004
|
items = ctx.namedTypeOrRename().map{|ctx| visit(ctx)}
|
2033
2005
|
|
2034
|
-
Model::
|
2006
|
+
Model::Interface.new({
|
2007
|
+
kind: Model::Interface::USE,
|
2035
2008
|
schema: schema,
|
2036
2009
|
items: items
|
2037
2010
|
})
|
@@ -2072,19 +2045,54 @@ module Expressir
|
|
2072
2045
|
raise 'Invalid state'
|
2073
2046
|
end
|
2074
2047
|
|
2075
|
-
expression = Model::Expressions::
|
2048
|
+
expression = Model::Expressions::BinaryExpression.new({
|
2076
2049
|
operator: operators[0],
|
2077
|
-
|
2050
|
+
operand1: operands[0],
|
2051
|
+
operand2: operands[1]
|
2078
2052
|
})
|
2079
2053
|
operators[1..(operators.length - 1)].each_with_index do |operator, i|
|
2080
|
-
expression = Model::Expressions::
|
2054
|
+
expression = Model::Expressions::BinaryExpression.new({
|
2081
2055
|
operator: operator,
|
2082
|
-
|
2056
|
+
operand1: expression,
|
2057
|
+
operand2: operands[i + 2]
|
2083
2058
|
})
|
2084
2059
|
end
|
2085
2060
|
expression
|
2086
2061
|
end
|
2087
2062
|
|
2063
|
+
def handleQualifiedRef(ref, qualifiers)
|
2064
|
+
qualifiers.reduce(ref) do |ref, ctx|
|
2065
|
+
if ctx.attributeQualifier()
|
2066
|
+
attribute = visit(ctx.attributeQualifier().attributeRef())
|
2067
|
+
|
2068
|
+
Model::Expressions::AttributeReference.new({
|
2069
|
+
ref: ref,
|
2070
|
+
attribute: attribute
|
2071
|
+
})
|
2072
|
+
elsif ctx.groupQualifier()
|
2073
|
+
entity = visit(ctx.groupQualifier().entityRef())
|
2074
|
+
|
2075
|
+
Model::Expressions::GroupReference.new({
|
2076
|
+
ref: ref,
|
2077
|
+
entity: entity
|
2078
|
+
})
|
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
|
2084
|
+
|
2085
|
+
Model::Expressions::IndexReference.new({
|
2086
|
+
ref: ref,
|
2087
|
+
index1: index1,
|
2088
|
+
index2: index2
|
2089
|
+
})
|
2090
|
+
else
|
2091
|
+
raise 'Invalid state'
|
2092
|
+
end
|
2093
|
+
end
|
2094
|
+
end
|
2095
|
+
|
2088
2096
|
def handleBinaryLiteral(ctx)
|
2089
2097
|
value = ctx.text[1..(ctx.text.length - 1)]
|
2090
2098
|
|