/** * Generalized Grammar System for Multilingual Hyperscript * * This system abstracts grammatical patterns across language families, * enabling deep multilingual support without per-language hardcoding. * * Key Linguistic Concepts: * - Word Order: SVO, SOV, VSO (and variations) * - Adposition Type: Preposition (English) vs Postposition (Japanese/Korean) * - Morphology: Isolating (Chinese) vs Agglutinative (Turkish) vs Fusional (Arabic) * - Text Direction: LTR vs RTL */ /** * Semantic roles in hyperscript commands. * These are universal across all 13 supported languages - only the surface form changes. * * ## Core Thematic Roles (from linguistic theory) * | Role | Usage | Purpose | Example | * |-------------|-------|-----------------------------|---------------------------| * | action | 100% | Command verb | toggle, put, fetch | * | patient | 90% | What is acted upon | .active, #count | * | destination | 40% | Where something goes | into #output, to .class | * | source | 13% | Where something comes from | from #input, from URL | * | event | 106% | Trigger events | click, keydown, submit | * | condition | 8% | Boolean expressions | if x > 5, when visible | * | agent | 0% | Who performs action | Reserved for future use | * | goal | 1% | Target value/state | to 'red' (in transition) | * * ## Quantitative Roles (answer "how much/long") * | Role | Usage | Purpose | Example | * |----------|-------|----------------|----------------------| * | quantity | 7% | Numeric amount | by 5, 3 times | * | duration | 1% | Time span | for 5 seconds, 500ms | * * ## Adverbial/Modifier Roles (answer "how/by what means") * | Role | Usage | Purpose | Example | * |--------------|-------|---------------------------|-------------------| * | style | 2% | Animation/behavior | with fade | * | manner | 2% | Insertion position | before, after | * | method | 1% | HTTP method/technique | via POST, as GET | * | responseType | 1% | Response format | as json, as html | * * ## Control Flow Roles * | Role | Usage | Purpose | Example | * |----------|-------|--------------|-----------------------| * | loopType | 6% | Loop variant | forever, until, times | * * ## Design Notes * - Low-usage roles (agent, goal, method, responseType) are intentionally kept for: * - Linguistic completeness across all 13 languages * - Future extensibility (AI agents, server-side execution) * - Command-specific semantics (fetch, transition) * - Each role has distinct grammatical markers per language (see profiles/index.ts) * - Usage percentages based on pattern database analysis */ export type SemanticRole = 'action' | 'agent' | 'patient' | 'source' | 'destination' | 'goal' | 'event' | 'condition' | 'quantity' | 'duration' | 'responseType' | 'method' | 'style' | 'manner' | 'loopType' | 'continues'; /** * Word order patterns * These represent the major typological categories */ export type WordOrder = 'SVO' | 'SOV' | 'VSO' | 'VOS' | 'OVS' | 'OSV' | 'free'; /** * Where grammatical markers appear relative to their noun/verb */ export type AdpositionType = 'preposition' | 'postposition' | 'circumposition' | 'none'; /** * Morphological typology - how words are constructed */ export type MorphologyType = 'isolating' | 'agglutinative' | 'fusional' | 'polysynthetic'; /** * A grammatical marker (particle, case ending, preposition) */ export interface GrammaticalMarker { form: string; role: SemanticRole; position: AdpositionType; required: boolean; alternatives?: string[]; } /** * Metadata for preserving line structure during translation. * Tracks indentation and blank lines so output maintains the same format. */ export interface LineMetadata { /** Trimmed line content (empty string for blank lines) */ content: string; /** Leading whitespace (tabs/spaces) from original line */ originalIndent: string; /** True if the line was empty or whitespace-only */ isBlank: boolean; } /** * Complete grammatical profile for a language * This captures the essential typological features needed for transformation */ export interface LanguageProfile { code: string; name: string; wordOrder: WordOrder; adpositionType: AdpositionType; morphology: MorphologyType; direction: 'ltr' | 'rtl'; markers: GrammaticalMarker[]; canonicalOrder: SemanticRole[]; rules?: GrammarRule[]; } /** * Pattern for transforming hyperscript structures */ export interface GrammarRule { name: string; description: string; match: PatternMatcher; transform: PatternTransform; priority: number; } /** * Matches a hyperscript pattern */ export interface PatternMatcher { commands?: string[]; requiredRoles: SemanticRole[]; optionalRoles?: SemanticRole[]; predicate?: (parsed: ParsedStatement) => boolean; } /** * Defines how to transform a matched pattern */ export interface PatternTransform { roleOrder: SemanticRole[]; insertMarkers?: boolean; custom?: (parsed: ParsedStatement, profile: LanguageProfile) => string; } /** * A parsed hyperscript statement broken into semantic components */ export interface ParsedStatement { type: 'event-handler' | 'command' | 'conditional' | 'loop'; roles: Map; original: string; } /** * A single element with its semantic role */ export interface ParsedElement { role: SemanticRole; value: string; translated?: string; isSelector?: boolean; isLiteral?: boolean; } /** * Universal templates for common hyperscript patterns * These define the semantic structure independent of surface form */ export declare const UNIVERSAL_PATTERNS: { readonly eventIncrement: { readonly name: "event-increment"; readonly roles: SemanticRole[]; readonly english: "on {event} {action} {patient}"; }; readonly putInto: { readonly name: "put-into"; readonly roles: SemanticRole[]; readonly english: "{action} {patient} into {destination}"; }; readonly addTo: { readonly name: "add-to"; readonly roles: SemanticRole[]; readonly english: "{action} {patient} to {destination}"; }; readonly toggleOn: { readonly name: "toggle-on"; readonly roles: SemanticRole[]; readonly english: "{action} {patient} on {destination}"; }; readonly waitDuration: { readonly name: "wait-duration"; readonly roles: SemanticRole[]; readonly english: "{action} {quantity}"; }; readonly conditional: { readonly name: "conditional"; readonly roles: SemanticRole[]; readonly english: "{action} {condition} then ... end"; }; readonly fetchAs: { readonly name: "fetch-as"; readonly roles: SemanticRole[]; readonly english: "{action} {source} as {method}"; }; readonly showWith: { readonly name: "show-with"; readonly roles: SemanticRole[]; readonly english: "{action} {patient} with {style}"; }; readonly transitionOver: { readonly name: "transition-over"; readonly roles: SemanticRole[]; readonly english: "{action} {patient} over {duration}"; }; }; /** * Default profiles for major language families * Individual languages inherit and override these */ export declare const LANGUAGE_FAMILY_DEFAULTS: Record>; /** * Reorder semantic roles according to target language. * Includes a safety net to append any roles present in input * but missing from the target order, preventing data loss. */ export declare function reorderRoles(roles: Map, targetOrder: SemanticRole[]): ParsedElement[]; /** * Insert grammatical markers between elements */ export declare function insertMarkers(elements: ParsedElement[], markers: GrammaticalMarker[], adpositionType: AdpositionType): string[]; /** * Intelligently joins tokens, handling agglutinative suffixes and prefixes. * * Rules: * 1. If a token ends with '-' (prefix marker), no space after it * 2. If a token starts with '-' (suffix marker), no space before it * 3. Removes the hyphen indicators from the final output * * Examples: * - ['#count', '-ta'] → '#countta' (Quechua accusative suffix) * - ['بـ-', 'الماوس'] → 'بـالماوس' (Arabic prefix attachment) * - ['value', 'を'] → 'value を' (Japanese particle, normal spacing) */ export declare function joinTokens(tokens: string[]): string; /** * Transform a parsed statement to target language */ export declare function transformStatement(parsed: ParsedStatement, _sourceProfile: LanguageProfile, targetProfile: LanguageProfile): string; //# sourceMappingURL=types.d.ts.map