Cooper. Loader
(Cooper v0.1.0)
Copy Markdown
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 (a load-time
error if it isn't a plain string -- an import path can't contain an
unresolved reference). 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 (a load-time
error if it isn't a plain string -- an import path can't contain an
unresolved reference). 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}.