expressir 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -13
  3. data/.rubocop_todo.yml +69 -6
  4. data/Gemfile +1 -1
  5. data/README.adoc +46 -0
  6. data/exe/expressir-format-test +2 -1
  7. data/expressir.gemspec +2 -3
  8. data/lib/expressir/express/cache.rb +6 -6
  9. data/lib/expressir/express/formatter.rb +754 -741
  10. data/lib/expressir/express/hyperlink_formatter.rb +2 -2
  11. data/lib/expressir/express/model_visitor.rb +1 -1
  12. data/lib/expressir/express/parser.rb +224 -100
  13. data/lib/expressir/express/resolve_references_model_visitor.rb +6 -6
  14. data/lib/expressir/express/schema_head_formatter.rb +3 -3
  15. data/lib/expressir/express/visitor.rb +353 -344
  16. data/lib/expressir/model/cache.rb +3 -3
  17. data/lib/expressir/model/data_type.rb +1 -1
  18. data/lib/expressir/model/data_types/aggregate.rb +3 -3
  19. data/lib/expressir/model/data_types/array.rb +6 -6
  20. data/lib/expressir/model/data_types/bag.rb +4 -4
  21. data/lib/expressir/model/data_types/binary.rb +3 -3
  22. data/lib/expressir/model/data_types/boolean.rb +1 -1
  23. data/lib/expressir/model/data_types/enumeration.rb +4 -4
  24. data/lib/expressir/model/data_types/enumeration_item.rb +2 -2
  25. data/lib/expressir/model/data_types/generic.rb +2 -2
  26. data/lib/expressir/model/data_types/generic_entity.rb +2 -2
  27. data/lib/expressir/model/data_types/integer.rb +1 -1
  28. data/lib/expressir/model/data_types/list.rb +5 -5
  29. data/lib/expressir/model/data_types/logical.rb +1 -1
  30. data/lib/expressir/model/data_types/number.rb +1 -1
  31. data/lib/expressir/model/data_types/real.rb +2 -2
  32. data/lib/expressir/model/data_types/select.rb +5 -5
  33. data/lib/expressir/model/data_types/set.rb +4 -4
  34. data/lib/expressir/model/data_types/string.rb +3 -3
  35. data/lib/expressir/model/declaration.rb +1 -1
  36. data/lib/expressir/model/declarations/attribute.rb +7 -7
  37. data/lib/expressir/model/declarations/constant.rb +4 -4
  38. data/lib/expressir/model/declarations/entity.rb +9 -9
  39. data/lib/expressir/model/declarations/function.rb +13 -13
  40. data/lib/expressir/model/declarations/interface.rb +4 -4
  41. data/lib/expressir/model/declarations/interface_item.rb +3 -3
  42. data/lib/expressir/model/declarations/interfaced_item.rb +6 -6
  43. data/lib/expressir/model/declarations/parameter.rb +4 -4
  44. data/lib/expressir/model/declarations/procedure.rb +12 -12
  45. data/lib/expressir/model/declarations/remark_item.rb +3 -3
  46. data/lib/expressir/model/declarations/rule.rb +14 -14
  47. data/lib/expressir/model/declarations/schema.rb +18 -18
  48. data/lib/expressir/model/declarations/schema_version.rb +3 -3
  49. data/lib/expressir/model/declarations/schema_version_item.rb +3 -3
  50. data/lib/expressir/model/declarations/subtype_constraint.rb +6 -6
  51. data/lib/expressir/model/declarations/type.rb +5 -5
  52. data/lib/expressir/model/declarations/unique_rule.rb +3 -3
  53. data/lib/expressir/model/declarations/variable.rb +4 -4
  54. data/lib/expressir/model/declarations/where_rule.rb +3 -3
  55. data/lib/expressir/model/expression.rb +1 -1
  56. data/lib/expressir/model/expressions/aggregate_initializer.rb +2 -2
  57. data/lib/expressir/model/expressions/aggregate_initializer_item.rb +3 -3
  58. data/lib/expressir/model/expressions/binary_expression.rb +12 -5
  59. data/lib/expressir/model/expressions/entity_constructor.rb +3 -3
  60. data/lib/expressir/model/expressions/function_call.rb +3 -3
  61. data/lib/expressir/model/expressions/interval.rb +6 -6
  62. data/lib/expressir/model/expressions/query_expression.rb +4 -4
  63. data/lib/expressir/model/expressions/unary_expression.rb +3 -3
  64. data/lib/expressir/model/identifier.rb +5 -5
  65. data/lib/expressir/model/literal.rb +1 -1
  66. data/lib/expressir/model/literals/binary.rb +2 -2
  67. data/lib/expressir/model/literals/integer.rb +2 -2
  68. data/lib/expressir/model/literals/logical.rb +2 -2
  69. data/lib/expressir/model/literals/real.rb +2 -2
  70. data/lib/expressir/model/literals/string.rb +3 -3
  71. data/lib/expressir/model/model_element.rb +35 -41
  72. data/lib/expressir/model/reference.rb +1 -1
  73. data/lib/expressir/model/references/attribute_reference.rb +3 -3
  74. data/lib/expressir/model/references/group_reference.rb +3 -3
  75. data/lib/expressir/model/references/index_reference.rb +4 -4
  76. data/lib/expressir/model/references/simple_reference.rb +3 -3
  77. data/lib/expressir/model/repository.rb +3 -4
  78. data/lib/expressir/model/statement.rb +1 -1
  79. data/lib/expressir/model/statements/alias.rb +4 -4
  80. data/lib/expressir/model/statements/assignment.rb +3 -3
  81. data/lib/expressir/model/statements/case.rb +4 -4
  82. data/lib/expressir/model/statements/case_action.rb +3 -3
  83. data/lib/expressir/model/statements/compound.rb +2 -2
  84. data/lib/expressir/model/statements/escape.rb +1 -1
  85. data/lib/expressir/model/statements/if.rb +4 -4
  86. data/lib/expressir/model/statements/null.rb +1 -1
  87. data/lib/expressir/model/statements/procedure_call.rb +3 -3
  88. data/lib/expressir/model/statements/repeat.rb +8 -8
  89. data/lib/expressir/model/statements/return.rb +2 -2
  90. data/lib/expressir/model/statements/skip.rb +1 -1
  91. data/lib/expressir/model/supertype_expression.rb +1 -1
  92. data/lib/expressir/model/supertype_expressions/binary_supertype_expression.rb +4 -4
  93. data/lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb +2 -2
  94. data/lib/expressir/version.rb +1 -1
  95. 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 = self.new
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
- if node.is_a? Model::Repository
55
+ case node
56
+ when Model::Repository
56
57
  format_repository(node)
57
- elsif node.is_a? Model::Declarations::Attribute
58
+ when Model::Declarations::Attribute
58
59
  format_declarations_attribute(node)
59
- elsif node.is_a? Model::Declarations::Constant
60
+ when Model::Declarations::Constant
60
61
  format_declarations_constant(node)
61
- elsif node.is_a? Model::Declarations::Entity
62
+ when Model::Declarations::Entity
62
63
  format_declarations_entity(node)
63
- elsif node.is_a? Model::Declarations::Function
64
+ when Model::Declarations::Function
64
65
  format_declarations_function(node)
65
- elsif node.is_a? Model::Declarations::Interface
66
+ when Model::Declarations::Interface
66
67
  format_declarations_interface(node)
67
- elsif node.is_a? Model::Declarations::InterfaceItem
68
+ when Model::Declarations::InterfaceItem
68
69
  format_declarations_interface_item(node)
69
- elsif node.is_a? Model::Declarations::Parameter
70
+ when Model::Declarations::Parameter
70
71
  format_declarations_parameter(node)
71
- elsif node.is_a? Model::Declarations::Procedure
72
+ when Model::Declarations::Procedure
72
73
  format_declarations_procedure(node)
73
- elsif node.is_a? Model::Declarations::Rule
74
+ when Model::Declarations::Rule
74
75
  format_declarations_rule(node)
75
- elsif node.is_a? Model::Declarations::Schema
76
+ when Model::Declarations::Schema
76
77
  format_declarations_schema(node)
77
- elsif node.is_a? Model::Declarations::SchemaVersion
78
+ when Model::Declarations::SchemaVersion
78
79
  format_declarations_schema_version(node)
79
- elsif node.is_a? Model::Declarations::SubtypeConstraint
80
+ when Model::Declarations::SubtypeConstraint
80
81
  format_declarations_subtype_constraint(node)
81
- elsif node.is_a? Model::Declarations::Type
82
+ when Model::Declarations::Type
82
83
  format_declarations_type(node)
83
- elsif node.is_a? Model::Declarations::UniqueRule
84
+ when Model::Declarations::UniqueRule
84
85
  format_declarations_unique_rule(node)
85
- elsif node.is_a? Model::Declarations::Variable
86
+ when Model::Declarations::Variable
86
87
  format_declarations_variable(node)
87
- elsif node.is_a? Model::Declarations::WhereRule
88
+ when Model::Declarations::WhereRule
88
89
  format_declarations_where_rule(node)
89
- elsif node.is_a? Model::DataTypes::Aggregate
90
+ when Model::DataTypes::Aggregate
90
91
  format_data_types_aggregate(node)
91
- elsif node.is_a? Model::DataTypes::Array
92
+ when Model::DataTypes::Array
92
93
  format_data_types_array(node)
93
- elsif node.is_a? Model::DataTypes::Bag
94
+ when Model::DataTypes::Bag
94
95
  format_data_types_bag(node)
95
- elsif node.is_a? Model::DataTypes::Binary
96
+ when Model::DataTypes::Binary
96
97
  format_data_types_binary(node)
97
- elsif node.is_a? Model::DataTypes::Boolean
98
+ when Model::DataTypes::Boolean
98
99
  format_data_types_boolean(node)
99
- elsif node.is_a? Model::DataTypes::Enumeration
100
+ when Model::DataTypes::Enumeration
100
101
  format_data_types_enumeration(node)
101
- elsif node.is_a? Model::DataTypes::EnumerationItem
102
+ when Model::DataTypes::EnumerationItem
102
103
  format_data_types_enumeration_item(node)
103
- elsif node.is_a? Model::DataTypes::GenericEntity
104
+ when Model::DataTypes::GenericEntity
104
105
  format_data_types_generic_entity(node)
105
- elsif node.is_a? Model::DataTypes::Generic
106
+ when Model::DataTypes::Generic
106
107
  format_data_types_generic(node)
107
- elsif node.is_a? Model::DataTypes::Integer
108
+ when Model::DataTypes::Integer
108
109
  format_data_types_integer(node)
109
- elsif node.is_a? Model::DataTypes::List
110
+ when Model::DataTypes::List
110
111
  format_data_types_list(node)
111
- elsif node.is_a? Model::DataTypes::Logical
112
+ when Model::DataTypes::Logical
112
113
  format_data_types_logical(node)
113
- elsif node.is_a? Model::DataTypes::Number
114
+ when Model::DataTypes::Number
114
115
  format_data_types_number(node)
115
- elsif node.is_a? Model::DataTypes::Real
116
+ when Model::DataTypes::Real
116
117
  format_data_types_real(node)
117
- elsif node.is_a? Model::DataTypes::Select
118
+ when Model::DataTypes::Select
118
119
  format_data_types_select(node)
119
- elsif node.is_a? Model::DataTypes::Set
120
+ when Model::DataTypes::Set
120
121
  format_data_types_set(node)
121
- elsif node.is_a? Model::DataTypes::String
122
+ when Model::DataTypes::String
122
123
  format_data_types_string(node)
123
- elsif node.is_a? Model::Expressions::AggregateInitializer
124
+ when Model::Expressions::AggregateInitializer
124
125
  format_expressions_aggregate_initializer(node)
125
- elsif node.is_a? Model::Expressions::AggregateInitializerItem
126
+ when Model::Expressions::AggregateInitializerItem
126
127
  format_expressions_aggregate_initializer_item(node)
127
- elsif node.is_a? Model::Expressions::BinaryExpression
128
+ when Model::Expressions::BinaryExpression
128
129
  format_expressions_binary_expression(node)
129
- elsif node.is_a? Model::Expressions::EntityConstructor
130
+ when Model::Expressions::EntityConstructor
130
131
  format_expressions_entity_constructor(node)
131
- elsif node.is_a? Model::Expressions::FunctionCall
132
+ when Model::Expressions::FunctionCall
132
133
  format_expressions_function_call(node)
133
- elsif node.is_a? Model::Expressions::Interval
134
+ when Model::Expressions::Interval
134
135
  format_expressions_interval(node)
135
- elsif node.is_a? Model::Expressions::QueryExpression
136
+ when Model::Expressions::QueryExpression
136
137
  format_expressions_query_expression(node)
137
- elsif node.is_a? Model::Expressions::UnaryExpression
138
+ when Model::Expressions::UnaryExpression
138
139
  format_expressions_unary_expression(node)
139
- elsif node.is_a? Model::Literals::Binary
140
+ when Model::Literals::Binary
140
141
  format_literals_binary(node)
141
- elsif node.is_a? Model::Literals::Integer
142
+ when Model::Literals::Integer
142
143
  format_literals_integer(node)
143
- elsif node.is_a? Model::Literals::Logical
144
+ when Model::Literals::Logical
144
145
  format_literals_logical(node)
145
- elsif node.is_a? Model::Literals::Real
146
+ when Model::Literals::Real
146
147
  format_literals_real(node)
147
- elsif node.is_a? Model::Literals::String
148
+ when Model::Literals::String
148
149
  format_literals_string(node)
149
- elsif node.is_a? Model::References::AttributeReference
150
+ when Model::References::AttributeReference
150
151
  format_references_attribute_reference(node)
151
- elsif node.is_a? Model::References::GroupReference
152
+ when Model::References::GroupReference
152
153
  format_references_group_reference(node)
153
- elsif node.is_a? Model::References::IndexReference
154
+ when Model::References::IndexReference
154
155
  format_references_index_reference(node)
155
- elsif node.is_a? Model::References::SimpleReference
156
+ when Model::References::SimpleReference
156
157
  format_references_simple_reference(node)
157
- elsif node.is_a? Model::Statements::Alias
158
+ when Model::Statements::Alias
158
159
  format_statements_alias(node)
159
- elsif node.is_a? Model::Statements::Assignment
160
+ when Model::Statements::Assignment
160
161
  format_statements_assignment(node)
161
- elsif node.is_a? Model::Statements::Case
162
+ when Model::Statements::Case
162
163
  format_statements_case(node)
163
- elsif node.is_a? Model::Statements::CaseAction
164
+ when Model::Statements::CaseAction
164
165
  format_statements_case_action(node)
165
- elsif node.is_a? Model::Statements::Compound
166
+ when Model::Statements::Compound
166
167
  format_statements_compound(node)
167
- elsif node.is_a? Model::Statements::Escape
168
+ when Model::Statements::Escape
168
169
  format_statements_escape(node)
169
- elsif node.is_a? Model::Statements::If
170
+ when Model::Statements::If
170
171
  format_statements_if(node)
171
- elsif node.is_a? Model::Statements::Null
172
+ when Model::Statements::Null
172
173
  format_statements_null(node)
173
- elsif node.is_a? Model::Statements::ProcedureCall
174
+ when Model::Statements::ProcedureCall
174
175
  format_statements_procedure_call(node)
175
- elsif node.is_a? Model::Statements::Repeat
176
+ when Model::Statements::Repeat
176
177
  format_statements_repeat(node)
177
- elsif node.is_a? Model::Statements::Return
178
+ when Model::Statements::Return
178
179
  format_statements_return(node)
179
- elsif node.is_a? Model::Statements::Skip
180
+ when Model::Statements::Skip
180
181
  format_statements_skip(node)
181
- elsif node.is_a? Model::SupertypeExpressions::BinarySupertypeExpression
182
+ when Model::SupertypeExpressions::BinarySupertypeExpression
182
183
  format_supertype_expressions_binary_supertype_expression(node)
183
- elsif node.is_a? Model::SupertypeExpressions::OneofSupertypeExpression
184
+ when Model::SupertypeExpressions::OneofSupertypeExpression
184
185
  format_supertype_expressions_oneof_supertype_expression(node)
185
186
  else
186
- STDERR.puts "#{node.class.name} format not implemented"
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
- format(node.supertype_attribute),
202
- " ",
203
- ].join("")
204
- end,
205
- *if node.supertype_attribute and node.id
206
- [
207
- "RENAMED",
208
- " ",
209
- ].join("")
210
- end,
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
- node.id,
214
- " ",
215
- ].join("")
216
- end,
213
+ [
214
+ node.id,
215
+ " ",
216
+ ].join("")
217
+ end,
217
218
  ":",
218
219
  *if node.optional
219
- [
220
- " ",
221
- "OPTIONAL",
222
- ].join("")
223
- end,
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
- format(node.expression),
232
- ].join("")
233
- elsif node.kind == Model::Declarations::Attribute::INVERSE
234
- [
235
- " ",
236
- "FOR",
237
- " ",
238
- format(node.expression),
239
- ].join("")
240
- end,
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 and !node.supertype_expression
271
- [
272
- "\n",
273
- indent([
274
- "ABSTRACT",
275
- " ",
276
- "SUPERTYPE",
277
- ].join("")),
278
- ].join("")
279
- end,
280
- *if node.abstract and node.supertype_expression
281
- [
282
- "\n",
283
- indent([
284
- "ABSTRACT",
285
- " ",
286
- "SUPERTYPE",
287
- " ",
288
- "OF",
289
- " ",
290
- "(",
291
- format(node.supertype_expression),
292
- ")",
293
- ].join("")),
294
- ].join("")
295
- end,
296
- *if !node.abstract and node.supertype_expression
297
- [
298
- "\n",
299
- indent([
300
- "SUPERTYPE",
301
- " ",
302
- "OF",
303
- " ",
304
- "(",
305
- format(node.supertype_expression),
306
- ")",
307
- ].join("")),
308
- ].join("")
309
- end,
310
- *if node.subtype_of.length > 0
311
- [
312
- "\n",
313
- indent([
314
- "SUBTYPE",
315
- " ",
316
- "OF",
317
- " ",
318
- "(",
319
- node.subtype_of.map { |x| format(x) }.join(", "),
320
- ")",
321
- ].join("")),
322
- ].join("")
323
- end,
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 and explicit_attributes.length > 0
327
- indent(explicit_attributes.map { |x| format(x) }.join("\n"))
328
- end,
329
- *if derived_attributes and derived_attributes.length > 0
330
- [
331
- "DERIVE",
332
- indent(derived_attributes.map { |x| format(x) }.join("\n")),
333
- ]
334
- end,
335
- *if inverse_attributes and inverse_attributes.length > 0
336
- [
337
- "INVERSE",
338
- indent(inverse_attributes.map { |x| format(x) }.join("\n")),
339
- ]
340
- end,
341
- *if node.unique_rules.length > 0
342
- [
343
- "UNIQUE",
344
- indent(node.unique_rules.map { |x| format(x) }.join("\n")),
345
- ]
346
- end,
347
- *if node.where_rules.length > 0
348
- [
349
- "WHERE",
350
- indent(node.where_rules.map { |x| format(x) }.join("\n")),
351
- ]
352
- end,
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 > 0
367
- parameter_indent = INDENT_CHAR * "FUNCTION #{node.id}(".length
368
- [
369
- "(",
370
- node.parameters.map { |x| format(x) }.join(";\n#{parameter_indent}"),
371
- ")",
372
- ].join("")
373
- end,
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 > 0
381
- indent(node.types.map { |x| format(x) }.join("\n"))
382
- end,
383
- *if node.entities.length > 0
384
- indent(node.entities.map { |x| format(x) }.join("\n"))
385
- end,
386
- *if node.subtype_constraints.length > 0
387
- indent(node.subtype_constraints.map { |x| format(x) }.join("\n"))
388
- end,
389
- *if node.functions.length > 0
390
- indent(node.functions.map { |x| format(x) }.join("\n"))
391
- end,
392
- *if node.procedures.length > 0
393
- indent(node.procedures.map { |x| format(x) }.join("\n"))
394
- end,
395
- *if node.constants.length > 0
396
- indent([
397
- "CONSTANT",
398
- indent(node.constants.map { |x| format(x) }.join("\n")),
399
- [
400
- "END_CONSTANT",
401
- ";",
402
- ].join(""),
403
- ].join("\n"))
404
- end,
405
- *if node.variables.length > 0
406
- indent([
407
- "LOCAL",
408
- indent(node.variables.map { |x| format(x) }.join("\n")),
409
- [
410
- "END_LOCAL",
411
- ";",
412
- ].join(""),
413
- ].join("\n"))
414
- end,
415
- *if node.statements.length > 0
416
- indent(node.statements.map { |x| format(x) }.join("\n"))
417
- end,
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 > 0
436
- item_indent = INDENT_CHAR * "(".length
437
- [
438
- "\n",
439
- indent([
440
- "(",
441
- node.items.map { |x| format(x) }.join(",\n#{item_indent}"),
442
- ")",
443
- ].join("")),
444
- ].join("")
445
- end,
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
- "AS",
457
- " ",
458
- node.id,
459
- ]
460
- end,
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
- "VAR",
469
- " ",
470
- ].join("")
471
- end,
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 > 0
487
- parameter_indent = INDENT_CHAR * "PROCEDURE #{node.id}(".length
488
- [
489
- "(",
490
- node.parameters.map { |x| format(x) }.join(";\n#{parameter_indent}"),
491
- ")",
492
- ].join("")
493
- end,
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 > 0
497
- indent(node.types.map { |x| format(x) }.join("\n"))
498
- end,
499
- *if node.entities.length > 0
500
- indent(node.entities.map { |x| format(x) }.join("\n"))
501
- end,
502
- *if node.subtype_constraints.length > 0
503
- indent(node.subtype_constraints.map { |x| format(x) }.join("\n"))
504
- end,
505
- *if node.functions.length > 0
506
- indent(node.functions.map { |x| format(x) }.join("\n"))
507
- end,
508
- *if node.procedures.length > 0
509
- indent(node.procedures.map { |x| format(x) }.join("\n"))
510
- end,
511
- *if node.constants.length > 0
512
- indent([
513
- "CONSTANT",
514
- indent(node.constants.map { |x| format(x) }.join("\n")),
515
- [
516
- "END_CONSTANT",
517
- ";",
518
- ].join(""),
519
- ].join("\n"))
520
- end,
521
- *if node.variables.length > 0
522
- indent([
523
- "LOCAL",
524
- indent(node.variables.map { |x| format(x) }.join("\n")),
525
- [
526
- "END_LOCAL",
527
- ";",
528
- ].join(""),
529
- ].join("\n"))
530
- end,
531
- *if node.statements.length > 0
532
- indent(node.statements.map { |x| format(x) }.join("\n"))
533
- end,
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 > 0
556
- indent(node.types.map { |x| format(x) }.join("\n"))
557
- end,
558
- *if node.entities.length > 0
559
- indent(node.entities.map { |x| format(x) }.join("\n"))
560
- end,
561
- *if node.subtype_constraints.length > 0
562
- indent(node.subtype_constraints.map { |x| format(x) }.join("\n"))
563
- end,
564
- *if node.functions.length > 0
565
- indent(node.functions.map { |x| format(x) }.join("\n"))
566
- end,
567
- *if node.procedures.length > 0
568
- indent(node.procedures.map { |x| format(x) }.join("\n"))
569
- end,
570
- *if node.constants.length > 0
571
- indent([
572
- "CONSTANT",
573
- indent(node.constants.map { |x| format(x) }.join("\n")),
574
- [
575
- "END_CONSTANT",
576
- ";",
577
- ].join(""),
578
- ].join("\n"))
579
- end,
580
- *if node.variables.length > 0
581
- indent([
582
- "LOCAL",
583
- indent(node.variables.map { |x| format(x) }.join("\n")),
584
- [
585
- "END_LOCAL",
586
- ";",
587
- ].join(""),
588
- ].join("\n"))
589
- end,
590
- *if node.statements.length > 0
591
- indent(node.statements.map { |x| format(x) }.join("\n"))
592
- end,
593
- *if node.where_rules.length > 0
594
- [
595
- "WHERE",
596
- indent(node.where_rules.map { |x| format(x) }.join("\n")),
597
- ]
598
- end,
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
- format(node.version),
616
- ].join("")
617
- end,
614
+ [
615
+ " ",
616
+ format(node.version),
617
+ ].join("")
618
+ end,
618
619
  ";",
619
620
  ].join(""),
620
- *if node.interfaces.length > 0
621
- [
622
- "",
623
- node.interfaces.map { |x| format(x) }.join("\n"),
624
- ]
625
- end,
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 > 0
632
- [
633
- "CONSTANT",
634
- indent(node.constants.map { |x| format(x) }.join("\n")),
635
- [
636
- "END_CONSTANT",
637
- ";",
638
- ].join(""),
639
- ].join("\n")
640
- end,
641
- *if node.types.length > 0
642
- node.types.map { |x| format(x) }
643
- end,
644
- *if node.entities.length > 0
645
- node.entities.map { |x| format(x) }
646
- end,
647
- *if node.subtype_constraints.length > 0
648
- node.subtype_constraints.map { |x| format(x) }
649
- end,
650
- *if node.functions.length > 0
651
- node.functions.map { |x| format(x) }
652
- end,
653
- *if node.rules.length > 0
654
- node.rules.map { |x| format(x) }
655
- end,
656
- *if node.procedures and node.procedures.length > 0
657
- node.procedures.map { |x| format(x) }
658
- end,
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 > 0
664
- [
665
- "",
666
- schema_declarations.join("\n\n"),
667
- "",
668
- ]
669
- end,
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
- indent([
700
- "ABSTRACT",
701
- " ",
702
- "SUPERTYPE",
703
- ";",
704
- ].join(""))
705
- end,
706
- *if node.total_over.length > 0
707
- indent([
708
- "TOTAL_OVER",
709
- "(",
710
- node.total_over.map { |x| format(x) }.join(", "),
711
- ")",
712
- ";",
713
- ].join(""))
714
- end,
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
- indent([
717
- format(node.supertype_expression),
718
- ";",
719
- ].join(""))
720
- end,
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 > 0
741
- [
742
- "WHERE",
743
- indent(node.where_rules.map { |x| format(x) }.join("\n")),
744
- ]
745
- end,
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
- node.id,
758
- ":",
759
- " ",
760
- ].join("")
761
- end,
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
- format(node.expression),
780
- ].join("")
781
- end,
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
- node.id,
791
- ":",
792
- " ",
793
- ].join("")
794
- end,
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 node.operand1.is_a? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand1.operator] > OPERATOR_PRECEDENCE[node.operator]
819
- "("
820
- end,
824
+ *if op1_bin_exp
825
+ "("
826
+ end,
821
827
  format(node.operand1),
822
- *if node.operand1.is_a? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand1.operator] > OPERATOR_PRECEDENCE[node.operator]
823
- ")"
824
- end,
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 node.operand2.is_a? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand2.operator] > OPERATOR_PRECEDENCE[node.operator]
851
- "("
852
- end,
856
+ *if op2_bin_exp
857
+ "("
858
+ end,
853
859
  format(node.operand2),
854
- *if node.operand2.is_a? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand2.operator] > OPERATOR_PRECEDENCE[node.operator]
855
- ")"
856
- end,
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 > 0 ? ["\n", *x, "\n"] : x },
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
- end,
935
+ "("
936
+ end,
931
937
  format(node.operand),
932
938
  *if node.operand.is_a? Model::Expressions::BinaryExpression
933
- ")"
934
- end,
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
- format(node.index2),
1002
- ].join("")
1003
- end,
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 > 0
1025
- indent(node.statements.map { |x| format(x) }.join("\n"))
1026
- end,
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 > 0
1050
- [
1051
- "(",
1052
- node.parameters.map { |x| format(x) }.join(", "),
1053
- ")",
1054
- ].join("")
1055
- end,
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 > 0
1070
- node.actions.map { |x| format(x) }
1071
- end,
1075
+ *if node.actions.length.positive?
1076
+ node.actions.map { |x| format(x) }
1077
+ end,
1072
1078
  *if node.otherwise_statement
1073
- [
1074
- [
1075
- "OTHERWISE",
1076
- " ",
1077
- ":",
1078
- ].join(""),
1079
- indent(format(node.otherwise_statement)),
1080
- ]
1081
- end,
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 > 0
1104
- indent(node.statements.map { |x| format(x) }.join("\n"))
1105
- end,
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(node)
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 > 0
1130
- indent(node.statements.map { |x| format(x) }.join("\n"))
1131
- end,
1132
- *if node.else_statements.length > 0
1133
- [
1134
- "ELSE",
1135
- indent(node.else_statements.map { |x| format(x) }.join("\n")),
1136
- ].join("\n")
1137
- end,
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(node)
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
- node.id,
1157
- " ",
1158
- ":=",
1159
- " ",
1160
- format(node.bound1),
1161
- " ",
1162
- "TO",
1163
- " ",
1164
- format(node.bound2),
1165
- *if node.increment
1166
- [
1167
- " ",
1168
- "BY",
1169
- " ",
1170
- format(node.increment),
1171
- ].join("")
1172
- end,
1173
- ].join("")
1174
- end,
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
- "WHILE",
1179
- " ",
1180
- format(node.while_expression),
1181
- ].join("")
1182
- end,
1182
+ [
1183
+ " ",
1184
+ "WHILE",
1185
+ " ",
1186
+ format(node.while_expression),
1187
+ ].join("")
1188
+ end,
1183
1189
  *if node.until_expression
1184
- [
1185
- " ",
1186
- "UNTIL",
1187
- " ",
1188
- format(node.until_expression),
1189
- ].join("")
1190
- end,
1190
+ [
1191
+ " ",
1192
+ "UNTIL",
1193
+ " ",
1194
+ format(node.until_expression),
1195
+ ].join("")
1196
+ end,
1191
1197
  ";",
1192
1198
  ].join(""),
1193
- *if node.statements.length > 0
1194
- indent(node.statements.map { |x| format(x) }.join("\n"))
1195
- end,
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
- format(node.expression),
1212
- ")",
1213
- ].join("")
1214
- end,
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(node)
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 node.operand1.is_a? Model::SupertypeExpressions::BinarySupertypeExpression and SUPERTYPE_OPERATOR_PRECEDENCE[node.operand1.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator]
1229
- "("
1230
- end,
1239
+ *if op1_higher_precedence
1240
+ "("
1241
+ end,
1231
1242
  format(node.operand1),
1232
- *if node.operand1.is_a? Model::SupertypeExpressions::BinarySupertypeExpression and SUPERTYPE_OPERATOR_PRECEDENCE[node.operand1.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator]
1233
- ")"
1234
- end,
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 node.operand2.is_a? Model::SupertypeExpressions::BinarySupertypeExpression and SUPERTYPE_OPERATOR_PRECEDENCE[node.operand2.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator]
1242
- "("
1243
- end,
1252
+ *if op2_higher_precedence
1253
+ "("
1254
+ end,
1244
1255
  format(node.operand2),
1245
- *if node.operand2.is_a? Model::SupertypeExpressions::BinarySupertypeExpression and SUPERTYPE_OPERATOR_PRECEDENCE[node.operand2.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator]
1246
- ")"
1247
- end,
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(node)
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 and node.bound2
1268
- [
1269
- " ",
1270
- "[",
1271
- format(node.bound1),
1272
- ":",
1273
- format(node.bound2),
1274
- "]",
1275
- ].join("")
1276
- end,
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
- "OPTIONAL",
1283
- ].join("")
1284
- end,
1291
+ [
1292
+ " ",
1293
+ "OPTIONAL",
1294
+ ].join("")
1295
+ end,
1285
1296
  *if node.unique
1286
- [
1287
- " ",
1288
- "UNIQUE",
1289
- ].join("")
1290
- end,
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 and node.bound2
1300
- [
1301
- " ",
1302
- "[",
1303
- format(node.bound1),
1304
- ":",
1305
- format(node.bound2),
1306
- "]",
1307
- ].join("")
1308
- end,
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
- format(node.width),
1324
- ")",
1325
- ].join("")
1326
- end,
1331
+ [
1332
+ " ",
1333
+ "(",
1334
+ format(node.width),
1335
+ ")",
1336
+ ].join("")
1337
+ end,
1327
1338
  *if node.fixed
1328
- [
1329
- " ",
1330
- "FIXED",
1331
- ].join("")
1332
- end,
1339
+ [
1340
+ " ",
1341
+ "FIXED",
1342
+ ].join("")
1343
+ end,
1333
1344
  ].join("")
1334
1345
  end
1335
1346
 
1336
- def format_data_types_boolean(node)
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
- "EXTENSIBLE",
1345
- " ",
1346
- ].join("")
1347
- end,
1354
+ [
1355
+ "EXTENSIBLE",
1356
+ " ",
1357
+ ].join("")
1358
+ end,
1348
1359
  "ENUMERATION",
1349
1360
  *if node.based_on
1350
- [
1351
- " ",
1352
- "BASED_ON",
1353
- " ",
1354
- format(node.based_on),
1355
- *if node.items.length > 0
1356
- item_indent = INDENT_CHAR * "(".length
1357
- [
1358
- " ",
1359
- "WITH",
1360
- "\n",
1361
- indent([
1362
- "(",
1363
- node.items.map { |x| format(x) }.join(",\n#{item_indent}"),
1364
- ")",
1365
- ].join("")),
1366
- ].join("")
1367
- end,
1368
- ].join("")
1369
- else
1370
- [
1371
- *if node.items.length > 0
1372
- item_indent = INDENT_CHAR * "(".length
1373
- [
1374
- " ",
1375
- "OF",
1376
- "\n",
1377
- indent([
1378
- "(",
1379
- node.items.map { |x| format(x) }.join(",\n#{item_indent}"),
1380
- ")",
1381
- ].join("")),
1382
- ].join("")
1383
- end,
1384
- ].join("")
1385
- end,
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
- node.id,
1400
- ]
1401
- end,
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
- node.id,
1412
- ]
1413
- end,
1420
+ [
1421
+ ":",
1422
+ node.id,
1423
+ ]
1424
+ end,
1414
1425
  ].join("")
1415
1426
  end
1416
1427
 
1417
- def format_data_types_integer(node)
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 and node.bound2
1425
- [
1426
- " ",
1427
- "[",
1428
- format(node.bound1),
1429
- ":",
1430
- format(node.bound2),
1431
- "]",
1432
- ].join("")
1433
- end,
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
- "UNIQUE",
1440
- ].join("")
1441
- end,
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(node)
1458
+ def format_data_types_logical(_node)
1448
1459
  "LOGICAL"
1449
1460
  end
1450
1461
 
1451
- def format_data_types_number(node)
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
- format(node.precision),
1463
- ")",
1464
- ].join("")
1465
- end,
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
- "EXTENSIBLE",
1474
- " ",
1475
- ].join("")
1476
- end,
1483
+ [
1484
+ "EXTENSIBLE",
1485
+ " ",
1486
+ ].join("")
1487
+ end,
1477
1488
  *if node.generic_entity
1478
- [
1479
- "GENERIC_ENTITY",
1480
- " ",
1481
- ].join("")
1482
- end,
1489
+ [
1490
+ "GENERIC_ENTITY",
1491
+ " ",
1492
+ ].join("")
1493
+ end,
1483
1494
  "SELECT",
1484
1495
  *if node.based_on
1485
- [
1486
- " ",
1487
- "BASED_ON",
1488
- " ",
1489
- format(node.based_on),
1490
- *if node.items.length > 0
1491
- item_indent = INDENT_CHAR * "(".length
1492
- [
1493
- " ",
1494
- "WITH",
1495
- "\n",
1496
- indent([
1497
- "(",
1498
- node.items.map { |x| format(x) }.join(",\n#{item_indent}"),
1499
- ")",
1500
- ].join("")),
1501
- ].join("")
1502
- end,
1503
- ].join("")
1504
- else
1505
- [
1506
- *if node.items.length > 0
1507
- item_indent = INDENT_CHAR * "(".length
1508
- [
1509
- "\n",
1510
- indent([
1511
- "(",
1512
- node.items.map { |x| format(x) }.join(",\n#{item_indent}"),
1513
- ")",
1514
- ].join("")),
1515
- ].join("")
1516
- end,
1517
- ].join("")
1518
- end,
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 and node.bound2
1526
- [
1527
- " ",
1528
- "[",
1529
- format(node.bound1),
1530
- ":",
1531
- format(node.bound2),
1532
- "]",
1533
- ].join("")
1534
- end,
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
- format(node.width),
1550
- ")",
1551
- ].join("")
1552
- end,
1557
+ [
1558
+ " ",
1559
+ "(",
1560
+ format(node.width),
1561
+ ")",
1562
+ ].join("")
1563
+ end,
1553
1564
  *if node.fixed
1554
- [
1555
- " ",
1556
- "FIXED",
1557
- ].join("")
1558
- end,
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 { |x| !x.is_a? Model::DataTypes::EnumerationItem or node.is_a? Model::Declarations::Type }.flat_map { |x| format_scope_remarks(x) },
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