expressir 2.4.75 → 2.4.76
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.
- checksums.yaml +4 -4
- data/ENGINE-COMPAT.json +4 -4
- data/ext/expressir_core/Cargo.toml +1 -1
- data/grammar-parg/express_literals.parg +1 -1
- data/lib/expressir/express/formatter.rb +7 -0
- data/lib/expressir/express/formatters/declarations_formatter.rb +4 -0
- data/lib/expressir/express/formatters/remark_formatter.rb +100 -15
- data/lib/expressir/express/formatters/remark_item_formatter.rb +11 -3
- data/lib/expressir/express/formatters/statements_formatter.rb +40 -0
- data/lib/expressir/express/grammar/parser.rb +6 -1
- data/lib/expressir/express/node_position_index.rb +7 -0
- data/lib/expressir/express/pretty_formatter.rb +4 -0
- data/lib/expressir/express/remark_attacher.rb +102 -15
- data/lib/expressir/model/declarations/attribute.rb +1 -0
- data/lib/expressir/model/declarations/function.rb +4 -0
- data/lib/expressir/model/declarations/variable.rb +1 -0
- data/lib/expressir/model/remark_placement.rb +5 -3
- data/lib/expressir/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf0d0bd6760431988064c4cbe00f29da0a050ebb357008cc6b5432fa7c5252ce
|
|
4
|
+
data.tar.gz: e9a5ff96a98d7c69c33a5c5d0cd2f2be19373db05cefa61d75c87870eab4219d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1bca706eeac0af8abb6f276c0e8fae58584cf6babc1d576b6c9ec2453b9e499efea2c6a008598ac5e84ee8f58dc34d6fdeefdcdf296b5ce891fa9228a4df542a
|
|
7
|
+
data.tar.gz: 4e7b389988827fccd8081a099c10acce30b91f8715f4832cfed693e0a147e48194a803c5b0335242c8c53e2a96c927fae2a0818ff4f0b0253cf945c1e8c31285
|
data/ENGINE-COMPAT.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"engine_commit": "
|
|
2
|
+
"engine_commit": "818c4c4",
|
|
3
3
|
"rubygems": "2.4.69",
|
|
4
|
-
"ext": "v0.1.
|
|
4
|
+
"ext": "v0.1.56",
|
|
5
5
|
"crates": "1.5.1",
|
|
6
6
|
"npm": null,
|
|
7
7
|
"pypi": null,
|
|
8
|
-
"released_at": "2026-11-
|
|
9
|
-
"_comment": "expressir#618
|
|
8
|
+
"released_at": "2026-11-21T00:00:00Z",
|
|
9
|
+
"_comment": "expressir#618 \u2014 the engine-compat manifest, mirroring parsanol-rs#423. Maps the expressir gem train to the expressir-rs ext tag and its engine commit; the null fields fill as the crates/npm/pypi tiers land (expressir#619/#622/#621). tools/check_engine_compat.rb verifies the pairings in CI; every release train updates this file."
|
|
10
10
|
}
|
|
@@ -13,7 +13,7 @@ magnus = { version = "0.9" }
|
|
|
13
13
|
# Pinned core release (M1, TODO.parity-ee/19): the ext never floats
|
|
14
14
|
# main — bump the tag per expressir release, alongside the validation
|
|
15
15
|
# run that pins it.
|
|
16
|
-
expressir = { git = "https://github.com/lutaml/expressir-rs", tag = "v0.1.
|
|
16
|
+
expressir = { git = "https://github.com/lutaml/expressir-rs", tag = "v0.1.56" }
|
|
17
17
|
serde_json = "1.0"
|
|
18
18
|
|
|
19
19
|
|
|
@@ -3,6 +3,6 @@ grammar ExpressLiterals version "0.1.0" edition 2 {
|
|
|
3
3
|
digit = %x30-39
|
|
4
4
|
atomic digits = digit 0* digit
|
|
5
5
|
atomic simpleId = !(anyKeyword) (express_remarks.spaces (((%x41-5A / %x61-7A / %x5F) 0* (%x30-39 / %x41-5A / %x61-7A / %x5F))) as str) as simpleId
|
|
6
|
-
simpleStringLiteral = (express_remarks.spaces ("'" 0* (!("'") %x01-10FFFF) "'") as str) as simpleStringLiteral
|
|
6
|
+
atomic simpleStringLiteral = (express_remarks.spaces ("'" 0* ("''" / (!("'") %x01-10FFFF)) "'") as str) as simpleStringLiteral
|
|
7
7
|
atomic unguardedId = (express_remarks.spaces (((%x41-5A / %x61-7A / %x5F) 0* (%x30-39 / %x41-5A / %x61-7A / %x5F))) as str) as simpleId
|
|
8
8
|
}
|
|
@@ -132,6 +132,13 @@ module Expressir
|
|
|
132
132
|
formatted = splice_opener_remark(formatted,
|
|
133
133
|
format_opener_remarks(node))
|
|
134
134
|
|
|
135
|
+
# The owner's own tagged descriptions (`(*"path" text *)`, the
|
|
136
|
+
# #679 storage contract) render as blocks after the declaration
|
|
137
|
+
# (#694) — every owner class, uniformly.
|
|
138
|
+
owner_blocks = format_owner_tagged_remarks(node)
|
|
139
|
+
formatted = [*formatted, *owner_blocks].join("\n\n") if
|
|
140
|
+
formatted.is_a?(String) && !owner_blocks.empty?
|
|
141
|
+
|
|
135
142
|
leading = format_leading_statement_remarks(node)
|
|
136
143
|
leading.empty? ? formatted : [*leading, formatted].join("\n")
|
|
137
144
|
end
|
|
@@ -744,6 +744,10 @@ module Expressir
|
|
|
744
744
|
";",
|
|
745
745
|
format_end_scope_remark(node),
|
|
746
746
|
].join,
|
|
747
|
+
# The enumeration items render inline inside ENUMERATION OF
|
|
748
|
+
# (...) and never reach the dispatch, so their tagged
|
|
749
|
+
# descriptions render here, after the TYPE (#694).
|
|
750
|
+
*format_enumeration_item_remarks(node).flat_map { |x| ["", x] },
|
|
747
751
|
].join("\n")
|
|
748
752
|
end
|
|
749
753
|
|
|
@@ -41,16 +41,21 @@ module Expressir
|
|
|
41
41
|
|
|
42
42
|
formatted_text = remark.tagged? ? "\"#{remark.tag}\" #{text}" : text
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
# A multi-line remark always renders as a block: the `--` /
|
|
45
|
+
# `---` tail forms would leak its continuation lines into the
|
|
46
|
+
# source as bare text the parser rejects (#691).
|
|
47
|
+
if text.include?("\n")
|
|
48
|
+
if remark.embedded_annotation?
|
|
49
|
+
["(**", formatted_text, "**)"].join("\n")
|
|
50
|
+
else
|
|
51
|
+
["(*", formatted_text, "*)"].join("\n")
|
|
52
|
+
end
|
|
53
|
+
elsif remark.tail_annotation?
|
|
45
54
|
"--- #{formatted_text}"
|
|
46
55
|
elsif remark.tail?
|
|
47
56
|
"-- #{formatted_text}"
|
|
48
|
-
elsif remark.embedded_annotation? && text.include?("\n")
|
|
49
|
-
["(**", formatted_text, "**)"].join("\n")
|
|
50
57
|
elsif remark.embedded_annotation?
|
|
51
58
|
"(** #{formatted_text} *)"
|
|
52
|
-
elsif text.include?("\n")
|
|
53
|
-
["(*", formatted_text, "*)"].join("\n")
|
|
54
59
|
else
|
|
55
60
|
"(* #{formatted_text} *)"
|
|
56
61
|
end
|
|
@@ -63,12 +68,25 @@ module Expressir
|
|
|
63
68
|
|
|
64
69
|
remark = node.untagged_remarks.first
|
|
65
70
|
return "" unless remark.is_a?(Model::RemarkInfo)
|
|
71
|
+
# Placement-carrying remarks render through their own paths
|
|
72
|
+
# (leading above the node, inline after the statement text);
|
|
73
|
+
# this appends the legacy tail.
|
|
74
|
+
return "" if remark.placement
|
|
66
75
|
|
|
67
76
|
text = remark.text
|
|
68
77
|
return "" if text.nil? || text.empty?
|
|
69
78
|
|
|
70
79
|
formatted_text = remark.tagged? ? "\"#{remark.tag}\" #{text}" : text
|
|
71
|
-
if
|
|
80
|
+
if text.include?("\n")
|
|
81
|
+
# A multi-line remark cannot ride the `--` tail forms: its
|
|
82
|
+
# continuation lines would leak as bare source text (#691).
|
|
83
|
+
# The block form keeps them inside a remark opener.
|
|
84
|
+
if remark.embedded_annotation?
|
|
85
|
+
" (**\n#{formatted_text}\n**)"
|
|
86
|
+
else
|
|
87
|
+
" (*\n#{formatted_text}\n*)"
|
|
88
|
+
end
|
|
89
|
+
elsif remark.tail_annotation?
|
|
72
90
|
" --- #{formatted_text}"
|
|
73
91
|
elsif remark.tail?
|
|
74
92
|
" -- #{formatted_text}"
|
|
@@ -145,7 +163,10 @@ module Expressir
|
|
|
145
163
|
node.is_a?(Model::Declarations::Rule)
|
|
146
164
|
|
|
147
165
|
preamble_remarks = node.untagged_remarks.select do |remark|
|
|
148
|
-
|
|
166
|
+
# Leading remarks render above the node (place_remarks);
|
|
167
|
+
# emitting them in the preamble would write them twice.
|
|
168
|
+
remark.is_a?(Model::RemarkInfo) && !remark.leading? &&
|
|
169
|
+
!remark.text.nil? && !remark.text.empty?
|
|
149
170
|
end
|
|
150
171
|
|
|
151
172
|
# For scope containers: exclude last remark ONLY if it's a tail remark (END_* remark)
|
|
@@ -220,8 +241,11 @@ module Expressir
|
|
|
220
241
|
|
|
221
242
|
def format_leading_statement_remarks(node)
|
|
222
243
|
return [] if @no_remarks && !@keep_untagged_remarks
|
|
223
|
-
return [] unless node.is_a?(Model::
|
|
244
|
+
return [] unless node.is_a?(Model::ModelElement)
|
|
224
245
|
|
|
246
|
+
# Leading remarks ride above their node — statements between
|
|
247
|
+
# the lines of a body, and declarations after a whole-line
|
|
248
|
+
# `--` comment (#696).
|
|
225
249
|
Array(node.untagged_remarks).filter_map do |remark|
|
|
226
250
|
next unless remark.leading?
|
|
227
251
|
|
|
@@ -304,17 +328,78 @@ module Expressir
|
|
|
304
328
|
# survives a source round trip (it re-attaches to the schema).
|
|
305
329
|
def format_schema_remarks(node)
|
|
306
330
|
return [] if @no_remarks
|
|
307
|
-
return [] unless node.is_a?(Model::Declarations::Schema)
|
|
308
331
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
332
|
+
tagged_remark_blocks(node) do |remark|
|
|
333
|
+
remark_block(node.id, remark)
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
# The owner's own tagged descriptions (`(*"path" text *)`) as
|
|
338
|
+
# remark blocks after its declaration (#694): the #679 storage
|
|
339
|
+
# contract puts renderable tagged texts on owner.remarks, and
|
|
340
|
+
# every owner class renders them. The SCHEMA renders its own in
|
|
341
|
+
# its body ({#format_schema_remarks}); enumeration items render
|
|
342
|
+
# with their TYPE (their owners never reach the dispatch).
|
|
343
|
+
def format_owner_tagged_remarks(node)
|
|
344
|
+
return [] if @no_remarks
|
|
345
|
+
return [] unless node.is_a?(Model::ModelElement)
|
|
346
|
+
return [] if node.is_a?(Model::Declarations::Schema)
|
|
347
|
+
# Enumeration items render inline inside ENUMERATION OF (...);
|
|
348
|
+
# their remarks belong after the TYPE, emitted by
|
|
349
|
+
# {#format_enumeration_item_remarks} — never appended here.
|
|
350
|
+
return [] if node.is_a?(Model::DataTypes::EnumerationItem)
|
|
351
|
+
# Remark items render themselves ({#format_remark_items});
|
|
352
|
+
# their own remarks carry the same text.
|
|
353
|
+
return [] if node.is_a?(Model::Declarations::RemarkItem)
|
|
354
|
+
return [] unless node.respond_to?(:remarks)
|
|
355
|
+
|
|
356
|
+
# A node whose schema-relative path does not resolve (a
|
|
357
|
+
# statement in a parentless walk) renders its texts through
|
|
358
|
+
# the remark-item channel instead — an empty tag would write
|
|
359
|
+
# a `(*""` block.
|
|
360
|
+
tag = schema_relative_path(node)
|
|
361
|
+
return [] if tag.nil? || tag.to_s.empty?
|
|
362
|
+
|
|
363
|
+
tagged_remark_blocks(node) do |remark|
|
|
364
|
+
remark_block(tag, remark)
|
|
365
|
+
end
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
# The enumeration items' tagged descriptions, rendered with their
|
|
369
|
+
# TYPE (the items render inline inside ENUMERATION OF (...) and
|
|
370
|
+
# never reach the dispatch themselves).
|
|
371
|
+
def format_enumeration_item_remarks(node)
|
|
372
|
+
return [] if @no_remarks
|
|
373
|
+
return [] unless node.is_a?(Model::Declarations::Type)
|
|
374
|
+
|
|
375
|
+
Array(node.enumeration_items).flat_map do |item|
|
|
376
|
+
tagged_remark_blocks(item) do |remark|
|
|
377
|
+
remark_block(schema_relative_path(item), remark)
|
|
315
378
|
end
|
|
316
379
|
end
|
|
317
380
|
end
|
|
381
|
+
|
|
382
|
+
private
|
|
383
|
+
|
|
384
|
+
# Yields each of the node's tagged remark texts through the block
|
|
385
|
+
# and collects the non-empty results.
|
|
386
|
+
def tagged_remark_blocks(node)
|
|
387
|
+
Array(node.remarks).reject do |text|
|
|
388
|
+
text.nil? || text.to_s.empty?
|
|
389
|
+
end.filter_map do |text|
|
|
390
|
+
yield text.to_s
|
|
391
|
+
end
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
# A tagged remark block in the source convention: the multi-line
|
|
395
|
+
# form when the text spans lines, the inline form otherwise.
|
|
396
|
+
def remark_block(tag, text)
|
|
397
|
+
if text.include?("\n")
|
|
398
|
+
"(*\"#{tag}\"\n#{text}\n*)"
|
|
399
|
+
else
|
|
400
|
+
"(*\"#{tag}\" #{text} *)"
|
|
401
|
+
end
|
|
402
|
+
end
|
|
318
403
|
end
|
|
319
404
|
end
|
|
320
405
|
end
|
|
@@ -31,9 +31,17 @@ module Expressir
|
|
|
31
31
|
# tail-form emission reads as phantom gains). Rule-context
|
|
32
32
|
# owners keep the historic tail form.
|
|
33
33
|
if rule_context
|
|
34
|
-
return node.remarks
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
return node.remarks.map do |remark|
|
|
35
|
+
remark = remark.to_s
|
|
36
|
+
if remark.include?("\n")
|
|
37
|
+
# A multi-line remark cannot ride the `--` tail form:
|
|
38
|
+
# its continuation lines would leak as bare source text
|
|
39
|
+
# the parser rejects (#691).
|
|
40
|
+
"(*\"#{tag}\"\n#{remark}\n*)"
|
|
41
|
+
else
|
|
42
|
+
"--\"#{tag}\" #{remark}"
|
|
43
|
+
end
|
|
44
|
+
end.join("\n")
|
|
37
45
|
end
|
|
38
46
|
node.remarks.map do |remark|
|
|
39
47
|
remark = remark.to_s
|
|
@@ -119,11 +119,51 @@ module Expressir
|
|
|
119
119
|
Array(node.labels).map { |x| format(x) }.join(", "),
|
|
120
120
|
" ",
|
|
121
121
|
":",
|
|
122
|
+
case_label_remark(node),
|
|
122
123
|
].join,
|
|
123
124
|
indent(format(node.statement)),
|
|
124
125
|
].join("\n")
|
|
125
126
|
end
|
|
126
127
|
|
|
128
|
+
# A remark trailing a bare case label (`1 : -- why`, the action on
|
|
129
|
+
# the next line) is owned by the CASE with the label region; it
|
|
130
|
+
# belongs back on the label line of the action it precedes (#693).
|
|
131
|
+
# Matched by offset when the remark carries one; otherwise by order —
|
|
132
|
+
# the k-th label remark precedes the k-th action (both read in source
|
|
133
|
+
# order).
|
|
134
|
+
def case_label_remark(action)
|
|
135
|
+
return "" if @no_remarks
|
|
136
|
+
|
|
137
|
+
case_node = action.parent
|
|
138
|
+
return "" unless case_node.is_a?(Model::Statements::Case)
|
|
139
|
+
|
|
140
|
+
actions = Array(case_node.actions)
|
|
141
|
+
index = actions.index { |a| a.equal?(action) }
|
|
142
|
+
return "" unless index
|
|
143
|
+
|
|
144
|
+
label_remarks = Array(case_node.untagged_remarks)
|
|
145
|
+
.select { |r| r.inline? && r.region == Model::RemarkPlacement::LABEL_REGION }
|
|
146
|
+
remark =
|
|
147
|
+
if label_remarks.first&.source_offset
|
|
148
|
+
anchor = Array(action.labels).filter_map(&:source_offset).min
|
|
149
|
+
bound = actions[(index + 1)..]
|
|
150
|
+
.filter_map { |a| Array(a.labels).filter_map(&:source_offset).min }
|
|
151
|
+
.min
|
|
152
|
+
return "" unless anchor
|
|
153
|
+
|
|
154
|
+
label_remarks.find do |r|
|
|
155
|
+
r.source_offset && r.source_offset >= anchor &&
|
|
156
|
+
(bound.nil? || r.source_offset < bound)
|
|
157
|
+
end
|
|
158
|
+
else
|
|
159
|
+
label_remarks[index]
|
|
160
|
+
end
|
|
161
|
+
return "" unless remark
|
|
162
|
+
|
|
163
|
+
formatted = format_untagged_remark(remark)
|
|
164
|
+
formatted.empty? ? "" : " #{formatted}"
|
|
165
|
+
end
|
|
166
|
+
|
|
127
167
|
def format_statements_compound(node)
|
|
128
168
|
statements = Array(node.statements)
|
|
129
169
|
[
|
|
@@ -732,7 +732,12 @@ module Expressir
|
|
|
732
732
|
cts(match("[a-zA-Z_][a-zA-Z0-9_]*").as(:str)).as(:simpleId)
|
|
733
733
|
end
|
|
734
734
|
rule(:simpleStringLiteral) do
|
|
735
|
-
|
|
735
|
+
# The doubled apostrophe is the in-string escape (ISO 10303-11,
|
|
736
|
+
# simple_string_literal); the body consumes both spellings, and
|
|
737
|
+
# the model keeps the source spelling (#698).
|
|
738
|
+
cts(
|
|
739
|
+
(str("'") >> (str("''") | (str("'").absent? >> any)).repeat >> str("'")).as(:str),
|
|
740
|
+
).as(:simpleStringLiteral)
|
|
736
741
|
end
|
|
737
742
|
rule(:simpleTypes) do
|
|
738
743
|
(binaryType | booleanType | integerType | logicalType | numberType | realType | stringType).as(:simpleTypes)
|
|
@@ -57,6 +57,13 @@ module Expressir
|
|
|
57
57
|
first_by_line && semantic_by_line[first_by_line]&.first
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
+
# The smallest line greater than `line` that a semantic node
|
|
61
|
+
# starts on, capped at `limit` (the enclosing scope's end).
|
|
62
|
+
def next_start_after(line, limit)
|
|
63
|
+
semantic_by_line.keys.bsearch { |l| l > line }
|
|
64
|
+
&.then { |l| l <= limit ? l : nil }
|
|
65
|
+
end
|
|
66
|
+
|
|
60
67
|
# Entries owned by `owner` within any of `collections`, in node order.
|
|
61
68
|
# Identity-keyed: ownership is object identity (the tree-walker's
|
|
62
69
|
# `.equal?` semantics), and value-equal model objects must not
|
|
@@ -97,6 +97,10 @@ module Expressir
|
|
|
97
97
|
return "" if remark.nil?
|
|
98
98
|
|
|
99
99
|
return "" unless remark.is_a?(Model::RemarkInfo)
|
|
100
|
+
# Placement-carrying remarks render through their own paths
|
|
101
|
+
# (leading above the node, inline after the statement text);
|
|
102
|
+
# this appends the legacy tail.
|
|
103
|
+
return "" if remark.placement
|
|
100
104
|
|
|
101
105
|
text = remark.text
|
|
102
106
|
return "" if text.nil? || text.empty?
|
|
@@ -286,8 +286,14 @@ module Expressir
|
|
|
286
286
|
# end-line check is restricted to statements: container end_lines are
|
|
287
287
|
# child-derived approximations that can collide with comment lines.
|
|
288
288
|
if inline_remark?(remark)
|
|
289
|
-
|
|
290
|
-
|
|
289
|
+
# The candidate pool carries both the nodes STARTING on the line
|
|
290
|
+
# (the remark trails a statement's own text) and the nodes ENDING
|
|
291
|
+
# on it (`END_IF; -- why` trails the statement that just closed —
|
|
292
|
+
# #693). A node never both starts and ends past the remark, so the
|
|
293
|
+
# two filters in inline_target stay disjoint.
|
|
294
|
+
target, placement, region = inline_target(
|
|
295
|
+
remark, @node_index.starting_at(line) + @node_index.ending_at(line)
|
|
296
|
+
)
|
|
291
297
|
return [target, placement, region] if target
|
|
292
298
|
|
|
293
299
|
# A remark trailing a mid-construct keyword (`ELSE -- why`) starts
|
|
@@ -295,7 +301,15 @@ module Expressir
|
|
|
295
301
|
# which would hand it to the enclosing construct unplaced — where
|
|
296
302
|
# nothing renders it.
|
|
297
303
|
mid = mid_keyword_inline_target(remark)
|
|
298
|
-
|
|
304
|
+
# mid.first, not mid: the miss sentinel is the [nil, nil, nil]
|
|
305
|
+
# array, which is truthy as a whole.
|
|
306
|
+
return mid if mid.first
|
|
307
|
+
|
|
308
|
+
# A remark on a LOCAL variable declaration line (`v : INTEGER; -- why`)
|
|
309
|
+
# trails a declaration whose nodes carry no source spans; resolved
|
|
310
|
+
# by the declared name (#693).
|
|
311
|
+
variable = local_variable_target(remark)
|
|
312
|
+
return variable if variable.first
|
|
299
313
|
end
|
|
300
314
|
|
|
301
315
|
# A closing keyword on the next code line is decisive: the comment
|
|
@@ -306,19 +320,44 @@ module Expressir
|
|
|
306
320
|
return closing if closing.first
|
|
307
321
|
|
|
308
322
|
enclosing, region, = statement_region_for(line)
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
323
|
+
if region
|
|
324
|
+
following = region
|
|
325
|
+
.select { |n| n[:line] > line }
|
|
326
|
+
.min_by { |n| n[:position] }
|
|
327
|
+
return [following[:node], Model::RemarkPlacement::LEADING, nil] if following
|
|
328
|
+
|
|
329
|
+
# No following statement and no closing keyword above: the comment is
|
|
330
|
+
# not demonstrably inside this body (it may sit after the whole
|
|
331
|
+
# declaration). Keep the legacy attachment rather than guessing.
|
|
332
|
+
return [enclosing[:node], nil, nil]
|
|
316
333
|
end
|
|
317
334
|
|
|
318
|
-
#
|
|
319
|
-
#
|
|
320
|
-
#
|
|
321
|
-
|
|
335
|
+
# A whole-line comment between declarations leads the next
|
|
336
|
+
# declaration: the nearest semantic node starting after the
|
|
337
|
+
# comment within the enclosing scope carries it with LEADING
|
|
338
|
+
# placement (#696). Attributes carry no source spans, so a
|
|
339
|
+
# comment inside an entity body finds nothing here and keeps
|
|
340
|
+
# the legacy attachment.
|
|
341
|
+
declaration = declaration_level_target(remark)
|
|
342
|
+
return declaration if declaration.first
|
|
343
|
+
|
|
344
|
+
[nil, nil, nil]
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
# The nearest semantic node starting after the remark's line but
|
|
348
|
+
# still inside the scope that contains the remark — the next
|
|
349
|
+
# declaration the comment introduces.
|
|
350
|
+
def declaration_level_target(remark)
|
|
351
|
+
line = remark.line
|
|
352
|
+
scope = @node_index.spanning(line)
|
|
353
|
+
.reject { |n| n[:node].is_a?(Model::ExpFile) }
|
|
354
|
+
.min_by { |n| [n[:end_line] - n[:line], n[:line]] }
|
|
355
|
+
limit = scope ? scope[:end_line] : line
|
|
356
|
+
next_line = @node_index.next_start_after(line, limit)
|
|
357
|
+
return [nil, nil, nil] unless next_line
|
|
358
|
+
|
|
359
|
+
node = @node_index.starting_at(next_line).first[:node]
|
|
360
|
+
[node, Model::RemarkPlacement::LEADING, nil]
|
|
322
361
|
end
|
|
323
362
|
|
|
324
363
|
# Whether the remark trails code on its own line. Decided from the
|
|
@@ -415,12 +454,16 @@ module Expressir
|
|
|
415
454
|
# Lines beginning with a mid-construct keyword. The keyword closes
|
|
416
455
|
# nothing and opens nothing, but the remark trailing it belongs to the
|
|
417
456
|
# construct it branches — written back after the keyword, not after the
|
|
418
|
-
# construct's END_.
|
|
457
|
+
# construct's END_. A bare case label (`1 :` with the action on the
|
|
458
|
+
# next line) is the same shape: the remark belongs back on the label
|
|
459
|
+
# line (#693).
|
|
419
460
|
MID_KEYWORD_REGIONS = {
|
|
420
461
|
/\AELSE\b/i => [Model::Statements::If,
|
|
421
462
|
Model::RemarkPlacement::ELSE_REGION],
|
|
422
463
|
/\AOTHERWISE\b/i => [Model::Statements::Case,
|
|
423
464
|
Model::RemarkPlacement::OTHERWISE_REGION],
|
|
465
|
+
/\A(?:\d+|[A-Za-z_]\w*)\s*:\s*\z/i => [Model::Statements::Case,
|
|
466
|
+
Model::RemarkPlacement::LABEL_REGION],
|
|
424
467
|
}.freeze
|
|
425
468
|
|
|
426
469
|
# Attach `ELSE -- why` / `OTHERWISE : -- why` to the innermost
|
|
@@ -445,6 +488,50 @@ module Expressir
|
|
|
445
488
|
[innermost[:node], Model::RemarkPlacement::INLINE, region]
|
|
446
489
|
end
|
|
447
490
|
|
|
491
|
+
# A remark on a LOCAL variable declaration line — `v : INTEGER; -- why`.
|
|
492
|
+
# Local variables carry no source spans, so the line's declared name is
|
|
493
|
+
# matched against the enclosing scope's variables (#693). A multi-name
|
|
494
|
+
# line (`a, b : INTEGER;`) matches any of its names.
|
|
495
|
+
def local_variable_target(remark)
|
|
496
|
+
content = line_content_for(remark.line).to_s
|
|
497
|
+
opener = content.index("--")
|
|
498
|
+
return [nil, nil, nil] unless opener
|
|
499
|
+
|
|
500
|
+
names = content[0...opener].scan(/[A-Za-z_]\w*\s*(?=,|\s*:)/)
|
|
501
|
+
.map(&:strip)
|
|
502
|
+
return [nil, nil, nil] if names.empty?
|
|
503
|
+
|
|
504
|
+
scope = @node_index.nodes.select do |n|
|
|
505
|
+
(n[:node].is_a?(Model::Declarations::Function) ||
|
|
506
|
+
n[:node].is_a?(Model::Declarations::Procedure) ||
|
|
507
|
+
n[:node].is_a?(Model::Declarations::Entity)) &&
|
|
508
|
+
n[:line] && n[:end_line] &&
|
|
509
|
+
n[:line] < remark.line && n[:end_line] > remark.line
|
|
510
|
+
end.min_by { |n| n[:end_line] - n[:line] }
|
|
511
|
+
return [nil, nil, nil] unless scope
|
|
512
|
+
|
|
513
|
+
owner = scope[:node]
|
|
514
|
+
# Callable locals and entity attributes (explicit, derived,
|
|
515
|
+
# inverse) carry no source spans; the declared name is what a
|
|
516
|
+
# trailing remark can be resolved by (#693, #696).
|
|
517
|
+
named_children = lambda do |node|
|
|
518
|
+
if node.respond_to?(:variables)
|
|
519
|
+
Array(node.variables)
|
|
520
|
+
elsif node.is_a?(Model::Declarations::Entity)
|
|
521
|
+
Array(node.attributes) + Array(node.derived_attributes) +
|
|
522
|
+
Array(node.inverse_attributes)
|
|
523
|
+
else
|
|
524
|
+
[]
|
|
525
|
+
end
|
|
526
|
+
end
|
|
527
|
+
variable = named_children.(owner).find do |v|
|
|
528
|
+
names.include?(v.id)
|
|
529
|
+
end
|
|
530
|
+
return [nil, nil, nil] unless variable
|
|
531
|
+
|
|
532
|
+
[variable, Model::RemarkPlacement::INLINE, nil]
|
|
533
|
+
end
|
|
534
|
+
|
|
448
535
|
# Which closing keyword ends which region of which owner. A comment
|
|
449
536
|
# sitting between a body's last statement and one of these keywords
|
|
450
537
|
# closes that body.
|
|
@@ -6,6 +6,10 @@ module Expressir
|
|
|
6
6
|
class Function < ModelElement
|
|
7
7
|
include Identifier
|
|
8
8
|
include ScopeContainer
|
|
9
|
+
# A tail remark on the function head line trails the declaration
|
|
10
|
+
# (`FUNCTION f (...) : INTEGER; -- why`); the formatter splices it
|
|
11
|
+
# back onto the head line.
|
|
12
|
+
include TakesInlineRemark
|
|
9
13
|
|
|
10
14
|
collection_attributes :parameters, :types, :entities,
|
|
11
15
|
:subtype_constraints, :functions, :procedures,
|
|
@@ -32,11 +32,13 @@ module Expressir
|
|
|
32
32
|
OPENER_REGION = "opener"
|
|
33
33
|
|
|
34
34
|
# Regions of INLINE remarks that trailed a mid-construct keyword line —
|
|
35
|
-
# `ELSE -- why
|
|
36
|
-
#
|
|
37
|
-
#
|
|
35
|
+
# `ELSE -- why`, `OTHERWISE : -- why`, or a case label whose action
|
|
36
|
+
# starts on the next line (`1 : -- why`). The owning construct is the
|
|
37
|
+
# enclosing IF / CASE, and the remark belongs back after that keyword
|
|
38
|
+
# or label, not after the construct's closing END_.
|
|
38
39
|
ELSE_REGION = "else"
|
|
39
40
|
OTHERWISE_REGION = "otherwise"
|
|
41
|
+
LABEL_REGION = "label"
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
44
|
end
|
data/lib/expressir/version.rb
CHANGED