Skip to content

Commit 19bb688

Browse files
committed
feat: enable .isc loading via Interscript.transliterate()
Interscript.locate now searches for .isc files (preferred) alongside .iml and .imp. Compiler.call detects the file extension and dispatches to the ISC parser + NodeAdapter for .isc files, or DSL.parse for .imp. This makes ISC a first-class source format: users can call Interscript.transliterate("foo") and it will use foo.isc if present, falling back to foo.imp. Verified: identical transliteration output from .isc and .imp.
1 parent 32a34be commit 19bb688

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

lib/interscript.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def locate map_name
3131
map_name = map_aliases[map_name] if map_aliases.include? map_name
3232

3333
load_path.each do |i|
34-
# iml is an extension for a library, imp for a map
35-
["iml", "imp"].each do |ext|
34+
# isc: new ISC format, iml: library, imp: legacy Ruby DSL
35+
["isc", "iml", "imp"].each do |ext|
3636
f = File.expand_path("#{map_name}.#{ext}", i)
3737
return f if File.exist?(f)
3838
end

lib/interscript/compiler.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,28 @@ class Interscript::Compiler
1010

1111
def self.call(map, **kwargs)
1212
if String === map
13-
map = Interscript::DSL.parse(map)
13+
path = Interscript.locate(map) rescue nil
14+
map = if path&.end_with?(".isc")
15+
parse_isc(path)
16+
else
17+
Interscript::DSL.parse(map)
18+
end
1419
end
1520
compiler = new
1621
compiler.compile(map, **kwargs)
1722
compiler
1823
end
1924

25+
# Parse an ISC source file into an Interscript::Node::Document.
26+
# This bridges the new ISC format to the existing runtime.
27+
def self.parse_isc(path)
28+
source = File.read(path, encoding: "UTF-8")
29+
filename = File.basename(path)
30+
tree = Interscript::Isc::Parser.parse(source, filename: filename)
31+
doc = Interscript::Isc::DocumentBuilder.build(tree, filename: filename)
32+
Interscript::Isc::NodeAdapter.to_interscript_node(doc)
33+
end
34+
2035
def compile(map)
2136
raise NotImplementedError, "Compile method on #{self.class} is not implemented"
2237
end

0 commit comments

Comments
 (0)