/** * Rendering a command through a language's own patterns: the renderer core * semantic's hyperscript renderer runs (domains rethink Phase 4.5, * `docs-internal/DOMAINS_RETHINK.md`), moved here from `@lokascript/semantic`. * * A node renders with the pattern its parser would read it back through: * `selectRenderPattern` scores a language's patterns for the node (the roles it * carries, the slots each pattern has, the values a pattern pins), and * `renderPattern` walks the chosen pattern's tokens. What a value looks like in * the language, and the grammar's preferences, are `PatternRenderHooks`. * (The domains' `renderer.ts` renders from the schema instead, for * `createMultilingualDSL`.) */ import type { GroupPatternToken, LanguagePattern, PatternToken, RolePatternToken, SemanticNode } from '../core/types'; /** * What the core reads of a node: its roles. A grammar's own node type (semantic's * `SemanticNode`) qualifies as it is; the hooks receive it unchanged. */ export interface RenderableNode { readonly roles: ReadonlyMap; } /** A grammar's part of rendering through patterns, for its node type `N`. */ export interface PatternRenderHooks { /** * The patterns a node may render with, from those that are not parse-only * (hyperscript: an event handler renders only with a trigger pattern, never a * fused `-event-*` one). */ candidates?(node: N, patterns: readonly LanguagePattern[]): readonly LanguagePattern[]; /** Whether the node carries `role` as written, not as a default its parser filled in. */ hasRealRole(node: N, role: string): boolean; /** The grammar's own preference between patterns, added to the score. */ adjustScore?(pattern: LanguagePattern, node: N): number; /** * Text for token `i` and the tokens after it it covers, when the grammar * writes them as one (hyperscript: a reference in its case, es `a mí`); * undefined renders the token as usual. */ span?(tokens: readonly PatternToken[], i: number, node: N, language: string, topLevel: boolean): { text: string; tokens: number; } | undefined; /** A role slot's text; null writes nothing. */ writeRole(token: RolePatternToken, node: N, language: string): string | null; /** * Whether an optional group whose required roles the node carries is written * (hyperscript: not for the implicit `me` its parser filled in). Default yes. */ writeGroup?(token: GroupPatternToken, node: N, language: string): boolean; /** * Add a token's text to `parts` (hyperscript: a marker written onto its * word, ko `#out에`). Default: a part of its own. */ pushPart?(parts: string[], text: string, token: PatternToken, previous: PatternToken | undefined, node: N, language: string): void; /** Before top-level token `i` (hyperscript: a scroll's direction word before its amount). */ beforeToken?(tokens: readonly PatternToken[], i: number, parts: string[], node: N, language: string): void; /** After a top-level token wrote `parts[part]` (hyperscript: where the event went). */ afterToken?(token: PatternToken, part: number, node: N): void; } /** * The pattern to render `node` with, or null when there is none. */ export declare function selectRenderPattern(node: N, patterns: readonly LanguagePattern[], hooks: PatternRenderHooks): LanguagePattern | null; /** * The parts `node` renders to through `pattern`'s tokens, in order: each * literal (unless parse-only), each role's text, each group that is written. * The grammar joins them (and adds what the pattern does not model). */ export declare function renderPattern(node: N, pattern: LanguagePattern, hooks: PatternRenderHooks): string[]; //# sourceMappingURL=pattern-render.d.ts.map