/** * A condition checked whole against the types of what it may read, before the * first spawn. * * Every address must exist and be typed, the result must be a boolean and * compared sides must agree. Enums are strict: `"aproved"` compared with an * `approved | rejected` field is refused here, since at run time it would only * ever be `false` and the loop would spin to its cap. A string a model wrote * in the person's language compares to no literal at all, for the same reason: * `"Yes"` against a clicked `"Oui"` is silently false. * * Problems are collected, not thrown at the first: a flow is refused with * every fault at once. A part already refused is read no further, so one typo * is one problem and not the three that follow from it. */ import { type ValueType } from "../type.ts"; import { type Expr } from "./parse.ts"; /** Why a condition was refused. Stable, so tests and the documentation's table can name them. */ export declare const CONDITION_CODES: readonly ["condition-syntax", "condition-unknown-address", "condition-type", "condition-enum-value", "condition-free-string"]; /** One of {@link CONDITION_CODES}. */ export type ConditionCode = (typeof CONDITION_CODES)[number]; /** One reason a condition is refused. The validator adds the file and the node. */ export type ConditionProblem = { readonly code: ConditionCode; readonly message: string; }; /** What a condition may read, by the first word of its address. */ export type Readable = Readonly>; /** A condition that passed the check. Only `compileCondition` makes one, and only one can be evaluated. */ export type Condition = { /** The condition as the file writes it. */ readonly source: string; /** Its parsed form, which only the evaluator reads. */ readonly expr: Expr; readonly [checked]: true; }; declare const checked: unique symbol; /** The outcome of compiling: a condition, or every problem found in it. */ export type Compiled = { readonly ok: true; readonly condition: Condition; } | { readonly ok: false; readonly problems: readonly ConditionProblem[]; }; /** * `source` parsed and type-checked against `readable`. * * A syntax fault is the only problem returned when there is one: a tree that * did not parse has nothing further to check. */ export declare function compileCondition(source: string, readable: Readable): Compiled; /** A checked part: its type, and the string literals it is made of, which a strict enum is held against. */ type Typed = { readonly type: ValueType; readonly literals?: readonly string[]; } | undefined; /** * The type checker, for a condition and for an address alike. * * `acceptsText` is the one difference: an address may name an agent's prose * whole, which is what `reads:` hands the next agent, while a condition never * reads prose at all. */ export declare class Checker { readonly problems: ConditionProblem[]; private readonly source; private readonly acceptsText; constructor(source: string, acceptsText: boolean); problem(code: ConditionCode, message: string): undefined; check(expr: Expr, scope: ReadonlyMap): Typed; /** What an address gave, unless it is prose a condition may not read. */ private typed; private list; private select; private binary; private booleans; /** Whether two sides may be compared, reporting why not. An enum met by a string literal holds it to its values. */ private equatable; private incomparable; /** Why a side is a string a model wrote, met by a literal of the file, when it is. */ private freeAgainstLiteral; private text; } export {}; //# sourceMappingURL=compile.d.ts.map