java.lang.Object
com.darkcollective.relix.semantic.internal.InMemoryScriptLoader
All Implemented Interfaces:
ScriptLoader

public final class InMemoryScriptLoader extends Object implements ScriptLoader
A 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 Details

    • InMemoryScriptLoader

      public InMemoryScriptLoader(Map<String,Script> scripts)
      Creates a loader backed by the given path-to-script map.
      Parameters:
      scripts - the registered scripts; must not be null
      Throws:
      NullPointerException - if scripts is null
  • Method Details

    • load

      public Script load(String path) throws IOException
      Returns the pre-parsed script registered for path.
      Specified by:
      load in interface ScriptLoader
      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 under path
      NullPointerException - if path is null
    • scripts

      public Map<String,Script> scripts()
      Returns an unmodifiable view of the registered path→script map.
      Returns:
      the script map; never null