Skip to content

Commit 96cd6c7

Browse files
committed
fix: make ISC documents addressable like .imp maps
Two parity gaps with the legacy DSL, both fatal to Compiler::Ruby: - Document#name now derives from the file name (locate() and Maps.transliterate address maps that way). Registering under the system code made every map whose code differs from its file name resolve to a Hash-default empty entry — stages[:main].call crashed. 3106 of the sweep's 3175 failures were this crash. - Every alias and stage now carries doc_name. The Ruby/JS compilers emit run directives as Maps.transliterate(stage.doc_name, ...); without it, aliased-dependency runs (un-ell runs elot, 131 maps) compiled to transliterate(nil, s, :main).
1 parent 72446e8 commit 96cd6c7

3 files changed

Lines changed: 48 additions & 7 deletions

File tree

‎lib/interscript/isc/node_adapter.rb‎

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,22 @@ def build
2626
Interscript::Node::Document.new.tap do |doc|
2727
doc.metadata = build_metadata
2828
doc.tests = build_tests
29-
doc.aliases = build_aliases
30-
build_stages.each { |name, stage| doc.stages[name] = stage }
29+
# Maps are addressed by their file-derived name (locate() and
30+
# Maps.transliterate use it); registering under the system code
31+
# made every map whose code differs from its file name resolve
32+
# to an auto-created empty entry — stages[:main].call crashed.
33+
doc.name = if @isc_doc[:filename]
34+
File.basename(@isc_doc[:filename].to_s, ".isc")
35+
else
36+
@isc_doc[:systemCode]
37+
end
38+
# The legacy DSL stamps doc_name on every alias and stage; the
39+
# Ruby/JS compilers emit run directives and alias lookups as
40+
# Maps.transliterate(stage.doc_name, ...) — without it every
41+
# aliased-dependency run compiled to transliterate(nil).
42+
doc.aliases = build_aliases(doc.name)
43+
build_stages(doc.name).each { |name, stage| doc.stages[name] = stage }
3144
build_dependencies(doc)
32-
doc.name = @isc_doc[:systemCode]
3345
end
3446
end
3547

@@ -53,12 +65,14 @@ def build_tests
5365
tests
5466
end
5567

56-
def build_aliases
68+
def build_aliases(doc_name)
5769
@isc_doc[:aliases].each_with_object({}) do |a, h|
5870
# The runtime resolves aliases through AliasDef#data (see
5971
# Interpreter::Stage#build_item); a bare item here hands it a
6072
# raw Array once Any#data unrolls.
61-
h[a[:name].to_sym] = Interscript::Node::AliasDef.new(a[:name].to_sym, convert_item(a[:value]))
73+
alias_def = Interscript::Node::AliasDef.new(a[:name].to_sym, convert_item(a[:value]))
74+
alias_def.doc_name = doc_name
75+
h[a[:name].to_sym] = alias_def
6276
end
6377
end
6478

@@ -90,9 +104,11 @@ def load_dependency_document(full_name)
90104
end
91105
end
92106

93-
def build_stages
107+
def build_stages(doc_name)
94108
@isc_doc[:stages].each_with_object({}) do |stage, h|
95-
h[stage[:name].to_sym] = build_stage(stage)
109+
built = build_stage(stage)
110+
built.doc_name = doc_name
111+
h[stage[:name].to_sym] = built
96112
end
97113
end
98114

‎spec/interscript/isc/node_adapter_spec.rb‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,18 @@ def parse_and_adapt(src)
358358
expect(interp.call("αγκα")).to eq("αnκα")
359359
end
360360
end
361+
362+
RSpec.describe "NodeAdapter document name derivation" do
363+
it "names the document after the file, not the system code — transliteration addresses maps by file name" do
364+
tree = Interscript::Isc::Parser.parse(
365+
'system "TOTALLY:diff-Code:frm:File" { stage main { sub { from "a" to "b" } } }'
366+
)
367+
doc = Interscript::Isc::DocumentBuilder.build(tree, filename: "test-map.isc")
368+
node = Interscript::Isc::NodeAdapter.to_interscript_node(doc)
369+
# The Ruby compiler registers compiled maps under Document#name and
370+
# Maps.transliterate looks them up by the map name (file-derived).
371+
# Registering under the system code auto-creates an empty entry via
372+
# the Hash default block and crashes on stages[:main].call.
373+
expect(node.name).to eq("test-map")
374+
end
375+
end

‎spec/isc_corpus_spec.rb‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,14 @@
2525
expect(Interscript.transliterate("bgnpcgn-deu-Latn-Latn-2000", "Tschüß!"))
2626
.to eq("Tschueß!")
2727
end
28+
29+
it "compiles an aliased-dependency run through the Ruby compiler (un-ell runs elot)" do
30+
skip "maps checkout not present" unless File.file?(File.expand_path("un-ell-Grek-Latn-1987-ts.isc", MAPS))
31+
32+
compiled = Interscript::Compiler::Ruby.call("un-ell-Grek-Latn-1987-ts")
33+
# The run directive compiles to Maps.transliterate(stage.doc_name, ...);
34+
# without doc_name stamped on ISC stages it emitted transliterate(nil)
35+
# and crashed on stages[:main].call at runtime.
36+
expect(compiled.call("Ένα")).to eq("Éna")
37+
end
2838
end

0 commit comments

Comments
 (0)