Repository navigation
Language
As of v1.0.0
This page is an overview of the language. Each section links to the page that owns its topic.
Typify is a metalanguage for line-oriented languages. A declaration file declares languages; a program is a text in one of them. The reader checks a program against its language and gives its meaning as data.
Meanings are terms (see Terms and counts). The form a line matches builds the line's term through its does line, and the term is checked against a declared signature. A program's meaning is the list of its lines' terms, in order, followed by its defaulted terms, printed as JSON.
A term's constructor is a fact or an effect. A fact's term is data. An effect is a primitive, which a host executes, or a constructor that a rule rewrites down to primitives. The reader computes the ordered list of primitives, the plan, and executes none of it (see Rules and plans).
A language can be asked about itself: every language accepts ? : <word>, and typify ask answers with the lines that declare the word; check takes no term from a question line and passes over it (see Questions).
The Catalog language, declared in the file languages.typify:
#lang typify
declare : Catalog
version : 1
file : catalog.typify
required!
is : category = "book" | "journal"
is : title = /[^=]+/
term : item : category title
form : item : <category> = <title>
does : item <category> <title>
example : item : book = Algebra
count : item = 1..*
end!
A program in that language, in the file catalog.typify:
item : journal = Market Research
Check it with typify check (see Command line):
typify check languages.typify Catalog catalog.typifyThe program is clean, so the command prints nothing and exits 0. With --json it prints the program's meaning as its terms:
typify check languages.typify Catalog catalog.typify --json{"ok": true, "terms": [["item", "journal", "Market Research"]], "diagnostics": []}JSON samples on this wiki are spaced and ordered for reading; the reader prints compact canonical JSON with object members sorted by key. Catalog declares no primitive, so item is a fact and its does builds data. The program's file name agrees with the declaration's file line, and the declaration file is named differently so that tree never reads it as a program. Examples walks through this language and a second one, Mounts, with rules and primitives.
Typify is defined independently of its reference host, by three things:
- its own pattern dialect, a regular core (see Classes);
- its own string domain: sequences of Unicode code points, so that no host's string model leaks into the language;
- a public corpus in the repository,
test/corpus/, of verdicts, terms, plans and answers, whose expected values never come from the reader under test and are each tagged with their provenance.
Racket is the current reference host, and the release script pins Racket 9.3 by the installer's hash. Any host that passes the corpus may replace Racket, and the language does not change (see Test your own host). Users never need Racket: the reader ships with its own runtime in an archive directory, typify/, and needs no Racket installed (see Install).
Typify has two defining languages, named on Contributing. The reader's host language supplies the line shapes and the term syntax, the meta forms, module reading, the nine library functions with their error cases, and the normalization order: each term left to right, innermost first, with that term's first failure reported. Beyond the normalization of one term, the reader reports every error it finds (see Commands). Each consumer's host language supplies the execution of its primitives and nothing else. There are no host predicates: what a host has tested about the filesystem reaches plan as a facts file, and reaches tree the same way when a declaration carries a guard or a reads line (see below).
A line ends at a line feed (LF) or at a carriage return followed by a line feed (CRLF). A lone carriage return (CR) ends no line, and it is a refused code point wherever it stands (see Refused code points).
A line is stripped of outer blanks and is then one of:
- nothing: a blank line, or a line that starts with the comment prefix (
#unless the language declares another); - a bang line,
verb!; - a colon line,
verb : argument, split at its first colon; - an arrow line,
left -> right, split at its first arrow, when the line has no colon.
Anything else is an error with the code E_LINE_SHAPE, which names the file and the line (see Diagnostics), and so is a colon line with an empty verb, a bang line with an empty verb, or an arrow line with an empty side. Every other line of one of the three shapes is decided by the forms, and a line that no form takes is an error with the code E_FORM_NONE. The verb class, which applies to the verb of a bang line and to the word a question echoes, is /[A-Za-z0-9][A-Za-z0-9-]*/. A refused code point makes no line shapeless: the shape is read from the line's colon, arrow or bang, and the code point is refused by the class of the token it stands in, or by the forms when it stands in a verb or a literal. The verb and the argument are each stripped of outer blanks at the split; inside the argument, a capture is the exact text the form's literals delimit, untrimmed, and its class decides. The shapes and the term syntax are the fixed kernel; everything above them is declared.
A declaration file opens with #lang typify and holds bodies, one per declared language. That line, the one token a host sees, marks the file as a Typify module, so no version selector is needed.
A program file has no header. The command that reads it names its language, or the declaration that locates it in a directory tree does (see Trees).
The version of the typify package is the version of the language: one grammar per release, no compatibility table, no legacy versions. A body's version line states its own language's version.
is : <name> = <class> binds a class, and the class of a placeholder decides what the placeholder may capture. A class expression is built from:
- a quoted literal,
"book"; - a pattern between slashes,
/[^=]+/, in a regular core: ranges with^,.for any allowed code point, alternation, grouping and the repetitions? * + {m} {m,n}; inside a pattern,\/,\|,\",\\and\.stand for the character after the backslash, the escapes\d,\w,\s,\xHH,\uHHHHand\u{H…H}are abbreviations of ranges, and the pattern ends at its first unescaped/; - a bare name, which refers to a class of the same body, of the meta body, or one of the three built-in classes:
letter, which matches one letter (a code point in the Unicode letter categories);canonical-path, which matches the root/, with zero components, and every other absolute path whose components are non-empty, over the allowed code points other than U+0020, the space, none of them.or.., with no trailing slash, so that a path with a space fails the class, a placeholder of the class can hold no delimiting space, andform : bind : <path> <mode>has no overlap; andrelative-path, which matches one or more components joined by single slashes, with no leading, trailing or repeated slash and none of them.or..or holding U+0020, the component rule ofcanonical-path, so a relative path joined under ascopealways yields a canonical path, and marks the signature positions whose arguments ascoperesolves (see From meaning to execution); - a sequence, by juxtaposition:
"0x" /[0-9a-f]+/; - alternation by
|:"rw" | "ro"; -
exceptfollowed by literals, which binds weakest:is : free-tag = tag except "all" | "none".
Grouping is written inside a pattern, and a run of letters is letter+. A class is anchored to the whole capture: a capture that fails its class is an error with the code E_CLASS, and a bare name in an is line that names no class is an error with the code E_CLASS_UNDECLARED. 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 a global intersection: a class's language is its pattern's language intersected with the allowed code points, so a negated range or . never admits a refused code point, and /[^=]+/ is accepted as a class. A class is legal whatever code points it names, and a class whose language is empty after the intersection carries the note N_CLASS_EMPTY at its is line, not an error. Caps bound the classes of each body; the meta body declares the defaults, and a body may lower them, never raise them. A capture longer than the length cap is an error with the code E_CAP, its cap being length, never E_CLASS. See Classes.
A body opens with declare : <Name> and closes with end!. Its lines are the meta forms below, grouped by the page that owns them. A body may not declare a class, term, primitive or cell under the name of a library function, a built-in class or a meta class (see Reserved names): such a line is refused with E_DECLARATION, its data.kind being duplicate and its actual the name. The same holds for a body named Typify, the meta body's name, and for a form with the verb ?, which the meta body alone declares, unless the declaration file's text is the reader's own meta source, byte for byte, which is the meta body itself (see Questions).
-
declare : <Name>andend!open and close a body. -
version : <number>states the declared language's own version. -
comment : <prefix>sets the comment prefix of the language's programs;#by default. -
order : strict | freestates whether a program's lines must follow the declaration order of their forms;freeby default. -
note : <constructor> = <text>attaches a note to a constructor,textbeing a meta class that admits any run of allowed code points;? : <word>prints the constructor'snotelines (see below). A check across the lines of one program, a fact beyond the six, and a mount whose path the host supplies are not in v1's model: each is a host precondition, oreffect : <primitive> = external, and stands in the consumer's declaration as anoteline, which? : <word>prints.
-
is : <name> = <class>binds a class. -
cap : states | repetition | depth | length = <n>lowers one of the body's caps: the control states of a class's compact pattern automaton (the pattern's minimal automaton, before any product with a length bound), the repetition, the reference depth, or the length of a capture, a counter of its own that is never charged against the states. The meta body's defaults are 4096, 256, 8 and 4096. Under the default length cap of 4096,/.*/is one control state and a counter.
-
form : <production>declares a legal line: one of the three shapes, with<placeholder>slots. -
restricts!, written below a form and belonging to the nearest form above it, marks a form whose absence fails open. -
does : <term>follows every form and gives its meaning. Besides the form's placeholders, it may use the placeholders of its language'sfiletemplate as captures (see Template placeholders in terms). -
example : <line>gives a line for the form above; the reader checks it and builds its term, library calls included, a template placeholder taking the shortest witness of its class, and a failing example is an error; an example whose library call fails carries the library's own code,E_LIBRARY_DOMAINorE_LIBRARY_PARENT, covering the library call in the form'sdoesline. Only a(context ...)or(inherited ...)is not evaluated at an example: its formation is still checked whole, and it is evaluated only when a located program is planned (see From meaning to execution). -
default : <line>stands after a form and gives a program line that is added when a program, present or absent, holds no term of that form's constructor (see below and Trees). Its arguments are literal text, never captures: adefaultline whose form'sdoesterm uses a template placeholder is refused withE_DECLARATION, itsdata.kindbeingsyntax, while text such as<name>written in adefaultline is read as literal text against the placeholder's class (refused withE_EXAMPLEwhen the class does not admit it). -
term : <constructor> : <class> ...declares a constructor and the classes of its arguments. A constructor with no arguments is written without a trailing colon,term : ready;term : ready :is refused withE_DECLARATION, itsdata.kindbeingsyntax. -
count : <constructor> = 1 | 0..1 | 1..* | *states how many terms of the constructor a program holds;*by default, and with only a keyed count the unkeyed bound is*. Withby <k>after the multiplicity it is a keyed count, which bounds each group of the constructor's terms that agree in their firstkarguments (see Counts and order);kis read under the meta classwidth, as the width ofdelete <k>is, soby 0is legal, and akgreater than the constructor's number of arguments is refused withE_DECLARATION, itsdata.kindbeingsyntax. A constructor carries at most one unkeyed and one keyedcount: a second of either kind isE_DECLARATIONof kindduplicate, with the line as written asactual, andby 0written out is the unkeyed form.
-
file : <template>locates the language's programs in a directory tree. A body holds onefileline, a second beingE_DECLARATIONof kindduplicate, and so is a placeholder name repeated within one template. The template's placeholders are bound in every program it locates: adoesline, a rule's right side or anensureline of the language may use<name>of a template placeholder as a capture of that placeholder's class, while awritesline, which is positional, takes none; a form placeholder or a rule variable of the same name isE_DECLARATIONof kindduplicate, and a language without afileline has no template placeholders (see Template placeholders in terms). A capture of a template placeholder reads the placeholders of the program that holds the term, whatever the term'sscope, which chooses only theworkdirthat joins arelative-pathargument, and a template placeholder's class is checked against the receiving signature when the declaration is read. In the one-program forms ofcheckandplan, the placeholders are bound by matching the program's path, as given on the command line, against the template, and a path that does not match isE_USAGE, with the path asactual. -
required!andoptional!make a missing program an error (the codeE_REQUIRED), or allow it.E_REQUIRED'sfileis the declaring file, the declaration file whose declaration carries therequired!line, by its path as given on the command line, and itsrangeisnull; the missing program's path, or, for arequired!template whose file name introduces a placeholder and that locates nothing, the template, isdata.pathalone and appears in no other field. -
sees : <Name>states that the programs name things another language's programs declare; 1.0 checks that the language exists. Aseesline names one body, and several bodies take severalseeslines:sees : Config Notesis one invalid name, refused withE_CLASSon theseesline, itsdata.classbeing the meta classname.
-
fact : <constructor>declares a constructor a fact, whose terms are data, in a body that declares primitives. -
primitive : <constructor> : <class> ...declares a term that a host executes, unless it is declaredeffect : <primitive> = state, with the classes of its arguments. A primitive with no arguments is written without a trailing colon,primitive : ready;primitive : ready :is refused withE_DECLARATION, itsdata.kindbeingsyntax. -
effect : <primitive> = external | statedeclares, withexternal, a primitive that has nowritesline;plancounts it unmodelled and prints itunchecked. Withstate, it declares a primitive that has itswritesand no host action:planlists its terms underrecorded, apart from the executed ones. A primitive that has nowritesline and is not declaredexternal, one declaredstateincluded, is refused bycheckwithE_DECLARATION, itsdata.kindbeingeffect. -
writes : <primitive> : <cell> = put <width>, optionally followed by a quoted literal, or= delete <width>, states the cell a primitive writes and its write. The width is the number of leading arguments that form the key, and the rest are the value; a put with no value writes the entrymasked, at whichboundfails. A state entry'smaskedis its own put's flag,trueexactly when the put that wrote the entry carried no value andfalsewhen it carried one; an entry hidden by a later mask at an ancestor keeps its ownmasked, since that hiding is visibility, judged by(visible ...)when an invariant is evaluated and serialized nowhere: a state entry has no visibility field. A quoted literal after the width, as inwrites : deny-access : denied = put 1 "denied", is a value appended after the primitive's remaining arguments, admitted as written; it stands in the state entry, not in the primitive's term. A cell's value is the put's values as written, zero or more, of no fixed arity, so in one cell a mask may put none and a bind two; the class of each value is the writing primitive's signature at that position, or the literal itself, and only ajoincell fixes one value argument, over its table's domain. A cell's key width is fixed by its first put writer, resolved in the declaration order of the languages, then in line order, never in tree order; every other put to the cell must have that width and every delete a width from 0 to it, a mismatch beingE_DECLARATIONof kindconflict. A root in which a cell has no put writer at all is refused atplanwithE_DECLARATIONof kindreference, and no width is guessed fordelete 0; a declaration file checked alone whose cell has only delete writers passescheckwith the noteN_CELL_WIDTH(see Writes and widths). A delete of widthkremoves every entry whose firstkkey components equal the term's firstkarguments, compared as whole components, never by path ancestry inside a component, and, on a cell that is not partitioned,delete 0clears the whole cell, a stacking cell included. On a partitioned cell (see below), adeletenames at least its partition components, on a stacking cell all key components but the last:delete kwithktheir number clears one partition,delete 1on a stacking cell whose key has width 2, and adelete kwithkbelow their number,delete 0included, isE_DECLARATIONof kindpartition, reported at thewritesline whole, with the line as written asactual. -
cell : <name> = shadow | first | join <table>, optionally followed bystacking, declares a cell and its law: undershadowa later put replaces, underfirstthe first put stays, and underjoinputs are combined by the named table.stackingmarks a cell whose keys end in paths, where a later put at an ancestor hides a descendant: its key is a tuple of width one or more whose last component is a path, of classcanonical-pathor a class the reader can show is a subset of it, and whose earlier components, if any, partition the cell. The earlier components of a partitioned key are all the placeholders of the holding program'sfiletemplate, in template order, and each such component of aputordeleteterm is a placeholder of that template; a put with fewer components, or any other value in those places, isE_DECLARATIONof kindpartition, reported when the declaration is read, on thedoesorruleline whole whose term supplies the components, with the term as written asactual. A program located by a template writes only partitioned cells, a stacking cell or any other: everyputordeletefrom it carries the template's placeholders as the leading key components, so a language with afileline has no unpartitioned write, and underfile : teams/<team>/shares.typifywithwrites : bind : mounts = put 1adoesorruleline buildingbindisE_DECLARATIONof kindpartitionat thatdoesorruleline whole (while awritesline whoseputwidth is smaller than the number of template placeholders, such asput 1underfile : teams/<team>/<kind>/shares.typify, is reported at thatwritesline whole); a template without placeholders supplies no component, and its writes are unchanged. Ancestry, masking and visibility are judged only among entries whose earlier components are equal, so one partition's mask never hides another partition's path (see Stacking cells). A stacking cell whose key's last component has any other class isE_KEY_CANONICAL, which covers thecellline whole, the cell being the subject of the defect. A cell that is not stacking may have a key of any width, at least as wide as the template's placeholders when a program located by a template writes it, a tuple of arguments. Cell names are global across the languages of a root: cells of one name are one cell only when they agree on the class of each key component, the same built-in class in both or a declared class of one name whose expression is identical as written in both bodies, and on their law, stacking, key width and join table, a disagreement beingE_DECLARATIONof kindconflict, and the state's keys are the bare cell names. -
join : modes : "ro" "rw" = "rw"is one line of the join tablemodes, and over the two literals"ro"and"rw"the whole table. Ajoincell has exactly one value argument, over a class of literals, and its table lists every unordered pair of distinct literals once: a line names its pair once,"ro" "rw"and"rw" "ro"being the same pair, and the reader derives the symmetric entry. A literal joined with itself is that literal, by idempotence, and need not be listed, so the table is commutative and idempotent by construction: the diagonal is implicit, a listed pair of a literal with itself whose result is its own literal is legal and ignored, and one whose result is another literal isE_JOIN_LAWwithexpectedidempotentand the diagonal's own literal, not the result, asactual. The table's domain is the literal class of the value argument of the cell that names it, and two cells that name one table must share that class, the latercellline in position order within the declaration file beingE_DECLARATIONof kindconflictotherwise. When it reads the declaration, the reader checks the table's laws and rejects a table that fails one with the codeE_JOIN_LAW, whoseexpectednames the law and whoseactualholds the values involved, decoded, a pair or a triple being its literals separated by one space, an authored pair in authored order, a pair or a triple that nothing authored in the order of the value class's literals, and, for a table no cell names, a triple that nothing authored in the order of its literals' first appearance in the table'sjoinlines, each line read left to right, its result included:complete, with a missing pair;once, for a pair listed twice with different results, with that pair;associative, with a triple;idempotent, with the diagonal's own literal; andclosed, for a pair or a result that names a literal outside the domain, with that literal. So the pair ofjoin : modes : "ro" "rw" = "rw"is theactualro rw. A table that no cell names is checked foronce,associativeandidempotentover the literals it lists, and forcompleteandclosedonly once a cell names it. A pair listed twice with different results is anchored at the second listing; otherwise the table's firstjoinline carriesE_JOIN_LAW.E_JOIN_LAWnames the table ascelland is reported once, whether two cells use the table or none, and acellline that names an undeclared table isE_DECLARATIONof kindreference. Joins over tuples are not in 1.0. -
reads : <primitive> : <fact> = skip | rejectstates a fact a primitive reads and what an absent fact does. A bare fact name is read at the primitive's key, the firstwidtharguments of itswrites, or, on a partitioned cell, with the key components after the partition: a fact of one argument takes one such component, and a key with more isE_DECLARATIONof kindarityon that line, which must then be a parenthesized call; a fact called in parentheses supplies its own arguments. The facts are six, the collector's five,exists,directory,symlink,modeandowner, andclean, which the reader derives from the facts file, and areadsorguardline naming another is refused withE_DECLARATION, itsdata.kindbeingreference. -
ensure : <constructor> : <name> = <predicate>attaches a named invariant to the terms of a constructor, whether the constructor is rewritten, a primitive or a fact. Its variables<1>to<n>are bound by position to the constructor's arguments. It is evaluated once per term that carries it, against the final predicted state, after the whole plan. The built-in predicates name the cell, then each component of the key as a separate argument; there is no list-valued key. With a one-component key they read(bound <cell> <key>), which holds when the latest put at the key has a value,(masked <cell> <key>), which holds when the latest put at the key has no value,(visible <cell> <key>)(bound, and no later put at a stacking ancestor in the same partition, an entry whose earlier key components are equal),(absent <cell> <key>), and, for a stacking cell,(covered <cell> <key>), which holds when some proper ancestor of the key's last component, in the key's partition, satisfiesvisible, and its negation(uncovered <cell> <key>). These state predicates are usable inensureonly (where binary conjunction(and P Q)may also join state or library predicates, evaluated left to right), and they observe only the final predicted state, whoever wrote it (see Invariants). A state predicate reads the cell it names and nothing else, so a check about one kind of entry reads a stacking cell that only that kind writes, keyed by the resolved path. Protected paths take two cells, written for instance by a program at the root:protected, a stacking cell of the protected paths, read with(uncovered protected <1>), which refuses a grant below one, andprotected-above, each protected path and its proper ancestors, written with(each <a> in (ancestors <p>) ...)plus the path itself and read with(absent protected-above <1>), which refuses a grant at or above one. Their writers put a value, as inwrites : protect : protected = put 1 "protected"andwrites : protect-above : protected-above = put 1 "protected", since a valueless put writes the entrymaskedanduncoveredwould then pass every grant. A state predicate inside(if ...), andcoveredoruncoveredon a cell that is not stacking, areE_DECLARATIONof kindsyntax, on theruleorensureline whole. In Mounts,ensure : share : child-visible = (visible mounts <1>)requires the path, the first argument ofshare, to be visible in the cellmounts.
-
rule : <constructor> <var> ... -> <term> ; <term> ...rewrites one term into a sequence of terms. -
stage : <primitive> = <n>puts a primitive in a stage; stages run in ascending order, and the default stage is 0. -
guard : <constructor> = <fact>plans a program that holds a term of that constructor only when the fact holds. A bare fact name takes the first argument of the constructor's own term as written when the constructor is rewritten, the key arguments of its firstwriteswhen it is a primitive, or, when that cell is partitioned, the key components after the partition: a fact of one argument takes one such component, and a key with more isE_DECLARATIONof kindarityon that line, which must then be a parenthesized call, and its first argument when it is a fact; a fact called in parentheses supplies its own arguments. A guard on a rewritten constructor is evaluated before any rule expansion, so no context, fuel or library error comes before a false guard. -
scope : <constructor> = program | parent | rootnames the program whoseworkdirterm resolves therelative-patharguments of that constructor's terms;programby default. The scope carries into every primitive the constructor's rules emit, until a constructor inside the expansion declares its own. -
fuel : <constructor> = <n>declares the fuel cap of a for-each,(each <var> in <list> <term>).
-
? : <word>is reserved in every language and asks it about a word. A question is never counted, never ordered and never part of a program's meaning:checktakes no term from it, and a host that answers it runstypify askfor the word. It is accepted wherever a line is read: in a declaration file, inside or outside a body, a well-spelled question line declares nothing and is not reported, and one whose word fails the verb class isE_QUESTION. An answer's forms are those whose verb is the asked word and those whosedoesline builds the constructor the word names, each once, in declaration order. A form line and itsdoesline are a pair, and the pairs come first, in declaration order. The answer's lines come in this order: the first form line, the language'sfileline, the firstdoesline and the form'srestricts!line when it has one, then each further form line with itsdoesline and itsrestricts!line when it has one; then, once, thetermorprimitiveline, theislines of the forms' and the template's placeholders that thedoeslines name, each once, in the order of their first naming, the constructor's own lines, every line whose first name after the introducer is the constructor (writes,reads,guard,effect,stage,scope,fueland, for a fact constructor,fact), in declaration order, whatever its kind, therulelines whose left side is the constructor, itsensurelines, the examples, the count lines (the unkeyedcountline, orcount : <constructor> = *when none is declared, then the keyed one when one exists), themissingline, thedefaultlines, and the constructor'snotelines last. An answer with more than one constructor prints the lines from thetermorprimitiveline through theensurelines, each constructor with theislines of the placeholders that its own forms'doeslines name, each once within its group, in the order of their first naming, and later thecount,missinganddefaultlines, for each constructor in turn; itsexamplelines print once, in their place, in form order, and itsnotelines last, for each constructor in turn.
A program line is tried against the forms in the order they are declared, and the first form that matches wins. Each placeholder captures the text up to the next occurrence of the literal that follows it in the form, or to the end of the line, and its class decides. The reader never backtracks. So a declaration is rejected when it is read if two of its forms shadow each other (the code E_FORM_SHADOW), or if two adjacent placeholders cannot both capture or a class can hold the literal that follows its placeholder (the code E_CLASS_OVERLAP). For every declaration that passes, the grammar that emit prints accepts exactly the lines that the reader accepts as well formed under the line shapes and the declaration's forms and classes: the formation judgment. Counts, order, the results of library calls and the resolution of names are judgments on programs and declarations that the reader makes after formation, and a line grammar cannot carry them. The differential test of the emission gate compares formation only; refusals such as parent of /, a library result outside its receiving class, or an empty program under count = 1 are semantic tests beside it, never grammar failures (see Emission). Constraints on counts and order in the emitted grammar are an option for 1.1.
count : <constructor> = 1 | 0..1 | 1..* | * states how many terms of a constructor a program holds: exactly one, at most one, at least one, or any number. * is the default, and the multiplicity has no other spellings. count : <constructor> = <multiplicity> by <k> applies the multiplicity to each distinct tuple of the first k arguments among the constructor's terms of one program, defaulted terms included; the plain form is by 0, one tuple, the empty one, so the whole program. The unkeyed count bounds the constructor's terms in a program, and the keyed one each group of them. A keyed count constrains only the groups that occur and requires none to exist, so it fails only by excess within a group and never satisfies restricts! on its own. A violation is E_PROGRAM_COUNT, with the multiplicity as written, a string, as expected, the group's count, an integer, as actual, and its tuple, an array of decoded strings, empty under an unkeyed count, as key. A keyed count gives one diagnostic per failing group, each anchored within its program as a count failure is, and an unkeyed failure's stands beside them, all in position order.
order : strict requires a program's lines to follow the declaration order of their forms, with each form's lines contiguous; a program that breaks it is an error with the code E_ORDER. order : free allows any order and is the default. See Terms and counts.
The reader is closed-world: a line that a program does not hold is no term. A default : <line> line stands after a form and is activated per constructor: when a program, present or absent, holds no term of that form's constructor by any form, every default line of that constructor's forms is added, in declaration order, after the program's own terms, with an origin of kind default, which names the declaration file and the line of the default line; a present line of the constructor suppresses them all. Activation precedes the count check, so a default satisfies count = 1, and an absent optional program holds only its defaults. count decides when an absence is an error: under count : item = 1..*, a catalog with no item fails with the code E_PROGRAM_COUNT.
A form whose absence would fail open is marked by a restricts! line below it; the nearest form above a restricts! line is the form it marks. Its constructor must then carry an unkeyed count = 1 or 1..*, or a default line under any form that builds it, and the reader rejects the declaration otherwise, with the code E_RESTRICTS. In the Shelf language of Trees, the restricting form access has a default line:
form : access : <state>
restricts!
does : access <state>
example : access : open
default : access : closed
count : access = 0..1
What happens when a program holds no term of a word's constructor is part of the answer to ? : <word>, its missing line, which states the case in one word: ? : missing : default, ? : missing : refused or ? : missing : empty, the default lines that follow stating the defaults themselves. In Shelf, the answer to typify ask DECLARATIONS Shelf access holds ? : missing : default, followed by ? : default : access : closed (see Questions). tree reports each program as present, defaulted, absent-empty, missing or guarded (see Trees).
A constructor is a fact or an effect. In a body that declares no primitive, every constructor is a fact and a does line builds data; Catalog is such a body. In a body that declares a primitive, every constructor is a primitive, is rewritten by a rule, or is declared fact : <constructor>; any other constructor is rejected when the declaration is read, with a column. The meta body declares primitives, so this rule binds the meta language whole. Its kernel primitives are declared external, so the reader treats each as external, and plan over the meta body is refused with E_USAGE. See Terms and counts and Rules and plans.
A host executes a term whose constructor is declared primitive, unless the primitive is declared effect : <primitive> = state; a term whose constructor has a rule is rewritten into a sequence of terms. Rules are stratified: a right side may use only constructors declared earlier in the body than the left side's constructor, primitives, and library functions. A left side is a constructor applied to variables, and a constructor has at most one rule, so every term has a normal form. Rule cycles and duplicate rules are rejected with a column; their codes are E_RULE_CYCLE and E_RULE_DUPLICATE.
A primitive names the cell it writes in its writes line, unless it is declared effect : <primitive> = external, and the facts it reads in its reads lines; a primitive with neither a writes line nor that declaration is refused with E_DECLARATION of kind effect. A cell's cell line gives its law, and ensure lines attach invariants to terms. From them the reader predicts the state a plan leaves. Rules and primitives have eight further constructs:
-
stage : <primitive> = <n>: primitives run in ascending stage, in plan order within a stage. Over a root, the plan is one list of every program's primitive terms, sorted by stage, stable in tree order and then term order. -
(context <constructor>): the first element of(inherited <constructor>), that is, the first argument of the nearest enclosing program's first term of that constructor, in line order; an error,E_CONTEXT, when no enclosing program has one. A program's enclosing programs are the programs whose located file lies in a proper ancestor directory of the program's own directory, nearest directory first. Programs in one directory are siblings and never enclose one another, and(context ...)searches enclosing programs only. Several programs in one enclosing directory are ordered by the declaration order of their languages, then by path. Both lookups takeLanguage.constructor; a bare name is resolved when the declaration is read, against the composition, the set of bodies of the declaration file, in the one-program forms as under a root: it is accepted when exactly one body declares it, and is otherwise refused withE_DECLARATIONof kindreference, with the name asactualand the declaring bodies inrelated. Every command reads the declaration first and reports all its diagnostics (see Commands), so a bare-name reference is refused bytree,plan,askandemitas bycheck. A constructor of more than one argument under either lookup isE_DECLARATIONof kindarity, with the constructor as named asactual, never truncated to its first argument. Under(context ...)and(inherited ...), formation is checked whole when the declaration is read: the constructor named exists, an undeclared one beingE_DECLARATIONof kindreference; the expression's sort is a list undereachand a string elsewhere,E_TERM_CLASSof kindsortotherwise; and a constructor whose rules carry aneachhas its fuel cap, acontextoutside anyeachrequiring none. Only the values are read when the located program is planned, against its enclosing programs. A lookup that crosses a guarded program adds to the reading program'sskipsthe entry{"reason": "guard", "fact": ..., "args": [...], "program": ...},factandargsbeing the guarded program's guard fact and its evaluated arguments, andprogramthe guarded program's portable path. - A keyed merge is a
joincell, and a reset is adeletewrite. -
(if <fact-call> (<term>)): the parenthesized term is emitted only when the fact holds for its arguments; otherwise nothing is, andplanrecords the skip with its origin, itsskipsentry carrying the suppressed term's constructor asconstructor, never that of the rule that carries the(if ...). The fact is always a call in parentheses with its arguments; a bare fact name there isE_DECLARATIONof kindsyntax.(if ...)takes a fact call or one of the library predicatesprefix,suffixandequal, never a state predicate: the state predicates observe only the final predicted state, and a conditional over the state is not in v1. A state predicate inside(if ...)isE_DECLARATIONof kindsyntax, on theruleline whole. - A check over constants is an
ensureline. -
guard : <constructor> = <fact>: a program holding a term of that constructor is planned only when the fact holds; otherwise its terms are skipped andtreereports the programguarded. -
scope : <constructor> = program | parent | root: the program whoseworkdirterm resolves the relative arguments of that term, and of every primitive its rules emit until a constructor inside the expansion declares its own scope. The valueprogram, the default, names the program itself;parentnames the nearest enclosing program, and requires one in a strict ancestor directory;rootnames the shallowest program among the program itself and its enclosing programs (nearest the root of the tree; an absent optional program there with noworkdirisE_CONTEXT). An argument is resolved only when the receiving primitive's or term's signature declares its positionrelative-path, or a class that is a bare reference to it, directly or through other bare references, as inprimitive : bind : relative-path mode. It is then joined to the first argument of theworkdirterm of the program the scope names, and the resolved value must be acanonical-path. A pattern, a literal alternation, a sequence or anexceptis an ordinary class even when its members are relative strings; a position of classcanonical-pathis never resolved, and a relative capture that reaches it fails its class check; no mark passes from a form's capture across a signature. A language with noworkdirterm admits no relative argument, and arelative-pathargument with noworkdirterm in scope isE_CONTEXT. -
(each <var> in <list> (<term>))withfuel : <constructor> = <n>: the parenthesized term once per element of the list, at mostnelements consumed, and more is an error,E_RULE_FUEL, which over a lookup carries inrelatedthe origin of the first term past the cap. Each loop, nested loops included, is bounded by its carrying constructor's fuel cap on its own, and the plan's bound takes every loop at its cap. Lists come fromancestors,splitandinheritedonly, as in(each <x> in (inherited deny-exec) (<term>)); a fact carries a boolean or a text value, never a list.
The nine library functions are pure, and Rules and plans gives each one's signature, result and domain: parent, join, split, ancestors and concat compute strings and lists from strings, inherited computes a list from the terms of the enclosing programs, which the reader has already read, and prefix, suffix and equal are predicates, usable only in (if ...) and ensure. None touches a file, a process or the network. (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 it is E_DECLARATION of kind arity, never truncated to its first argument. Like split and ancestors, it is used on a rule's right side, written in parentheses, and as the list of a for-each, (each <x> in (inherited <constructor>) <term>), which emits in list order, nearest first: a shadow cell then keeps the farthest program's value and a first cell the nearest, so a consumer that wants the nearer program to win declares the cell first. prefix compares strings and never stands for path containment, which is equal over ancestors, or covered on a stacking cell. parent, split, ancestors and the first argument of join take a canonical-path, the root / included, and refuse any other string with the code E_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 and none . or .. or holding U+0020, and is refused otherwise; concat, prefix, suffix and equal take any allowed strings; inherited takes a declared constructor, an undeclared one being E_DECLARATION of kind reference. There are no other edge cases: outside its domain a call is an error, never a host default, and parent of / stays an error, with the code E_LIBRARY_PARENT, although / itself is a canonical path.
typify plan is tree followed by normalization; for a language without a file line it plans one program, as check checks one. It prints the ordered primitive terms of each program and, beside them, the predicted final state (over a root, the state after one fold over the stage-sorted list of all its programs' primitive terms), its bound, the origin of every executed term, each state entry carrying its own origin, the results of the ensure lines, each evaluated once per term that carries it against that final state, listed per program and for the root, the skips, each naming its constructor, fact, arguments, reason (if, read or guard) and origin, except the entry of a lookup that crossed a guarded program, given above, and, over a root, listed in each program's entry and nowhere at the top level (see typify plan), how many primitives are modelled, as k of n, counting executed terms only, and, under recorded, apart from plan and, over a root, beside it in each program's entry and nowhere at the top level, the terms of every primitive declared effect : <primitive> = state, an array of {"term": [...], "origin": {"kind": ..., "path": ..., "line": ...}} objects in plan order, the top-level origins referring to the executed terms of plan only; a primitive that is not modelled is printed unchecked, never ok, and no plan that holds one reads green. Such a plan is not an error: a modelled term is an array, its constructor then its arguments, and an external one the object {"term": [...], "unchecked": true}, the plan's status is failed when a diagnostic of error severity exists, and otherwise ok when every primitive is modelled and unchecked when one is not, text mode prints the status on its first line, and the exit status is 0 unless a diagnostic of error severity exists. In JSON the state is one list of entries per cell, in key order (on a stacking cell each surviving entry also carries sequence, the zero-based position of the write that established it; see Primitives and state), over a root the object also carries schedule (the stage-sorted list of operations across all programs) and inputs (see docs/plan-wire.md and docs/inputs.md in the repository), and the object carries a diagnostics array, empty when nothing is reported. A complete expansion can fail only at the fold, with E_FACT_REJECT, or after it, with E_ENSURE, and either failure prints status failed and exits with status 1. On E_ENSURE the fold is complete, and plan --json prints its arrays, state and ensure whole, with one E_ENSURE per false entry. On E_FACT_REJECT the fold stops at the rejected read: state is {} and ensure is [], since every invariant is evaluated against the final state after the whole fold, which does not exist; skips holds the skips decided before the rejection, each skipped term out of plan, origins, recorded and modelled; plan and origins hold the expanded plan as a successful plan would print it up to the rejected read, the rejected term itself, and every term after the rejected read as expanded, undecided. recorded and modelled describe the expanded plan, whether or not the fold reached a term: recorded holds the terms of state primitives in plan order, before and after the rejected read, all but those skipped before it, and modelled counts every term of plan, the undecided ones included. E_CONTEXT, E_LIBRARY_DOMAIN, E_LIBRARY_PARENT, E_RULE_FUEL and every other diagnostic raised while a plan is expanded or normalized are failures within expansion, since lookups, inherited lists and library calls are evaluated as a rule's right side is rewritten. Such a failure prints the object of a plan where nothing was planned, with plan, origins, recorded and skips empty, state {}, over a root programs [], modelled "0 of 0", status failed and its computed bound, and exits with status 1; the failing term is named by the diagnostic's range and data alone, never by the arrays, and nothing of a partial rewrite is printed. A rule cycle is not a failure within expansion: E_RULE_CYCLE is found when the declaration is read, and a rewrite that runs away ends as E_RULE_FUEL. When nothing was planned, because a declaration has an error, an input cannot be read or the expansion fails, plan --json prints its object with status failed, its arrays empty, over a root programs included, state {}, modelled "0 of 0" and diagnostics holding the diagnostics. Every plan terminates, and its length is within the bound the reader computes from the declaration and the input; bound is a member of the JSON object whenever both were read, and text mode prints no bound line, a failed plan included, and zeros are never printed in its place; it is null when the declaration has an error and nothing could be computed. c_D bounds every folded event, executed and recorded alike, and the state's size is at most k times the sum of the lengths of plan and recorded.
The filesystem enters as data. typify facts ROOT writes the facts file for a root, holding the collector's five facts, exists, directory, symlink, mode and owner; an absent collected fact is false. The collector 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. The sixth fact of v1, (clean <path> <name>), is derived by the reader from the facts file and written by no collector: it holds when <path> belongs to the observed facts root and no entry 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. It is usable wherever a fact call is, in a guard, a reads line or (if ...), as in guard : share = (clean <1> ".git"). 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 a facts file given with --facts FILE, or without it runs the collector itself over its root, and plan --json carries the file's hash in its facts member, so a plan is a pure function of the declarations and the facts; the one-program plan has no root to collect from, so when the declaration reads a fact and no --facts is given, it is E_USAGE, with --facts as actual. The hash, the facts member of plan --json, is sha256: followed by sixty-four lowercase hex digits, or none. Over a root without --facts, a plan that needs a fact runs the collector, and facts is the digest of the collector's output exactly as typify facts ROOT writes it. The digest names the bytes read: whenever the declaration reads a fact and a facts document was read and accepted, facts carries its sha256: digest in every outcome, status failed included, and facts 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 its hash is none even when its bytes were read. A tree or plan that needs no fact accepts a --facts FILE and ignores it, without opening the file; check never reads a fact, and accepts a --facts FILE and ignores it. The reader executes no primitive: a host is a loop over the plan's primitives. See Primitives and state and Rules and plans.
Each command is described on Command line.
-
typify check DECLARATIONSchecks a declaration file, andtypify check DECLARATIONS LANGUAGE PROGRAM [--facts FILE]checks a program;checknever reads a fact, so a--factsgiven to it is accepted and ignored, and theE_USAGEfor a missing--factsisplan's alone; without--bounds,checkin text mode prints diagnostics only, and nothing when there is no diagnostic; a note is printed although the exit status stays 0. -
typify check DECLARATIONS --boundsreports the derived work bounds of the emptiness and overlap checks, as text or with--json, separately from the normalcheckresponse and from the grammar. In text mode the report is one guard per line; with--jsonit is one object with the membersok,boundsanddiagnostics,boundsbeing an object that holds every declared cap, keyedLanguage.capeven for one body, defaulted effective caps included, each constructor's fuel cap, keyedLanguage.constructor.fuel, and each host guard by its own name, each with{"limit": n}, and, when any body has rules,candk, the rule bound ofcheck --json, as plain integers, the maxima over the composition. The bounds depend on the host: the corpus never compares them, and the report claims neither CPU steps nor a representation another host must copy. -
typify tree DECLARATIONS ROOTreads every program the declarations locate under a root. When a declaration carries aguardor areadsline, it takes--facts FILEor runs the collector asplandoes; otherwise it needs no facts and ignores a--facts FILEwithout opening it. In text mode it prints one line per program, its status then its path, and with--jsonit prints one object, the model underprograms, one entry per program, besideok,diagnostics,factsandinputs. -
typify plan DECLARATIONS ROOT [--facts FILE]plans every program under a root and, in text mode when the fold completes, prints its status,failed,okorunchecked, on the first line, then one primitive term per line, prefixed by its program's path, a recorded term also by the wordrecorded, and an external term ending withunchecked(when nothing could be planned, standard output is empty and only the diagnostics print);typify plan DECLARATIONS LANGUAGE PROGRAM [--facts FILE]plans one program. -
typify facts ROOTwrites the facts file for a root. -
typify ask DECLARATIONS LANGUAGE WORDasks a language about a word and prints the answer lines. -
typify emit DECLARATIONS LANGUAGEprints a language's grammar as JSON, under--jsonor by default, or as GBNF with--gbnf;typify emit Typifyprints the meta language's grammar.emitprints the grammar alone, a document and not a report: it never carries adiagnosticskey and never prints a note, whichcheckreports, and on a failed declaration it prints{"ok": false, "diagnostics": [...]}under--jsonand the text projection otherwise, and exits with status 1, ascheckdoes;--gbnfwith--jsonisE_USAGE, with--gbnfasactual. The JSON grammar holds the language's name and version, a top-levelcommentstring (always present: the body's comment prefix, or empty when comments are disabled), the effective caps, every class the language reaches as a node tree under its qualified name, and the forms (see Emission). -
typify --versionprints the reader's version and reader-source digest on one line (1.0.0 sha256:followed by 64 lowercase hexadecimal digits; with--json,versionandbuild).
check, tree, plan, ask and emit take --json. With --json, check, tree and plan each print their own object in every outcome, and the object carries a diagnostics array, empty when nothing is reported; ask prints its answer object, whose diagnostics carries what reading the declaration reports, notes included, or, on a failed declaration, an unreadable file or a word that fails the verb class, {"ok": false, "diagnostics": [...]} with no answer fields; emit prints the grammar alone; a usage error, an unknown command included, prints {"ok": false, "diagnostics": [...]} when --json is among the arguments, and the text projection otherwise. The exit status is 0 when clean, 1 on errors, and 2 on a usage error or an unreadable file; a note never changes it. The reader reports every error it can find, ordered by position (file, line and column) and, within one position, in the order it detected them. It reads a declaration whole and reports all its errors, and it reads a program only when the program's declaration has no diagnostic of severity error: check of a program under a failed declaration reports the declaration's diagnostics and exits 1 without reading the program. After a malformed declaration line the reader recovers, as if the line were well formed where it has exactly one well-formed reading and as if it were absent otherwise, and it reports no diagnostic that only the recovery would cause (in a program, a line that fails its class or matches no form builds no term, so a count of its constructor can fail beside E_CLASS or E_FORM_NONE). Every diagnostic is one JSON document with the nine fields code, severity, file, range, message, related, fix, data and fingerprints, text mode prints its projection, and --sarif, --lsp and --github-annotations print its editor and CI projections. Its file, and a related entry's, is the path as given for a file named on the command line, and the root-relative portable path for a program the tree located. Its code is one of the 31 codes of the registry, 29 of severity error and two, N_CLASS_EMPTY and N_CELL_WIDTH, of severity note; the registry gives each code's meaning and its data fields (see Diagnostics). A key in a diagnostic's data, under E_ENSURE, E_FACT_REJECT, E_PROGRAM_COUNT and E_CONTEXT, is an array of decoded string components in key order, the shape of a state entry's key: a width-one key is a one-element array and an empty key the empty array [], never a bare string. Under E_CONTEXT it is [] for a (context <constructor>) with no enclosing program's term of that constructor. For a relative-path argument with no workdir term in scope, it is the full tuple of the key the term writes, one decoded string per component with that argument as written among them, never split at its slashes, only when the failing argument is one of that key's components; whenever it is not, as for an argument in a value position of a writing primitive, an argument of a term that writes no cell, or any other relative-path position, it is the one-element array holding the failing argument as written, and no cell key is carried. A cell key is never widened for a diagnostic. No evaluation is run to report the failure: a key component not yet evaluated when E_CONTEXT is raised, such as a library call or a lookup to the right of the failing argument, stands as written, so the tuple keeps the cell's width, while a component already evaluated carries its decoded string.
Apart from the text of its note lines, a declaration holds no English. Prose lives in this wiki and in the comments of programs. A declaration documents itself by its names, its example lines and its answers to ? : <word> (see Questions): a does line is a term, not a sentence, and a class is a pattern, not a description. A caveat the language cannot state is attached to a constructor with note : <constructor> = <text>, which ? : <word> prints.
A program carries its own prose as comments:
# Periodicals are listed as journals.
item : journal = Market Research
Some of Typify's words mean something else elsewhere.
-
formis a formation rule and a slot frame: it says which lines are well formed and names their slots. It is not a Lisp form, although the reference host is a Lisp. See Terms and counts. - A form with its classes is a frame in the knowledge-representation sense: slots with filler classes and
defaultvalues. -
treeis the directory tree that programs live in; a program's syntax tree is its term list. See Trees. -
planis a degenerate task network: an ordered list of primitive terms, with no choice, no preconditions and no search. See Rules and plans. -
countholds multiplicities. -
doesbuilds a term. Whether the term executes depends on its constructor: a fact's term is data, and an effect's term is a primitive or is rewritten down to primitives. Adoesline is not a description. -
factnames two things: a constructor declaredfact, whose terms are data, and an entry of the facts file, such asexists, which records what was tested about the filesystem.
Declarations are written in a Typify language of their own, the meta language Typify. Its forms are defined once, in the reader, as one table. The release build writes that table's declaration source out as typify.typify, and every release carries that file at typify/share/typify.typify, beside bin/, while typify emit Typify prints its JSON grammar (see Emission and Command line). The repository holds no hand-written .typify source file (the .typify files under test/ are test inputs), so declaration and reader cannot drift: one is written from the other. Questions about the meta forms are answered from the same table, with typify ask DECLARATIONS Typify WORD.
The file typify.typify is a self-representation, the language described inside the language. It is not a self-interpreter: the host interprets every level, the meta language included.
Deferred to 1.1: uses imports across files, derived! program files, conditional rules, term-sorted arguments (a user term nested inside another), cross-program name resolution for sees, and, for questions, the accepts lines and the fixes of diagnostics (see Questions). No solver ships in 1.0. The Changelog lists what 1.0 changes.