expressir 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -3,7 +3,7 @@ require "expressir/model"
|
|
3
3
|
module Expressir
|
4
4
|
module Express
|
5
5
|
class Formatter
|
6
|
-
INDENT_CHAR = " "
|
6
|
+
INDENT_CHAR = " ".freeze
|
7
7
|
INDENT_WIDTH = 2
|
8
8
|
INDENT = INDENT_CHAR * INDENT_WIDTH
|
9
9
|
OPERATOR_PRECEDENCE = {
|
@@ -28,11 +28,11 @@ module Expressir
|
|
28
28
|
Model::Expressions::BinaryExpression::INSTANCE_NOT_EQUAL => 4,
|
29
29
|
Model::Expressions::BinaryExpression::IN => 4,
|
30
30
|
Model::Expressions::BinaryExpression::LIKE => 4,
|
31
|
-
}
|
31
|
+
}.freeze
|
32
32
|
SUPERTYPE_OPERATOR_PRECEDENCE = {
|
33
33
|
Model::SupertypeExpressions::BinarySupertypeExpression::AND => 1,
|
34
34
|
Model::SupertypeExpressions::BinarySupertypeExpression::ANDOR => 2,
|
35
|
-
}
|
35
|
+
}.freeze
|
36
36
|
|
37
37
|
private_constant :INDENT_CHAR
|
38
38
|
private_constant :INDENT_WIDTH
|
@@ -44,7 +44,7 @@ module Expressir
|
|
44
44
|
# @param [Model::ModelElement] node
|
45
45
|
# @return [String]
|
46
46
|
def self.format(node)
|
47
|
-
formatter =
|
47
|
+
formatter = new
|
48
48
|
formatter.format(node)
|
49
49
|
end
|
50
50
|
|
@@ -52,138 +52,139 @@ module Expressir
|
|
52
52
|
# @param [Model::ModelElement] node
|
53
53
|
# @return [String]
|
54
54
|
def format(node)
|
55
|
-
|
55
|
+
case node
|
56
|
+
when Model::Repository
|
56
57
|
format_repository(node)
|
57
|
-
|
58
|
+
when Model::Declarations::Attribute
|
58
59
|
format_declarations_attribute(node)
|
59
|
-
|
60
|
+
when Model::Declarations::Constant
|
60
61
|
format_declarations_constant(node)
|
61
|
-
|
62
|
+
when Model::Declarations::Entity
|
62
63
|
format_declarations_entity(node)
|
63
|
-
|
64
|
+
when Model::Declarations::Function
|
64
65
|
format_declarations_function(node)
|
65
|
-
|
66
|
+
when Model::Declarations::Interface
|
66
67
|
format_declarations_interface(node)
|
67
|
-
|
68
|
+
when Model::Declarations::InterfaceItem
|
68
69
|
format_declarations_interface_item(node)
|
69
|
-
|
70
|
+
when Model::Declarations::Parameter
|
70
71
|
format_declarations_parameter(node)
|
71
|
-
|
72
|
+
when Model::Declarations::Procedure
|
72
73
|
format_declarations_procedure(node)
|
73
|
-
|
74
|
+
when Model::Declarations::Rule
|
74
75
|
format_declarations_rule(node)
|
75
|
-
|
76
|
+
when Model::Declarations::Schema
|
76
77
|
format_declarations_schema(node)
|
77
|
-
|
78
|
+
when Model::Declarations::SchemaVersion
|
78
79
|
format_declarations_schema_version(node)
|
79
|
-
|
80
|
+
when Model::Declarations::SubtypeConstraint
|
80
81
|
format_declarations_subtype_constraint(node)
|
81
|
-
|
82
|
+
when Model::Declarations::Type
|
82
83
|
format_declarations_type(node)
|
83
|
-
|
84
|
+
when Model::Declarations::UniqueRule
|
84
85
|
format_declarations_unique_rule(node)
|
85
|
-
|
86
|
+
when Model::Declarations::Variable
|
86
87
|
format_declarations_variable(node)
|
87
|
-
|
88
|
+
when Model::Declarations::WhereRule
|
88
89
|
format_declarations_where_rule(node)
|
89
|
-
|
90
|
+
when Model::DataTypes::Aggregate
|
90
91
|
format_data_types_aggregate(node)
|
91
|
-
|
92
|
+
when Model::DataTypes::Array
|
92
93
|
format_data_types_array(node)
|
93
|
-
|
94
|
+
when Model::DataTypes::Bag
|
94
95
|
format_data_types_bag(node)
|
95
|
-
|
96
|
+
when Model::DataTypes::Binary
|
96
97
|
format_data_types_binary(node)
|
97
|
-
|
98
|
+
when Model::DataTypes::Boolean
|
98
99
|
format_data_types_boolean(node)
|
99
|
-
|
100
|
+
when Model::DataTypes::Enumeration
|
100
101
|
format_data_types_enumeration(node)
|
101
|
-
|
102
|
+
when Model::DataTypes::EnumerationItem
|
102
103
|
format_data_types_enumeration_item(node)
|
103
|
-
|
104
|
+
when Model::DataTypes::GenericEntity
|
104
105
|
format_data_types_generic_entity(node)
|
105
|
-
|
106
|
+
when Model::DataTypes::Generic
|
106
107
|
format_data_types_generic(node)
|
107
|
-
|
108
|
+
when Model::DataTypes::Integer
|
108
109
|
format_data_types_integer(node)
|
109
|
-
|
110
|
+
when Model::DataTypes::List
|
110
111
|
format_data_types_list(node)
|
111
|
-
|
112
|
+
when Model::DataTypes::Logical
|
112
113
|
format_data_types_logical(node)
|
113
|
-
|
114
|
+
when Model::DataTypes::Number
|
114
115
|
format_data_types_number(node)
|
115
|
-
|
116
|
+
when Model::DataTypes::Real
|
116
117
|
format_data_types_real(node)
|
117
|
-
|
118
|
+
when Model::DataTypes::Select
|
118
119
|
format_data_types_select(node)
|
119
|
-
|
120
|
+
when Model::DataTypes::Set
|
120
121
|
format_data_types_set(node)
|
121
|
-
|
122
|
+
when Model::DataTypes::String
|
122
123
|
format_data_types_string(node)
|
123
|
-
|
124
|
+
when Model::Expressions::AggregateInitializer
|
124
125
|
format_expressions_aggregate_initializer(node)
|
125
|
-
|
126
|
+
when Model::Expressions::AggregateInitializerItem
|
126
127
|
format_expressions_aggregate_initializer_item(node)
|
127
|
-
|
128
|
+
when Model::Expressions::BinaryExpression
|
128
129
|
format_expressions_binary_expression(node)
|
129
|
-
|
130
|
+
when Model::Expressions::EntityConstructor
|
130
131
|
format_expressions_entity_constructor(node)
|
131
|
-
|
132
|
+
when Model::Expressions::FunctionCall
|
132
133
|
format_expressions_function_call(node)
|
133
|
-
|
134
|
+
when Model::Expressions::Interval
|
134
135
|
format_expressions_interval(node)
|
135
|
-
|
136
|
+
when Model::Expressions::QueryExpression
|
136
137
|
format_expressions_query_expression(node)
|
137
|
-
|
138
|
+
when Model::Expressions::UnaryExpression
|
138
139
|
format_expressions_unary_expression(node)
|
139
|
-
|
140
|
+
when Model::Literals::Binary
|
140
141
|
format_literals_binary(node)
|
141
|
-
|
142
|
+
when Model::Literals::Integer
|
142
143
|
format_literals_integer(node)
|
143
|
-
|
144
|
+
when Model::Literals::Logical
|
144
145
|
format_literals_logical(node)
|
145
|
-
|
146
|
+
when Model::Literals::Real
|
146
147
|
format_literals_real(node)
|
147
|
-
|
148
|
+
when Model::Literals::String
|
148
149
|
format_literals_string(node)
|
149
|
-
|
150
|
+
when Model::References::AttributeReference
|
150
151
|
format_references_attribute_reference(node)
|
151
|
-
|
152
|
+
when Model::References::GroupReference
|
152
153
|
format_references_group_reference(node)
|
153
|
-
|
154
|
+
when Model::References::IndexReference
|
154
155
|
format_references_index_reference(node)
|
155
|
-
|
156
|
+
when Model::References::SimpleReference
|
156
157
|
format_references_simple_reference(node)
|
157
|
-
|
158
|
+
when Model::Statements::Alias
|
158
159
|
format_statements_alias(node)
|
159
|
-
|
160
|
+
when Model::Statements::Assignment
|
160
161
|
format_statements_assignment(node)
|
161
|
-
|
162
|
+
when Model::Statements::Case
|
162
163
|
format_statements_case(node)
|
163
|
-
|
164
|
+
when Model::Statements::CaseAction
|
164
165
|
format_statements_case_action(node)
|
165
|
-
|
166
|
+
when Model::Statements::Compound
|
166
167
|
format_statements_compound(node)
|
167
|
-
|
168
|
+
when Model::Statements::Escape
|
168
169
|
format_statements_escape(node)
|
169
|
-
|
170
|
+
when Model::Statements::If
|
170
171
|
format_statements_if(node)
|
171
|
-
|
172
|
+
when Model::Statements::Null
|
172
173
|
format_statements_null(node)
|
173
|
-
|
174
|
+
when Model::Statements::ProcedureCall
|
174
175
|
format_statements_procedure_call(node)
|
175
|
-
|
176
|
+
when Model::Statements::Repeat
|
176
177
|
format_statements_repeat(node)
|
177
|
-
|
178
|
+
when Model::Statements::Return
|
178
179
|
format_statements_return(node)
|
179
|
-
|
180
|
+
when Model::Statements::Skip
|
180
181
|
format_statements_skip(node)
|
181
|
-
|
182
|
+
when Model::SupertypeExpressions::BinarySupertypeExpression
|
182
183
|
format_supertype_expressions_binary_supertype_expression(node)
|
183
|
-
|
184
|
+
when Model::SupertypeExpressions::OneofSupertypeExpression
|
184
185
|
format_supertype_expressions_oneof_supertype_expression(node)
|
185
186
|
else
|
186
|
-
|
187
|
+
warn "#{node.class.name} format not implemented"
|
187
188
|
""
|
188
189
|
end
|
189
190
|
end
|
@@ -197,47 +198,47 @@ module Expressir
|
|
197
198
|
def format_declarations_attribute(node)
|
198
199
|
[
|
199
200
|
*if node.supertype_attribute
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
*if node.supertype_attribute
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
201
|
+
[
|
202
|
+
format(node.supertype_attribute),
|
203
|
+
" ",
|
204
|
+
].join("")
|
205
|
+
end,
|
206
|
+
*if node.supertype_attribute && node.id
|
207
|
+
[
|
208
|
+
"RENAMED",
|
209
|
+
" ",
|
210
|
+
].join("")
|
211
|
+
end,
|
211
212
|
*if node.id
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
213
|
+
[
|
214
|
+
node.id,
|
215
|
+
" ",
|
216
|
+
].join("")
|
217
|
+
end,
|
217
218
|
":",
|
218
219
|
*if node.optional
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
220
|
+
[
|
221
|
+
" ",
|
222
|
+
"OPTIONAL",
|
223
|
+
].join("")
|
224
|
+
end,
|
224
225
|
" ",
|
225
226
|
format(node.type),
|
226
227
|
*if node.kind == Model::Declarations::Attribute::DERIVED
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
228
|
+
[
|
229
|
+
" ",
|
230
|
+
":=",
|
231
|
+
" ",
|
232
|
+
format(node.expression),
|
233
|
+
].join("")
|
234
|
+
elsif node.kind == Model::Declarations::Attribute::INVERSE
|
235
|
+
[
|
236
|
+
" ",
|
237
|
+
"FOR",
|
238
|
+
" ",
|
239
|
+
format(node.expression),
|
240
|
+
].join("")
|
241
|
+
end,
|
241
242
|
";",
|
242
243
|
].join("")
|
243
244
|
end
|
@@ -267,89 +268,89 @@ module Expressir
|
|
267
268
|
"ENTITY",
|
268
269
|
" ",
|
269
270
|
node.id,
|
270
|
-
*if node.abstract
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
*if node.abstract
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
*if !node.abstract
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
*if node.subtype_of.length
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
271
|
+
*if node.abstract && !node.supertype_expression
|
272
|
+
[
|
273
|
+
"\n",
|
274
|
+
indent([
|
275
|
+
"ABSTRACT",
|
276
|
+
" ",
|
277
|
+
"SUPERTYPE",
|
278
|
+
].join("")),
|
279
|
+
].join("")
|
280
|
+
end,
|
281
|
+
*if node.abstract && node.supertype_expression
|
282
|
+
[
|
283
|
+
"\n",
|
284
|
+
indent([
|
285
|
+
"ABSTRACT",
|
286
|
+
" ",
|
287
|
+
"SUPERTYPE",
|
288
|
+
" ",
|
289
|
+
"OF",
|
290
|
+
" ",
|
291
|
+
"(",
|
292
|
+
format(node.supertype_expression),
|
293
|
+
")",
|
294
|
+
].join("")),
|
295
|
+
].join("")
|
296
|
+
end,
|
297
|
+
*if !node.abstract && node.supertype_expression
|
298
|
+
[
|
299
|
+
"\n",
|
300
|
+
indent([
|
301
|
+
"SUPERTYPE",
|
302
|
+
" ",
|
303
|
+
"OF",
|
304
|
+
" ",
|
305
|
+
"(",
|
306
|
+
format(node.supertype_expression),
|
307
|
+
")",
|
308
|
+
].join("")),
|
309
|
+
].join("")
|
310
|
+
end,
|
311
|
+
*if node.subtype_of.length.positive?
|
312
|
+
[
|
313
|
+
"\n",
|
314
|
+
indent([
|
315
|
+
"SUBTYPE",
|
316
|
+
" ",
|
317
|
+
"OF",
|
318
|
+
" ",
|
319
|
+
"(",
|
320
|
+
node.subtype_of.map { |x| format(x) }.join(", "),
|
321
|
+
")",
|
322
|
+
].join("")),
|
323
|
+
].join("")
|
324
|
+
end,
|
324
325
|
";",
|
325
326
|
].join(""),
|
326
|
-
*if explicit_attributes
|
327
|
-
|
328
|
-
|
329
|
-
*if derived_attributes
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
*if inverse_attributes
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
*if node.unique_rules.length
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
*if node.where_rules.length
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
327
|
+
*if explicit_attributes&.length&.positive?
|
328
|
+
indent(explicit_attributes.map { |x| format(x) }.join("\n"))
|
329
|
+
end,
|
330
|
+
*if derived_attributes&.length&.positive?
|
331
|
+
[
|
332
|
+
"DERIVE",
|
333
|
+
indent(derived_attributes.map { |x| format(x) }.join("\n")),
|
334
|
+
]
|
335
|
+
end,
|
336
|
+
*if inverse_attributes&.length&.positive?
|
337
|
+
[
|
338
|
+
"INVERSE",
|
339
|
+
indent(inverse_attributes.map { |x| format(x) }.join("\n")),
|
340
|
+
]
|
341
|
+
end,
|
342
|
+
*if node.unique_rules.length.positive?
|
343
|
+
[
|
344
|
+
"UNIQUE",
|
345
|
+
indent(node.unique_rules.map { |x| format(x) }.join("\n")),
|
346
|
+
]
|
347
|
+
end,
|
348
|
+
*if node.where_rules.length.positive?
|
349
|
+
[
|
350
|
+
"WHERE",
|
351
|
+
indent(node.where_rules.map { |x| format(x) }.join("\n")),
|
352
|
+
]
|
353
|
+
end,
|
353
354
|
[
|
354
355
|
"END_ENTITY",
|
355
356
|
";",
|
@@ -363,58 +364,58 @@ module Expressir
|
|
363
364
|
"FUNCTION",
|
364
365
|
" ",
|
365
366
|
node.id,
|
366
|
-
*if node.parameters.length
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
367
|
+
*if node.parameters.length.positive?
|
368
|
+
parameter_indent = INDENT_CHAR * "FUNCTION #{node.id}(".length
|
369
|
+
[
|
370
|
+
"(",
|
371
|
+
node.parameters.map { |x| format(x) }.join(";\n#{parameter_indent}"),
|
372
|
+
")",
|
373
|
+
].join("")
|
374
|
+
end,
|
374
375
|
" ",
|
375
376
|
":",
|
376
377
|
" ",
|
377
378
|
format(node.return_type),
|
378
379
|
";",
|
379
380
|
].join(""),
|
380
|
-
*if node.types.length
|
381
|
-
|
382
|
-
|
383
|
-
*if node.entities.length
|
384
|
-
|
385
|
-
|
386
|
-
*if node.subtype_constraints.length
|
387
|
-
|
388
|
-
|
389
|
-
*if node.functions.length
|
390
|
-
|
391
|
-
|
392
|
-
*if node.procedures.length
|
393
|
-
|
394
|
-
|
395
|
-
*if node.constants.length
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
*if node.variables.length
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
*if node.statements.length
|
416
|
-
|
417
|
-
|
381
|
+
*if node.types.length.positive?
|
382
|
+
indent(node.types.map { |x| format(x) }.join("\n"))
|
383
|
+
end,
|
384
|
+
*if node.entities.length.positive?
|
385
|
+
indent(node.entities.map { |x| format(x) }.join("\n"))
|
386
|
+
end,
|
387
|
+
*if node.subtype_constraints.length.positive?
|
388
|
+
indent(node.subtype_constraints.map { |x| format(x) }.join("\n"))
|
389
|
+
end,
|
390
|
+
*if node.functions.length.positive?
|
391
|
+
indent(node.functions.map { |x| format(x) }.join("\n"))
|
392
|
+
end,
|
393
|
+
*if node.procedures.length.positive?
|
394
|
+
indent(node.procedures.map { |x| format(x) }.join("\n"))
|
395
|
+
end,
|
396
|
+
*if node.constants.length.positive?
|
397
|
+
indent([
|
398
|
+
"CONSTANT",
|
399
|
+
indent(node.constants.map { |x| format(x) }.join("\n")),
|
400
|
+
[
|
401
|
+
"END_CONSTANT",
|
402
|
+
";",
|
403
|
+
].join(""),
|
404
|
+
].join("\n"))
|
405
|
+
end,
|
406
|
+
*if node.variables.length.positive?
|
407
|
+
indent([
|
408
|
+
"LOCAL",
|
409
|
+
indent(node.variables.map { |x| format(x) }.join("\n")),
|
410
|
+
[
|
411
|
+
"END_LOCAL",
|
412
|
+
";",
|
413
|
+
].join(""),
|
414
|
+
].join("\n"))
|
415
|
+
end,
|
416
|
+
*if node.statements.length.positive?
|
417
|
+
indent(node.statements.map { |x| format(x) }.join("\n"))
|
418
|
+
end,
|
418
419
|
[
|
419
420
|
"END_FUNCTION",
|
420
421
|
";",
|
@@ -432,17 +433,17 @@ module Expressir
|
|
432
433
|
"FROM",
|
433
434
|
" ",
|
434
435
|
format(node.schema),
|
435
|
-
*if node.items.length
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
436
|
+
*if node.items.length.positive?
|
437
|
+
item_indent = INDENT_CHAR * "(".length
|
438
|
+
[
|
439
|
+
"\n",
|
440
|
+
indent([
|
441
|
+
"(",
|
442
|
+
node.items.map { |x| format(x) }.join(",\n#{item_indent}"),
|
443
|
+
")",
|
444
|
+
].join("")),
|
445
|
+
].join("")
|
446
|
+
end,
|
446
447
|
";",
|
447
448
|
].join("")
|
448
449
|
end
|
@@ -451,24 +452,24 @@ module Expressir
|
|
451
452
|
[
|
452
453
|
format(node.ref),
|
453
454
|
*if node.id
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
455
|
+
[
|
456
|
+
" ",
|
457
|
+
"AS",
|
458
|
+
" ",
|
459
|
+
node.id,
|
460
|
+
]
|
461
|
+
end,
|
461
462
|
].join("")
|
462
463
|
end
|
463
464
|
|
464
465
|
def format_declarations_parameter(node)
|
465
466
|
[
|
466
467
|
*if node.var
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
468
|
+
[
|
469
|
+
"VAR",
|
470
|
+
" ",
|
471
|
+
].join("")
|
472
|
+
end,
|
472
473
|
node.id,
|
473
474
|
" ",
|
474
475
|
":",
|
@@ -483,54 +484,54 @@ module Expressir
|
|
483
484
|
"PROCEDURE",
|
484
485
|
" ",
|
485
486
|
node.id,
|
486
|
-
*if node.parameters.length
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
487
|
+
*if node.parameters.length.positive?
|
488
|
+
parameter_indent = INDENT_CHAR * "PROCEDURE #{node.id}(".length
|
489
|
+
[
|
490
|
+
"(",
|
491
|
+
node.parameters.map { |x| format(x) }.join(";\n#{parameter_indent}"),
|
492
|
+
")",
|
493
|
+
].join("")
|
494
|
+
end,
|
494
495
|
";",
|
495
496
|
].join(""),
|
496
|
-
*if node.types.length
|
497
|
-
|
498
|
-
|
499
|
-
*if node.entities.length
|
500
|
-
|
501
|
-
|
502
|
-
*if node.subtype_constraints.length
|
503
|
-
|
504
|
-
|
505
|
-
*if node.functions.length
|
506
|
-
|
507
|
-
|
508
|
-
*if node.procedures.length
|
509
|
-
|
510
|
-
|
511
|
-
*if node.constants.length
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
*if node.variables.length
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
*if node.statements.length
|
532
|
-
|
533
|
-
|
497
|
+
*if node.types.length.positive?
|
498
|
+
indent(node.types.map { |x| format(x) }.join("\n"))
|
499
|
+
end,
|
500
|
+
*if node.entities.length.positive?
|
501
|
+
indent(node.entities.map { |x| format(x) }.join("\n"))
|
502
|
+
end,
|
503
|
+
*if node.subtype_constraints.length.positive?
|
504
|
+
indent(node.subtype_constraints.map { |x| format(x) }.join("\n"))
|
505
|
+
end,
|
506
|
+
*if node.functions.length.positive?
|
507
|
+
indent(node.functions.map { |x| format(x) }.join("\n"))
|
508
|
+
end,
|
509
|
+
*if node.procedures.length.positive?
|
510
|
+
indent(node.procedures.map { |x| format(x) }.join("\n"))
|
511
|
+
end,
|
512
|
+
*if node.constants.length.positive?
|
513
|
+
indent([
|
514
|
+
"CONSTANT",
|
515
|
+
indent(node.constants.map { |x| format(x) }.join("\n")),
|
516
|
+
[
|
517
|
+
"END_CONSTANT",
|
518
|
+
";",
|
519
|
+
].join(""),
|
520
|
+
].join("\n"))
|
521
|
+
end,
|
522
|
+
*if node.variables.length.positive?
|
523
|
+
indent([
|
524
|
+
"LOCAL",
|
525
|
+
indent(node.variables.map { |x| format(x) }.join("\n")),
|
526
|
+
[
|
527
|
+
"END_LOCAL",
|
528
|
+
";",
|
529
|
+
].join(""),
|
530
|
+
].join("\n"))
|
531
|
+
end,
|
532
|
+
*if node.statements.length.positive?
|
533
|
+
indent(node.statements.map { |x| format(x) }.join("\n"))
|
534
|
+
end,
|
534
535
|
[
|
535
536
|
"END_PROCEDURE",
|
536
537
|
";",
|
@@ -552,50 +553,50 @@ module Expressir
|
|
552
553
|
")",
|
553
554
|
";",
|
554
555
|
].join(""),
|
555
|
-
*if node.types.length
|
556
|
-
|
557
|
-
|
558
|
-
*if node.entities.length
|
559
|
-
|
560
|
-
|
561
|
-
*if node.subtype_constraints.length
|
562
|
-
|
563
|
-
|
564
|
-
*if node.functions.length
|
565
|
-
|
566
|
-
|
567
|
-
*if node.procedures.length
|
568
|
-
|
569
|
-
|
570
|
-
*if node.constants.length
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
*if node.variables.length
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
*if node.statements.length
|
591
|
-
|
592
|
-
|
593
|
-
*if node.where_rules.length
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
556
|
+
*if node.types.length.positive?
|
557
|
+
indent(node.types.map { |x| format(x) }.join("\n"))
|
558
|
+
end,
|
559
|
+
*if node.entities.length.positive?
|
560
|
+
indent(node.entities.map { |x| format(x) }.join("\n"))
|
561
|
+
end,
|
562
|
+
*if node.subtype_constraints.length.positive?
|
563
|
+
indent(node.subtype_constraints.map { |x| format(x) }.join("\n"))
|
564
|
+
end,
|
565
|
+
*if node.functions.length.positive?
|
566
|
+
indent(node.functions.map { |x| format(x) }.join("\n"))
|
567
|
+
end,
|
568
|
+
*if node.procedures.length.positive?
|
569
|
+
indent(node.procedures.map { |x| format(x) }.join("\n"))
|
570
|
+
end,
|
571
|
+
*if node.constants.length.positive?
|
572
|
+
indent([
|
573
|
+
"CONSTANT",
|
574
|
+
indent(node.constants.map { |x| format(x) }.join("\n")),
|
575
|
+
[
|
576
|
+
"END_CONSTANT",
|
577
|
+
";",
|
578
|
+
].join(""),
|
579
|
+
].join("\n"))
|
580
|
+
end,
|
581
|
+
*if node.variables.length.positive?
|
582
|
+
indent([
|
583
|
+
"LOCAL",
|
584
|
+
indent(node.variables.map { |x| format(x) }.join("\n")),
|
585
|
+
[
|
586
|
+
"END_LOCAL",
|
587
|
+
";",
|
588
|
+
].join(""),
|
589
|
+
].join("\n"))
|
590
|
+
end,
|
591
|
+
*if node.statements.length.positive?
|
592
|
+
indent(node.statements.map { |x| format(x) }.join("\n"))
|
593
|
+
end,
|
594
|
+
*if node.where_rules.length.positive?
|
595
|
+
[
|
596
|
+
"WHERE",
|
597
|
+
indent(node.where_rules.map { |x| format(x) }.join("\n")),
|
598
|
+
]
|
599
|
+
end,
|
599
600
|
[
|
600
601
|
"END_RULE",
|
601
602
|
";",
|
@@ -610,63 +611,63 @@ module Expressir
|
|
610
611
|
" ",
|
611
612
|
node.id,
|
612
613
|
*if node.version
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
614
|
+
[
|
615
|
+
" ",
|
616
|
+
format(node.version),
|
617
|
+
].join("")
|
618
|
+
end,
|
618
619
|
";",
|
619
620
|
].join(""),
|
620
|
-
*if node.interfaces.length
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
621
|
+
*if node.interfaces.length.positive?
|
622
|
+
[
|
623
|
+
"",
|
624
|
+
node.interfaces.map { |x| format(x) }.join("\n"),
|
625
|
+
]
|
626
|
+
end,
|
626
627
|
].join("\n")
|
627
628
|
end
|
628
629
|
|
629
630
|
def format_declarations_schema(node)
|
630
631
|
schema_declarations = [
|
631
|
-
*if node.constants.length
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
*if node.types.length
|
642
|
-
|
643
|
-
|
644
|
-
*if node.entities.length
|
645
|
-
|
646
|
-
|
647
|
-
*if node.subtype_constraints.length
|
648
|
-
|
649
|
-
|
650
|
-
*if node.functions.length
|
651
|
-
|
652
|
-
|
653
|
-
*if node.rules.length
|
654
|
-
|
655
|
-
|
656
|
-
*if node.procedures
|
657
|
-
|
658
|
-
|
632
|
+
*if node.constants.length.positive?
|
633
|
+
[
|
634
|
+
"CONSTANT",
|
635
|
+
indent(node.constants.map { |x| format(x) }.join("\n")),
|
636
|
+
[
|
637
|
+
"END_CONSTANT",
|
638
|
+
";",
|
639
|
+
].join(""),
|
640
|
+
].join("\n")
|
641
|
+
end,
|
642
|
+
*if node.types.length.positive?
|
643
|
+
node.types.map { |x| format(x) }
|
644
|
+
end,
|
645
|
+
*if node.entities.length.positive?
|
646
|
+
node.entities.map { |x| format(x) }
|
647
|
+
end,
|
648
|
+
*if node.subtype_constraints.length.positive?
|
649
|
+
node.subtype_constraints.map { |x| format(x) }
|
650
|
+
end,
|
651
|
+
*if node.functions.length.positive?
|
652
|
+
node.functions.map { |x| format(x) }
|
653
|
+
end,
|
654
|
+
*if node.rules.length.positive?
|
655
|
+
node.rules.map { |x| format(x) }
|
656
|
+
end,
|
657
|
+
*if node.procedures&.length&.positive?
|
658
|
+
node.procedures.map { |x| format(x) }
|
659
|
+
end,
|
659
660
|
]
|
660
661
|
|
661
662
|
[
|
662
663
|
format_declarations_schema_head(node),
|
663
|
-
*if schema_declarations.length
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
664
|
+
*if schema_declarations.length.positive?
|
665
|
+
[
|
666
|
+
"",
|
667
|
+
schema_declarations.join("\n\n"),
|
668
|
+
"",
|
669
|
+
]
|
670
|
+
end,
|
670
671
|
[
|
671
672
|
"END_SCHEMA",
|
672
673
|
";",
|
@@ -696,28 +697,28 @@ module Expressir
|
|
696
697
|
";",
|
697
698
|
].join(""),
|
698
699
|
*if node.abstract
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
*if node.total_over.length
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
700
|
+
indent([
|
701
|
+
"ABSTRACT",
|
702
|
+
" ",
|
703
|
+
"SUPERTYPE",
|
704
|
+
";",
|
705
|
+
].join(""))
|
706
|
+
end,
|
707
|
+
*if node.total_over.length.positive?
|
708
|
+
indent([
|
709
|
+
"TOTAL_OVER",
|
710
|
+
"(",
|
711
|
+
node.total_over.map { |x| format(x) }.join(", "),
|
712
|
+
")",
|
713
|
+
";",
|
714
|
+
].join(""))
|
715
|
+
end,
|
715
716
|
*if node.supertype_expression
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
717
|
+
indent([
|
718
|
+
format(node.supertype_expression),
|
719
|
+
";",
|
720
|
+
].join(""))
|
721
|
+
end,
|
721
722
|
[
|
722
723
|
"END_SUBTYPE_CONSTRAINT",
|
723
724
|
";",
|
@@ -737,12 +738,12 @@ module Expressir
|
|
737
738
|
format(node.underlying_type),
|
738
739
|
";",
|
739
740
|
].join(""),
|
740
|
-
*if node.where_rules.length
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
741
|
+
*if node.where_rules.length.positive?
|
742
|
+
[
|
743
|
+
"WHERE",
|
744
|
+
indent(node.where_rules.map { |x| format(x) }.join("\n")),
|
745
|
+
]
|
746
|
+
end,
|
746
747
|
[
|
747
748
|
"END_TYPE",
|
748
749
|
";",
|
@@ -753,12 +754,12 @@ module Expressir
|
|
753
754
|
def format_declarations_unique_rule(node)
|
754
755
|
[
|
755
756
|
*if node.id
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
757
|
+
[
|
758
|
+
node.id,
|
759
|
+
":",
|
760
|
+
" ",
|
761
|
+
].join("")
|
762
|
+
end,
|
762
763
|
node.attributes.map { |x| format(x) }.join(", "),
|
763
764
|
";",
|
764
765
|
].join("")
|
@@ -772,13 +773,13 @@ module Expressir
|
|
772
773
|
" ",
|
773
774
|
format(node.type),
|
774
775
|
*if node.expression
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
776
|
+
[
|
777
|
+
" ",
|
778
|
+
":=",
|
779
|
+
" ",
|
780
|
+
format(node.expression),
|
781
|
+
].join("")
|
782
|
+
end,
|
782
783
|
";",
|
783
784
|
].join("")
|
784
785
|
end
|
@@ -786,12 +787,12 @@ module Expressir
|
|
786
787
|
def format_declarations_where_rule(node)
|
787
788
|
[
|
788
789
|
*if node.id
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
790
|
+
[
|
791
|
+
node.id,
|
792
|
+
":",
|
793
|
+
" ",
|
794
|
+
].join("")
|
795
|
+
end,
|
795
796
|
format(node.expression),
|
796
797
|
";",
|
797
798
|
].join("")
|
@@ -814,14 +815,19 @@ module Expressir
|
|
814
815
|
end
|
815
816
|
|
816
817
|
def format_expressions_binary_expression(node)
|
818
|
+
op1_bin_exp = node.operand1.is_a?(Model::Expressions::BinaryExpression) &&
|
819
|
+
(OPERATOR_PRECEDENCE[node.operand1.operator] > OPERATOR_PRECEDENCE[node.operator])
|
820
|
+
op2_bin_exp = node.operand2.is_a?(Model::Expressions::BinaryExpression) &&
|
821
|
+
(OPERATOR_PRECEDENCE[node.operand2.operator] > OPERATOR_PRECEDENCE[node.operator])
|
822
|
+
|
817
823
|
[
|
818
|
-
*if
|
819
|
-
|
820
|
-
|
824
|
+
*if op1_bin_exp
|
825
|
+
"("
|
826
|
+
end,
|
821
827
|
format(node.operand1),
|
822
|
-
*if
|
823
|
-
|
824
|
-
|
828
|
+
*if op1_bin_exp
|
829
|
+
")"
|
830
|
+
end,
|
825
831
|
" ",
|
826
832
|
case node.operator
|
827
833
|
when Model::Expressions::BinaryExpression::ADDITION then "+"
|
@@ -847,13 +853,13 @@ module Expressir
|
|
847
853
|
when Model::Expressions::BinaryExpression::XOR then "XOR"
|
848
854
|
end,
|
849
855
|
" ",
|
850
|
-
*if
|
851
|
-
|
852
|
-
|
856
|
+
*if op2_bin_exp
|
857
|
+
"("
|
858
|
+
end,
|
853
859
|
format(node.operand2),
|
854
|
-
*if
|
855
|
-
|
856
|
-
|
860
|
+
*if op2_bin_exp
|
861
|
+
")"
|
862
|
+
end,
|
857
863
|
].join("")
|
858
864
|
end
|
859
865
|
|
@@ -910,7 +916,7 @@ module Expressir
|
|
910
916
|
"|",
|
911
917
|
" ",
|
912
918
|
format(node.expression),
|
913
|
-
*format_remarks(node).instance_eval { |x| x.length
|
919
|
+
*format_remarks(node).instance_eval { |x| x.length.positive? ? ["\n", *x, "\n"] : x },
|
914
920
|
")",
|
915
921
|
].join("")
|
916
922
|
end
|
@@ -926,12 +932,12 @@ module Expressir
|
|
926
932
|
" "
|
927
933
|
end,
|
928
934
|
*if node.operand.is_a? Model::Expressions::BinaryExpression
|
929
|
-
|
930
|
-
|
935
|
+
"("
|
936
|
+
end,
|
931
937
|
format(node.operand),
|
932
938
|
*if node.operand.is_a? Model::Expressions::BinaryExpression
|
933
|
-
|
934
|
-
|
939
|
+
")"
|
940
|
+
end,
|
935
941
|
].join("")
|
936
942
|
end
|
937
943
|
|
@@ -985,7 +991,7 @@ module Expressir
|
|
985
991
|
def format_references_group_reference(node)
|
986
992
|
[
|
987
993
|
format(node.ref),
|
988
|
-
|
994
|
+
"\\",
|
989
995
|
format(node.entity),
|
990
996
|
].join("")
|
991
997
|
end
|
@@ -996,11 +1002,11 @@ module Expressir
|
|
996
1002
|
"[",
|
997
1003
|
format(node.index1),
|
998
1004
|
*if node.index2
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1005
|
+
[
|
1006
|
+
":",
|
1007
|
+
format(node.index2),
|
1008
|
+
].join("")
|
1009
|
+
end,
|
1004
1010
|
"]",
|
1005
1011
|
].join("")
|
1006
1012
|
end
|
@@ -1021,9 +1027,9 @@ module Expressir
|
|
1021
1027
|
format(node.expression),
|
1022
1028
|
";",
|
1023
1029
|
].join(""),
|
1024
|
-
*if node.statements.length
|
1025
|
-
|
1026
|
-
|
1030
|
+
*if node.statements.length.positive?
|
1031
|
+
indent(node.statements.map { |x| format(x) }.join("\n"))
|
1032
|
+
end,
|
1027
1033
|
*format_remarks(node),
|
1028
1034
|
[
|
1029
1035
|
"END_ALIAS",
|
@@ -1046,13 +1052,13 @@ module Expressir
|
|
1046
1052
|
def format_statements_procedure_call(node)
|
1047
1053
|
[
|
1048
1054
|
format(node.procedure),
|
1049
|
-
*if node.parameters.length
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1055
|
+
*if node.parameters.length.positive?
|
1056
|
+
[
|
1057
|
+
"(",
|
1058
|
+
node.parameters.map { |x| format(x) }.join(", "),
|
1059
|
+
")",
|
1060
|
+
].join("")
|
1061
|
+
end,
|
1056
1062
|
";",
|
1057
1063
|
].join("")
|
1058
1064
|
end
|
@@ -1066,19 +1072,19 @@ module Expressir
|
|
1066
1072
|
" ",
|
1067
1073
|
"OF",
|
1068
1074
|
].join(""),
|
1069
|
-
*if node.actions.length
|
1070
|
-
|
1071
|
-
|
1075
|
+
*if node.actions.length.positive?
|
1076
|
+
node.actions.map { |x| format(x) }
|
1077
|
+
end,
|
1072
1078
|
*if node.otherwise_statement
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1079
|
+
[
|
1080
|
+
[
|
1081
|
+
"OTHERWISE",
|
1082
|
+
" ",
|
1083
|
+
":",
|
1084
|
+
].join(""),
|
1085
|
+
indent(format(node.otherwise_statement)),
|
1086
|
+
]
|
1087
|
+
end,
|
1082
1088
|
[
|
1083
1089
|
"END_CASE",
|
1084
1090
|
";",
|
@@ -1100,9 +1106,9 @@ module Expressir
|
|
1100
1106
|
def format_statements_compound(node)
|
1101
1107
|
[
|
1102
1108
|
"BEGIN",
|
1103
|
-
*if node.statements.length
|
1104
|
-
|
1105
|
-
|
1109
|
+
*if node.statements.length.positive?
|
1110
|
+
indent(node.statements.map { |x| format(x) }.join("\n"))
|
1111
|
+
end,
|
1106
1112
|
[
|
1107
1113
|
"END",
|
1108
1114
|
";",
|
@@ -1110,7 +1116,7 @@ module Expressir
|
|
1110
1116
|
].join("\n")
|
1111
1117
|
end
|
1112
1118
|
|
1113
|
-
def format_statements_escape(
|
1119
|
+
def format_statements_escape(_node)
|
1114
1120
|
[
|
1115
1121
|
"ESCAPE",
|
1116
1122
|
";",
|
@@ -1126,15 +1132,15 @@ module Expressir
|
|
1126
1132
|
" ",
|
1127
1133
|
"THEN",
|
1128
1134
|
].join(""),
|
1129
|
-
*if node.statements.length
|
1130
|
-
|
1131
|
-
|
1132
|
-
*if node.else_statements.length
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1135
|
+
*if node.statements.length.positive?
|
1136
|
+
indent(node.statements.map { |x| format(x) }.join("\n"))
|
1137
|
+
end,
|
1138
|
+
*if node.else_statements.length.positive?
|
1139
|
+
[
|
1140
|
+
"ELSE",
|
1141
|
+
indent(node.else_statements.map { |x| format(x) }.join("\n")),
|
1142
|
+
].join("\n")
|
1143
|
+
end,
|
1138
1144
|
[
|
1139
1145
|
"END_IF",
|
1140
1146
|
";",
|
@@ -1142,7 +1148,7 @@ module Expressir
|
|
1142
1148
|
].join("\n")
|
1143
1149
|
end
|
1144
1150
|
|
1145
|
-
def format_statements_null(
|
1151
|
+
def format_statements_null(_node)
|
1146
1152
|
";"
|
1147
1153
|
end
|
1148
1154
|
|
@@ -1151,48 +1157,48 @@ module Expressir
|
|
1151
1157
|
[
|
1152
1158
|
"REPEAT",
|
1153
1159
|
*if node.id
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1160
|
+
[
|
1161
|
+
" ",
|
1162
|
+
node.id,
|
1163
|
+
" ",
|
1164
|
+
":=",
|
1165
|
+
" ",
|
1166
|
+
format(node.bound1),
|
1167
|
+
" ",
|
1168
|
+
"TO",
|
1169
|
+
" ",
|
1170
|
+
format(node.bound2),
|
1171
|
+
*if node.increment
|
1172
|
+
[
|
1173
|
+
" ",
|
1174
|
+
"BY",
|
1175
|
+
" ",
|
1176
|
+
format(node.increment),
|
1177
|
+
].join("")
|
1178
|
+
end,
|
1179
|
+
].join("")
|
1180
|
+
end,
|
1175
1181
|
*if node.while_expression
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1182
|
+
[
|
1183
|
+
" ",
|
1184
|
+
"WHILE",
|
1185
|
+
" ",
|
1186
|
+
format(node.while_expression),
|
1187
|
+
].join("")
|
1188
|
+
end,
|
1183
1189
|
*if node.until_expression
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1190
|
+
[
|
1191
|
+
" ",
|
1192
|
+
"UNTIL",
|
1193
|
+
" ",
|
1194
|
+
format(node.until_expression),
|
1195
|
+
].join("")
|
1196
|
+
end,
|
1191
1197
|
";",
|
1192
1198
|
].join(""),
|
1193
|
-
*if node.statements.length
|
1194
|
-
|
1195
|
-
|
1199
|
+
*if node.statements.length.positive?
|
1200
|
+
indent(node.statements.map { |x| format(x) }.join("\n"))
|
1201
|
+
end,
|
1196
1202
|
*format_remarks(node),
|
1197
1203
|
[
|
1198
1204
|
"END_REPEAT",
|
@@ -1205,18 +1211,18 @@ module Expressir
|
|
1205
1211
|
[
|
1206
1212
|
"RETURN",
|
1207
1213
|
*if node.expression
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1214
|
+
[
|
1215
|
+
" ",
|
1216
|
+
"(",
|
1217
|
+
format(node.expression),
|
1218
|
+
")",
|
1219
|
+
].join("")
|
1220
|
+
end,
|
1215
1221
|
";",
|
1216
1222
|
].join("")
|
1217
1223
|
end
|
1218
1224
|
|
1219
|
-
def format_statements_skip(
|
1225
|
+
def format_statements_skip(_node)
|
1220
1226
|
[
|
1221
1227
|
"SKIP",
|
1222
1228
|
";",
|
@@ -1224,27 +1230,32 @@ module Expressir
|
|
1224
1230
|
end
|
1225
1231
|
|
1226
1232
|
def format_supertype_expressions_binary_supertype_expression(node)
|
1233
|
+
op1_higher_precedence = node.operand1.is_a?(Model::SupertypeExpressions::BinarySupertypeExpression) &&
|
1234
|
+
(SUPERTYPE_OPERATOR_PRECEDENCE[node.operand1.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator])
|
1235
|
+
op2_higher_precedence = node.operand2.is_a?(Model::SupertypeExpressions::BinarySupertypeExpression) &&
|
1236
|
+
(SUPERTYPE_OPERATOR_PRECEDENCE[node.operand2.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator])
|
1237
|
+
|
1227
1238
|
[
|
1228
|
-
*if
|
1229
|
-
|
1230
|
-
|
1239
|
+
*if op1_higher_precedence
|
1240
|
+
"("
|
1241
|
+
end,
|
1231
1242
|
format(node.operand1),
|
1232
|
-
*if
|
1233
|
-
|
1234
|
-
|
1243
|
+
*if op1_higher_precedence
|
1244
|
+
")"
|
1245
|
+
end,
|
1235
1246
|
" ",
|
1236
1247
|
case node.operator
|
1237
1248
|
when Model::SupertypeExpressions::BinarySupertypeExpression::AND then "AND"
|
1238
1249
|
when Model::SupertypeExpressions::BinarySupertypeExpression::ANDOR then "ANDOR"
|
1239
1250
|
end,
|
1240
1251
|
" ",
|
1241
|
-
*if
|
1242
|
-
|
1243
|
-
|
1252
|
+
*if op2_higher_precedence
|
1253
|
+
"("
|
1254
|
+
end,
|
1244
1255
|
format(node.operand2),
|
1245
|
-
*if
|
1246
|
-
|
1247
|
-
|
1256
|
+
*if op2_higher_precedence
|
1257
|
+
")"
|
1258
|
+
end,
|
1248
1259
|
].join("")
|
1249
1260
|
end
|
1250
1261
|
|
@@ -1257,37 +1268,37 @@ module Expressir
|
|
1257
1268
|
].join("")
|
1258
1269
|
end
|
1259
1270
|
|
1260
|
-
def format_data_types_aggregate(
|
1271
|
+
def format_data_types_aggregate(_node)
|
1261
1272
|
"AGGREGATE"
|
1262
1273
|
end
|
1263
1274
|
|
1264
1275
|
def format_data_types_array(node)
|
1265
1276
|
[
|
1266
1277
|
"ARRAY",
|
1267
|
-
*if node.bound1
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1278
|
+
*if node.bound1 && node.bound2
|
1279
|
+
[
|
1280
|
+
" ",
|
1281
|
+
"[",
|
1282
|
+
format(node.bound1),
|
1283
|
+
":",
|
1284
|
+
format(node.bound2),
|
1285
|
+
"]",
|
1286
|
+
].join("")
|
1287
|
+
end,
|
1277
1288
|
" ",
|
1278
1289
|
"OF",
|
1279
1290
|
*if node.optional
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1291
|
+
[
|
1292
|
+
" ",
|
1293
|
+
"OPTIONAL",
|
1294
|
+
].join("")
|
1295
|
+
end,
|
1285
1296
|
*if node.unique
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1297
|
+
[
|
1298
|
+
" ",
|
1299
|
+
"UNIQUE",
|
1300
|
+
].join("")
|
1301
|
+
end,
|
1291
1302
|
" ",
|
1292
1303
|
format(node.base_type),
|
1293
1304
|
].join("")
|
@@ -1296,16 +1307,16 @@ module Expressir
|
|
1296
1307
|
def format_data_types_bag(node)
|
1297
1308
|
[
|
1298
1309
|
"BAG",
|
1299
|
-
*if node.bound1
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1310
|
+
*if node.bound1 && node.bound2
|
1311
|
+
[
|
1312
|
+
" ",
|
1313
|
+
"[",
|
1314
|
+
format(node.bound1),
|
1315
|
+
":",
|
1316
|
+
format(node.bound2),
|
1317
|
+
"]",
|
1318
|
+
].join("")
|
1319
|
+
end,
|
1309
1320
|
" ",
|
1310
1321
|
"OF",
|
1311
1322
|
" ",
|
@@ -1317,72 +1328,72 @@ module Expressir
|
|
1317
1328
|
[
|
1318
1329
|
"BINARY",
|
1319
1330
|
*if node.width
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1331
|
+
[
|
1332
|
+
" ",
|
1333
|
+
"(",
|
1334
|
+
format(node.width),
|
1335
|
+
")",
|
1336
|
+
].join("")
|
1337
|
+
end,
|
1327
1338
|
*if node.fixed
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1339
|
+
[
|
1340
|
+
" ",
|
1341
|
+
"FIXED",
|
1342
|
+
].join("")
|
1343
|
+
end,
|
1333
1344
|
].join("")
|
1334
1345
|
end
|
1335
1346
|
|
1336
|
-
def format_data_types_boolean(
|
1347
|
+
def format_data_types_boolean(_node)
|
1337
1348
|
"BOOLEAN"
|
1338
1349
|
end
|
1339
1350
|
|
1340
1351
|
def format_data_types_enumeration(node)
|
1341
1352
|
[
|
1342
1353
|
*if node.extensible
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1354
|
+
[
|
1355
|
+
"EXTENSIBLE",
|
1356
|
+
" ",
|
1357
|
+
].join("")
|
1358
|
+
end,
|
1348
1359
|
"ENUMERATION",
|
1349
1360
|
*if node.based_on
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1361
|
+
[
|
1362
|
+
" ",
|
1363
|
+
"BASED_ON",
|
1364
|
+
" ",
|
1365
|
+
format(node.based_on),
|
1366
|
+
*if node.items.length.positive?
|
1367
|
+
item_indent = INDENT_CHAR * "(".length
|
1368
|
+
[
|
1369
|
+
" ",
|
1370
|
+
"WITH",
|
1371
|
+
"\n",
|
1372
|
+
indent([
|
1373
|
+
"(",
|
1374
|
+
node.items.map { |x| format(x) }.join(",\n#{item_indent}"),
|
1375
|
+
")",
|
1376
|
+
].join("")),
|
1377
|
+
].join("")
|
1378
|
+
end,
|
1379
|
+
].join("")
|
1380
|
+
else
|
1381
|
+
[
|
1382
|
+
*if node.items.length.positive?
|
1383
|
+
item_indent = INDENT_CHAR * "(".length
|
1384
|
+
[
|
1385
|
+
" ",
|
1386
|
+
"OF",
|
1387
|
+
"\n",
|
1388
|
+
indent([
|
1389
|
+
"(",
|
1390
|
+
node.items.map { |x| format(x) }.join(",\n#{item_indent}"),
|
1391
|
+
")",
|
1392
|
+
].join("")),
|
1393
|
+
].join("")
|
1394
|
+
end,
|
1395
|
+
].join("")
|
1396
|
+
end,
|
1386
1397
|
].join("")
|
1387
1398
|
end
|
1388
1399
|
|
@@ -1394,11 +1405,11 @@ module Expressir
|
|
1394
1405
|
[
|
1395
1406
|
"GENERIC_ENTITY",
|
1396
1407
|
*if node.id
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1408
|
+
[
|
1409
|
+
":",
|
1410
|
+
node.id,
|
1411
|
+
]
|
1412
|
+
end,
|
1402
1413
|
].join("")
|
1403
1414
|
end
|
1404
1415
|
|
@@ -1406,49 +1417,49 @@ module Expressir
|
|
1406
1417
|
[
|
1407
1418
|
"GENERIC",
|
1408
1419
|
*if node.id
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1420
|
+
[
|
1421
|
+
":",
|
1422
|
+
node.id,
|
1423
|
+
]
|
1424
|
+
end,
|
1414
1425
|
].join("")
|
1415
1426
|
end
|
1416
1427
|
|
1417
|
-
def format_data_types_integer(
|
1428
|
+
def format_data_types_integer(_node)
|
1418
1429
|
"INTEGER"
|
1419
1430
|
end
|
1420
1431
|
|
1421
1432
|
def format_data_types_list(node)
|
1422
1433
|
[
|
1423
1434
|
"LIST",
|
1424
|
-
*if node.bound1
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1435
|
+
*if node.bound1 && node.bound2
|
1436
|
+
[
|
1437
|
+
" ",
|
1438
|
+
"[",
|
1439
|
+
format(node.bound1),
|
1440
|
+
":",
|
1441
|
+
format(node.bound2),
|
1442
|
+
"]",
|
1443
|
+
].join("")
|
1444
|
+
end,
|
1434
1445
|
" ",
|
1435
1446
|
"OF",
|
1436
1447
|
*if node.unique
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1448
|
+
[
|
1449
|
+
" ",
|
1450
|
+
"UNIQUE",
|
1451
|
+
].join("")
|
1452
|
+
end,
|
1442
1453
|
" ",
|
1443
1454
|
format(node.base_type),
|
1444
1455
|
].join("")
|
1445
1456
|
end
|
1446
1457
|
|
1447
|
-
def format_data_types_logical(
|
1458
|
+
def format_data_types_logical(_node)
|
1448
1459
|
"LOGICAL"
|
1449
1460
|
end
|
1450
1461
|
|
1451
|
-
def format_data_types_number(
|
1462
|
+
def format_data_types_number(_node)
|
1452
1463
|
"NUMBER"
|
1453
1464
|
end
|
1454
1465
|
|
@@ -1456,82 +1467,82 @@ module Expressir
|
|
1456
1467
|
[
|
1457
1468
|
"REAL",
|
1458
1469
|
*if node.precision
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1470
|
+
[
|
1471
|
+
" ",
|
1472
|
+
"(",
|
1473
|
+
format(node.precision),
|
1474
|
+
")",
|
1475
|
+
].join("")
|
1476
|
+
end,
|
1466
1477
|
].join("")
|
1467
1478
|
end
|
1468
1479
|
|
1469
1480
|
def format_data_types_select(node)
|
1470
1481
|
[
|
1471
1482
|
*if node.extensible
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1483
|
+
[
|
1484
|
+
"EXTENSIBLE",
|
1485
|
+
" ",
|
1486
|
+
].join("")
|
1487
|
+
end,
|
1477
1488
|
*if node.generic_entity
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1489
|
+
[
|
1490
|
+
"GENERIC_ENTITY",
|
1491
|
+
" ",
|
1492
|
+
].join("")
|
1493
|
+
end,
|
1483
1494
|
"SELECT",
|
1484
1495
|
*if node.based_on
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1496
|
+
[
|
1497
|
+
" ",
|
1498
|
+
"BASED_ON",
|
1499
|
+
" ",
|
1500
|
+
format(node.based_on),
|
1501
|
+
*if node.items.length.positive?
|
1502
|
+
item_indent = INDENT_CHAR * "(".length
|
1503
|
+
[
|
1504
|
+
" ",
|
1505
|
+
"WITH",
|
1506
|
+
"\n",
|
1507
|
+
indent([
|
1508
|
+
"(",
|
1509
|
+
node.items.map { |x| format(x) }.join(",\n#{item_indent}"),
|
1510
|
+
")",
|
1511
|
+
].join("")),
|
1512
|
+
].join("")
|
1513
|
+
end,
|
1514
|
+
].join("")
|
1515
|
+
else
|
1516
|
+
[
|
1517
|
+
*if node.items.length.positive?
|
1518
|
+
item_indent = INDENT_CHAR * "(".length
|
1519
|
+
[
|
1520
|
+
"\n",
|
1521
|
+
indent([
|
1522
|
+
"(",
|
1523
|
+
node.items.map { |x| format(x) }.join(",\n#{item_indent}"),
|
1524
|
+
")",
|
1525
|
+
].join("")),
|
1526
|
+
].join("")
|
1527
|
+
end,
|
1528
|
+
].join("")
|
1529
|
+
end,
|
1519
1530
|
].join("")
|
1520
1531
|
end
|
1521
1532
|
|
1522
1533
|
def format_data_types_set(node)
|
1523
1534
|
[
|
1524
1535
|
"SET",
|
1525
|
-
*if node.bound1
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1536
|
+
*if node.bound1 && node.bound2
|
1537
|
+
[
|
1538
|
+
" ",
|
1539
|
+
"[",
|
1540
|
+
format(node.bound1),
|
1541
|
+
":",
|
1542
|
+
format(node.bound2),
|
1543
|
+
"]",
|
1544
|
+
].join("")
|
1545
|
+
end,
|
1535
1546
|
" ",
|
1536
1547
|
"OF",
|
1537
1548
|
" ",
|
@@ -1543,19 +1554,19 @@ module Expressir
|
|
1543
1554
|
[
|
1544
1555
|
"STRING",
|
1545
1556
|
*if node.width
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1557
|
+
[
|
1558
|
+
" ",
|
1559
|
+
"(",
|
1560
|
+
format(node.width),
|
1561
|
+
")",
|
1562
|
+
].join("")
|
1563
|
+
end,
|
1553
1564
|
*if node.fixed
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1565
|
+
[
|
1566
|
+
" ",
|
1567
|
+
"FIXED",
|
1568
|
+
].join("")
|
1569
|
+
end,
|
1559
1570
|
].join("")
|
1560
1571
|
end
|
1561
1572
|
|
@@ -1600,7 +1611,9 @@ module Expressir
|
|
1600
1611
|
def format_scope_remarks(node)
|
1601
1612
|
[
|
1602
1613
|
*format_remarks(node),
|
1603
|
-
*node.children.select
|
1614
|
+
*node.children.select do |x|
|
1615
|
+
!x.is_a? Model::DataTypes::EnumerationItem or node.is_a? Model::Declarations::Type
|
1616
|
+
end.flat_map { |x| format_scope_remarks(x) },
|
1604
1617
|
]
|
1605
1618
|
end
|
1606
1619
|
end
|