Hello,
We’re adding support for splitting ATD type definitions into smaller files. It wasn’t possible to conveniently reference types defined from other ATD files until now, resulting in large interface files (example).
I would like a pair of eyes to help me check the sanity of the spec which is copy-pasted below from the pull request before this goes live in atd 4.0.0.
Import declarations
An ATD file may import other ATD modules using import declarations.
Import declarations must appear after any top-level annotations and before
any type definitions.
Syntax:
import module.path as alias
The as clause is optional. Without it, the local name of the imported
module is the last component of the dotted path (e.g. import foo.bar
binds the local name bar).
Type names from an imported module are referenced using dot notation:
alias.typename (or lastcomponent.typename when no alias is given).
For example, if a module types is imported, the type date from
that module is written types.date in type expressions.
Annotations on the path or alias allow language-specific backends to
override the module name used in generated code. The annotation
<ocaml name="..."> (or the equivalent for another target language)
on the path controls how the module is referenced in generated output,
while the same annotation on the as clause controls the local alias
name used in the generated code.
Examples:
(* Simple import: local name is "common" *)
import mylib.common
(* Import with an alias *)
import mylib.common as c
(* Using an imported type in a definition *)
type event = {
id : string;
timestamp : common.date;
}
(* Language-specific name annotation on the path *)
import mylib.common <ocaml name="Mylib_common">
(* Language-specific name annotation on the alias *)
import mylib.common as c <ocaml name="Common">
Warning:
Dotted module paths (e.g.
import foo.bar.baz) are an experimental
feature. Each code generator maps them to file paths in its own way and
there is currently no guarantee of consistent behavior across backends.
When possible, prefer single-component module names (e.g.import baz
orimport foo as bar). Support for dotted module paths may be removed
in a future release.