Référence › Référence du langage › Programs

Référence › Référence du langage

Cette page n’est pas encore traduite : voici la version anglaise.

Programs

A program's modules: each one TypeScript file, with its types and functions.

On this page: module · use · native

A program written in arche-lang (the program extension, ADR 010): its modules, each one TypeScript file archec gen --target typescript writes, with the types, constants, variables and functions written in it, the names it uses from another module and the packages it uses.

module#

A module of a program (the program extension, ADR 010): one TypeScript file archec gen --target typescript writes, with the types, constants, variables and functions written in it. Its function bodies are read from its body file (code). Its structs, unions and functions may be generic, struct Result<T>, union Either<L, R>, fn first<T>(xs: T[]) -> optional T (a function may return optional T, nothing or a T; a parameter and a variable may be optional T too): a type parameter is known inside its declaration only, and each use, Result<string>, is made concrete as a generic struct's is. A generic union or function outside a module is a program-type error. Its names (types, constants, variables, functions) are its own, as a package's: written bare in it, seen in another module that uses them, and not outside modules — two modules may each have a Span. native names a Node module or a package of package.json, and async fn a function TypeScript awaits. A constant or variable may have a TypeScript expression as its value, ts …, kept as written for the generated file. A function's parameter may have a default, cwd: string = ```ts process.cwd()````, and one written root: optional string = nil may be left out (root?: string). A type TypeScript has and the model does not is written quoted, "Record<string, number>" (optional "…"too), and each is counted (infots-type; a quoted "any"isany-type). A class(beta;abstract class, extends, implements) is export classin its file: the model declares its shape — fields,constructor(…) with its parameter properties (private x: T), fnmethods,getgetters, a field of a function type for an arrow-function field, each withprivate, protected, public, readonly, static, abstractorasync before it — and the body file writes the class itself, with the same members and their code (ts-class). export use x { a }andexport native "../x.ts" { a }` re-export names (beta).

  • Keywords: module
  • Set: programs
  • Where: top level, inside package
  • Syntax: module id ["Label"] { path "src/x.ts" [code "x.body.ts"] use other { a, B } native "pkg" as ns native "pkg" { type T; fn f(…) -> T } type … enum … struct Id[<T, …>] … union Id[<T, …>] … const X: T = value | ```ts …``` var … [async] fn id[<T, …>](../…) -> [optional] T … [abstract] class Id [extends T] [implements T, …] { [mods] x: T; constructor([mods] p: T); [mods] fn m(…) -> T; [mods] get g -> T } export use other [type] { a [as b] } | export use other [as ns] }
Property Value Meaning
description text Prose description. $…$ and $$…$$ are LaTeX math; a ```latex block is kept as LaTeX.
path string The file it is written to, relative to the project root: path "src/durations.ts". Every module has one, a .ts file inside the project, and no two the same (module-path).
code string The TypeScript file its function bodies are read from, relative to this file: code "durations.body.ts". Each fn of the module has its function there, unless it has a ```ts body, with the signature the model gives it — the same parameters, by name and TypeScript type, and the same result (ts-signature, ts-missing-body); a function there the model does not declare is the module's own, which no other module may use (ts-extra-export).
layout grouped | source | exact How its file is laid out: layout grouped (the default) writes the types, then the constants and variables, the body file's own statements, and the functions; layout source writes the body file's order: each fn where its function is, each other member where a place line // @place NAME names it (body-place), and the doc comments with their lines as written; layout exact is layout source and also writes the imports (native, use) and re-exports (export use) in the order the model declares them, a side-effect import where it is, not sorted. Beta.
module durations "Durations" {
  path "src/durations.ts"
  code "durations.body.ts"
  const SECOND = 1000
  fn toMs(s: float64) -> float64
}

use#

Names of another module of the program (the program extension), written bare in this one: its types, constants, variables and functions. A module the model does not have, or a name it does not declare, is use-unknown. The generated file imports them from the other's. export use x { a, b as c } re-exports them instead (export { a, b as c } from './x'), export use x all of them (export * from), export use x as ns as a namespace (export * as ns from), export use type x { A } as types (export type { A } from): a re-export brings no name into the module. Beta.

  • Keywords: use
  • Set: programs
  • Where: inside module
  • Syntax: use module { name [as other], … } | export use [type] module [{ name [as other], … }] [as ns]
use durations { parseDuration, DURATION_UNITS }

native#

A Node module or an npm package a program's module uses (the program extension): as fs names it as a namespace (import * as fs from "fs"), default pad its default export (import pad from "left-pad"); a block names what it takes from it, typed by the model (type SourceFile is one the package declares). A package that is neither Node's nor in the dependencies or devDependencies of the project's package.json is native-unknown: nothing is fetched. native "../ast.ts" { … } names a file of the project, relative to the module's file (info hand-import); native type "x" … brings in types only (import type); fn a as b(…) gives a name another; native "../extensions.ts" alone is imported for what it does. export native "../emit.ts" { systemModelFile } re-exports names of a file or a package (export { systemModelFile } from '../emit'), export native "x" all of them, export native "x" as ns as a namespace.

  • Keywords: native
  • Set: programs
  • Where: inside module
  • Syntax: native [type] "package" as name | native [type] "package" [default name] { type T; class C; const K: T; fn f(…) -> T; fn a as b(…) } | native "../file.ts" | export native [type] "package" [{ a, b as c }] [as ns]
native "fs" as fs
native "typescript" {
  type SourceFile
  fn createSourceFile(name: string, text: string) -> SourceFile
}