/** * Patterns from command schemas: the generator semantic's hyperscript parser * runs (domains rethink Phase 4.4, `docs-internal/DOMAINS_RETHINK.md`), moved * here from `@lokascript/semantic`; `createMultilingualDSL` generates every * domain's patterns with it (the classic generator went in 5.0, Phase 6). * * Per command and language it builds the main pattern and its variants: the * simple variant (required roles only), the omit-role, widened-type and * required-role variants, an SOV language's verb-first fallback, and the * value-prefix-literal variants (`RoleSpec` / `CommandSchema` document each). * What differs between grammars is a hook (`SchemaPatternGrammar`); what a * grammar adds on top (hyperscript's fused event-handler patterns) stays in the * grammar's package. */ import type { LanguagePattern, PatternToken } from '../core/types'; import type { CommandSchema, RoleSpec } from '../schema'; /** What differs between grammars in how a schema becomes patterns. */ export interface SchemaPatternGrammar { /** * How `svoPosition` / `sovPosition` sort: `'ascending'` puts the lowest first * (hyperscript's schemas, 1-based), `'descending'` the highest (a domain's * schemas, as `sortRolesByWordOrder` and the schema renderer read them). */ readonly positionOrder: 'ascending' | 'descending'; } /** A role marker in a language profile. */ export interface SchemaPatternMarker { readonly primary: string; readonly alternatives?: string[]; readonly position: 'before' | 'after'; } /** What the generator reads of a language profile. */ export interface SchemaPatternProfile { readonly code: string; readonly wordOrder: string; readonly keywords: Readonly>; readonly roleMarkers: Readonly>>; /** * The language may drop its role markers colloquially (Turkish case * suffixes): each marker becomes an optional group that still renders. */ readonly markersOptional?: boolean; } /** The generator, bound to a grammar (`createSchemaPatternGenerator`). */ export interface SchemaPatternGenerator { /** The main pattern for a command in a language. */ generatePattern(schema: CommandSchema, profile: SchemaPatternProfile, config?: SchemaPatternConfig): LanguagePattern; /** The command without its optional roles; null when it has none. */ generateSimplePattern(schema: CommandSchema, profile: SchemaPatternProfile, config?: SchemaPatternConfig): LanguagePattern | null; /** An SOV language's verb-first fallback; null for other word orders. */ generateVerbFirstPattern(schema: CommandSchema, profile: SchemaPatternProfile, config?: SchemaPatternConfig): LanguagePattern | null; /** The main pattern and every variant the schema and config ask for. */ generatePatternVariants(schema: CommandSchema, profile: SchemaPatternProfile, config?: SchemaPatternConfig): LanguagePattern[]; /** The token(s) of one role: its value slot and marker, in the language's order. */ buildRoleToken(roleSpec: RoleSpec, profile: SchemaPatternProfile): PatternToken[]; } /** A generator for the grammar's schemas. */ export declare function createSchemaPatternGenerator(grammar: SchemaPatternGrammar): SchemaPatternGenerator; /** The schema without its variant-only roles: what every pattern but a required-role variant is built from. */ export declare function withoutVariantOnlyRoles(schema: S): S; /** * Minimum interface for role specs that can have marker resolution. * Compatible with the RoleSpec type from command-schemas. */ export interface RoleSpecWithMarker { role: string; markerOverride?: Record; markerLegacy?: Record; markerVariants?: Record; methodCarrier?: string; } /** * Resolved marker information for a role. */ export interface ResolvedMarker { /** Primary marker string (may be empty string for no marker) */ primary: string; /** Alternative markers */ alternatives?: string[]; /** Position relative to role value */ position: 'before' | 'after'; /** Whether this is an override marker */ isOverride: boolean; } /** * Resolve the marker for a role in a specific language. * * Checks for command-specific marker overrides first, * then falls back to the default marker from the language profile. * * @param roleSpec Role specification with optional override * @param profile Language profile with role markers * @returns Resolved marker info, or null if no marker */ export declare function resolveMarkerForRole(roleSpec: RoleSpecWithMarker, profile: SchemaPatternProfile): ResolvedMarker | null; /** * Alternatives an OVERRIDE marker accepts: the role's {@link RoleSpecWithMarker.markerLegacy} * entries for this language, minus the override itself. * * Every generator that resolves a marker has its own override branch, and each * one used to drop alternatives entirely — so correcting a marker silently * stopped the previous one parsing. This is the single definition of what an * override still accepts; call it from each of those branches. * * Prefer {@link schemaMarkerAlternatives}, which also merges `markerVariants`. * This narrower entry point remains for callers that must exclude variants. */ export declare function legacyMarkerAlternatives(roleSpec: RoleSpecWithMarker, languageCode: string, overrideMarker: string): string[] | undefined; /** * Every schema-declared alternative a role's marker accepts in this language: * `markerLegacy` ∪ `markerVariants`, minus the marker itself. * * **The single definition — call it from every branch of every generator.** The * two fields used to sit on DIFFERENT branches: the override branch read only * `markerLegacy`, the profile-default branch only `markerVariants`. So giving a * language a `markerOverride` silently deleted its `markerVariants`, and giving * it `markerVariants` did nothing at all wherever an override existed. Both * halves were live: tr `set`'s dative allomorphs (`e|a|ye|ya`) were declared as * variants but dropped by the tr override, so `… doğru ya ayarla` parsed only * inside an event handler — the one generator that happened to merge both. * * `markerVariants` are held out for a role with a {@link RoleSpecWithMarker.methodCarrier}: * there they are not synonyms but distinct command shapes recorded into another * role (`put`'s `into|before|after` → `method`), and merging them as synonyms is * what broke `put-before`/`put-after` in 23 languages at once. That flag is the * discriminator because it is set on exactly the role whose variants carry * meaning — pinned by `schema-consistency.test.ts`, which fails if a new * `markerVariants` appears without that decision being made. */ export declare function schemaMarkerAlternatives(roleSpec: RoleSpecWithMarker, languageCode: string, marker: string): string[] | undefined; /** * Configuration for pattern generation. */ export interface SchemaPatternConfig { /** Base priority for generated patterns (higher = checked first) */ basePriority?: number; /** Whether to generate simple patterns (without optional roles) */ generateSimpleVariants?: boolean; /** Whether to generate alternative keyword patterns */ generateAlternatives?: boolean; /** * Whether to generate verb-first fallback patterns for SOV languages * (`トグル .active` alongside the canonical `.active を トグル`). Default on. * These are strictly lower priority than the canonical patterns, so native * SOV order always wins; this only accepts bilingual/code-switched input. */ generateVerbFirstVariants?: boolean; } //# sourceMappingURL=schema-patterns.d.ts.map