Class InMemoryScriptLoader
- All Implemented Interfaces:
ScriptLoader
ScriptLoader that serves pre-parsed Scripts from an
in-memory map, keyed by path string.
It serves Scripts that are already built and so needs no
grammar of its own — which is why it stays in the engine while the text
frontend's FileSystemScriptLoader moved to relix-console. Where the scripts in
the map came from is the caller's
business: parsed .relix, deserialized, or hand-built.
Primarily intended for tests and embedded sessions — it lets you build multi-file import scenarios without touching the file system:
Script main = ScriptParser.parse("import './helpers.relix'; ...");
Script helpers = ScriptParser.parse("def double(x: NUMBER): NUMBER := { x * 2 };");
var loader = new InMemoryScriptLoader(Map.of(
"main.relix", main,
"helpers.relix", helpers));
SemanticResult result = new SemanticAnalyzer(loader).analyze("main.relix");
Path keys should be normalized (no . or ..
components). The loader performs exact key lookup and does not normalize
paths before matching. Use ImportGraph.resolvePath(java.lang.String, java.lang.String) to normalize
import paths when constructing the map.
The map is defensively copied at construction; subsequent changes to the original map do not affect this loader. This class is thread-safe.
-
Constructor Summary
ConstructorsConstructorDescriptionInMemoryScriptLoader(Map<String, Script> scripts) Creates a loader backed by the given path-to-script map. -
Method Summary
-
Constructor Details
-
InMemoryScriptLoader
Creates a loader backed by the given path-to-script map.- Parameters:
scripts- the registered scripts; must not be null- Throws:
NullPointerException- ifscriptsis null
-
-
Method Details
-
load
Returns the pre-parsed script registered forpath.- Specified by:
loadin interfaceScriptLoader- Parameters:
path- the exact key to look up (case-sensitive, not normalized)- Returns:
- the script for that path
- Throws:
IOException- if no script is registered underpathNullPointerException- ifpathis null
-
scripts
Returns an unmodifiable view of the registered path→script map.- Returns:
- the script map; never null
-