/** * Natural Language Renderer * * Interface and utilities for rendering SemanticNode → human-readable text * in any supported language. This is the inverse of parsing: it converts * a language-neutral semantic representation back to natural-language syntax. * * Every domain that supports `translate()` needs a renderer. */ import type { SemanticNode } from '../core/types'; import type { CommandSchema } from '../schema'; import { type PatternGenLanguageProfile } from './profile'; /** * Renders a SemanticNode to human-readable text in a target language. */ export interface NaturalLanguageRenderer { render(node: SemanticNode, language: string): string; } /** * Keyword table: action → language → translated keyword. * * @example * ```typescript * const KEYWORDS: KeywordTable = { * select: { en: 'select', ja: '選択', es: 'seleccionar' }, * insert: { en: 'insert', ja: '挿入', es: 'insertar' }, * }; * ``` */ export type KeywordTable = Record>; /** * Marker table: marker name → language → translated marker. * * @example * ```typescript * const MARKERS: MarkerTable = { * from: { en: 'from', ja: 'から', es: 'de' }, * into: { en: 'into', ja: 'に', es: 'en' }, * }; * ``` */ export type MarkerTable = Record>; /** * Configuration for building a renderer from schemas and profiles. */ export interface RendererConfig { /** Command keyword translations per language */ readonly keywords: KeywordTable; /** Role marker translations per language (prepositions/particles) */ readonly markers: MarkerTable; /** Languages that use SOV word order */ readonly sovLanguages: ReadonlySet; /** Languages that use VSO word order (optional, defaults to empty) */ readonly vsoLanguages?: ReadonlySet; } /** * Look up a command keyword in the target language. * Falls back to the key itself if no translation found. */ export declare function lookupKeyword(keywords: KeywordTable, action: string, language: string): string; /** * Look up a role marker in the target language. * Falls back to the key itself if no translation found. */ export declare function lookupMarker(markers: MarkerTable, marker: string, language: string): string; /** * Build a phrase from parts, filtering empty strings and joining with space. * * @example * ```typescript * buildPhrase('select', '', 'name', 'from', 'users') * // → 'select name from users' * ``` */ export declare function buildPhrase(...parts: string[]): string; /** * Build keyword and marker tables from schemas and language profiles. * Extracts translations from the profile's keyword definitions and * role marker overrides. * * @example * ```typescript * const { keywords, markers } = buildTablesFromProfiles(schemas, profiles); * ``` */ export declare function buildTablesFromProfiles(schemas: readonly CommandSchema[], profiles: readonly PatternGenLanguageProfile[]): { keywords: KeywordTable; markers: MarkerTable; }; /** * Detect word order from language profiles. * Returns sets of SOV and VSO language codes. */ export declare function detectWordOrders(profiles: readonly PatternGenLanguageProfile[]): { sovLanguages: Set; vsoLanguages: Set; }; /** * Create a basic renderer from schemas and profiles. * * This generates a renderer that handles word-order reordering automatically. * For each command, it constructs the output by placing the keyword and * role values in the correct order for the target language. * * For complex domain-specific rendering, implement `NaturalLanguageRenderer` * directly instead. * * @example * ```typescript * const renderer = createSchemaRenderer(schemas, profiles); * renderer.render(node, 'ja'); // → "users から name 選択" * ``` */ export declare function createSchemaRenderer(schemas: readonly CommandSchema[], profiles: readonly PatternGenLanguageProfile[]): NaturalLanguageRenderer; /** * Renders a SemanticNode, or returns `null` when the action cannot be rendered. * * The nullable counterpart to {@link NaturalLanguageRenderer}: `null` means "I * do not know this action", which callers can act on. A domain that signals the * same condition with a sentinel string forces consumers into string matching. */ export type DomainRenderFn = (node: SemanticNode, language: string) => string | null; /** * Configuration for {@link createDomainRenderer}. */ export interface DomainRendererConfig { /** Schemas for this domain's commands, including any extensions. */ readonly schemas: readonly CommandSchema[]; /** Language profiles supplying keywords and role markers. */ readonly profiles: readonly PatternGenLanguageProfile[]; /** * Hand-written renderers per action. These take absolute precedence over the * schema-driven path, so a domain's existing output is preserved byte for byte. * * An override returning `null` means "this action cannot be rendered" and is * passed straight through — it does not fall through to the schema path, * since a hand-written renderer knows more about its action than the schema does. */ readonly overrides?: Readonly>; } /** * Create a renderer that composes a domain's hand-written per-action renderers * with the schema-driven fallback. * * Resolution order: * 1. `overrides[node.action]` — the domain's own rendering, unchanged * 2. schema-driven rendering — any action with a schema but no hand-written case * 3. `null` — no override and no schema * * Step 2 is what makes a domain extensible: a consumer that adds a command * schema (with per-language keywords in the profiles) gets correct word order, * markers and keywords for free, without the domain package having to know * about that command. * * @example * ```typescript * const render = createDomainRenderer({ * schemas: allSchemas, * profiles: allProfiles, * overrides: { select: renderSelect, insert: renderInsert }, * }); * render(node, 'ja'); // hand-written for `select`, schema-driven otherwise * render(bogusNode, 'en'); // → null * ``` */ export declare function createDomainRenderer(config: DomainRendererConfig): DomainRenderFn; //# sourceMappingURL=renderer.d.ts.map