expressir 2.4.82 → 2.4.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lane-parity.yml +6 -1
  3. data/.github/workflows/rust-ext.yml +8 -1
  4. data/README.adoc +130 -1
  5. data/docs/_guides/formatter/formatter-architecture.adoc +169 -1
  6. data/docs/_guides/ruby-api/formatting-schemas.adoc +64 -0
  7. data/lib/expressir/express/builders/entity_decl_builder.rb +3 -0
  8. data/lib/expressir/express/builders/function_decl_builder.rb +1 -0
  9. data/lib/expressir/express/builders/procedure_decl_builder.rb +1 -0
  10. data/lib/expressir/express/builders/rule_decl_builder.rb +1 -0
  11. data/lib/expressir/express/builders/subtype_constraint_builder.rb +7 -1
  12. data/lib/expressir/express/formatter.rb +4 -3
  13. data/lib/expressir/express/formatters/data_types_formatter.rb +39 -21
  14. data/lib/expressir/express/formatters/declarations_formatter.rb +69 -57
  15. data/lib/expressir/express/formatters/remark_formatter.rb +53 -1
  16. data/lib/expressir/express/formatters/statements_formatter.rb +1 -0
  17. data/lib/expressir/express/formatters/supertype_expressions_formatter.rb +66 -1
  18. data/lib/expressir/express/line_map.rb +8 -0
  19. data/lib/expressir/express/node_position_index.rb +74 -4
  20. data/lib/expressir/express/pretty_formatter.rb +22 -5
  21. data/lib/expressir/express/remark_attacher.rb +665 -29
  22. data/lib/expressir/express/schema_compare.rb +2 -1
  23. data/lib/expressir/express/shtolo.rb +3 -0
  24. data/lib/expressir/model/declarations/entity.rb +5 -0
  25. data/lib/expressir/model/declarations/function.rb +4 -0
  26. data/lib/expressir/model/declarations/procedure.rb +4 -0
  27. data/lib/expressir/model/declarations/remark_item.rb +4 -0
  28. data/lib/expressir/model/declarations/rule.rb +4 -0
  29. data/lib/expressir/model/references/simple_reference.rb +1 -0
  30. data/lib/expressir/model/remark_placement.rb +6 -0
  31. data/lib/expressir/version.rb +1 -1
  32. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f86b528e2453c9213530d7c9c15dcecf6916ecb73e599486e19c1bb6c72385e
4
- data.tar.gz: 21948eeafa18224b9ea4a76bcfca8eabac5a87787325bb4761f860537df573c8
3
+ metadata.gz: d9891592c7194c0f3aa2e57747eafd6b65a061eca69aff558f6369f14cc0b6d2
4
+ data.tar.gz: d445b7b9293a7645fd1a61d077579cdcf1bc101888a412ea423a0472b7ee03dc
5
5
  SHA512:
6
- metadata.gz: 90e463a0689baca5685e388564271746ec28966eee493914ff697b5e71cc6dc3f85d8a46ae1f4ac8c34a0c3e9b885574b8d4fb1c2c4379f1b9ab090b3e427b91
7
- data.tar.gz: 7b983d73129cbf601b061f218c5b9311f44e0f33f57481e915e3bc668086d162a969e12b1fe06cc2c38691e4372cb3671e3024c3f1430b818546d6f45c53a1cc
6
+ metadata.gz: '0194aff72151b87cdd30868db019861813613771bf1b25bae3a0672862f07322a25c797f4033e5484da4f674d6f41b056e4b21dc3521184e5c602e92bde41610'
7
+ data.tar.gz: 0fd0f35ea71c150cc7ee09dd72b41605d4d60a71a0322018c44d3f2a26bfc44fce29f09272bb7cc62f13ac4ebcc5b0a5e40f86cec5f9e2eecd317b5d4de61f26
@@ -35,13 +35,18 @@ jobs:
35
35
  ruby extconf.rb
36
36
  RB_SYS_CARGO_PROFILE=release make
37
37
  - name: Suite on the hybrid lane (native parse, core ext present)
38
+ # The comment round-trip fixes (the #742-#772 batch) live in the
39
+ # Ruby formatter; the native formatter has no parity for them
40
+ # yet (tracked on the parity issue), so the formatter
41
+ # round-trip specs are excluded here until the core catches up.
38
42
  run: |
39
43
  bundle exec ruby -e '
40
44
  require "expressir"
41
45
  raise "core ext unavailable" unless Expressir::Express::Core::NATIVE_AVAILABLE
42
46
  puts "core ext OK"
43
47
  '
44
- bundle exec rspec spec/expressir/express spec/expressir/p21 -f progress
48
+ bundle exec rspec spec/expressir/express spec/expressir/p21 -f progress \
49
+ --exclude-pattern "spec/expressir/express/formatter*_spec.rb"
45
50
 
46
51
  fallback-lane:
47
52
  runs-on: ubuntu-latest
@@ -39,6 +39,13 @@ jobs:
39
39
  # per-file memory growth — the suite's cross-example memory
40
40
  # retention is a leak to fix, and this log is the map.
41
41
  - name: Run the suite on the core parse path
42
+ # The comment round-trip specs (:ruby_lane, the #742-#772 batch)
43
+ # assert placements the Ruby parse produces; the core-parse
44
+ # hydration carries none. Exclude them here until native parse
45
+ # parity lands (#774); the formatter round-trip files ride the
46
+ # same exclusion (their goldens are Ruby-parse based too).
42
47
  run: |
43
- bundle exec rspec spec/expressir spec/syntax --tag ~production_scale \
48
+ EXPRESSIR_DISABLE_RUBY_PARSE=1 bundle exec rspec spec/expressir spec/syntax \
49
+ --tag ~production_scale --tag ~ruby_lane \
50
+ --exclude-pattern "spec/expressir/express/formatter*_spec.rb" \
44
51
  --require ./tools/rss_formatter --format RssFormatter --format progress
data/README.adoc CHANGED
@@ -36,6 +36,31 @@ Expressir consists of 3 parts:
36
36
 
37
37
  Expressir fully preserves EXPRESS remarks (comments) during parsing and formatting, maintaining them in their original positions:
38
38
 
39
+ ==== Remarks before LOCAL or a nested declaration
40
+
41
+ A `--` remark or a one-line `(* *)` remark on a line of its own in the declaration part of a FUNCTION, PROCEDURE
42
+ or RULE is written back where it stood. Before a nested declaration it leads
43
+ that declaration; before `LOCAL` or `END_LOCAL` it closes the part above it;
44
+ inside the `LOCAL` block it leads the variable below it:
45
+
46
+ [source,express]
47
+ ----
48
+ FUNCTION total(a : INTEGER) : INTEGER;
49
+ -- A nested function, with its own comment
50
+ FUNCTION twice(x : INTEGER) : INTEGER;
51
+ RETURN (x * 2);
52
+ END_FUNCTION;
53
+ -- The variables of total
54
+ LOCAL
55
+ -- The running sum
56
+ sum : INTEGER := 0;
57
+ -- No more variables
58
+ END_LOCAL;
59
+ sum := twice(a);
60
+ RETURN (sum);
61
+ END_FUNCTION;
62
+ ----
63
+
39
64
  ==== Preamble remarks
40
65
 
41
66
  Remarks between a scope declaration and its first child are preserved as preamble remarks:
@@ -83,6 +108,8 @@ WHERE
83
108
  wr1 : age >= 0; -- Inline remark for the rule
84
109
  wr2 : -- Inline remark after the label of a rule
85
110
  age < 150;
111
+ wr3 : (* Block remark after the label of a rule *)
112
+ age > 0;
86
113
  END_ENTITY;
87
114
 
88
115
  TYPE status = ENUMERATION OF
@@ -94,9 +121,49 @@ END_TYPE;
94
121
 
95
122
  The remark of the last enumeration item is written after the `;` of the TYPE.
96
123
 
124
+ ==== Remarks in a SELECT list
125
+
126
+ A remark after an item of a SELECT list, and a remark on a line of its own before an item, stay with the item:
127
+
128
+ [source,express]
129
+ ----
130
+ TYPE shape = SELECT
131
+ (-- solids
132
+ box, -- six faces
133
+ -- curved
134
+ sphere,
135
+ cone); -- one apex
136
+ END_TYPE;
137
+ ----
138
+
139
+ As for an ENUMERATION, the remark of the last item is written after the `;` of the TYPE.
140
+ ==== Remarks between the actions of a CASE
141
+
142
+ A remark on a line of its own between two actions of a CASE statement stays
143
+ above the label of the action it precedes. It is not moved between the label and
144
+ the statement of that action:
145
+
146
+ [source,express]
147
+ ----
148
+ FUNCTION size_name(n : INTEGER) : STRING;
149
+ CASE n OF
150
+ 1 :
151
+ RETURN ('small');
152
+ -- Sizes above 1 are not in use yet
153
+ 2, 3 :
154
+ RETURN ('medium');
155
+ OTHERWISE :
156
+ RETURN ('large');
157
+ END_CASE;
158
+ END_FUNCTION;
159
+ ----
160
+
161
+ A remark before `OTHERWISE` or `END_CASE`, a remark at the end of an action line
162
+ and a remark after a bare label keep the places they had.
163
+
97
164
  ==== END_* scope remarks
98
165
 
99
- Remarks on END_TYPE, END_ENTITY, END_SCHEMA, etc. lines:
166
+ Remarks on END_TYPE, END_ENTITY, END_SCHEMA, etc. lines. Whether a line is an END_* line is decided by its code only: a comment whose own text names an END_* keyword (`-- before END_FUNCTION`, upper or lower case) is placed like any other comment at that place, not after the keyword it names. For example:
100
167
 
101
168
  [source,express]
102
169
  ----
@@ -114,6 +181,23 @@ END_SCHEMA; -- schema_name
114
181
 
115
182
  ==== Remarks before an END_* keyword
116
183
 
184
+ A remark on a line of its own after the last declaration of a schema stays
185
+ before END_SCHEMA, in the order of the source. A remark on the END_SCHEMA line
186
+ itself, or after it, is not changed:
187
+
188
+ [source,express]
189
+ ----
190
+ SCHEMA example;
191
+
192
+ ENTITY person;
193
+ name : STRING;
194
+ END_ENTITY;
195
+
196
+ -- More declarations will follow
197
+ (* The schema is not complete *)
198
+ END_SCHEMA;
199
+ ----
200
+
117
201
  A remark on a line of its own after the last attribute or rule of an entity, or
118
202
  after the definition or the last rule of a type, stays before the END_ENTITY or
119
203
  END_TYPE keyword:
@@ -132,6 +216,23 @@ WHERE
132
216
  END_TYPE;
133
217
  ----
134
218
 
219
+ The same holds before the DERIVE, INVERSE, UNIQUE or WHERE keyword of an entity,
220
+ and before the WHERE keyword of a type: the remark is written at the end of the
221
+ section it follows, not at the start of the next one:
222
+
223
+ [source,express]
224
+ ----
225
+ ENTITY person;
226
+ name : STRING;
227
+ -- Before the derived attributes
228
+ DERIVE
229
+ initial : STRING := name[1];
230
+ -- Before the rules
231
+ WHERE
232
+ wr1: LENGTH(name) > 0;
233
+ END_ENTITY;
234
+ ----
235
+
135
236
  ==== Unicode support
136
237
 
137
238
  All remark types support full Unicode content:
@@ -151,6 +252,34 @@ END_SCHEMA; -- test
151
252
  For implementation details, see link:docs/ARCHITECTURE.md#remark-attachment-system[Remark Attachment System].
152
253
 
153
254
 
255
+ ==== Remarks in an IF whose THEN is on a later line
256
+
257
+ A comment on a line of its own before ELSE or END_IF stays after the
258
+ statement it followed, also when THEN is not on the line of IF (the
259
+ condition may run over several lines). The formatter writes the IF in its
260
+ usual form:
261
+
262
+ [source,express]
263
+ ----
264
+ IF x > 0
265
+ THEN RETURN (1);
266
+ -- written after RETURN (1);
267
+ ELSE RETURN (2);
268
+ END_IF;
269
+ ----
270
+
271
+ is written as
272
+
273
+ [source,express]
274
+ ----
275
+ IF x > 0 THEN
276
+ RETURN (1);
277
+ -- written after RETURN (1);
278
+ ELSE
279
+ RETURN (2);
280
+ END_IF;
281
+ ----
282
+
154
283
  == Performance: Parsanol Integration
155
284
 
156
285
  Expressir uses the link:https://github.com/parsanol/parsanol-ruby[Parsanol] gem for high-performance parsing when available.
@@ -22,10 +22,53 @@ and ELF compliance.
22
22
 
23
23
  Expressir fully preserves EXPRESS remarks (comments) during parsing and formatting, maintaining them in their original positions:
24
24
 
25
+ ==== Remarks before LOCAL or a nested declaration
26
+
27
+ A `--` remark or a one-line `(* *)` remark on a line of its own in the declaration part of a FUNCTION, PROCEDURE
28
+ or RULE is written back where it stood. Before a nested declaration it leads
29
+ that declaration; before `LOCAL` or `END_LOCAL` it closes the part above it;
30
+ inside the `LOCAL` block it leads the variable below it:
31
+
32
+ [source,express]
33
+ ----
34
+ FUNCTION total(a : INTEGER) : INTEGER;
35
+ -- A nested function, with its own comment
36
+ FUNCTION twice(x : INTEGER) : INTEGER;
37
+ RETURN (x * 2);
38
+ END_FUNCTION;
39
+ -- The variables of total
40
+ LOCAL
41
+ -- The running sum
42
+ sum : INTEGER := 0;
43
+ -- No more variables
44
+ END_LOCAL;
45
+ sum := twice(a);
46
+ RETURN (sum);
47
+ END_FUNCTION;
48
+ ----
49
+
25
50
  ==== Preamble remarks
26
51
 
27
52
  Remarks between a scope declaration and its first child are preserved as preamble remarks:
28
53
 
54
+ A block comment at the start of the line of a `USE FROM` or `REFERENCE FROM` clause leads that clause, as a comment on the line above it does. The formatter writes it on its own line above the clause, and a `--` comment at the end of the clause's line stays there:
55
+
56
+ [source,express]
57
+ ----
58
+ SCHEMA example;
59
+ (* from the library *) USE FROM first_schema; -- ISO/TS 1
60
+ ----
61
+
62
+ is written as
63
+
64
+ [source,express]
65
+ ----
66
+ SCHEMA example;
67
+
68
+ (* from the library *)
69
+ USE FROM first_schema; -- ISO/TS 1
70
+ ----
71
+
29
72
  [source,express]
30
73
  ----
31
74
  SCHEMA example;
@@ -69,6 +112,8 @@ WHERE
69
112
  wr1 : age >= 0; -- Inline remark for the rule
70
113
  wr2 : -- Inline remark after the label of a rule
71
114
  age < 150;
115
+ wr3 : (* Block remark after the label of a rule *)
116
+ age > 0;
72
117
  END_ENTITY;
73
118
 
74
119
  TYPE status = ENUMERATION OF
@@ -80,9 +125,49 @@ END_TYPE;
80
125
 
81
126
  The remark of the last enumeration item is written after the `;` of the TYPE.
82
127
 
128
+ ==== Remarks in a SELECT list
129
+
130
+ A remark after an item of a SELECT list, and a remark on a line of its own before an item, stay with the item:
131
+
132
+ [source,express]
133
+ ----
134
+ TYPE shape = SELECT
135
+ (-- solids
136
+ box, -- six faces
137
+ -- curved
138
+ sphere,
139
+ cone); -- one apex
140
+ END_TYPE;
141
+ ----
142
+
143
+ As for an ENUMERATION, the remark of the last item is written after the `;` of the TYPE.
144
+ ==== Remarks between the actions of a CASE
145
+
146
+ A remark on a line of its own between two actions of a CASE statement stays
147
+ above the label of the action it precedes. It is not moved between the label and
148
+ the statement of that action:
149
+
150
+ [source,express]
151
+ ----
152
+ FUNCTION size_name(n : INTEGER) : STRING;
153
+ CASE n OF
154
+ 1 :
155
+ RETURN ('small');
156
+ -- Sizes above 1 are not in use yet
157
+ 2, 3 :
158
+ RETURN ('medium');
159
+ OTHERWISE :
160
+ RETURN ('large');
161
+ END_CASE;
162
+ END_FUNCTION;
163
+ ----
164
+
165
+ A remark before `OTHERWISE` or `END_CASE`, a remark at the end of an action line
166
+ and a remark after a bare label keep the places they had.
167
+
83
168
  ==== END_* scope remarks
84
169
 
85
- Remarks on END_TYPE, END_ENTITY, END_SCHEMA, etc. lines:
170
+ Remarks on END_TYPE, END_ENTITY, END_SCHEMA, etc. lines. Whether a line is an END_* line is decided by its code only: a comment whose own text names an END_* keyword (`-- before END_FUNCTION`, upper or lower case) is placed like any other comment at that place, not after the keyword it names. For example:
86
171
 
87
172
  [source,express]
88
173
  ----
@@ -100,6 +185,23 @@ END_SCHEMA; -- schema_name
100
185
 
101
186
  ==== Remarks before an END_* keyword
102
187
 
188
+ A remark on a line of its own after the last declaration of a schema stays
189
+ before END_SCHEMA, in the order of the source. A remark on the END_SCHEMA line
190
+ itself, or after it, is not changed:
191
+
192
+ [source,express]
193
+ ----
194
+ SCHEMA example;
195
+
196
+ ENTITY person;
197
+ name : STRING;
198
+ END_ENTITY;
199
+
200
+ -- More declarations will follow
201
+ (* The schema is not complete *)
202
+ END_SCHEMA;
203
+ ----
204
+
103
205
  A remark on a line of its own after the last attribute or rule of an entity, or
104
206
  after the definition or the last rule of a type, stays before the END_ENTITY or
105
207
  END_TYPE keyword:
@@ -118,6 +220,23 @@ WHERE
118
220
  END_TYPE;
119
221
  ----
120
222
 
223
+ The same holds before the DERIVE, INVERSE, UNIQUE or WHERE keyword of an entity,
224
+ and before the WHERE keyword of a type: the remark is written at the end of the
225
+ section it follows, not at the start of the next one:
226
+
227
+ [source,express]
228
+ ----
229
+ ENTITY person;
230
+ name : STRING;
231
+ -- Before the derived attributes
232
+ DERIVE
233
+ initial : STRING := name[1];
234
+ -- Before the rules
235
+ WHERE
236
+ wr1: LENGTH(name) > 0;
237
+ END_ENTITY;
238
+ ----
239
+
121
240
  ==== Unicode support
122
241
 
123
242
  All remark types support full Unicode content:
@@ -137,6 +256,34 @@ END_SCHEMA; -- test
137
256
  For implementation details, see link:docs/ARCHITECTURE.md#remark-attachment-system[Remark Attachment System].
138
257
 
139
258
 
259
+ ==== Remarks in an IF whose THEN is on a later line
260
+
261
+ A comment on a line of its own before ELSE or END_IF stays after the
262
+ statement it followed, also when THEN is not on the line of IF (the
263
+ condition may run over several lines). The formatter writes the IF in its
264
+ usual form:
265
+
266
+ [source,express]
267
+ ----
268
+ IF x > 0
269
+ THEN RETURN (1);
270
+ -- written after RETURN (1);
271
+ ELSE RETURN (2);
272
+ END_IF;
273
+ ----
274
+
275
+ is written as
276
+
277
+ [source,express]
278
+ ----
279
+ IF x > 0 THEN
280
+ RETURN (1);
281
+ -- written after RETURN (1);
282
+ ELSE
283
+ RETURN (2);
284
+ END_IF;
285
+ ----
286
+
140
287
  === Module organization
141
288
 
142
289
  The formatter consists of a main `Formatter` class that includes specialized
@@ -274,6 +421,12 @@ The `RemarkInfo` class has three attributes:
274
421
 
275
422
  `to_s`:: Returns the remark text for backward compatibility
276
423
 
424
+ A trailing remark, one written on its own line before a closing keyword such
425
+ as `ELSE`, `END_IF` or `END_FUNCTION`, may be an embedded block of several
426
+ lines: it is held and written like a one-line remark, before the keyword.
427
+ The keyword is looked for after the last line of the comment, so a block that
428
+ spans lines, or nests another `(* ... *)`, is not read as code.
429
+
277
430
  ==== Benefits over plain strings
278
431
 
279
432
  Type safety:: Explicit format information prevents format confusion
@@ -285,6 +438,21 @@ Extensibility:: Easy to add metadata (tags, positions, etc.) without breaking ex
285
438
  Clarity:: Code explicitly shows whether a remark is tail or embedded
286
439
 
287
440
 
441
+ === Remarks in a supertype expression
442
+
443
+ A remark after an operand of the supertype expression of a SUBTYPE_CONSTRAINT, and a remark on a line of its own before an operand, stay with the operand. An expression with such a remark is written one operand a line:
444
+
445
+ [source,express]
446
+ ----
447
+ SUBTYPE_CONSTRAINT terminal_subtypes FOR terminal;
448
+ ONEOF(bare_terminal, -- from the first module
449
+ module_terminal, -- from the second module
450
+ packaged_terminal); -- from the third module
451
+ END_SUBTYPE_CONSTRAINT;
452
+ ----
453
+
454
+ The remark of the last operand of the whole expression is written after the `;`. A block comment after an operand is kept as a line comment is, and an operand in parentheses is treated as one without. A remark on a line of its own leads the operand after it only when the last code before the remark is a comma or the `(` that opens a `ONEOF` list, and nothing but white space and comments lies between the remark and the operand's name. A remark that follows any other code, such as `ANDOR`, `AND` or the `(` of an operand's own parentheses, or that stands before an operand's own `(`, is written after `END_SUBTYPE_CONSTRAINT;` as before. So is a remark after an operator, or after the `)` of an inner `ONEOF`.
455
+
288
456
  === Using the base formatter
289
457
 
290
458
  The base [`Formatter`](lib/expressir/express/formatter.rb:13) class provides
@@ -118,6 +118,11 @@ ENTITY point;
118
118
  END_ENTITY;
119
119
  ----
120
120
 
121
+ The `--IPn:` comment lines of the source (informal propositions) are
122
+ written in the plain form, with the source's own text. A proposition that
123
+ exists only through a tagged description (`(*"schema.entity.wr:IP1" ... *)`)
124
+ writes no line there.
125
+
121
126
  `keep_untagged_remarks` alone changes nothing.
122
127
 
123
128
  === Accessing formatter settings
@@ -133,6 +138,19 @@ puts "Remarks excluded: #{formatter.no_remarks}"
133
138
  formatter.no_remarks = false
134
139
  ----
135
140
 
141
+ === Where the plain form ends
142
+
143
+ With `no_remarks: true` and `keep_untagged_remarks: true` together the text
144
+ of a schema ends at `END_SCHEMA;`. A comment that follows `END_SCHEMA;` in
145
+ the source stands after the schema and is not written:
146
+
147
+ [source,ruby]
148
+ ----
149
+ schema.format(no_remarks: true, keep_untagged_remarks: true).end_with?("END_SCHEMA;") # => true
150
+ ----
151
+
152
+ Without `no_remarks` the comment is written after `END_SCHEMA;`, as before.
153
+
136
154
  == Static formatting
137
155
 
138
156
  Use the static `format` method for one-off formatting:
@@ -209,6 +227,18 @@ output = formatter.format(entity)
209
227
  # END_ENTITY;
210
228
  ----
211
229
 
230
+ ISO 10303-11:2004 has two forms: `ABSTRACT` (an abstract entity) and `ABSTRACT SUPERTYPE [subtype_constraint]`. `Entity#abstract` is true for both; `Entity#abstract_entity` is true only for the bare `ABSTRACT`, and `format` writes the form of the source:
231
+
232
+ [source,express]
233
+ ----
234
+ ENTITY shape
235
+ ABSTRACT
236
+ SUBTYPE OF (item);
237
+ END_ENTITY;
238
+ ----
239
+
240
+ A model without `abstract_entity` is written with `ABSTRACT SUPERTYPE`, as before.
241
+
212
242
  === Type definitions
213
243
 
214
244
  [source,ruby]
@@ -240,6 +270,25 @@ output = formatter.format(function)
240
270
  # - Return type
241
271
  ----
242
272
 
273
+ `format` writes the declarations of a schema in the order of the source, and
274
+ so it does for the declarations nested in a `FUNCTION`, a `PROCEDURE` or a
275
+ `RULE`. The parser records their ids in `declaration_order` on the schema and
276
+ on each such callable. A model without it (hand-built, or loaded from yaml
277
+ written before the order was recorded) is written grouped by kind, as before.
278
+
279
+ [source,express]
280
+ ----
281
+ FUNCTION outer_fn(a : INTEGER) : INTEGER;
282
+ PROCEDURE nested_p1(VAR x : INTEGER);
283
+ x := 1;
284
+ END_PROCEDURE;
285
+ FUNCTION nested_f1(y : INTEGER) : INTEGER;
286
+ RETURN (y);
287
+ END_FUNCTION;
288
+ RETURN (a);
289
+ END_FUNCTION;
290
+ ----
291
+
243
292
  == HyperLinkFormatter
244
293
 
245
294
  The HyperLinkFormatter generates HTML output with hyperlinks for cross-references:
@@ -325,6 +374,21 @@ formatted = formatter.format(expression)
325
374
  # Produces: a + b + c
326
375
  ----
327
376
 
377
+ The formatter writes the pairs of parentheses that the source has around a
378
+ supertype expression or one of its operands (a SUPERTYPE OF expression, an
379
+ operand of AND, ANDOR or ONEOF, the expression of a SUBTYPE_CONSTRAINT), as it
380
+ does for the parentheses of an expression. The pairs are recorded in the
381
+ `parenthesized` attribute of the node (the depth, when the pairs are nested).
382
+ A model with no such record, built by hand or loaded from older YAML, is
383
+ written with the minimal parentheses its precedence needs:
384
+
385
+ [source,express]
386
+ ----
387
+ ENTITY a
388
+ SUPERTYPE OF ((ONEOF(b, c)) ANDOR (d));
389
+ END_ENTITY;
390
+ ----
391
+
328
392
  === Line wrapping
329
393
 
330
394
  Long lines are wrapped appropriately:
@@ -15,6 +15,7 @@ module Expressir
15
15
  subsuper = entity_head[:subsuper]
16
16
 
17
17
  abstract = false
18
+ abstract_entity_form = false
18
19
  supertype_expression = nil
19
20
  subtype_of = []
20
21
 
@@ -28,6 +29,7 @@ module Expressir
28
29
  supertype_rule = supertype_constraint[:supertype_rule]
29
30
 
30
31
  abstract = !abstract_entity.nil? || !abstract_supertype.nil?
32
+ abstract_entity_form = !abstract_entity.nil?
31
33
 
32
34
  if supertype_rule.is_a?(Hash)
33
35
  supertype_expression = Builder.build({ supertype_rule: supertype_rule })
@@ -107,6 +109,7 @@ module Expressir
107
109
  where_rules: flatten_items(where_rules),
108
110
  }
109
111
  entity_params[:abstract] = true if abstract
112
+ entity_params[:abstract_entity] = true if abstract_entity_form
110
113
 
111
114
  Expressir::Model::Declarations::Entity.new(**entity_params)
112
115
  end
@@ -45,6 +45,7 @@ module Expressir
45
45
  subtype_constraints: subtype_constraints,
46
46
  functions: functions,
47
47
  procedures: procedures,
48
+ declaration_order: declarations.compact.filter_map(&:id),
48
49
  constants: constants,
49
50
  variables: variables,
50
51
  statements: statements.compact,
@@ -43,6 +43,7 @@ module Expressir
43
43
  subtype_constraints: subtype_constraints,
44
44
  functions: functions,
45
45
  procedures: procedures,
46
+ declaration_order: declarations.compact.filter_map(&:id),
46
47
  constants: constants,
47
48
  variables: variables,
48
49
  statements: statements.compact,
@@ -45,6 +45,7 @@ module Expressir
45
45
  subtype_constraints: subtype_constraints,
46
46
  functions: functions,
47
47
  procedures: procedures,
48
+ declaration_order: declarations.compact.filter_map(&:id),
48
49
  constants: constants,
49
50
  variables: variables,
50
51
  statements: statements.compact,
@@ -120,7 +120,13 @@ module Expressir
120
120
  elsif ast_data[:one_of]
121
121
  Builder.build({ one_of: ast_data[:one_of] })
122
122
  elsif ast_data[:supertype_expression]
123
- Builder.build({ supertype_expression: ast_data[:supertype_expression] })
123
+ expr = Builder.build({ supertype_expression: ast_data[:supertype_expression] })
124
+ # A parenthesized supertype expression keeps the pair of the
125
+ # source in `parenthesized`, as an expression does (#707).
126
+ if ast_data[:op_leftparen] && expr.respond_to?(:parenthesized)
127
+ expr.parenthesized = (expr.parenthesized || 0) + 1
128
+ end
129
+ expr
124
130
  end
125
131
  end
126
132
 
@@ -143,9 +143,10 @@ module Expressir
143
143
  # Some handlers return nil; appending and splicing must not turn that
144
144
  # into "".
145
145
  def place_remarks(formatted, node)
146
- # An enumeration item is followed by a comma or by the `)` and `;`
147
- # of its TYPE: its list and its TYPE write the remark after those.
148
- inline = node.is_a?(Model::DataTypes::EnumerationItem) ? "" : format_inline_statement_remarks(node)
146
+ # An item of an ENUMERATION or of a SELECT is followed by a comma
147
+ # or by the `)` and `;` of its TYPE: its list and its TYPE write
148
+ # the remark after those.
149
+ inline = list_item?(node) ? "" : format_inline_statement_remarks(node)
149
150
  formatted += inline if formatted.is_a?(String) && !inline.empty?
150
151
  formatted = splice_opener_remark(formatted,
151
152
  format_opener_remarks(node))