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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 843dcf34e7a34f2c8061e48c708bea2c16d54b773e96f781937c0fef7df2367d
|
4
|
+
data.tar.gz: 74039ed222ac962849d6e2e79ee6596ab26e7da6d4396bba89ab07f6f9b2917f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38109ed8b49e910c3af2410c6df591d71298211ae8f95d7fdbb08f73aec6b11b56761410d4a3793f0c34f8c0e56a31796bad0b1281e71c79d7175d6c1d5378ec
|
7
|
+
data.tar.gz: eb61333805b6199136e48a4136dd012292b96874f2ae25089f65b56f1f3208a0f31bee5e127b0a3666d573dd4be37c51e8f712c99eb6a8f3045dfb2cd3ffc86d
|
data/.gitignore
CHANGED
@@ -0,0 +1,1444 @@
|
|
1
|
+
require 'expressir/model'
|
2
|
+
|
3
|
+
module Expressir
|
4
|
+
module ExpressExp
|
5
|
+
class Formatter
|
6
|
+
INDENT_CHAR = ' '
|
7
|
+
INDENT_WIDTH = 2
|
8
|
+
INDENT = INDENT_CHAR * INDENT_WIDTH
|
9
|
+
|
10
|
+
OPERATOR_PRECEDENCE = {
|
11
|
+
Model::Expressions::BinaryExpression::EXPONENTIATION => 1,
|
12
|
+
Model::Expressions::BinaryExpression::MULTIPLICATION => 2,
|
13
|
+
Model::Expressions::BinaryExpression::REAL_DIVISION => 2,
|
14
|
+
Model::Expressions::BinaryExpression::INTEGER_DIVISION => 2,
|
15
|
+
Model::Expressions::BinaryExpression::MODULO => 2,
|
16
|
+
Model::Expressions::BinaryExpression::AND => 2,
|
17
|
+
Model::Expressions::BinaryExpression::COMBINE => 2,
|
18
|
+
Model::Expressions::BinaryExpression::SUBTRACTION => 3,
|
19
|
+
Model::Expressions::BinaryExpression::ADDITION => 3,
|
20
|
+
Model::Expressions::BinaryExpression::OR => 3,
|
21
|
+
Model::Expressions::BinaryExpression::XOR => 3,
|
22
|
+
Model::Expressions::BinaryExpression::EQUAL => 4,
|
23
|
+
Model::Expressions::BinaryExpression::NOT_EQUAL => 4,
|
24
|
+
Model::Expressions::BinaryExpression::LESS_THAN_OR_EQUAL => 4,
|
25
|
+
Model::Expressions::BinaryExpression::GREATER_THAN_OR_EQUAL => 4,
|
26
|
+
Model::Expressions::BinaryExpression::LESS_THAN => 4,
|
27
|
+
Model::Expressions::BinaryExpression::GREATER_THAN => 4,
|
28
|
+
Model::Expressions::BinaryExpression::INSTANCE_EQUAL => 4,
|
29
|
+
Model::Expressions::BinaryExpression::INSTANCE_NOT_EQUAL => 4,
|
30
|
+
Model::Expressions::BinaryExpression::IN => 4,
|
31
|
+
Model::Expressions::BinaryExpression::LIKE => 4,
|
32
|
+
Model::Expressions::BinaryExpression::ANDOR => 4,
|
33
|
+
}
|
34
|
+
|
35
|
+
def self.format(node)
|
36
|
+
formatter = self.new
|
37
|
+
formatter.format(node)
|
38
|
+
end
|
39
|
+
|
40
|
+
def format(node)
|
41
|
+
if node.instance_of? Model::Attribute
|
42
|
+
format_attribute(node)
|
43
|
+
elsif node.instance_of? Model::Constant
|
44
|
+
format_constant(node)
|
45
|
+
elsif node.instance_of? Model::Entity
|
46
|
+
format_entity(node)
|
47
|
+
elsif node.instance_of? Model::EnumerationItem
|
48
|
+
format_enumeration_item(node)
|
49
|
+
elsif node.instance_of? Model::Function
|
50
|
+
format_function(node)
|
51
|
+
elsif node.instance_of? Model::Interface
|
52
|
+
format_interface(node)
|
53
|
+
elsif node.instance_of? Model::Parameter
|
54
|
+
format_parameter(node)
|
55
|
+
elsif node.instance_of? Model::Procedure
|
56
|
+
format_procedure(node)
|
57
|
+
elsif node.instance_of? Model::RenamedRef
|
58
|
+
format_renamed_ref(node)
|
59
|
+
elsif node.instance_of? Model::Repository
|
60
|
+
format_repository(node)
|
61
|
+
elsif node.instance_of? Model::Rule
|
62
|
+
format_rule(node)
|
63
|
+
elsif node.instance_of? Model::Schema
|
64
|
+
format_schema(node)
|
65
|
+
elsif node.instance_of? Model::SubtypeConstraint
|
66
|
+
format_subtype_constraint(node)
|
67
|
+
elsif node.instance_of? Model::Type
|
68
|
+
format_type(node)
|
69
|
+
elsif node.instance_of? Model::Unique
|
70
|
+
format_unique(node)
|
71
|
+
elsif node.instance_of? Model::Variable
|
72
|
+
format_variable(node)
|
73
|
+
elsif node.instance_of? Model::Where
|
74
|
+
format_where(node)
|
75
|
+
elsif node.instance_of? Model::Expressions::AggregateInitializer
|
76
|
+
format_expressions_aggregate_initializer(node)
|
77
|
+
elsif node.instance_of? Model::Expressions::AggregateItem
|
78
|
+
format_expressions_aggregate_item(node)
|
79
|
+
elsif node.instance_of? Model::Expressions::AttributeReference
|
80
|
+
format_expressions_attribute_reference(node)
|
81
|
+
elsif node.instance_of? Model::Expressions::BinaryExpression
|
82
|
+
format_expressions_binary_expression(node)
|
83
|
+
elsif node.instance_of? Model::Expressions::Call
|
84
|
+
format_expressions_call(node)
|
85
|
+
elsif node.instance_of? Model::Expressions::EntityConstructor
|
86
|
+
format_expressions_entity_constructor(node)
|
87
|
+
elsif node.instance_of? Model::Expressions::GroupReference
|
88
|
+
format_expressions_group_reference(node)
|
89
|
+
elsif node.instance_of? Model::Expressions::IndexReference
|
90
|
+
format_expressions_index_reference(node)
|
91
|
+
elsif node.instance_of? Model::Expressions::Interval
|
92
|
+
format_expressions_interval(node)
|
93
|
+
elsif node.instance_of? Model::Expressions::QueryExpression
|
94
|
+
format_expressions_query_expression(node)
|
95
|
+
elsif node.instance_of? Model::Expressions::SimpleReference
|
96
|
+
format_expressions_simple_reference(node)
|
97
|
+
elsif node.instance_of? Model::Expressions::UnaryExpression
|
98
|
+
format_expressions_unary_expression(node)
|
99
|
+
elsif node.instance_of? Model::Literals::Binary
|
100
|
+
format_literals_binary(node)
|
101
|
+
elsif node.instance_of? Model::Literals::Integer
|
102
|
+
format_literals_integer(node)
|
103
|
+
elsif node.instance_of? Model::Literals::Logical
|
104
|
+
format_literals_logical(node)
|
105
|
+
elsif node.instance_of? Model::Literals::Real
|
106
|
+
format_literals_real(node)
|
107
|
+
elsif node.instance_of? Model::Literals::String
|
108
|
+
format_literals_string(node)
|
109
|
+
elsif node.instance_of? Model::Statements::Alias
|
110
|
+
format_statements_alias(node)
|
111
|
+
elsif node.instance_of? Model::Statements::Assignment
|
112
|
+
format_statements_assignment(node)
|
113
|
+
elsif node.instance_of? Model::Statements::Call
|
114
|
+
format_statements_call(node)
|
115
|
+
elsif node.instance_of? Model::Statements::Case
|
116
|
+
format_statements_case(node)
|
117
|
+
elsif node.instance_of? Model::Statements::CaseAction
|
118
|
+
format_statements_case_action(node)
|
119
|
+
elsif node.instance_of? Model::Statements::Compound
|
120
|
+
format_statements_compound(node)
|
121
|
+
elsif node.instance_of? Model::Statements::Escape
|
122
|
+
format_statements_escape(node)
|
123
|
+
elsif node.instance_of? Model::Statements::If
|
124
|
+
format_statements_if(node)
|
125
|
+
elsif node.instance_of? Model::Statements::Null
|
126
|
+
format_statements_null(node)
|
127
|
+
elsif node.instance_of? Model::Statements::Repeat
|
128
|
+
format_statements_repeat(node)
|
129
|
+
elsif node.instance_of? Model::Statements::Return
|
130
|
+
format_statements_return(node)
|
131
|
+
elsif node.instance_of? Model::Statements::Skip
|
132
|
+
format_statements_skip(node)
|
133
|
+
elsif node.instance_of? Model::Types::Aggregate
|
134
|
+
format_types_aggregate(node)
|
135
|
+
elsif node.instance_of? Model::Types::Array
|
136
|
+
format_types_array(node)
|
137
|
+
elsif node.instance_of? Model::Types::Bag
|
138
|
+
format_types_bag(node)
|
139
|
+
elsif node.instance_of? Model::Types::Binary
|
140
|
+
format_types_binary(node)
|
141
|
+
elsif node.instance_of? Model::Types::Boolean
|
142
|
+
format_types_boolean(node)
|
143
|
+
elsif node.instance_of? Model::Types::Enumeration
|
144
|
+
format_types_enumeration(node)
|
145
|
+
elsif node.instance_of? Model::Types::GenericEntity
|
146
|
+
format_types_generic_entity(node)
|
147
|
+
elsif node.instance_of? Model::Types::Generic
|
148
|
+
format_types_generic(node)
|
149
|
+
elsif node.instance_of? Model::Types::Integer
|
150
|
+
format_types_integer(node)
|
151
|
+
elsif node.instance_of? Model::Types::List
|
152
|
+
format_types_list(node)
|
153
|
+
elsif node.instance_of? Model::Types::Logical
|
154
|
+
format_types_logical(node)
|
155
|
+
elsif node.instance_of? Model::Types::Number
|
156
|
+
format_types_number(node)
|
157
|
+
elsif node.instance_of? Model::Types::Real
|
158
|
+
format_types_real(node)
|
159
|
+
elsif node.instance_of? Model::Types::Select
|
160
|
+
format_types_select(node)
|
161
|
+
elsif node.instance_of? Model::Types::Set
|
162
|
+
format_types_set(node)
|
163
|
+
elsif node.instance_of? Model::Types::String
|
164
|
+
format_types_string(node)
|
165
|
+
else
|
166
|
+
puts node.class
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
private
|
171
|
+
|
172
|
+
def format_attribute(node)
|
173
|
+
[
|
174
|
+
*if node.kind == Model::Attribute::DERIVED
|
175
|
+
[
|
176
|
+
'DERIVE',
|
177
|
+
' '
|
178
|
+
].join('')
|
179
|
+
elsif node.kind == Model::Attribute::INVERSE
|
180
|
+
[
|
181
|
+
'INVERSE',
|
182
|
+
' '
|
183
|
+
].join('')
|
184
|
+
end,
|
185
|
+
*if node.supertype_attribute
|
186
|
+
[
|
187
|
+
format(node.supertype_attribute),
|
188
|
+
' ',
|
189
|
+
].join('')
|
190
|
+
end,
|
191
|
+
*if node.supertype_attribute and node.id
|
192
|
+
[
|
193
|
+
'RENAMED',
|
194
|
+
' '
|
195
|
+
].join('')
|
196
|
+
end,
|
197
|
+
*if node.id
|
198
|
+
[
|
199
|
+
node.id,
|
200
|
+
' '
|
201
|
+
].join('')
|
202
|
+
end,
|
203
|
+
':',
|
204
|
+
*if node.optional
|
205
|
+
[
|
206
|
+
' ',
|
207
|
+
'OPTIONAL'
|
208
|
+
].join('')
|
209
|
+
end,
|
210
|
+
' ',
|
211
|
+
format(node.type),
|
212
|
+
*if node.kind == Model::Attribute::DERIVED
|
213
|
+
[
|
214
|
+
' ',
|
215
|
+
':=',
|
216
|
+
' ',
|
217
|
+
format(node.expression)
|
218
|
+
].join('')
|
219
|
+
elsif node.kind == Model::Attribute::INVERSE
|
220
|
+
[
|
221
|
+
' ',
|
222
|
+
'FOR',
|
223
|
+
' ',
|
224
|
+
format(node.expression)
|
225
|
+
].join('')
|
226
|
+
end,
|
227
|
+
';',
|
228
|
+
].join('')
|
229
|
+
end
|
230
|
+
|
231
|
+
def format_constant(node)
|
232
|
+
[
|
233
|
+
node.id,
|
234
|
+
' ',
|
235
|
+
':',
|
236
|
+
' ',
|
237
|
+
format(node.type),
|
238
|
+
' ',
|
239
|
+
':=',
|
240
|
+
' ',
|
241
|
+
format(node.expression),
|
242
|
+
';'
|
243
|
+
].join('')
|
244
|
+
end
|
245
|
+
|
246
|
+
def format_entity(node)
|
247
|
+
[
|
248
|
+
[
|
249
|
+
'ENTITY',
|
250
|
+
' ',
|
251
|
+
node.id,
|
252
|
+
*if node.abstract and !node.supertype_expression
|
253
|
+
[
|
254
|
+
"\n",
|
255
|
+
' ',
|
256
|
+
'ABSTRACT',
|
257
|
+
' ',
|
258
|
+
'SUPERTYPE'
|
259
|
+
].join('')
|
260
|
+
end,
|
261
|
+
*if node.abstract and node.supertype_expression
|
262
|
+
[
|
263
|
+
"\n",
|
264
|
+
' ',
|
265
|
+
'ABSTRACT',
|
266
|
+
' ',
|
267
|
+
'SUPERTYPE',
|
268
|
+
' ',
|
269
|
+
'OF',
|
270
|
+
' ',
|
271
|
+
'(',
|
272
|
+
format(node.supertype_expression),
|
273
|
+
')'
|
274
|
+
].join('')
|
275
|
+
end,
|
276
|
+
*if !node.abstract and node.supertype_expression
|
277
|
+
[
|
278
|
+
"\n",
|
279
|
+
' ',
|
280
|
+
'SUPERTYPE',
|
281
|
+
' ',
|
282
|
+
'OF',
|
283
|
+
' ',
|
284
|
+
'(',
|
285
|
+
format(node.supertype_expression),
|
286
|
+
')'
|
287
|
+
].join('')
|
288
|
+
end,
|
289
|
+
*if node.subtype_of and node.subtype_of.length > 0
|
290
|
+
[
|
291
|
+
"\n",
|
292
|
+
' ',
|
293
|
+
'SUBTYPE',
|
294
|
+
' ',
|
295
|
+
'OF',
|
296
|
+
' ',
|
297
|
+
'(',
|
298
|
+
node.subtype_of.map{|x| format(x)}.join(', '),
|
299
|
+
')'
|
300
|
+
].join('')
|
301
|
+
end,
|
302
|
+
';'
|
303
|
+
].join(''),
|
304
|
+
*if node.attributes and node.attributes.length > 0
|
305
|
+
indent(node.attributes.map{|x| format(x)}.join("\n"))
|
306
|
+
end,
|
307
|
+
*if node.unique and node.unique.length > 0
|
308
|
+
indent([
|
309
|
+
'UNIQUE',
|
310
|
+
indent(node.unique.map{|x| format(x)}.join("\n"))
|
311
|
+
].join("\n"))
|
312
|
+
end,
|
313
|
+
*if node.where and node.where.length > 0
|
314
|
+
indent([
|
315
|
+
'WHERE',
|
316
|
+
indent(node.where.map{|x| format(x)}.join("\n")),
|
317
|
+
].join("\n"))
|
318
|
+
end,
|
319
|
+
*format_scope_remarks(node),
|
320
|
+
[
|
321
|
+
'END_ENTITY',
|
322
|
+
';'
|
323
|
+
].join('')
|
324
|
+
].join("\n")
|
325
|
+
end
|
326
|
+
|
327
|
+
def format_enumeration_item(node)
|
328
|
+
node.id
|
329
|
+
end
|
330
|
+
|
331
|
+
def format_function(node)
|
332
|
+
[
|
333
|
+
[
|
334
|
+
'FUNCTION',
|
335
|
+
' ',
|
336
|
+
node.id,
|
337
|
+
*if node.parameters and node.parameters.length > 0
|
338
|
+
[
|
339
|
+
'(',
|
340
|
+
node.parameters.map{|x| format(x)}.join('; '),
|
341
|
+
')'
|
342
|
+
].join('')
|
343
|
+
end,
|
344
|
+
' ',
|
345
|
+
':',
|
346
|
+
' ',
|
347
|
+
format(node.return_type),
|
348
|
+
';'
|
349
|
+
].join(''),
|
350
|
+
*if node.declarations and node.declarations.length > 0
|
351
|
+
indent(node.declarations.map{|x| format(x)}.join("\n"))
|
352
|
+
end,
|
353
|
+
*if node.constants and node.constants.length > 0
|
354
|
+
indent([
|
355
|
+
'CONSTANT',
|
356
|
+
indent(node.constants.map{|x| format(x)}.join("\n")),
|
357
|
+
[
|
358
|
+
'END_CONSTANT',
|
359
|
+
';'
|
360
|
+
].join('')
|
361
|
+
].join("\n"))
|
362
|
+
end,
|
363
|
+
*if node.variables and node.variables.length > 0
|
364
|
+
indent([
|
365
|
+
'LOCAL',
|
366
|
+
indent(node.variables.map{|x| format(x)}.join("\n")),
|
367
|
+
[
|
368
|
+
'END_LOCAL',
|
369
|
+
';'
|
370
|
+
].join('')
|
371
|
+
].join("\n"))
|
372
|
+
end,
|
373
|
+
*if node.statements and node.statements.length > 0
|
374
|
+
indent(node.statements.map{|x| format(x)}.join("\n"))
|
375
|
+
end,
|
376
|
+
*format_scope_remarks(node),
|
377
|
+
[
|
378
|
+
'END_FUNCTION',
|
379
|
+
';'
|
380
|
+
].join('')
|
381
|
+
].join("\n")
|
382
|
+
end
|
383
|
+
|
384
|
+
def format_interface(node)
|
385
|
+
[
|
386
|
+
case node.kind
|
387
|
+
when Model::Interface::USE then 'USE'
|
388
|
+
when Model::Interface::REFERENCE then 'REFERENCE'
|
389
|
+
end,
|
390
|
+
' ',
|
391
|
+
'FROM',
|
392
|
+
' ',
|
393
|
+
format(node.schema),
|
394
|
+
*if node.items and node.items.length > 0
|
395
|
+
[
|
396
|
+
"\n",
|
397
|
+
' ',
|
398
|
+
'(',
|
399
|
+
node.items.map{|x| format(x)},
|
400
|
+
')'
|
401
|
+
].join('')
|
402
|
+
end,
|
403
|
+
';',
|
404
|
+
].join('')
|
405
|
+
end
|
406
|
+
|
407
|
+
def format_parameter(node)
|
408
|
+
[
|
409
|
+
*if node.var
|
410
|
+
[
|
411
|
+
'VAR',
|
412
|
+
' '
|
413
|
+
].join('')
|
414
|
+
end,
|
415
|
+
node.id,
|
416
|
+
' ',
|
417
|
+
':',
|
418
|
+
' ',
|
419
|
+
format(node.type)
|
420
|
+
].join('')
|
421
|
+
end
|
422
|
+
|
423
|
+
def format_procedure(node)
|
424
|
+
[
|
425
|
+
[
|
426
|
+
'PROCEDURE',
|
427
|
+
' ',
|
428
|
+
node.id,
|
429
|
+
*if node.parameters and node.parameters.length > 0
|
430
|
+
[
|
431
|
+
'(',
|
432
|
+
node.parameters.map{|x| format(x)}.join('; '),
|
433
|
+
')'
|
434
|
+
].join('')
|
435
|
+
end,
|
436
|
+
';'
|
437
|
+
].join(''),
|
438
|
+
*if node.declarations and node.declarations.length > 0
|
439
|
+
indent(node.declarations.map{|x| format(x)}.join("\n"))
|
440
|
+
end,
|
441
|
+
*if node.constants and node.constants.length > 0
|
442
|
+
indent([
|
443
|
+
'CONSTANT',
|
444
|
+
indent(node.constants.map{|x| format(x)}.join("\n")),
|
445
|
+
[
|
446
|
+
'END_CONSTANT',
|
447
|
+
';'
|
448
|
+
].join('')
|
449
|
+
].join("\n"))
|
450
|
+
end,
|
451
|
+
*if node.variables and node.variables.length > 0
|
452
|
+
indent([
|
453
|
+
'LOCAL',
|
454
|
+
indent(node.variables.map{|x| format(x)}.join("\n")),
|
455
|
+
[
|
456
|
+
'END_LOCAL',
|
457
|
+
';'
|
458
|
+
].join('')
|
459
|
+
].join("\n"))
|
460
|
+
end,
|
461
|
+
*if node.statements and node.statements.length > 0
|
462
|
+
indent(node.statements.map{|x| format(x)}.join("\n"))
|
463
|
+
end,
|
464
|
+
*format_scope_remarks(node),
|
465
|
+
[
|
466
|
+
'END_PROCEDURE',
|
467
|
+
';'
|
468
|
+
].join('')
|
469
|
+
].join("\n")
|
470
|
+
end
|
471
|
+
|
472
|
+
def format_renamed_ref(node)
|
473
|
+
[
|
474
|
+
format(node.ref),
|
475
|
+
' ',
|
476
|
+
'AS',
|
477
|
+
' ',
|
478
|
+
node.id
|
479
|
+
].join('')
|
480
|
+
end
|
481
|
+
|
482
|
+
def format_repository(node)
|
483
|
+
[
|
484
|
+
*if node.schemas and node.schemas.length > 0
|
485
|
+
node.schemas.map{|node| format(node)}
|
486
|
+
end,
|
487
|
+
*format_scope_remarks(node)
|
488
|
+
].join("\n")
|
489
|
+
end
|
490
|
+
|
491
|
+
def format_rule(node)
|
492
|
+
[
|
493
|
+
[
|
494
|
+
'RULE',
|
495
|
+
' ',
|
496
|
+
node.id,
|
497
|
+
' ',
|
498
|
+
'FOR',
|
499
|
+
' ',
|
500
|
+
'(',
|
501
|
+
node.applies_to.map{|x| format(x)}.join(', '),
|
502
|
+
')',
|
503
|
+
';'
|
504
|
+
].join(''),
|
505
|
+
*if node.declarations and node.declarations.length > 0
|
506
|
+
indent(node.declarations.map{|x| format(x)}.join("\n"))
|
507
|
+
end,
|
508
|
+
*if node.constants and node.constants.length > 0
|
509
|
+
indent([
|
510
|
+
'CONSTANT',
|
511
|
+
indent(node.constants.map{|x| format(x)}.join("\n")),
|
512
|
+
[
|
513
|
+
'END_CONSTANT',
|
514
|
+
';'
|
515
|
+
].join('')
|
516
|
+
].join("\n"))
|
517
|
+
end,
|
518
|
+
*if node.variables and node.variables.length > 0
|
519
|
+
indent([
|
520
|
+
'LOCAL',
|
521
|
+
indent(node.variables.map{|x| format(x)}.join("\n")),
|
522
|
+
[
|
523
|
+
'END_LOCAL',
|
524
|
+
';'
|
525
|
+
].join('')
|
526
|
+
].join("\n"))
|
527
|
+
end,
|
528
|
+
*if node.statements and node.statements.length > 0
|
529
|
+
indent(node.statements.map{|x| format(x)}.join("\n"))
|
530
|
+
end,
|
531
|
+
*if node.where and node.where.length > 0
|
532
|
+
indent([
|
533
|
+
'WHERE',
|
534
|
+
indent(node.where.map{|x| format(x)}.join("\n"))
|
535
|
+
].join("\n"))
|
536
|
+
end,
|
537
|
+
*format_scope_remarks(node),
|
538
|
+
[
|
539
|
+
'END_RULE',
|
540
|
+
';'
|
541
|
+
].join('')
|
542
|
+
].join("\n")
|
543
|
+
end
|
544
|
+
|
545
|
+
def format_schema(node)
|
546
|
+
[
|
547
|
+
[
|
548
|
+
'SCHEMA',
|
549
|
+
' ',
|
550
|
+
node.id,
|
551
|
+
*if node.version
|
552
|
+
[
|
553
|
+
' ',
|
554
|
+
format(node.version),
|
555
|
+
].join('')
|
556
|
+
end,
|
557
|
+
';'
|
558
|
+
].join(''),
|
559
|
+
*if node.interfaces and node.interfaces.length > 0
|
560
|
+
node.interfaces.map{|x| format(x)}.join("\n")
|
561
|
+
end,
|
562
|
+
*if node.constants and node.constants.length > 0
|
563
|
+
[
|
564
|
+
'CONSTANT',
|
565
|
+
indent(node.constants.map{|x| format(x)}.join("\n")),
|
566
|
+
[
|
567
|
+
'END_CONSTANT',
|
568
|
+
';'
|
569
|
+
].join('')
|
570
|
+
].join("\n")
|
571
|
+
end,
|
572
|
+
*if node.declarations and node.declarations.length > 0
|
573
|
+
node.declarations.map{|x| format(x)}.join("\n\n")
|
574
|
+
end,
|
575
|
+
*format_scope_remarks(node),
|
576
|
+
[
|
577
|
+
'END_SCHEMA',
|
578
|
+
';'
|
579
|
+
].join('')
|
580
|
+
].join("\n")
|
581
|
+
end
|
582
|
+
|
583
|
+
def format_subtype_constraint(node)
|
584
|
+
[
|
585
|
+
[
|
586
|
+
'SUBTYPE_CONSTRAINT',
|
587
|
+
' ',
|
588
|
+
node.id,
|
589
|
+
' ',
|
590
|
+
'FOR',
|
591
|
+
' ',
|
592
|
+
format(node.applies_to),
|
593
|
+
';'
|
594
|
+
].join(''),
|
595
|
+
*if node.abstract
|
596
|
+
indent([
|
597
|
+
'ABSTRACT',
|
598
|
+
' ',
|
599
|
+
'SUPERTYPE',
|
600
|
+
';'
|
601
|
+
].join(''))
|
602
|
+
end,
|
603
|
+
*if node.total_over and node.total_over.length > 0
|
604
|
+
indent([
|
605
|
+
'TOTAL_OVER',
|
606
|
+
'(',
|
607
|
+
node.total_over.map{|x| format(x)}.join(', '),
|
608
|
+
')',
|
609
|
+
';'
|
610
|
+
].join(''))
|
611
|
+
end,
|
612
|
+
*if node.supertype_expression
|
613
|
+
indent([
|
614
|
+
format(node.supertype_expression),
|
615
|
+
';'
|
616
|
+
].join(''))
|
617
|
+
end,
|
618
|
+
[
|
619
|
+
'END_SUBTYPE_CONSTRAINT',
|
620
|
+
';'
|
621
|
+
].join('')
|
622
|
+
].join("\n")
|
623
|
+
end
|
624
|
+
|
625
|
+
def format_type(node)
|
626
|
+
[
|
627
|
+
[
|
628
|
+
'TYPE',
|
629
|
+
' ',
|
630
|
+
node.id,
|
631
|
+
' ',
|
632
|
+
'=',
|
633
|
+
' ',
|
634
|
+
format(node.type),
|
635
|
+
';',
|
636
|
+
].join(''),
|
637
|
+
*if node.where and node.where.length > 0
|
638
|
+
indent([
|
639
|
+
'WHERE',
|
640
|
+
indent(node.where.map{|x| format(x)}.join("\n"))
|
641
|
+
].join("\n"))
|
642
|
+
end,
|
643
|
+
*format_scope_remarks(node),
|
644
|
+
[
|
645
|
+
'END_TYPE',
|
646
|
+
';'
|
647
|
+
].join('')
|
648
|
+
].join("\n")
|
649
|
+
end
|
650
|
+
|
651
|
+
def format_unique(node)
|
652
|
+
[
|
653
|
+
*if node.id
|
654
|
+
[
|
655
|
+
node.id,
|
656
|
+
' ',
|
657
|
+
':',
|
658
|
+
' '
|
659
|
+
].join('')
|
660
|
+
end,
|
661
|
+
node.attributes.map{|x| format(x)}.join(', '),
|
662
|
+
';'
|
663
|
+
].join('')
|
664
|
+
end
|
665
|
+
|
666
|
+
def format_variable(node)
|
667
|
+
[
|
668
|
+
node.id,
|
669
|
+
' ',
|
670
|
+
':',
|
671
|
+
' ',
|
672
|
+
format(node.type),
|
673
|
+
*if node.expression
|
674
|
+
[
|
675
|
+
' ',
|
676
|
+
':=',
|
677
|
+
' ',
|
678
|
+
format(node.expression),
|
679
|
+
].join('')
|
680
|
+
end,
|
681
|
+
';'
|
682
|
+
].join('')
|
683
|
+
end
|
684
|
+
|
685
|
+
def format_where(node)
|
686
|
+
[
|
687
|
+
*if node.id
|
688
|
+
[
|
689
|
+
node.id,
|
690
|
+
' ',
|
691
|
+
':',
|
692
|
+
' '
|
693
|
+
].join('')
|
694
|
+
end,
|
695
|
+
format(node.expression),
|
696
|
+
';'
|
697
|
+
].join('')
|
698
|
+
end
|
699
|
+
|
700
|
+
def format_expressions_aggregate_initializer(node)
|
701
|
+
[
|
702
|
+
'[',
|
703
|
+
node.items.map{|x| format(x)}.join(', '),
|
704
|
+
']'
|
705
|
+
].join('')
|
706
|
+
end
|
707
|
+
|
708
|
+
def format_expressions_aggregate_item(node)
|
709
|
+
[
|
710
|
+
format(node.expression),
|
711
|
+
':',
|
712
|
+
format(node.repetition)
|
713
|
+
].join('')
|
714
|
+
end
|
715
|
+
|
716
|
+
def format_expressions_attribute_reference(node)
|
717
|
+
[
|
718
|
+
format(node.ref),
|
719
|
+
'.',
|
720
|
+
format(node.attribute)
|
721
|
+
].join('')
|
722
|
+
end
|
723
|
+
|
724
|
+
def format_expressions_binary_expression(node)
|
725
|
+
[
|
726
|
+
*if node.operand1.instance_of? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand1.operator] > OPERATOR_PRECEDENCE[node.operator]
|
727
|
+
'('
|
728
|
+
end,
|
729
|
+
format(node.operand1),
|
730
|
+
*if node.operand1.instance_of? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand1.operator] > OPERATOR_PRECEDENCE[node.operator]
|
731
|
+
')'
|
732
|
+
end,
|
733
|
+
' ',
|
734
|
+
case node.operator
|
735
|
+
when Model::Expressions::BinaryExpression::ADDITION then '+'
|
736
|
+
when Model::Expressions::BinaryExpression::AND then 'AND'
|
737
|
+
when Model::Expressions::BinaryExpression::ANDOR then 'ANDOR'
|
738
|
+
when Model::Expressions::BinaryExpression::COMBINE then '||'
|
739
|
+
when Model::Expressions::BinaryExpression::EQUAL then '='
|
740
|
+
when Model::Expressions::BinaryExpression::EXPONENTIATION then '**'
|
741
|
+
when Model::Expressions::BinaryExpression::GREATER_THAN then '>'
|
742
|
+
when Model::Expressions::BinaryExpression::GREATER_THAN_OR_EQUAL then '>='
|
743
|
+
when Model::Expressions::BinaryExpression::IN then 'IN'
|
744
|
+
when Model::Expressions::BinaryExpression::INSTANCE_EQUAL then ':=:'
|
745
|
+
when Model::Expressions::BinaryExpression::INSTANCE_NOT_EQUAL then ':<>:'
|
746
|
+
when Model::Expressions::BinaryExpression::INTEGER_DIVISION then 'DIV'
|
747
|
+
when Model::Expressions::BinaryExpression::LESS_THAN then '<'
|
748
|
+
when Model::Expressions::BinaryExpression::LESS_THAN_OR_EQUAL then '<='
|
749
|
+
when Model::Expressions::BinaryExpression::LIKE then 'LIKE'
|
750
|
+
when Model::Expressions::BinaryExpression::MODULO then 'MOD'
|
751
|
+
when Model::Expressions::BinaryExpression::MULTIPLICATION then '*'
|
752
|
+
when Model::Expressions::BinaryExpression::NOT_EQUAL then '<>'
|
753
|
+
when Model::Expressions::BinaryExpression::OR then 'OR'
|
754
|
+
when Model::Expressions::BinaryExpression::REAL_DIVISION then '/'
|
755
|
+
when Model::Expressions::BinaryExpression::SUBTRACTION then '-'
|
756
|
+
when Model::Expressions::BinaryExpression::XOR then 'XOR'
|
757
|
+
end,
|
758
|
+
' ',
|
759
|
+
*if node.operand2.instance_of? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand2.operator] > OPERATOR_PRECEDENCE[node.operator]
|
760
|
+
'('
|
761
|
+
end,
|
762
|
+
format(node.operand2),
|
763
|
+
*if node.operand2.instance_of? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand2.operator] > OPERATOR_PRECEDENCE[node.operator]
|
764
|
+
')'
|
765
|
+
end,
|
766
|
+
].join('')
|
767
|
+
end
|
768
|
+
|
769
|
+
def format_expressions_call(node)
|
770
|
+
[
|
771
|
+
format(node.ref),
|
772
|
+
'(',
|
773
|
+
node.parameters.map{|x| format(x)}.join(', '),
|
774
|
+
')'
|
775
|
+
].join('')
|
776
|
+
end
|
777
|
+
|
778
|
+
def format_expressions_entity_constructor(node)
|
779
|
+
[
|
780
|
+
format(node.entity),
|
781
|
+
'(',
|
782
|
+
node.parameters.map{|x| format(x)}.join(', '),
|
783
|
+
')'
|
784
|
+
].join('')
|
785
|
+
end
|
786
|
+
|
787
|
+
def format_expressions_group_reference(node)
|
788
|
+
[
|
789
|
+
format(node.ref),
|
790
|
+
'\\',
|
791
|
+
format(node.entity)
|
792
|
+
].join('')
|
793
|
+
end
|
794
|
+
|
795
|
+
def format_expressions_index_reference(node)
|
796
|
+
[
|
797
|
+
format(node.ref),
|
798
|
+
'[',
|
799
|
+
format(node.index1),
|
800
|
+
*if node.index2
|
801
|
+
[
|
802
|
+
':',
|
803
|
+
format(node.index2)
|
804
|
+
].join('')
|
805
|
+
end,
|
806
|
+
']'
|
807
|
+
].join('')
|
808
|
+
end
|
809
|
+
|
810
|
+
def format_expressions_interval(node)
|
811
|
+
[
|
812
|
+
'{',
|
813
|
+
format(node.low),
|
814
|
+
' ',
|
815
|
+
case node.operator1
|
816
|
+
when Model::Expressions::BinaryExpression::LESS_THAN then '<'
|
817
|
+
when Model::Expressions::BinaryExpression::LESS_THAN_OR_EQUAL then '<='
|
818
|
+
end,
|
819
|
+
' ',
|
820
|
+
format(node.item),
|
821
|
+
' ',
|
822
|
+
case node.operator2
|
823
|
+
when Model::Expressions::BinaryExpression::LESS_THAN then '<'
|
824
|
+
when Model::Expressions::BinaryExpression::LESS_THAN_OR_EQUAL then '<='
|
825
|
+
end,
|
826
|
+
' ',
|
827
|
+
format(node.high),
|
828
|
+
'}'
|
829
|
+
].join('')
|
830
|
+
end
|
831
|
+
|
832
|
+
def format_expressions_query_expression(node)
|
833
|
+
[
|
834
|
+
'QUERY',
|
835
|
+
'(',
|
836
|
+
node.id,
|
837
|
+
' ',
|
838
|
+
'<*',
|
839
|
+
' ',
|
840
|
+
format(node.source),
|
841
|
+
' ',
|
842
|
+
'|',
|
843
|
+
' ',
|
844
|
+
format(node.expression),
|
845
|
+
*format_scope_remarks(node).instance_eval{|x| x.length > 0 ? ["\n", *x, "\n"] : x},
|
846
|
+
')'
|
847
|
+
].join('')
|
848
|
+
end
|
849
|
+
|
850
|
+
def format_expressions_simple_reference(node)
|
851
|
+
node.id
|
852
|
+
end
|
853
|
+
|
854
|
+
def format_expressions_unary_expression(node)
|
855
|
+
[
|
856
|
+
case node.operator
|
857
|
+
when Model::Expressions::UnaryExpression::MINUS then '-'
|
858
|
+
when Model::Expressions::UnaryExpression::NOT then 'NOT'
|
859
|
+
when Model::Expressions::UnaryExpression::PLUS then '+'
|
860
|
+
end,
|
861
|
+
if node.operator == Model::Expressions::UnaryExpression::NOT
|
862
|
+
' '
|
863
|
+
end,
|
864
|
+
*if node.operand.instance_of? Model::Expressions::BinaryExpression
|
865
|
+
'('
|
866
|
+
end,
|
867
|
+
format(node.operand),
|
868
|
+
*if node.operand.instance_of? Model::Expressions::BinaryExpression
|
869
|
+
')'
|
870
|
+
end
|
871
|
+
].join('')
|
872
|
+
end
|
873
|
+
|
874
|
+
def format_literals_binary(node)
|
875
|
+
[
|
876
|
+
'%',
|
877
|
+
node.value
|
878
|
+
].join('')
|
879
|
+
end
|
880
|
+
|
881
|
+
def format_literals_integer(node)
|
882
|
+
node.value
|
883
|
+
end
|
884
|
+
|
885
|
+
def format_literals_logical(node)
|
886
|
+
case node.value
|
887
|
+
when Model::Literals::Logical::TRUE then 'TRUE'
|
888
|
+
when Model::Literals::Logical::FALSE then 'FALSE'
|
889
|
+
when Model::Literals::Logical::UNKNOWN then 'UNKNOWN'
|
890
|
+
end
|
891
|
+
end
|
892
|
+
|
893
|
+
def format_literals_real(node)
|
894
|
+
node.value
|
895
|
+
end
|
896
|
+
|
897
|
+
def format_literals_string(node)
|
898
|
+
if node.encoded
|
899
|
+
[
|
900
|
+
"\"",
|
901
|
+
node.value,
|
902
|
+
"\""
|
903
|
+
].join('')
|
904
|
+
else
|
905
|
+
[
|
906
|
+
"'",
|
907
|
+
node.value,
|
908
|
+
"'"
|
909
|
+
].join('')
|
910
|
+
end
|
911
|
+
end
|
912
|
+
|
913
|
+
def format_statements_alias(node)
|
914
|
+
[
|
915
|
+
[
|
916
|
+
'ALIAS',
|
917
|
+
' ',
|
918
|
+
node.id,
|
919
|
+
' ',
|
920
|
+
'FOR',
|
921
|
+
' ',
|
922
|
+
format(node.expression),
|
923
|
+
';'
|
924
|
+
].join(''),
|
925
|
+
*if node.statements and node.statements.length > 0
|
926
|
+
indent(node.statements.map{|x| format(x)}.join("\n"))
|
927
|
+
end,
|
928
|
+
*format_scope_remarks(node),
|
929
|
+
[
|
930
|
+
'END_ALIAS',
|
931
|
+
';'
|
932
|
+
].join('')
|
933
|
+
].join("\n")
|
934
|
+
end
|
935
|
+
|
936
|
+
def format_statements_assignment(node)
|
937
|
+
[
|
938
|
+
format(node.ref),
|
939
|
+
' ',
|
940
|
+
':=',
|
941
|
+
' ',
|
942
|
+
format(node.expression),
|
943
|
+
';'
|
944
|
+
].join('')
|
945
|
+
end
|
946
|
+
|
947
|
+
def format_statements_call(node)
|
948
|
+
[
|
949
|
+
format(node.ref),
|
950
|
+
*if node.parameters and node.parameters.length > 0
|
951
|
+
[
|
952
|
+
'(',
|
953
|
+
node.parameters.map{|x| format(x)}.join(', '),
|
954
|
+
')'
|
955
|
+
].join('')
|
956
|
+
end,
|
957
|
+
';'
|
958
|
+
].join('')
|
959
|
+
end
|
960
|
+
|
961
|
+
def format_statements_case(node)
|
962
|
+
[
|
963
|
+
[
|
964
|
+
'CASE',
|
965
|
+
' ',
|
966
|
+
format(node.expression),
|
967
|
+
' ',
|
968
|
+
'OF'
|
969
|
+
].join(''),
|
970
|
+
*if node.actions and node.actions.length > 0
|
971
|
+
node.actions.map{|x| format(x)}
|
972
|
+
end,
|
973
|
+
*if node.otherwise_statement
|
974
|
+
[
|
975
|
+
[
|
976
|
+
'OTHERWISE',
|
977
|
+
' ',
|
978
|
+
':'
|
979
|
+
].join(''),
|
980
|
+
indent(format(node.otherwise_statement))
|
981
|
+
]
|
982
|
+
end,
|
983
|
+
[
|
984
|
+
'END_CASE',
|
985
|
+
';'
|
986
|
+
].join('')
|
987
|
+
].join("\n")
|
988
|
+
end
|
989
|
+
|
990
|
+
def format_statements_case_action(node)
|
991
|
+
[
|
992
|
+
[
|
993
|
+
node.labels.map{|x| format(x)}.join(', '),
|
994
|
+
' ',
|
995
|
+
':'
|
996
|
+
].join(''),
|
997
|
+
indent(format(node.statement))
|
998
|
+
].join("\n")
|
999
|
+
end
|
1000
|
+
|
1001
|
+
def format_statements_compound(node)
|
1002
|
+
[
|
1003
|
+
'BEGIN',
|
1004
|
+
*if node.statements and node.statements.length > 0
|
1005
|
+
indent(node.statements.map{|x| format(x)}.join("\n"))
|
1006
|
+
end,
|
1007
|
+
[
|
1008
|
+
'END',
|
1009
|
+
';'
|
1010
|
+
].join('')
|
1011
|
+
].join("\n")
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
def format_statements_escape(node)
|
1015
|
+
[
|
1016
|
+
'ESCAPE',
|
1017
|
+
';'
|
1018
|
+
].join('')
|
1019
|
+
end
|
1020
|
+
|
1021
|
+
def format_statements_if(node)
|
1022
|
+
[
|
1023
|
+
[
|
1024
|
+
'IF',
|
1025
|
+
' ',
|
1026
|
+
format(node.expression),
|
1027
|
+
' ',
|
1028
|
+
'THEN'
|
1029
|
+
].join(''),
|
1030
|
+
*if node.statements and node.statements.length > 0
|
1031
|
+
indent(node.statements.map{|x| format(x)}.join("\n"))
|
1032
|
+
end,
|
1033
|
+
*if node.else_statements and node.else_statements.length > 0
|
1034
|
+
[
|
1035
|
+
'ELSE',
|
1036
|
+
indent(node.else_statements.map{|x| format(x)}.join("\n")),
|
1037
|
+
].join("\n")
|
1038
|
+
end,
|
1039
|
+
[
|
1040
|
+
'END_IF',
|
1041
|
+
';'
|
1042
|
+
].join('')
|
1043
|
+
].join("\n")
|
1044
|
+
end
|
1045
|
+
|
1046
|
+
def format_statements_null(node)
|
1047
|
+
';'
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
def format_statements_repeat(node)
|
1051
|
+
[
|
1052
|
+
[
|
1053
|
+
'REPEAT',
|
1054
|
+
*if node.id
|
1055
|
+
[
|
1056
|
+
' ',
|
1057
|
+
node.id,
|
1058
|
+
' ',
|
1059
|
+
':=',
|
1060
|
+
' ',
|
1061
|
+
format(node.bound1),
|
1062
|
+
' ',
|
1063
|
+
'TO',
|
1064
|
+
' ',
|
1065
|
+
format(node.bound2),
|
1066
|
+
*if node.increment
|
1067
|
+
[
|
1068
|
+
' ',
|
1069
|
+
'BY',
|
1070
|
+
' ',
|
1071
|
+
format(node.increment)
|
1072
|
+
].join('')
|
1073
|
+
end
|
1074
|
+
].join('')
|
1075
|
+
end,
|
1076
|
+
*if node.while_expression
|
1077
|
+
[
|
1078
|
+
' ',
|
1079
|
+
'WHILE',
|
1080
|
+
' ',
|
1081
|
+
format(node.while_expression)
|
1082
|
+
].join('')
|
1083
|
+
end,
|
1084
|
+
*if node.until_expression
|
1085
|
+
[
|
1086
|
+
' ',
|
1087
|
+
'UNTIL',
|
1088
|
+
' ',
|
1089
|
+
format(node.until_expression)
|
1090
|
+
].join('')
|
1091
|
+
end,
|
1092
|
+
';'
|
1093
|
+
].join(''),
|
1094
|
+
*if node.statements and node.statements.length > 0
|
1095
|
+
indent(node.statements.map{|x| format(x)}.join("\n"))
|
1096
|
+
end,
|
1097
|
+
*format_scope_remarks(node),
|
1098
|
+
[
|
1099
|
+
'END_REPEAT',
|
1100
|
+
';'
|
1101
|
+
].join('')
|
1102
|
+
].join("\n")
|
1103
|
+
end
|
1104
|
+
|
1105
|
+
def format_statements_return(node)
|
1106
|
+
[
|
1107
|
+
'RETURN',
|
1108
|
+
*if node.expression
|
1109
|
+
[
|
1110
|
+
' ',
|
1111
|
+
'(',
|
1112
|
+
format(node.expression),
|
1113
|
+
')'
|
1114
|
+
].join('')
|
1115
|
+
end,
|
1116
|
+
';'
|
1117
|
+
].join('')
|
1118
|
+
end
|
1119
|
+
|
1120
|
+
def format_statements_skip(node)
|
1121
|
+
[
|
1122
|
+
'SKIP',
|
1123
|
+
';'
|
1124
|
+
].join('')
|
1125
|
+
end
|
1126
|
+
|
1127
|
+
def format_types_aggregate(node)
|
1128
|
+
'AGGREGATE'
|
1129
|
+
end
|
1130
|
+
|
1131
|
+
def format_types_array(node)
|
1132
|
+
[
|
1133
|
+
'ARRAY',
|
1134
|
+
*if node.bound1 and node.bound2
|
1135
|
+
[
|
1136
|
+
' ',
|
1137
|
+
'[',
|
1138
|
+
format(node.bound1),
|
1139
|
+
':',
|
1140
|
+
format(node.bound2),
|
1141
|
+
']',
|
1142
|
+
].join('')
|
1143
|
+
end,
|
1144
|
+
' ',
|
1145
|
+
'OF',
|
1146
|
+
*if node.optional
|
1147
|
+
[
|
1148
|
+
' ',
|
1149
|
+
'OPTIONAL'
|
1150
|
+
].join('')
|
1151
|
+
end,
|
1152
|
+
*if node.unique
|
1153
|
+
[
|
1154
|
+
' ',
|
1155
|
+
'UNIQUE'
|
1156
|
+
].join('')
|
1157
|
+
end,
|
1158
|
+
' ',
|
1159
|
+
format(node.base_type)
|
1160
|
+
].join('')
|
1161
|
+
end
|
1162
|
+
|
1163
|
+
def format_types_bag(node)
|
1164
|
+
[
|
1165
|
+
'BAG',
|
1166
|
+
*if node.bound1 and node.bound2
|
1167
|
+
[
|
1168
|
+
' ',
|
1169
|
+
'[',
|
1170
|
+
format(node.bound1),
|
1171
|
+
':',
|
1172
|
+
format(node.bound2),
|
1173
|
+
']',
|
1174
|
+
].join('')
|
1175
|
+
end,
|
1176
|
+
' ',
|
1177
|
+
'OF',
|
1178
|
+
' ',
|
1179
|
+
format(node.base_type)
|
1180
|
+
].join('')
|
1181
|
+
end
|
1182
|
+
|
1183
|
+
def format_types_binary(node)
|
1184
|
+
[
|
1185
|
+
'BINARY',
|
1186
|
+
*if node.width
|
1187
|
+
[
|
1188
|
+
' ',
|
1189
|
+
'(',
|
1190
|
+
format(node.width),
|
1191
|
+
')'
|
1192
|
+
].join('')
|
1193
|
+
end,
|
1194
|
+
*if node.fixed
|
1195
|
+
[
|
1196
|
+
' ',
|
1197
|
+
'FIXED'
|
1198
|
+
].join('')
|
1199
|
+
end
|
1200
|
+
].join('')
|
1201
|
+
end
|
1202
|
+
|
1203
|
+
def format_types_boolean(node)
|
1204
|
+
'BOOLEAN'
|
1205
|
+
end
|
1206
|
+
|
1207
|
+
def format_types_enumeration(node)
|
1208
|
+
[
|
1209
|
+
*if node.extensible
|
1210
|
+
[
|
1211
|
+
'EXTENSIBLE',
|
1212
|
+
' '
|
1213
|
+
].join('')
|
1214
|
+
end,
|
1215
|
+
'ENUMERATION',
|
1216
|
+
*if node.items and node.items.length > 0
|
1217
|
+
[
|
1218
|
+
' ',
|
1219
|
+
'OF',
|
1220
|
+
' ',
|
1221
|
+
'(',
|
1222
|
+
node.items.map{|x| format(x)}.join(', '),
|
1223
|
+
')'
|
1224
|
+
].join('')
|
1225
|
+
end,
|
1226
|
+
*if node.extension_type
|
1227
|
+
[
|
1228
|
+
' ',
|
1229
|
+
'BASED_ON',
|
1230
|
+
' ',
|
1231
|
+
format(node.extension_type)
|
1232
|
+
].join('')
|
1233
|
+
end,
|
1234
|
+
*if node.extension_items
|
1235
|
+
[
|
1236
|
+
' ',
|
1237
|
+
'WITH',
|
1238
|
+
' ',
|
1239
|
+
'(',
|
1240
|
+
node.extension_items.map{|x| format(x)}.join(', '),
|
1241
|
+
')'
|
1242
|
+
].join('')
|
1243
|
+
end
|
1244
|
+
].join('')
|
1245
|
+
end
|
1246
|
+
|
1247
|
+
def format_types_generic_entity(node)
|
1248
|
+
'GENERIC_ENTITY'
|
1249
|
+
end
|
1250
|
+
|
1251
|
+
def format_types_generic(node)
|
1252
|
+
'GENERIC'
|
1253
|
+
end
|
1254
|
+
|
1255
|
+
def format_types_integer(node)
|
1256
|
+
'INTEGER'
|
1257
|
+
end
|
1258
|
+
|
1259
|
+
def format_types_list(node)
|
1260
|
+
[
|
1261
|
+
'LIST',
|
1262
|
+
*if node.bound1 and node.bound2
|
1263
|
+
[
|
1264
|
+
' ',
|
1265
|
+
'[',
|
1266
|
+
format(node.bound1),
|
1267
|
+
':',
|
1268
|
+
format(node.bound2),
|
1269
|
+
']',
|
1270
|
+
].join('')
|
1271
|
+
end,
|
1272
|
+
' ',
|
1273
|
+
'OF',
|
1274
|
+
*if node.unique
|
1275
|
+
[
|
1276
|
+
' ',
|
1277
|
+
'UNIQUE'
|
1278
|
+
].join('')
|
1279
|
+
end,
|
1280
|
+
' ',
|
1281
|
+
format(node.base_type)
|
1282
|
+
].join('')
|
1283
|
+
end
|
1284
|
+
|
1285
|
+
def format_types_logical(node)
|
1286
|
+
'LOGICAL'
|
1287
|
+
end
|
1288
|
+
|
1289
|
+
def format_types_number(node)
|
1290
|
+
'NUMBER'
|
1291
|
+
end
|
1292
|
+
|
1293
|
+
def format_types_real(node)
|
1294
|
+
[
|
1295
|
+
'REAL',
|
1296
|
+
*if node.precision
|
1297
|
+
[
|
1298
|
+
' ',
|
1299
|
+
'(',
|
1300
|
+
format(node.precision),
|
1301
|
+
')'
|
1302
|
+
].join('')
|
1303
|
+
end
|
1304
|
+
].join('')
|
1305
|
+
end
|
1306
|
+
|
1307
|
+
def format_types_select(node)
|
1308
|
+
[
|
1309
|
+
*if node.extensible
|
1310
|
+
[
|
1311
|
+
'EXTENSIBLE',
|
1312
|
+
' '
|
1313
|
+
].join('')
|
1314
|
+
end,
|
1315
|
+
*if node.generic_entity
|
1316
|
+
[
|
1317
|
+
'GENERIC_ENTITY',
|
1318
|
+
' '
|
1319
|
+
].join('')
|
1320
|
+
end,
|
1321
|
+
'SELECT',
|
1322
|
+
*if node.items and node.items.length > 0
|
1323
|
+
[
|
1324
|
+
' ',
|
1325
|
+
'(',
|
1326
|
+
node.items.map{|x| format(x)}.join(', '),
|
1327
|
+
')'
|
1328
|
+
].join('')
|
1329
|
+
end,
|
1330
|
+
*if node.extension_type
|
1331
|
+
[
|
1332
|
+
' ',
|
1333
|
+
'BASED_ON',
|
1334
|
+
' ',
|
1335
|
+
format(node.extension_type)
|
1336
|
+
].join('')
|
1337
|
+
end,
|
1338
|
+
*if node.extension_items
|
1339
|
+
[
|
1340
|
+
' ',
|
1341
|
+
'WITH',
|
1342
|
+
' ',
|
1343
|
+
'(',
|
1344
|
+
node.extension_items.map{|x| format(x)}.join(', '),
|
1345
|
+
')'
|
1346
|
+
].join('')
|
1347
|
+
end
|
1348
|
+
].join('')
|
1349
|
+
end
|
1350
|
+
|
1351
|
+
def format_types_set(node)
|
1352
|
+
[
|
1353
|
+
'SET',
|
1354
|
+
*if node.bound1 and node.bound2
|
1355
|
+
[
|
1356
|
+
' ',
|
1357
|
+
'[',
|
1358
|
+
format(node.bound1),
|
1359
|
+
':',
|
1360
|
+
format(node.bound2),
|
1361
|
+
']',
|
1362
|
+
].join('')
|
1363
|
+
end,
|
1364
|
+
' ',
|
1365
|
+
'OF',
|
1366
|
+
' ',
|
1367
|
+
format(node.base_type)
|
1368
|
+
].join('')
|
1369
|
+
end
|
1370
|
+
|
1371
|
+
def format_types_string(node)
|
1372
|
+
[
|
1373
|
+
'STRING',
|
1374
|
+
*if node.width
|
1375
|
+
[
|
1376
|
+
' ',
|
1377
|
+
'(',
|
1378
|
+
format(node.width),
|
1379
|
+
')'
|
1380
|
+
].join('')
|
1381
|
+
end,
|
1382
|
+
*if node.fixed
|
1383
|
+
[
|
1384
|
+
' ',
|
1385
|
+
'FIXED'
|
1386
|
+
].join('')
|
1387
|
+
end
|
1388
|
+
].join('')
|
1389
|
+
end
|
1390
|
+
|
1391
|
+
def indent(str)
|
1392
|
+
str.split("\n").map{|x| "#{INDENT}#{x}"}.join("\n")
|
1393
|
+
end
|
1394
|
+
|
1395
|
+
def format_remark(node, remark)
|
1396
|
+
if remark.include?("\n")
|
1397
|
+
[
|
1398
|
+
[
|
1399
|
+
'(*',
|
1400
|
+
'"',
|
1401
|
+
format_remark_ref(node),
|
1402
|
+
'"',
|
1403
|
+
].join(''),
|
1404
|
+
remark,
|
1405
|
+
'*)'
|
1406
|
+
].join("\n")
|
1407
|
+
else
|
1408
|
+
[
|
1409
|
+
'--',
|
1410
|
+
'"',
|
1411
|
+
format_remark_ref(node),
|
1412
|
+
'"',
|
1413
|
+
' ',
|
1414
|
+
remark
|
1415
|
+
].join('')
|
1416
|
+
end
|
1417
|
+
end
|
1418
|
+
|
1419
|
+
def format_remark_ref(node)
|
1420
|
+
[
|
1421
|
+
*if node.class.method_defined? :parent and node.parent != node
|
1422
|
+
[
|
1423
|
+
node.parent.id,
|
1424
|
+
'.'
|
1425
|
+
].join('')
|
1426
|
+
end,
|
1427
|
+
node.id,
|
1428
|
+
].join('')
|
1429
|
+
end
|
1430
|
+
|
1431
|
+
def format_scope_remarks(node)
|
1432
|
+
node.children.flat_map do |x|
|
1433
|
+
if x.remarks and x.remarks.length > 0
|
1434
|
+
x.remarks.map do |remark|
|
1435
|
+
format_remark(x, remark)
|
1436
|
+
end
|
1437
|
+
else
|
1438
|
+
[]
|
1439
|
+
end
|
1440
|
+
end
|
1441
|
+
end
|
1442
|
+
end
|
1443
|
+
end
|
1444
|
+
end
|