Repository navigation
Test your own host
As of v1.0.0
Racket is Typify's current reference host. The reader is a Racket package, and the archives on the Install page are built with it. Racket is not the definition of the language. A reader built on another host can replace it, and this page says what that reader must supply and how it is tested.
Three things define Typify, and none of them belongs to a host.
-
Its pattern dialect. A class is a quoted literal, a pattern
/.../in the regular core anchored to the whole capture, or a reference to a named class; classes combine by sequence, by alternation and byexceptover a list of literals. No class matches a control character (Cc), a format character (Cf, the zero-width joiner included), a line or paragraph separator (Zl, Zp), or any space separator (Zs) other than U+0020. The refusal is an intersection: a class's language is its pattern's language intersected with the allowed code points, so a negated range or., which matches any allowed code point, never admits a refused one, and a pattern such as/[^=]+/is accepted. A class is legal whatever code points it names, and a class whose language is empty after the intersection carries the noteN_CLASS_EMPTY, never an error. No host's regular-expression syntax is part of the language. See Classes. - Its string domain. A string is a sequence of Unicode code points. Strings are compared exactly, with no case folding and no normalisation. A diagnostic's columns count code points, with a byte offset beside them. A host whose own strings are bytes or UTF-16 code units still counts and compares code points. See Diagnostics.
-
Its public corpus, in
test/corpus/, of verdicts, terms, plans and answers. No expected value in it comes from the reader under test, and each value is tagged with its provenance: a value copied from the reader it tests cannot catch that reader's mistakes.
A host that passes the corpus may replace Racket without any change to the language.
Two defining languages are named and pinned. The reader's host language, Racket 9.3, pinned by the installer's hash in the release script, runs the reader. Each consumer's host language carries out what the reader computes. Contributing names both.
The reader's host supplies:
- The line shapes and the term syntax. A line is blank or a comment, a bang line, a colon line or an arrow line. Its outer blanks are stripped, and the verb and the argument are each stripped at the split. Inside the argument, a capture is the exact text the form's literals delimit, untrimmed, and its class decides. A term is a constructor followed by its arguments. See Language and Terms and counts.
-
The meta forms. The reader holds the forms of the meta language as one table. Every release carries that table's declaration source at
typify/share/typify.typify, besidebin/, andtypify emit Typifyprints its JSON grammar, or its GBNF text with--gbnf. See Emission. -
Module reading. A declaration file opens with
#lang typify, and the host reads it as a Typify module. -
The nine library functions:
parent,join,split,ancestors,prefix,suffix,equal,concatandinherited, each with the signature, result and domain of the table in Rules and plans. Each function takes only the arguments of its domain, which that table gives.parent,splitandancestors, andjoinin its first argument, take acanonical-path, the root/included, and refuse any other string with the codeE_LIBRARY_DOMAIN.join's second argument is one or more components joined by single slashes, with no leading, trailing or repeated slash, no empty component, none.or..and none holding U+0020, andjoinrefuses any other second argument, an absolute one included.concat,prefix,suffixandequaltake any allowed strings.inheritedtakes a declared constructor, an undeclared one beingE_DECLARATIONof kindreference:(inherited <constructor>)is the list of the first arguments of every term of that constructor in the program's enclosing programs, nearest program first and in line order within a program, and the empty list when there is none, whose loop emits nothing; a constructor of more than one argument under(inherited ...)or(context ...)isE_DECLARATIONof kindarity, never truncated to its first argument. It is evaluated when the located program is planned, and(context <constructor>)is its first element,E_CONTEXTwhen the list is empty. Inside the domain,parentof the root/is the one error;join / bis/b, andsplit /andancestors /are the empty list. A host reproduces each refusal and each error as an error, never as a host default, and there are no other edge cases.prefix,suffixandequalare predicates, usable only in(if ...)andensure. The functions are pure. None reads a file, starts a process or uses the network:inherited, the one that is not a function over strings, reads the terms of the enclosing programs, which the reader has already read.ancestors,splitandinheritedreturn lists, which(each <var> in <list> <term>)consumes under the cap of afuelline, as in(each <x> in (inherited deny-exec) <term>). -
The normalization order. Each term is reduced left to right, innermost first, and only that term's first failure is reported. A term with two failing library calls therefore reports the same failure on every host. Beyond one term, the reader reports every error it can find, ordered by file, line and column and, within one position, in the order of detection. A declaration is read whole, with all its errors reported, and a program is read only when its declaration has no diagnostic of error severity:
checkof a program under a failed declaration reports the declaration's diagnostics and exits with status 1 without reading the program. After a malformed line, the reader recovers as Every error, in order describes, and reports no diagnostic that only the recovery would cause. See Diagnostics.
There are three built-in classes, and a host adds no class of its own. letter matches one letter, a code point in the Unicode letter categories; a run of letters is letter+. canonical-path matches the root /, which has no components, and every other absolute path whose components are non-empty and none . or .., with no trailing slash, over the allowed code points other than U+0020, the space, so a path with a space fails the class. relative-path matches one or more clean components joined by single slashes, with no leading, trailing or repeated slash, no component . or .. and none holding U+0020, so a relative path joined under scope always yields a canonical path. An argument is resolved under scope only when the signature of the primitive or term that receives it declares it relative-path, or a class that is a bare reference to relative-path, directly or through further bare references: the reader joins it to the workdir of the program the scope names, and the resolved value must then be a canonical-path. In a variant of the Mounts example's bind declared primitive : bind : relative-path mode, the first position is resolved and the second is not; Mounts itself declares primitive : bind : path mode, whose path is a canonical-path, so nothing in Mounts is resolved. A pattern, a literal alternation, a sequence or an except is an ordinary class even when its members are relative strings, and a position of class canonical-path is never resolved; see Scope. A stacking cell's key is a tuple of width one or more whose last component is a path, of class canonical-path or a class the reader can show is a subset of it, and whose earlier components, if any, partition the cell: they are all the placeholders of the holding program's file template, in template order, and a put with fewer components, or any other value in those places, is E_DECLARATION of kind partition (see Stacking cells). A program located by a template writes only partitioned cells, stacking or not: every put or delete from it carries the template's placeholders as its leading key components, so a language with a file line has no unpartitioned write, and a template without placeholders supplies no component and leaves its writes unchanged. There are no host predicates: what a host has tested about the filesystem reaches the reader as a facts file, which typify facts ROOT writes and in which an absent fact of the collector's is false. The facts of version 1 are six: the collector's five, exists, directory, symlink, mode and owner, and clean, which the reader derives from the facts file and no collector writes, so it adds nothing to the file's wire. (clean <path> <name>) holds when <path> belongs to the observed facts root and no entry of the file at depth two or more below <path>, for which directory or symlink holds, has <name> as its last component: the entry <path>/<name> itself, a root's own immediate marker, is not a nested one, a regular file of that name is ignored, and an ancestor marker is declared separately, over ancestors; a reads or guard line naming any other fact is E_DECLARATION of kind reference. The collector writes canonical absolute paths, in root and in every argument, modes as four-digit octal strings, and the owner as the decimal uid in text. It never follows a symbolic link: a symlink fact carries the link's target text as its value. It reads each entry by lstat: exists holds for every entry it does not omit, dangling links included; directory holds only for a real directory, never for a link's target; and mode and owner are the entry's own metadata, a link's included. It includes the root itself. It omits an entry whose path is not a canonical-path, a space (U+0020) in a component included, and writes "omitted": n beside facts, n counting each omitted entry once, the descendants of an omitted directory included, since the traversal is not pruned, and never once per fact, when n is positive, and no omitted member otherwise; a fact over an omitted entry is absent, and clean does not see below it. omitted is part of the facts wire: when present it is a positive integer, checked as the rest of the file is, and when absent it is zero. Canonical is lexical: nothing resolves a symbolic link, neither the collector nor the reader. A facts file given with --facts whose collector string, root, fact names, arguments, modes or owners do not follow this wire is refused with E_FILE, carrying that file's path, and an E_FILE from a collector run carries the path of the root or entry that could not be read. A declaration reads a fact when it holds a guard line, a reads line, or a fact call inside (if ...) in a rule; tree needs facts for the first two only, and plan for all three. A command that needs a fact reads the facts file with --facts FILE, or, over a root, runs the collector itself without that flag; a one-program plan whose declaration reads a fact and that is given no --facts is E_USAGE, with --facts as actual, since there is no root to collect from; a tree or plan that needs no fact accepts a --facts FILE and ignores it, without opening the file. See Primitives and state.
A consumer's host supplies the execution of the primitives, and nothing else. plan prints the ordered primitive terms of each program as JSON, so the host is a loop over primitives. A primitive declared effect : <primitive> = state has its writes and no host action: plan --json lists its terms under recorded, an array of {"term": [...], "origin": {"kind": ..., "path": ..., "line": ...}} objects in plan order, apart from plan. The top-level origins refers to the executed terms of plan only, each state entry carrying its own origin, modelled counts executed terms only, and the host executes only the executed terms. Over a root, the plan is one list of every program's primitive terms, the schedule member, sorted by stage, stable in tree order and then term order, each entry carrying program, stage, sequence, term, origin, modelled and kind ("host" or "recorded"), and the predicted state is one fold over that list. Which primitives run, with which arguments and in which order, is declared in rules and computed by the reader.
In the Mounts example (see Examples), the rule rule : share <p> <m> -> mask (parent <p>) ; bind <p> <m> turns the program line share : /shares/research into a plan. Mounts has no file line, so it is planned one program at a time: typify plan mounts.typify Mounts shares.typify --json. Its plan member is:
[["mask", "/shares"], ["bind", "/shares/research", "rw"]]and its modelled member is "2 of 2", so its status member is "ok". The consumer's host implements mask and bind. It receives these terms, never the share line. Plans compare as ordered argument lists, never as sets.
A primitive may lack a writes line only when it is declared effect : <primitive> = external. plan then counts it unmodelled: each of its terms is printed as an object whose term member holds the term's array and whose unchecked member is true, where a modelled term is the array itself, and, when no diagnostic of error severity exists, the plan's status is "unchecked" in place of "ok". This is not an error: plan exits with status 0 unless a diagnostic of error severity exists. A primitive with neither a writes line nor that declaration is refused by check with E_DECLARATION, its data.kind being effect.
The public corpus is test/corpus/, one directory per case, indexed by test/corpus/MANIFEST.md. Each case holds its declaration, its programs and expected.json, which holds the case's expected verdicts, terms, plans and answers, each with its provenance tag. A case over a root whose declaration reads a fact also holds its facts.json, so that no result depends on the machine that runs it.
The corpus is written blind, from the language's text alone, by someone other than the author of the meta table, and imported verbatim. The reader's own fixtures never count as the corpus. No expected value comes from the reader under test.
Two further sets are public with it:
-
The hostile corpus,
test/corpus/hostile.json. All 107 of its hostile tokens are refused; the file also holds 10 delimiter cases and 9 positive controls, which are accepted. -
The outside multi-slot forms, in
test/decoder-corpus.json: five forms with several placeholders, restricted test dialects of five documented line-oriented formats outside this repository (an HTTP header field, systemdBindPaths, an OpenSSHRemoteForward, an APT one-line source and apasswdrecord). They are internal differential cases for the emission gate, separate from the blind verdict corpus; see Emission.
For each case, a host runs typify check, typify tree, typify plan, typify ask or typify emit with --json (or an invalid command or flag with --json for usage-error cases), or, for a case that tests the GBNF text, typify emit with --gbnf and without --json, in the forms the commands take:
typify check DECLARATIONS --json
typify check DECLARATIONS LANGUAGE PROGRAM [--facts FILE] --json
typify tree DECLARATIONS ROOT [--facts FILE] --json
typify plan DECLARATIONS ROOT [--facts FILE] --json
typify plan DECLARATIONS LANGUAGE PROGRAM [--facts FILE] --json
typify ask DECLARATIONS LANGUAGE WORD --json
typify emit DECLARATIONS LANGUAGE --json
typify emit DECLARATIONS LANGUAGE --gbnfA case over a root whose declaration reads a fact is run with --facts, FILE being the case's own facts.json, never with facts collected on the machine that runs it. The runner may pass --facts to every case over a root: a plan that needs no fact accepts the flag and ignores it, without opening the file, and prints none as the facts hash. The hash is none only when the declaration reads no fact or when no facts document was read and accepted: a facts file that cannot be read, or that does not follow the facts wire, is E_FILE, and a file off the wire leaves the hash none although its bytes were read. Whenever the declaration reads a fact and a facts document was read and accepted, the hash is that document's sha256: digest in every outcome, status failed included. Over a root without --facts, a plan that needs a fact runs the collector, and the hash is the digest of the collector's output exactly as typify facts ROOT writes it. check never reads a fact: a --facts given to it is accepted and ignored. A diagnostic's file, and a related entry's, is the path as given for a file named on the command line, and the portable path relative to the root, written with /, for a program the tree located; so a one-program case names its files relative to its directory.
The comparison reads these fields of a case's expected.json: stdout_json, diagnostics and the exit status, as Command line gives them, and, for a --gbnf invocation, gbnf_assertions, an object {"required_nonterminals": [...], "accepts_lines": [...], "rejects_lines": [...]} whose required_nonterminals holds the root alone, the root rule's presence and the membership of accepts_lines and rejects_lines in the language the GBNF text recognizes (see The GBNF text). Any other field of expected.json, aliases and LSP or SARIF projections included, is the case author's note and is not compared. The host's JSON output is compared as canonical JSON: keys sorted, no whitespace. The runner never compares bytes, so the order of an object's members and the spacing a candidate host prints do not matter. A diagnostic is compared by its code, file, range, and of data only the fields the registry lists for the code, never by its severity, message, fix or related; a host may add other fields to data, which the comparison ignores (see Codes and the registry). A note, such as N_CLASS_EMPTY, is compared like an error, by its code, file, range and data, and never changes the exit status. A diagnostic's range is a start and an exclusive end, each a one-based line, a one-based column counted in code points and a zero-based byteOffset counted in UTF-8 bytes from the start of the file, and expected.json compares that shape exactly; the range of E_REQUIRED, E_FILE and E_USAGE is null, and expected.json compares that too, as it compares the file of E_USAGE, the empty string ""; the Diagnostics page gives what the range of each code covers, under What a range covers. On the Catalog example (see Examples), whose program catalog.typify is the line item : journal = Market Research, typify check languages.typify Catalog catalog.typify --json prints:
{"ok": true, "terms": [["item", "journal", "Market Research"]], "diagnostics": []}and its canonical form is:
{"diagnostics":[],"ok":true,"terms":[["item","journal","Market Research"]]}A candidate host passes when, for every case, its output and its exit status match the case's stdout_json, diagnostics and exit status under these rules: canonical JSON, and diagnostics by code, file, range, and of data only the fields the registry lists for the code; and, for a --gbnf invocation, when its GBNF text satisfies the case's gbnf_assertions.
The corpus never compares the derived work bounds of the emptiness and overlap checks (see Caps). typify check DECLARATIONS --bounds reports them, as text, one guard per line, or with --json as one object, {"ok": true | false, "bounds": {...}, "diagnostics": [...]}, whose bounds member is an object holding each declared cap, keyed Language.cap even for one body, defaulted effective caps included, each constructor's fuel cap, keyed Language.constructor.fuel, and each host guard by its own name, each with {"limit": n}, and, when any body has rules, c and k, plain integers, the composition-wide maxima, separately from the normal check response and from the emitted grammar; they are not the bound member of check --json, which bounds plans. See Command line. The work bounds are host-dependent, and the report claims neither CPU steps nor a representation another host must copy.
A host may add guards of its own beside the declared caps. Its --bounds report lists them under the host's own names, such as temporary-states or reference-nodes. A guard that trips is reported as E_CAP, with the guard's name as cap, its configured limit as limit and the attempted count as actual; see Codes and the registry. No corpus case depends on a host's guard.
See Command line for the commands and their JSON, and Contributing for the measures every change to the reference host keeps green.