diff --git a/lib/interscript/isc/normalizer.rb b/lib/interscript/isc/normalizer.rb index 8fe2dc71..a79bef04 100644 --- a/lib/interscript/isc/normalizer.rb +++ b/lib/interscript/isc/normalizer.rb @@ -64,7 +64,7 @@ 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 @@ -72,6 +72,20 @@ def normalize_block(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) diff --git a/spec/interscript/isc/node_adapter_spec.rb b/spec/interscript/isc/node_adapter_spec.rb index bbc16731..c5886a60 100644 --- a/spec/interscript/isc/node_adapter_spec.rb +++ b/spec/interscript/isc/node_adapter_spec.rb @@ -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