/** * Fail-loud translation: what a translation checks before it returns (domains * rethink Phase 4.5, `docs-internal/DOMAINS_RETHINK.md`). Moved from * `@lokascript/semantic`'s `explicit/lossy.ts`, whose `translate` runs it with * hyperscript's rules; `createMultilingualDSL`'s `translate` keeps its own * read-back (`TranslationReadBackError`). * * A parse that matches a prefix of a script and leaves the rest unread used to * come back from `translate()` as though it were the whole: `toggle .a .b` * became `toggle .a`. A surface that cannot carry a script now says so: the * translation throws a {@link LossyTranslationError}, which carries the output * it would have returned and what it loses. Four checks, cheapest first: * * - `truncation` the parse of the input left input bound to no role (its * `unconsumed-input` diagnostics); * - `core-only` the input holds a form the grammar's writer has no spelling * for (hyperscript: a form only `@hyperfixi/core` ran, which * upstream reads with another meaning) — `rules.unwritable`; * - `read-back` the output, read in the target language, does not read, * leaves input unread, or differs from what was written * (`rules.differences`, in order); * - `invariant` a value the translation must write verbatim is missing * from the output (`rules.missingValues`). * * None of them can say a translation is right. Each says one way it is wrong. */ export type TranslationLossKind = 'truncation' | 'core-only' | 'read-back' | 'invariant'; /** One way a translation loses part of its input. */ export interface TranslationLoss { kind: TranslationLossKind; /** * What is lost: the input left unread (`truncation`); the forms nothing * writes (`core-only`, as `swap `); the output left unread or what * it reads back without or with in excess (`read-back`, as `-cmd` / `+cmd`); * or the verbatim values missing from the output (`invariant`). */ lost: string[]; } export declare class LossyTranslationError extends Error { /** The output `translate()` would have returned: NOT the whole script. */ readonly partial: string; readonly loss: TranslationLoss; readonly from: string; readonly to: string; readonly name = "LossyTranslationError"; constructor( /** The output `translate()` would have returned: NOT the whole script. */ partial: string, loss: TranslationLoss, from: string, to: string); } /** What the checks read of a parse: its diagnostics. */ export interface LossCheckedNode { readonly diagnostics?: ReadonlyArray<{ readonly code?: string; readonly message: string; }>; } /** The spans a parse left bound to no role (its top node carries them all). */ export declare function unconsumedSpans(node: LossCheckedNode): string[]; /** A grammar's rules for `findTranslationLoss`, for its node type `N`. */ export interface TranslationLossRules { /** The forms in `node` the grammar's writer has no spelling for (`core-only`). */ unwritable?(node: N): string[]; /** * `node` as it was written into the target language, to compare its * read-back with (hyperscript: in upstream's spelling for English). Default: * `node` itself. */ written?(node: N): N; /** * How the read-back differs from what was written, checked in order: the * first that finds a difference is the loss (hyperscript: commands, then * roles, then clauses kept as written). */ readonly differences: ReadonlyArray<(written: N, back: N) => string[]>; /** The values `input` holds that `output` must write verbatim and does not (`invariant`). */ missingValues?(input: string, output: string): string[]; } /** * How a translation of `input` (parsed as `node`) into `output` loses part of * it, or undefined. `readBack` parses the output in the target language; it * throws when the output does not read. */ export declare function findTranslationLoss(input: string, node: N, output: string, readBack: (output: string) => N, rules: TranslationLossRules): TranslationLoss | undefined; //# sourceMappingURL=translation-loss.d.ts.map