/** * The round-trip gate kit (domains rethink Phase 4.6, `docs-internal/DOMAINS_RETHINK.md`): every * command of a grammar, written in each of its languages by its own renderer and read back by its own * parser. Moved from lokascript-domains' `packages/domains/gate/round-trip.ts` (the domain gate, Phase * 2), so any grammar on the framework runs the same gate; the domains repo keeps its fixtures * (`gate/values.ts`), baselines and regen tool. * * A case is a command (bracket syntax, parsed in English) and a language: * * - **round trip**: `render(ref, lang)`, then `parse`. `pass` when the parse is the reference node, or, * for a grammar whose compiled output does not depend on the language, when the text compiles to what * the command itself (its bracket form) compiles to (a parser may keep a translated word that the * generator normalizes: bdd ja `#box0 が 表示 前提` is `visible`). English is a lane like the others. * `refused` when the render is null or the parse throws: the caller is told. `silent` otherwise: it * reads, or compiles to, something else. * - **leftover**: the same render plus one unknown word. `refused` is the expected outcome: the parse * throws, or the input does not compile. `pass` where the word is READ: the parse is the text's own * with the word in one role (an open-text role extended by it, `where active zzqx`, or a role the * text left empty, `list zzqx`), and the word is in the code (for a command that never compiles on * its own, `englishDoesNotCompile`, the parse alone). `silent` otherwise: the input is accepted and * read as something else (`when clicks zzqx`: actor `clicks`, action `zzqx`), or the word goes * nowhere (voice `back zzqx` compiles as `back`). * * The outcomes are the command-shape gate's (hyperfixi `testing-framework`). A baseline lists every * case that is not at its best outcome; `compare` reports a case worse than listed and one better than * listed, so a gate built on it only shrinks. */ export type Outcome = 'pass' | 'refused' | 'silent'; export type CaseKind = 'roundTrip' | 'leftover'; /** Best first. A round trip's best is `pass`; leftover input's is `refused`. */ export declare const RANK: Record>; export declare const BEST: Record; /** Appended for the leftover cases: a word no grammar's vocabulary has. */ export declare const UNKNOWN_WORD = "zzqx"; export interface CaseResult { /** The grammar (a domain's name). */ grammar: string; kind: CaseKind; /** The command, in bracket syntax (read in English). */ source: string; lang: string; outcome: Outcome; /** What the renderer wrote (plus the unknown word, for leftover). */ text?: string; /** Why it is not `pass`: the error, or what the parse read instead. */ why?: string; /** The round trip's parse, summarized (`summarize`); absent when it was refused. */ read?: string; } /** What the gate reads of a role in a schema. */ export interface GateRoleSpec { readonly role: string; readonly required?: boolean; readonly expectedTypes?: readonly string[]; } /** What the gate reads of a command schema. */ export interface GateSchema { readonly action: string; readonly roles: readonly GateRoleSpec[]; } /** What the gate reads of a parse. */ export interface GateNode { readonly action: string; readonly roles: ReadonlyMap | Readonly>; } /** The grammar's DSL, as the gate drives it. */ export interface GateDSL { parse(input: string, language: string): GateNode; compile(input: string, language: string): { ok: boolean; code?: string; errors?: string[]; }; render?(node: GateNode, language: string): string | null; getSupportedLanguages(): string[]; } /** * The values the gate writes into each role. A role not listed gets a plain name no vocabulary uses * (`v0x`, or `#box0` where only a selector fits): its value must come back verbatim. A role that takes * FIXED words lists every word the grammar's renderer and generator know, in English: the gate writes * the command once per word, in every language, so a word one of the two tables lacks fails in the * languages where it is missing. */ export interface GateFixture { /** * `compile`: a round trip also passes when the text compiles to the command's own code (the grammar * compiles to something that does not depend on the language). `node`: only the parse counts (a * grammar that compiles to a sentence in each language). */ oracle: 'compile' | 'node'; /** Keys are `.` or `` (every action). The first value is the one the other cases use. */ values: Record; /** * Commands (bracket syntax) written besides the generated ones, where one role's value depends on * another's and no single list fits both: behaviorspec's `[given subject:#box value:visible]` beside * `[given subject:viewport value:1024x768]`. */ commands?: string[]; /** * Actions that do not compile on their own (a gate may check every other one does). Leftover input * in such a command is judged by its parse alone. */ englishDoesNotCompile?: string[]; } /** * The commands a grammar is checked on: for each schema, its required roles alone and all its roles * (each with its first value), then each further value of a role that takes fixed words, alone. */ export declare function commandsFor(schemas: readonly GateSchema[], fixture: GateFixture): string[]; /** A parse as one line: `action role:type=value …`, roles sorted. What the parse snapshot records. */ export declare function summarize(node: GateNode): string; /** * Whether `read`, the parse of a text plus `word`, is `back`, the text's own parse, with the word read * into it: the same action and roles, except one role, whose value is its value in `back` followed by * the word (an open-text role at the end: sql `where active zzqx`) or, where `back` has no such role, * the word itself (todo `list zzqx`). */ export declare function readsWord(back: GateNode, read: GateNode, word: string): boolean; /** What a command (bracket syntax) compiles to; null when it does not compile on its own. */ export declare function referenceCode(dsl: GateDSL, source: string): string | null; /** Run every case of one grammar: each command of `commandsFor` in each of the DSL's languages. */ export declare function runRoundTrip(grammar: string, dsl: GateDSL, schemas: readonly GateSchema[], fixture: GateFixture): CaseResult[]; export interface ListedCase { outcome: Exclude; text?: string; why?: string; } export interface GateBaseline { /** The upstream packages this was measured on (the grammar's lockfile). */ upstream: Record; /** Per grammar and kind: cases and outcomes. Written by the regen tool for the reader; not checked. */ counts: Record>>; /** Per grammar, command and language: every round trip that is not `pass`. */ roundTrip: Record>>; /** Per grammar and command: the languages whose leftover case was accepted (`silent`). */ leftover: Record>; } export interface DriftCase { kind: CaseKind; source: string; lang: string; listed: Outcome; now: Outcome; text?: string; why?: string; } export interface Drift { worse: DriftCase[]; better: DriftCase[]; /** Listed cases that are no longer cases at all. */ stale: { kind: CaseKind; source: string; lang: string; }[]; } /** How one grammar's results moved against the baseline. */ export declare function compare(grammar: string, results: CaseResult[], baseline: GateBaseline): Drift; /** The baseline entries for one grammar's results. */ export declare function listingOf(results: CaseResult[]): { roundTrip: Record>; leftover: Record; }; export declare function countsOf(results: CaseResult[]): Record>; /** * Every round trip's parse, so a change that moves a parse shows it, whether or not an outcome moved * (a value's type, a role a passing case gained, what a silent case reads now). `refused` where the * parse threw. Leftover cases are not in it: their outcome is the baseline's. */ export interface ParseSnapshot { upstream: Record; /** Per grammar, command and language. */ parses: Record>>; } export declare function snapshotOf(results: CaseResult[]): Record>; export interface SnapshotChange { source: string; lang: string; was?: string; now?: string; } /** Every round trip whose parse differs from the snapshot's, for one grammar. */ export declare function snapshotChanges(grammar: string, results: CaseResult[], snapshot: ParseSnapshot): SnapshotChange[]; //# sourceMappingURL=round-trip.d.ts.map