Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/interscript/isc/normalizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,28 @@ def normalize_block(block)
elsif block.key?(:tests)
{tests: merge_tests(Array(block[:tests]))}
elsif block.key?(:stage)
{stage_name: scalar(block[:stage_name]), stage: block[:stage]}
{stage_name: scalar(block[:stage_name]), stage: normalize_stage_items(block[:stage])}
elsif block.key?(:target)
{target: scalar(block[:target]), alias: scalar(block[:alias])}.compact
else
block
end
end

# A capture-free block (empty or comment-only body — comments are
# consumed as whitespace) folds to a raw slice under .as; the .parg
# artifact's empty capture is an array. Match it.
def normalize_stage_items(items)
Array(items).map do |item|
if item.is_a?(Hash)
%i[parallel sequence].each do |k|
item = {k => []} if item.key?(k) && !item[k].is_a?(Array)
end
end
item
end
end

# {field_name: {identifier: "authority"}, field_value: {string: [...]}}
# becomes {authority: "BGN-PCGN"}.
def normalize_meta_field(field)
Expand Down
21 changes: 21 additions & 0 deletions spec/interscript/isc/node_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,24 @@ def parse_and_adapt(src)
expect(interp.call("чч")).to eq("ч")
end
end

RSpec.describe "comment-only blocks" do
it "normalize to an empty block, matching the artifact tree" do
src = <<~ISC
system "t:a-b:C-D:1" {
metadata { name "T" }
stage main {
parallel {
# This is a comment
}
}
}
ISC
tree = Interscript::Isc::Parser.parse(src)
stage = tree[:system][:body].find { |b| b.is_a?(Hash) && b[:stage] }[:stage]
# The grammar consumes comments as whitespace; a capture-free block
# folds to a raw slice that must normalize to an empty array like
# the .parg artifact's empty capture.
expect(stage).to eq([{parallel: []}])
end
end
Loading