Resolves and loads a CASC.md §5.1 import "..." statement, called
directly from Cooper.Actions' own handle_rule/3 clause for
:import_statement (not a separate, later pass) -- an import has to
be resolved inline, at the point it's parsed, so that variables it
brings in are visible
to whatever follows it in the importing file, for loops included,
exactly the way an ordinary @name = ... declaration already is.
Two import forms:
- A bare path -- resolves relative to
ctx.root(the current file's own directory, not the original entry file's -- each file's own imports are always relative to itself).**(glob) and{a,b}(brace) patterns expand against the filesystem; matches load in lexicographic order. - A
scheme://path -- dispatched toctx.import_schemes[scheme], the same map asCooper's own:import_schemesoption. An unregistered scheme is a load-time error naming it.
Each resolved file is a complete CASC file (own version header),
recursively run through the entire pipeline (this module calls back
into Cooper.Grammar's own run_with_context/3) before its ops ever
reach the importer. Import cycles (ctx.importing, a MapSet of
already-in-progress absolute paths) are a load-time error naming the
chain.
Summary
Functions
path is the import statement's already-evaluated string, or an
interpolated string whose references are all ${NAME}/${NAME:default}
-- those resolve from ctx.env, which is available while parsing. A
reference needing the finished tree (%{...}) cannot be, since an
import is resolved as the file is parsed, and is a load-time error. Returns the imported file(s)' spliced-together
op/var-decl entries and ctx with their public variables folded
into ctx.vars, ready to hand straight back as handle_rule/3's own
{:ok, entries, ctx}.
Functions
@spec load_import(term(), map()) :: {:ok, list(), map()} | {:error, Ichor.Error.t()}
path is the import statement's already-evaluated string, or an
interpolated string whose references are all ${NAME}/${NAME:default}
-- those resolve from ctx.env, which is available while parsing. A
reference needing the finished tree (%{...}) cannot be, since an
import is resolved as the file is parsed, and is a load-time error. Returns the imported file(s)' spliced-together
op/var-decl entries and ctx with their public variables folded
into ctx.vars, ready to hand straight back as handle_rule/3's own
{:ok, entries, ctx}.