Skip to content

Commit 373c522

Browse files
authored
Merge pull request #788 from interscript/feat/gate-complete
fix: capture-free blocks normalize to empty — .parg tree gate 289/289
2 parents 5cf9152 + 098cd2a commit 373c522

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎lib/interscript/isc/normalizer.rb‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,28 @@ def normalize_block(block)
6464
elsif block.key?(:tests)
6565
{tests: merge_tests(Array(block[:tests]))}
6666
elsif block.key?(:stage)
67-
{stage_name: scalar(block[:stage_name]), stage: block[:stage]}
67+
{stage_name: scalar(block[:stage_name]), stage: normalize_stage_items(block[:stage])}
6868
elsif block.key?(:target)
6969
{target: scalar(block[:target]), alias: scalar(block[:alias])}.compact
7070
else
7171
block
7272
end
7373
end
7474

75+
# A capture-free block (empty or comment-only body — comments are
76+
# consumed as whitespace) folds to a raw slice under .as; the .parg
77+
# artifact's empty capture is an array. Match it.
78+
def normalize_stage_items(items)
79+
Array(items).map do |item|
80+
if item.is_a?(Hash)
81+
%i[parallel sequence].each do |k|
82+
item = {k => []} if item.key?(k) && !item[k].is_a?(Array)
83+
end
84+
end
85+
item
86+
end
87+
end
88+
7589
# {field_name: {identifier: "authority"}, field_value: {string: [...]}}
7690
# becomes {authority: "BGN-PCGN"}.
7791
def normalize_meta_field(field)

‎spec/interscript/isc/node_adapter_spec.rb‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,24 @@ def parse_and_adapt(src)
421421
expect(interp.call("чч")).to eq("ч")
422422
end
423423
end
424+
425+
RSpec.describe "comment-only blocks" do
426+
it "normalize to an empty block, matching the artifact tree" do
427+
src = <<~ISC
428+
system "t:a-b:C-D:1" {
429+
metadata { name "T" }
430+
stage main {
431+
parallel {
432+
# This is a comment
433+
}
434+
}
435+
}
436+
ISC
437+
tree = Interscript::Isc::Parser.parse(src)
438+
stage = tree[:system][:body].find { |b| b.is_a?(Hash) && b[:stage] }[:stage]
439+
# The grammar consumes comments as whitespace; a capture-free block
440+
# folds to a raw slice that must normalize to an empty array like
441+
# the .parg artifact's empty capture.
442+
expect(stage).to eq([{parallel: []}])
443+
end
444+
end

0 commit comments

Comments
 (0)