@lokascript/framework 2.7.1 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.js +6 -2
- package/dist/api/index.js.map +1 -1
- package/dist/core/index.js +41 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/tokenization/base-tokenizer.d.ts +24 -0
- package/dist/core/tokenization/base-tokenizer.d.ts.map +1 -1
- package/dist/core/tokenization/extractors.d.ts +6 -0
- package/dist/core/tokenization/extractors.d.ts.map +1 -1
- package/dist/core/tokenization/index.js +41 -1
- package/dist/core/tokenization/index.js.map +1 -1
- package/dist/generation/index.js +2 -1
- package/dist/generation/index.js.map +1 -1
- package/dist/generation/pattern-generator.d.ts.map +1 -1
- package/dist/index.cjs +47 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +47 -3
- package/dist/index.js.map +1 -1
- package/dist/multilingual/index.js +41 -1
- package/dist/multilingual/index.js.map +1 -1
- package/dist/testing/index.js +4 -12
- package/dist/testing/index.js.map +1 -1
- package/package.json +2 -2
- package/src/core/tokenization/base-tokenizer.ts +55 -1
- package/src/core/tokenization/colon-qualifier.test.ts +129 -0
- package/src/core/tokenization/extractors.ts +6 -0
- package/src/generation/pattern-generator.ts +5 -1
- package/src/ir/protocol-json.test.ts +21 -0
- package/src/ir/references.test.ts +5 -2
- package/src/prompts/prompt-generator.ts +4 -1
package/dist/generation/index.js
CHANGED
|
@@ -129,7 +129,8 @@ function buildFormatString(schema, profile, keyword) {
|
|
|
129
129
|
if (profile.wordOrder === "SVO" || profile.wordOrder === "VSO") {
|
|
130
130
|
parts.push(keyword);
|
|
131
131
|
}
|
|
132
|
-
|
|
132
|
+
const sortedRoles = sortRolesByWordOrder(schema.roles, profile.wordOrder);
|
|
133
|
+
for (const role of sortedRoles) {
|
|
133
134
|
const marker = getMarkerForRole(role, profile);
|
|
134
135
|
const roleName = `{${role.role}}`;
|
|
135
136
|
if (marker) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/generation/pattern-generator.ts","../../src/core/types.ts","../../src/generation/renderer.ts","../../src/generation/diagnostics.ts"],"sourcesContent":["/**\n * Pattern Generator\n *\n * Generates LanguagePattern objects from CommandSchema + LanguageProfile.\n * This solves the pattern explosion problem by deriving patterns from\n * high-level schema definitions rather than hand-writing each one.\n */\n\nimport type { LanguagePattern, PatternToken, ExtractionRule } from '../core/types';\nimport type { CommandSchema, RoleSpec } from '../schema';\n\n/**\n * Minimal language profile interface for pattern generation.\n */\nexport interface PatternGenLanguageProfile {\n readonly code: string;\n readonly wordOrder: 'SVO' | 'SOV' | 'VSO' | 'VOS' | 'OSV' | 'OVS' | 'free';\n readonly keywords: Record<string, { primary: string; alternatives?: string[] }>;\n readonly roleMarkers?: Record<\n string,\n { primary: string; alternatives?: string[]; position?: 'before' | 'after' }\n >;\n}\n\n/**\n * Configuration for pattern generation.\n */\nexport interface GeneratorConfig {\n /** Base priority for generated patterns (default: 100) */\n readonly basePriority?: number;\n /** Include optional role variants (default: true) */\n readonly includeOptionalVariants?: boolean;\n}\n\nconst defaultConfig: GeneratorConfig = {\n basePriority: 100,\n includeOptionalVariants: true,\n};\n\n/**\n * Generate a language pattern from a command schema and language profile.\n *\n * @param schema - Command schema defining the command structure\n * @param profile - Language profile with word order and keywords\n * @param config - Optional configuration\n * @returns Generated language pattern\n */\nexport function generatePattern(\n schema: CommandSchema,\n profile: PatternGenLanguageProfile,\n config: GeneratorConfig = defaultConfig\n): LanguagePattern {\n const id = `${schema.action}-${profile.code}-generated`;\n const priority = config.basePriority ?? 100;\n\n // Get keyword translation\n const keyword = profile.keywords[schema.action];\n if (!keyword) {\n throw new Error(`No keyword translation for '${schema.action}' in ${profile.code}`);\n }\n\n // Build tokens based on word order\n const tokens = buildTokens(schema, profile, keyword.primary, keyword.alternatives);\n\n // Build extraction rules\n const extraction = buildExtractionRules(schema, profile);\n\n // Build format string for documentation\n const format = buildFormatString(schema, profile, keyword.primary);\n\n return {\n id,\n language: profile.code,\n command: schema.action,\n priority,\n template: {\n format,\n tokens,\n },\n extraction,\n };\n}\n\n/**\n * Build pattern tokens based on word order and role markers.\n */\nfunction buildTokens(\n schema: CommandSchema,\n profile: PatternGenLanguageProfile,\n keyword: string,\n alternatives?: string[]\n): PatternToken[] {\n const tokens: PatternToken[] = [];\n const keywordToken: PatternToken = {\n type: 'literal',\n value: keyword,\n ...(alternatives?.length && { alternatives }),\n };\n\n // Sort roles by word order\n const sortedRoles = sortRolesByWordOrder(schema.roles, profile.wordOrder);\n\n // For SVO: [action, patient, destination, source, ...]\n if (profile.wordOrder === 'SVO') {\n // Add keyword first\n tokens.push(keywordToken);\n\n // Add roles with markers\n for (const role of sortedRoles) {\n addRoleWithMarker(tokens, role, profile);\n }\n }\n // For SOV: [patient, destination, source, ..., action]\n else if (profile.wordOrder === 'SOV') {\n // Add roles with markers first\n for (const role of sortedRoles) {\n addRoleWithMarker(tokens, role, profile);\n }\n\n // Add keyword last\n tokens.push(keywordToken);\n }\n // For VSO: [action, destination, patient, source, ...]\n else if (profile.wordOrder === 'VSO') {\n // Add keyword first\n tokens.push(keywordToken);\n\n // Add roles with markers\n for (const role of sortedRoles) {\n addRoleWithMarker(tokens, role, profile);\n }\n }\n // Other word orders can be added as needed\n else {\n // Fallback to SVO-style ordering\n tokens.push(keywordToken);\n for (const role of sortedRoles) {\n addRoleWithMarker(tokens, role, profile);\n }\n }\n\n return tokens;\n}\n\n/**\n * Add a role token with its grammatical marker if needed.\n * For optional roles, wraps the role + marker in a group.\n */\nfunction addRoleWithMarker(\n tokens: PatternToken[],\n roleSpec: RoleSpec,\n profile: PatternGenLanguageProfile\n): void {\n const marker = getMarkerForRole(roleSpec, profile);\n const isOptional = !roleSpec.required;\n\n // Build the role token\n const roleToken: PatternToken = {\n type: 'role',\n role: roleSpec.role,\n optional: isOptional,\n expectedTypes: roleSpec.expectedTypes,\n ...(roleSpec.greedy && { greedy: true }),\n };\n\n if (marker) {\n const markerInfo = profile.roleMarkers?.[roleSpec.role];\n // Priority: schema markerPosition → profile roleMarkers position → word-order default\n const defaultPosition = profile.wordOrder === 'SOV' ? 'after' : 'before';\n const position = roleSpec.markerPosition ?? markerInfo?.position ?? defaultPosition;\n\n if (isOptional) {\n // Optional role: wrap marker + role in optional group\n if (position === 'before') {\n tokens.push({\n type: 'group',\n optional: true,\n tokens: [{ type: 'literal', value: marker }, roleToken],\n });\n } else {\n tokens.push({\n type: 'group',\n optional: true,\n tokens: [roleToken, { type: 'literal', value: marker }],\n });\n }\n } else {\n // Required role: add marker + role separately\n if (position === 'before') {\n tokens.push({ type: 'literal', value: marker });\n tokens.push(roleToken);\n } else {\n tokens.push(roleToken);\n tokens.push({ type: 'literal', value: marker });\n }\n }\n } else {\n // No marker - just add the role\n tokens.push(roleToken);\n }\n}\n\n/**\n * Get the grammatical marker for a role from the profile.\n */\nfunction getMarkerForRole(\n roleSpec: RoleSpec,\n profile: PatternGenLanguageProfile\n): string | undefined {\n // Check for role-specific override first\n if (roleSpec.markerOverride?.[profile.code]) {\n return roleSpec.markerOverride[profile.code];\n }\n\n // Use profile's default marker for this role\n return profile.roleMarkers?.[roleSpec.role]?.primary;\n}\n\n/**\n * Sort roles by word order for pattern building.\n */\nfunction sortRolesByWordOrder(roles: RoleSpec[], wordOrder: string): RoleSpec[] {\n const sorted = [...roles];\n\n if (wordOrder === 'SVO') {\n // Sort by svoPosition (higher = earlier)\n sorted.sort((a, b) => (b.svoPosition ?? 0) - (a.svoPosition ?? 0));\n } else if (wordOrder === 'SOV') {\n // Sort by sovPosition (higher = earlier)\n sorted.sort((a, b) => (b.sovPosition ?? 0) - (a.sovPosition ?? 0));\n }\n // VSO and others use SVO-style ordering\n\n return sorted;\n}\n\n/**\n * Build extraction rules for capturing role values during parsing.\n */\nfunction buildExtractionRules(\n schema: CommandSchema,\n profile: PatternGenLanguageProfile\n): Record<string, ExtractionRule> {\n const rules: Record<string, ExtractionRule> = {};\n\n for (const roleSpec of schema.roles) {\n // Build the rule object correctly with readonly properties\n const marker = getMarkerForRole(roleSpec, profile);\n\n const rule: ExtractionRule = {\n ...(roleSpec.default !== undefined && { default: roleSpec.default }),\n ...(marker && { marker }),\n };\n\n rules[roleSpec.role] = rule;\n }\n\n return rules;\n}\n\n/**\n * Build a human-readable format string for the pattern.\n */\nfunction buildFormatString(\n schema: CommandSchema,\n profile: PatternGenLanguageProfile,\n keyword: string\n): string {\n const parts: string[] = [];\n\n if (profile.wordOrder === 'SVO' || profile.wordOrder === 'VSO') {\n parts.push(keyword);\n }\n\n for (const role of schema.roles) {\n const marker = getMarkerForRole(role, profile);\n const roleName = `{${role.role}}`;\n\n if (marker) {\n const markerInfo = profile.roleMarkers?.[role.role];\n if (markerInfo?.position === 'after') {\n parts.push(`${roleName} ${marker}`);\n } else {\n parts.push(`${marker} ${roleName}`);\n }\n } else {\n parts.push(roleName);\n }\n }\n\n if (profile.wordOrder === 'SOV') {\n parts.push(keyword);\n }\n\n return parts.join(' ');\n}\n\n/**\n * Generate multiple pattern variants (with and without optional roles).\n */\nexport function generatePatternVariants(\n schema: CommandSchema,\n profile: PatternGenLanguageProfile,\n config: GeneratorConfig = defaultConfig\n): LanguagePattern[] {\n const patterns: LanguagePattern[] = [];\n\n // Main pattern (all roles)\n patterns.push(generatePattern(schema, profile, config));\n\n // TODO: Generate variants with optional roles omitted\n // This can be added later when needed\n\n return patterns;\n}\n","/**\n * Core Types — re-exported from @lokascript/intent + framework-specific extensions\n *\n * The universal semantic types (SemanticNode, SemanticValue, etc.) now live in\n * @lokascript/intent and are re-exported here for backward compatibility.\n *\n * Framework-specific types (tokenization, pattern matching) are defined below.\n */\n\n// =============================================================================\n// Re-export everything from @lokascript/intent\n// =============================================================================\n\nexport type {\n ActionType,\n SemanticRole,\n SemanticValue,\n ExpectedType,\n LiteralValue,\n SelectorValue,\n ReferenceValue,\n PropertyPathValue,\n ExpressionValue,\n FlagValue,\n Annotation,\n ProtocolDiagnostic,\n AsyncVariant,\n MatchArm,\n SemanticNode,\n SemanticMetadata,\n SourcePosition,\n CommandSemanticNode,\n EventHandlerSemanticNode,\n EventModifiers,\n ConditionalSemanticNode,\n CompoundSemanticNode,\n LoopVariant,\n LoopSemanticNode,\n LSEEnvelope,\n} from '@lokascript/intent';\n\nexport {\n createLiteral,\n createSelector,\n createReference,\n createPropertyPath,\n createExpression,\n createFlag,\n createCommandNode,\n createEventHandlerNode,\n createConditionalNode,\n createCompoundNode,\n createLoopNode,\n createTryNode,\n createAsyncNode,\n createMatchNode,\n extractValue,\n extractRoleValue,\n getRoleValue,\n} from '@lokascript/intent';\n\n// =============================================================================\n// Framework-specific types (multilingual DSL infrastructure)\n// =============================================================================\n\nimport type {\n ActionType,\n SemanticRole,\n SemanticValue,\n SelectorValue,\n ExpectedType,\n SourcePosition,\n} from '@lokascript/intent';\n\n/**\n * Token kind - categorizes what type of token this is.\n */\nexport type TokenKind =\n | 'keyword' // Command or modifier keyword\n | 'selector' // CSS selector or identifier (#id, .class, table-name)\n | 'literal' // String or number literal\n | 'particle' // Grammatical particle (を, に, من)\n | 'conjunction' // Grammatical conjunction\n | 'event-modifier' // Event modifier (.once, .debounce(300))\n | 'identifier' // Generic identifier\n | 'operator' // Operators (., +, -, etc.)\n | 'punctuation' // Punctuation (parentheses, etc.)\n | 'url'; // URL or path\n\n/**\n * A language token - the result of tokenization.\n */\nexport interface LanguageToken {\n readonly value: string;\n readonly kind: TokenKind;\n readonly position: SourcePosition;\n readonly normalized?: string;\n readonly stem?: string;\n readonly stemConfidence?: number;\n readonly metadata?: Record<string, unknown>;\n}\n\n/**\n * Token stream - provides sequential access to tokens with backtracking.\n */\nexport interface TokenStream {\n readonly tokens: readonly LanguageToken[];\n readonly language: string;\n peek(offset?: number): LanguageToken | null;\n advance(): LanguageToken;\n isAtEnd(): boolean;\n mark(): StreamMark;\n reset(mark: StreamMark): void;\n position(): number;\n}\n\nexport interface StreamMark {\n readonly position: number;\n}\n\n/**\n * Language tokenizer interface - converts text to tokens.\n */\nexport interface LanguageTokenizer {\n readonly language: string;\n readonly direction: 'ltr' | 'rtl';\n tokenize(input: string): TokenStream;\n classifyToken(token: string): TokenKind;\n}\n\n// =============================================================================\n// Pattern Matching Types\n// =============================================================================\n\nexport interface LanguagePattern {\n readonly id: string;\n readonly language: string;\n readonly command: ActionType;\n readonly priority: number;\n readonly template: PatternTemplate;\n readonly extraction: ExtractionRules;\n readonly constraints?: PatternConstraints;\n}\n\nexport interface PatternTemplate {\n readonly format: string;\n readonly tokens: PatternToken[];\n}\n\nexport type PatternToken = LiteralPatternToken | RolePatternToken | GroupPatternToken;\n\nexport interface LiteralPatternToken {\n readonly type: 'literal';\n readonly value: string;\n readonly alternatives?: string[];\n}\n\nexport interface RolePatternToken {\n readonly type: 'role';\n readonly role: SemanticRole;\n readonly optional?: boolean;\n readonly expectedTypes?: Array<ExpectedType>;\n readonly greedy?: boolean;\n}\n\nexport interface GroupPatternToken {\n readonly type: 'group';\n readonly tokens: PatternToken[];\n readonly optional?: boolean;\n}\n\nexport interface ExtractionRules {\n readonly [role: string]: ExtractionRule;\n}\n\nexport interface ExtractionRule {\n readonly position?: number;\n readonly marker?: string;\n readonly markerAlternatives?: string[];\n readonly transform?: (raw: string) => SemanticValue;\n readonly default?: SemanticValue;\n readonly value?: string;\n readonly fromRole?: string;\n}\n\nexport interface PatternConstraints {\n readonly requiredRoles?: SemanticRole[];\n readonly forbiddenRoles?: SemanticRole[];\n readonly validPatientTypes?: Array<SelectorValue['selectorKind']>;\n readonly conflictsWith?: string[];\n}\n\nexport interface PatternMatchResult {\n readonly pattern: LanguagePattern;\n readonly captured: ReadonlyMap<SemanticRole, SemanticValue>;\n readonly consumedTokens: number;\n readonly confidence: number;\n}\n\nexport interface PatternMatchError {\n readonly message: string;\n readonly position: SourcePosition;\n readonly expectedPatterns?: string[];\n readonly partialMatch?: Partial<PatternMatchResult>;\n}\n","/**\n * Natural Language Renderer\n *\n * Interface and utilities for rendering SemanticNode → human-readable text\n * in any supported language. This is the inverse of parsing: it converts\n * a language-neutral semantic representation back to natural-language syntax.\n *\n * Every domain that supports `translate()` needs a renderer.\n */\n\nimport type { SemanticNode } from '../core/types';\nimport { extractRoleValue } from '../core/types';\nimport type { CommandSchema, RoleSpec } from '../schema';\nimport type { PatternGenLanguageProfile } from './pattern-generator';\n\n// =============================================================================\n// Renderer Interface\n// =============================================================================\n\n/**\n * Renders a SemanticNode to human-readable text in a target language.\n */\nexport interface NaturalLanguageRenderer {\n render(node: SemanticNode, language: string): string;\n}\n\n// =============================================================================\n// Renderer Helpers\n// =============================================================================\n\n/**\n * Keyword table: action → language → translated keyword.\n *\n * @example\n * ```typescript\n * const KEYWORDS: KeywordTable = {\n * select: { en: 'select', ja: '選択', es: 'seleccionar' },\n * insert: { en: 'insert', ja: '挿入', es: 'insertar' },\n * };\n * ```\n */\nexport type KeywordTable = Record<string, Record<string, string>>;\n\n/**\n * Marker table: marker name → language → translated marker.\n *\n * @example\n * ```typescript\n * const MARKERS: MarkerTable = {\n * from: { en: 'from', ja: 'から', es: 'de' },\n * into: { en: 'into', ja: 'に', es: 'en' },\n * };\n * ```\n */\nexport type MarkerTable = Record<string, Record<string, string>>;\n\n/**\n * Configuration for building a renderer from schemas and profiles.\n */\nexport interface RendererConfig {\n /** Command keyword translations per language */\n readonly keywords: KeywordTable;\n\n /** Role marker translations per language (prepositions/particles) */\n readonly markers: MarkerTable;\n\n /** Languages that use SOV word order */\n readonly sovLanguages: ReadonlySet<string>;\n\n /** Languages that use VSO word order (optional, defaults to empty) */\n readonly vsoLanguages?: ReadonlySet<string>;\n}\n\n/**\n * Look up a command keyword in the target language.\n * Falls back to the key itself if no translation found.\n */\nexport function lookupKeyword(keywords: KeywordTable, action: string, language: string): string {\n return keywords[action]?.[language] ?? action;\n}\n\n/**\n * Look up a role marker in the target language.\n * Falls back to the key itself if no translation found.\n */\nexport function lookupMarker(markers: MarkerTable, marker: string, language: string): string {\n return markers[marker]?.[language] ?? marker;\n}\n\n/**\n * Build a phrase from parts, filtering empty strings and joining with space.\n *\n * @example\n * ```typescript\n * buildPhrase('select', '', 'name', 'from', 'users')\n * // → 'select name from users'\n * ```\n */\nexport function buildPhrase(...parts: string[]): string {\n return parts.filter(Boolean).join(' ');\n}\n\n/**\n * Build keyword and marker tables from schemas and language profiles.\n * Extracts translations from the profile's keyword definitions and\n * role marker overrides.\n *\n * @example\n * ```typescript\n * const { keywords, markers } = buildTablesFromProfiles(schemas, profiles);\n * ```\n */\nexport function buildTablesFromProfiles(\n schemas: readonly CommandSchema[],\n profiles: readonly PatternGenLanguageProfile[]\n): { keywords: KeywordTable; markers: MarkerTable } {\n const keywords: KeywordTable = {};\n const markers: MarkerTable = {};\n\n // Build keyword table from profiles\n for (const profile of profiles) {\n for (const [action, kw] of Object.entries(profile.keywords)) {\n if (!keywords[action]) keywords[action] = {};\n keywords[action][profile.code] = kw.primary;\n }\n }\n\n // Build marker table from schema markerOverrides\n for (const schema of schemas) {\n for (const role of schema.roles) {\n if (role.markerOverride) {\n // Use role name as marker key\n const markerKey = role.role;\n if (!markers[markerKey]) markers[markerKey] = {};\n for (const [lang, markerText] of Object.entries(role.markerOverride)) {\n markers[markerKey][lang] = markerText;\n }\n }\n }\n }\n\n // Also extract role markers from profiles\n for (const profile of profiles) {\n if (profile.roleMarkers) {\n for (const [markerKey, markerDef] of Object.entries(profile.roleMarkers)) {\n if (!markers[markerKey]) markers[markerKey] = {};\n markers[markerKey][profile.code] = markerDef.primary;\n }\n }\n }\n\n return { keywords, markers };\n}\n\n/**\n * Detect word order from language profiles.\n * Returns sets of SOV and VSO language codes.\n */\nexport function detectWordOrders(profiles: readonly PatternGenLanguageProfile[]): {\n sovLanguages: Set<string>;\n vsoLanguages: Set<string>;\n} {\n const sovLanguages = new Set<string>();\n const vsoLanguages = new Set<string>();\n\n for (const profile of profiles) {\n if (profile.wordOrder === 'SOV') sovLanguages.add(profile.code);\n if (profile.wordOrder === 'VSO') vsoLanguages.add(profile.code);\n }\n\n return { sovLanguages, vsoLanguages };\n}\n\n/**\n * Create a basic renderer from schemas and profiles.\n *\n * This generates a renderer that handles word-order reordering automatically.\n * For each command, it constructs the output by placing the keyword and\n * role values in the correct order for the target language.\n *\n * For complex domain-specific rendering, implement `NaturalLanguageRenderer`\n * directly instead.\n *\n * @example\n * ```typescript\n * const renderer = createSchemaRenderer(schemas, profiles);\n * renderer.render(node, 'ja'); // → \"users から name 選択\"\n * ```\n */\nexport function createSchemaRenderer(\n schemas: readonly CommandSchema[],\n profiles: readonly PatternGenLanguageProfile[]\n): NaturalLanguageRenderer {\n const { keywords, markers } = buildTablesFromProfiles(schemas, profiles);\n const { sovLanguages } = detectWordOrders(profiles);\n const schemaMap = new Map<string, CommandSchema>();\n for (const s of schemas) schemaMap.set(s.action, s);\n\n return {\n render(node: SemanticNode, language: string): string {\n const schema = schemaMap.get(node.action);\n if (!schema) return node.action;\n\n const keyword = lookupKeyword(keywords, node.action, language);\n const isSOV = sovLanguages.has(language);\n\n // Collect role parts in schema order\n const roleParts: Array<{ marker?: string; value: string; role: RoleSpec }> = [];\n for (const role of schema.roles) {\n const value = extractRoleValue(node, role.role);\n if (!value && !role.required) continue;\n\n const markerText =\n role.markerOverride?.[language] ?? markers[role.role]?.[language] ?? undefined;\n\n roleParts.push({\n ...(markerText != null && { marker: markerText }),\n value: value || '',\n role,\n });\n }\n\n const parts: string[] = [];\n\n if (isSOV) {\n // SOV: roles (with markers after values) then keyword\n for (const rp of roleParts) {\n if (rp.value) parts.push(rp.value);\n if (rp.marker) parts.push(rp.marker);\n }\n parts.push(keyword);\n } else {\n // SVO/VSO: keyword then roles (with markers before values)\n parts.push(keyword);\n for (const rp of roleParts) {\n if (rp.marker) parts.push(rp.marker);\n if (rp.value) parts.push(rp.value);\n }\n }\n\n return buildPhrase(...parts);\n },\n };\n}\n","/**\n * Structured Error Diagnostics\n *\n * Re-exported from @lokascript/intent.\n * This module is the framework's re-export point for the diagnostic types\n * that live in the universal intent package.\n */\n\nexport type {\n DiagnosticSeverity,\n Diagnostic,\n DiagnosticResult,\n DiagnosticSummary,\n DiagnosticCollector,\n DiagnosticOptions,\n} from '@lokascript/intent';\n\nexport { createDiagnosticCollector, fromError, filterBySeverity } from '@lokascript/intent';\n"],"mappings":";AAkCA,IAAM,gBAAiC;AAAA,EACrC,cAAc;AAAA,EACd,yBAAyB;AAC3B;AAUO,SAAS,gBACd,QACA,SACA,SAA0B,eACT;AACjB,QAAM,KAAK,GAAG,OAAO,MAAM,IAAI,QAAQ,IAAI;AAC3C,QAAM,WAAW,OAAO,gBAAgB;AAGxC,QAAM,UAAU,QAAQ,SAAS,OAAO,MAAM;AAC9C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,+BAA+B,OAAO,MAAM,QAAQ,QAAQ,IAAI,EAAE;AAAA,EACpF;AAGA,QAAM,SAAS,YAAY,QAAQ,SAAS,QAAQ,SAAS,QAAQ,YAAY;AAGjF,QAAM,aAAa,qBAAqB,QAAQ,OAAO;AAGvD,QAAM,SAAS,kBAAkB,QAAQ,SAAS,QAAQ,OAAO;AAEjE,SAAO;AAAA,IACL;AAAA,IACA,UAAU,QAAQ;AAAA,IAClB,SAAS,OAAO;AAAA,IAChB;AAAA,IACA,UAAU;AAAA,MACR;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACF;AAKA,SAAS,YACP,QACA,SACA,SACA,cACgB;AAChB,QAAM,SAAyB,CAAC;AAChC,QAAM,eAA6B;AAAA,IACjC,MAAM;AAAA,IACN,OAAO;AAAA,IACP,GAAI,cAAc,UAAU,EAAE,aAAa;AAAA,EAC7C;AAGA,QAAM,cAAc,qBAAqB,OAAO,OAAO,QAAQ,SAAS;AAGxE,MAAI,QAAQ,cAAc,OAAO;AAE/B,WAAO,KAAK,YAAY;AAGxB,eAAW,QAAQ,aAAa;AAC9B,wBAAkB,QAAQ,MAAM,OAAO;AAAA,IACzC;AAAA,EACF,WAES,QAAQ,cAAc,OAAO;AAEpC,eAAW,QAAQ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,MAAoB,UAA0B;AACnD,YAAM,SAAS,UAAU,IAAI,KAAK,MAAM;AACxC,UAAI,CAAC,OAAQ,QAAO,KAAK;AAEzB,YAAM,UAAU,cAAc,UAAU,KAAK,QAAQ,QAAQ;AAC7D,YAAM,QAAQ,aAAa,IAAI,QAAQ;AAGvC,YAAM,YAAuE,CAAC;AAC9E,iBAAW,QAAQ,OAAO,OAAO;AAC/B,cAAM,QAAQ,iBAAiB,MAAM,KAAK,IAAI;AAC9C,YAAI,CAAC,SAAS,CAAC,KAAK,SAAU;AAE9B,cAAM,aACJ,KAAK,iBAAiB,QAAQ,KAAK,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK;AAEvE,kBAAU,KAAK;AAAA,UACb,GAAI,cAAc,QAAQ,EAAE,QAAQ,WAAW;AAAA,UAC/C,OAAO,SAAS;AAAA,UAChB;AAAA,QACF,CAAC;AAAA,MACH;AAEA,YAAM,QAAkB,CAAC;AAEzB,UAAI,OAAO;AAET,mBAAW,MAAM,WAAW;AAC1B,cAAI,GAAG,MAAO,OAAM,KAAK,GAAG,KAAK;AACjC,cAAI,GAAG,OAAQ,OAAM,KAAK,GAAG,MAAM;AAAA,QACrC;AACA,cAAM,KAAK,OAAO;AAAA,MACpB,OAAO;AAEL,cAAM,KAAK,OAAO;AAClB,mBAAW,MAAM,WAAW;AAC1B,cAAI,GAAG,OAAQ,OAAM,KAAK,GAAG,MAAM;AACnC,cAAI,GAAG,MAAO,OAAM,KAAK,GAAG,KAAK;AAAA,QACnC;AAAA,MACF;AAEA,aAAO,YAAY,GAAG,KAAK;AAAA,IAC7B;AAAA,EACF;AACF;;;AClOA,SAAS,2BAA2B,WAAW,wBAAwB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/generation/pattern-generator.ts","../../src/core/types.ts","../../src/generation/renderer.ts","../../src/generation/diagnostics.ts"],"sourcesContent":["/**\n * Pattern Generator\n *\n * Generates LanguagePattern objects from CommandSchema + LanguageProfile.\n * This solves the pattern explosion problem by deriving patterns from\n * high-level schema definitions rather than hand-writing each one.\n */\n\nimport type { LanguagePattern, PatternToken, ExtractionRule } from '../core/types';\nimport type { CommandSchema, RoleSpec } from '../schema';\n\n/**\n * Minimal language profile interface for pattern generation.\n */\nexport interface PatternGenLanguageProfile {\n readonly code: string;\n readonly wordOrder: 'SVO' | 'SOV' | 'VSO' | 'VOS' | 'OSV' | 'OVS' | 'free';\n readonly keywords: Record<string, { primary: string; alternatives?: string[] }>;\n readonly roleMarkers?: Record<\n string,\n { primary: string; alternatives?: string[]; position?: 'before' | 'after' }\n >;\n}\n\n/**\n * Configuration for pattern generation.\n */\nexport interface GeneratorConfig {\n /** Base priority for generated patterns (default: 100) */\n readonly basePriority?: number;\n /** Include optional role variants (default: true) */\n readonly includeOptionalVariants?: boolean;\n}\n\nconst defaultConfig: GeneratorConfig = {\n basePriority: 100,\n includeOptionalVariants: true,\n};\n\n/**\n * Generate a language pattern from a command schema and language profile.\n *\n * @param schema - Command schema defining the command structure\n * @param profile - Language profile with word order and keywords\n * @param config - Optional configuration\n * @returns Generated language pattern\n */\nexport function generatePattern(\n schema: CommandSchema,\n profile: PatternGenLanguageProfile,\n config: GeneratorConfig = defaultConfig\n): LanguagePattern {\n const id = `${schema.action}-${profile.code}-generated`;\n const priority = config.basePriority ?? 100;\n\n // Get keyword translation\n const keyword = profile.keywords[schema.action];\n if (!keyword) {\n throw new Error(`No keyword translation for '${schema.action}' in ${profile.code}`);\n }\n\n // Build tokens based on word order\n const tokens = buildTokens(schema, profile, keyword.primary, keyword.alternatives);\n\n // Build extraction rules\n const extraction = buildExtractionRules(schema, profile);\n\n // Build format string for documentation\n const format = buildFormatString(schema, profile, keyword.primary);\n\n return {\n id,\n language: profile.code,\n command: schema.action,\n priority,\n template: {\n format,\n tokens,\n },\n extraction,\n };\n}\n\n/**\n * Build pattern tokens based on word order and role markers.\n */\nfunction buildTokens(\n schema: CommandSchema,\n profile: PatternGenLanguageProfile,\n keyword: string,\n alternatives?: string[]\n): PatternToken[] {\n const tokens: PatternToken[] = [];\n const keywordToken: PatternToken = {\n type: 'literal',\n value: keyword,\n ...(alternatives?.length && { alternatives }),\n };\n\n // Sort roles by word order\n const sortedRoles = sortRolesByWordOrder(schema.roles, profile.wordOrder);\n\n // For SVO: [action, patient, destination, source, ...]\n if (profile.wordOrder === 'SVO') {\n // Add keyword first\n tokens.push(keywordToken);\n\n // Add roles with markers\n for (const role of sortedRoles) {\n addRoleWithMarker(tokens, role, profile);\n }\n }\n // For SOV: [patient, destination, source, ..., action]\n else if (profile.wordOrder === 'SOV') {\n // Add roles with markers first\n for (const role of sortedRoles) {\n addRoleWithMarker(tokens, role, profile);\n }\n\n // Add keyword last\n tokens.push(keywordToken);\n }\n // For VSO: [action, destination, patient, source, ...]\n else if (profile.wordOrder === 'VSO') {\n // Add keyword first\n tokens.push(keywordToken);\n\n // Add roles with markers\n for (const role of sortedRoles) {\n addRoleWithMarker(tokens, role, profile);\n }\n }\n // Other word orders can be added as needed\n else {\n // Fallback to SVO-style ordering\n tokens.push(keywordToken);\n for (const role of sortedRoles) {\n addRoleWithMarker(tokens, role, profile);\n }\n }\n\n return tokens;\n}\n\n/**\n * Add a role token with its grammatical marker if needed.\n * For optional roles, wraps the role + marker in a group.\n */\nfunction addRoleWithMarker(\n tokens: PatternToken[],\n roleSpec: RoleSpec,\n profile: PatternGenLanguageProfile\n): void {\n const marker = getMarkerForRole(roleSpec, profile);\n const isOptional = !roleSpec.required;\n\n // Build the role token\n const roleToken: PatternToken = {\n type: 'role',\n role: roleSpec.role,\n optional: isOptional,\n expectedTypes: roleSpec.expectedTypes,\n ...(roleSpec.greedy && { greedy: true }),\n };\n\n if (marker) {\n const markerInfo = profile.roleMarkers?.[roleSpec.role];\n // Priority: schema markerPosition → profile roleMarkers position → word-order default\n const defaultPosition = profile.wordOrder === 'SOV' ? 'after' : 'before';\n const position = roleSpec.markerPosition ?? markerInfo?.position ?? defaultPosition;\n\n if (isOptional) {\n // Optional role: wrap marker + role in optional group\n if (position === 'before') {\n tokens.push({\n type: 'group',\n optional: true,\n tokens: [{ type: 'literal', value: marker }, roleToken],\n });\n } else {\n tokens.push({\n type: 'group',\n optional: true,\n tokens: [roleToken, { type: 'literal', value: marker }],\n });\n }\n } else {\n // Required role: add marker + role separately\n if (position === 'before') {\n tokens.push({ type: 'literal', value: marker });\n tokens.push(roleToken);\n } else {\n tokens.push(roleToken);\n tokens.push({ type: 'literal', value: marker });\n }\n }\n } else {\n // No marker - just add the role\n tokens.push(roleToken);\n }\n}\n\n/**\n * Get the grammatical marker for a role from the profile.\n */\nfunction getMarkerForRole(\n roleSpec: RoleSpec,\n profile: PatternGenLanguageProfile\n): string | undefined {\n // Check for role-specific override first\n if (roleSpec.markerOverride?.[profile.code]) {\n return roleSpec.markerOverride[profile.code];\n }\n\n // Use profile's default marker for this role\n return profile.roleMarkers?.[roleSpec.role]?.primary;\n}\n\n/**\n * Sort roles by word order for pattern building.\n */\nfunction sortRolesByWordOrder(roles: RoleSpec[], wordOrder: string): RoleSpec[] {\n const sorted = [...roles];\n\n if (wordOrder === 'SVO') {\n // Sort by svoPosition (higher = earlier)\n sorted.sort((a, b) => (b.svoPosition ?? 0) - (a.svoPosition ?? 0));\n } else if (wordOrder === 'SOV') {\n // Sort by sovPosition (higher = earlier)\n sorted.sort((a, b) => (b.sovPosition ?? 0) - (a.sovPosition ?? 0));\n }\n // VSO and others use SVO-style ordering\n\n return sorted;\n}\n\n/**\n * Build extraction rules for capturing role values during parsing.\n */\nfunction buildExtractionRules(\n schema: CommandSchema,\n profile: PatternGenLanguageProfile\n): Record<string, ExtractionRule> {\n const rules: Record<string, ExtractionRule> = {};\n\n for (const roleSpec of schema.roles) {\n // Build the rule object correctly with readonly properties\n const marker = getMarkerForRole(roleSpec, profile);\n\n const rule: ExtractionRule = {\n ...(roleSpec.default !== undefined && { default: roleSpec.default }),\n ...(marker && { marker }),\n };\n\n rules[roleSpec.role] = rule;\n }\n\n return rules;\n}\n\n/**\n * Build a human-readable format string for the pattern.\n */\nfunction buildFormatString(\n schema: CommandSchema,\n profile: PatternGenLanguageProfile,\n keyword: string\n): string {\n const parts: string[] = [];\n\n if (profile.wordOrder === 'SVO' || profile.wordOrder === 'VSO') {\n parts.push(keyword);\n }\n\n // Order roles the same way buildTokens does (descending position). Iterating\n // declaration order here would disagree with the token order whenever a\n // schema's roles are declared in a different order than their positions imply.\n const sortedRoles = sortRolesByWordOrder(schema.roles, profile.wordOrder);\n for (const role of sortedRoles) {\n const marker = getMarkerForRole(role, profile);\n const roleName = `{${role.role}}`;\n\n if (marker) {\n const markerInfo = profile.roleMarkers?.[role.role];\n if (markerInfo?.position === 'after') {\n parts.push(`${roleName} ${marker}`);\n } else {\n parts.push(`${marker} ${roleName}`);\n }\n } else {\n parts.push(roleName);\n }\n }\n\n if (profile.wordOrder === 'SOV') {\n parts.push(keyword);\n }\n\n return parts.join(' ');\n}\n\n/**\n * Generate multiple pattern variants (with and without optional roles).\n */\nexport function generatePatternVariants(\n schema: CommandSchema,\n profile: PatternGenLanguageProfile,\n config: GeneratorConfig = defaultConfig\n): LanguagePattern[] {\n const patterns: LanguagePattern[] = [];\n\n // Main pattern (all roles)\n patterns.push(generatePattern(schema, profile, config));\n\n // TODO: Generate variants with optional roles omitted\n // This can be added later when needed\n\n return patterns;\n}\n","/**\n * Core Types — re-exported from @lokascript/intent + framework-specific extensions\n *\n * The universal semantic types (SemanticNode, SemanticValue, etc.) now live in\n * @lokascript/intent and are re-exported here for backward compatibility.\n *\n * Framework-specific types (tokenization, pattern matching) are defined below.\n */\n\n// =============================================================================\n// Re-export everything from @lokascript/intent\n// =============================================================================\n\nexport type {\n ActionType,\n SemanticRole,\n SemanticValue,\n ExpectedType,\n LiteralValue,\n SelectorValue,\n ReferenceValue,\n PropertyPathValue,\n ExpressionValue,\n FlagValue,\n Annotation,\n ProtocolDiagnostic,\n AsyncVariant,\n MatchArm,\n SemanticNode,\n SemanticMetadata,\n SourcePosition,\n CommandSemanticNode,\n EventHandlerSemanticNode,\n EventModifiers,\n ConditionalSemanticNode,\n CompoundSemanticNode,\n LoopVariant,\n LoopSemanticNode,\n LSEEnvelope,\n} from '@lokascript/intent';\n\nexport {\n createLiteral,\n createSelector,\n createReference,\n createPropertyPath,\n createExpression,\n createFlag,\n createCommandNode,\n createEventHandlerNode,\n createConditionalNode,\n createCompoundNode,\n createLoopNode,\n createTryNode,\n createAsyncNode,\n createMatchNode,\n extractValue,\n extractRoleValue,\n getRoleValue,\n} from '@lokascript/intent';\n\n// =============================================================================\n// Framework-specific types (multilingual DSL infrastructure)\n// =============================================================================\n\nimport type {\n ActionType,\n SemanticRole,\n SemanticValue,\n SelectorValue,\n ExpectedType,\n SourcePosition,\n} from '@lokascript/intent';\n\n/**\n * Token kind - categorizes what type of token this is.\n */\nexport type TokenKind =\n | 'keyword' // Command or modifier keyword\n | 'selector' // CSS selector or identifier (#id, .class, table-name)\n | 'literal' // String or number literal\n | 'particle' // Grammatical particle (を, に, من)\n | 'conjunction' // Grammatical conjunction\n | 'event-modifier' // Event modifier (.once, .debounce(300))\n | 'identifier' // Generic identifier\n | 'operator' // Operators (., +, -, etc.)\n | 'punctuation' // Punctuation (parentheses, etc.)\n | 'url'; // URL or path\n\n/**\n * A language token - the result of tokenization.\n */\nexport interface LanguageToken {\n readonly value: string;\n readonly kind: TokenKind;\n readonly position: SourcePosition;\n readonly normalized?: string;\n readonly stem?: string;\n readonly stemConfidence?: number;\n readonly metadata?: Record<string, unknown>;\n}\n\n/**\n * Token stream - provides sequential access to tokens with backtracking.\n */\nexport interface TokenStream {\n readonly tokens: readonly LanguageToken[];\n readonly language: string;\n peek(offset?: number): LanguageToken | null;\n advance(): LanguageToken;\n isAtEnd(): boolean;\n mark(): StreamMark;\n reset(mark: StreamMark): void;\n position(): number;\n}\n\nexport interface StreamMark {\n readonly position: number;\n}\n\n/**\n * Language tokenizer interface - converts text to tokens.\n */\nexport interface LanguageTokenizer {\n readonly language: string;\n readonly direction: 'ltr' | 'rtl';\n tokenize(input: string): TokenStream;\n classifyToken(token: string): TokenKind;\n}\n\n// =============================================================================\n// Pattern Matching Types\n// =============================================================================\n\nexport interface LanguagePattern {\n readonly id: string;\n readonly language: string;\n readonly command: ActionType;\n readonly priority: number;\n readonly template: PatternTemplate;\n readonly extraction: ExtractionRules;\n readonly constraints?: PatternConstraints;\n}\n\nexport interface PatternTemplate {\n readonly format: string;\n readonly tokens: PatternToken[];\n}\n\nexport type PatternToken = LiteralPatternToken | RolePatternToken | GroupPatternToken;\n\nexport interface LiteralPatternToken {\n readonly type: 'literal';\n readonly value: string;\n readonly alternatives?: string[];\n}\n\nexport interface RolePatternToken {\n readonly type: 'role';\n readonly role: SemanticRole;\n readonly optional?: boolean;\n readonly expectedTypes?: Array<ExpectedType>;\n readonly greedy?: boolean;\n}\n\nexport interface GroupPatternToken {\n readonly type: 'group';\n readonly tokens: PatternToken[];\n readonly optional?: boolean;\n}\n\nexport interface ExtractionRules {\n readonly [role: string]: ExtractionRule;\n}\n\nexport interface ExtractionRule {\n readonly position?: number;\n readonly marker?: string;\n readonly markerAlternatives?: string[];\n readonly transform?: (raw: string) => SemanticValue;\n readonly default?: SemanticValue;\n readonly value?: string;\n readonly fromRole?: string;\n}\n\nexport interface PatternConstraints {\n readonly requiredRoles?: SemanticRole[];\n readonly forbiddenRoles?: SemanticRole[];\n readonly validPatientTypes?: Array<SelectorValue['selectorKind']>;\n readonly conflictsWith?: string[];\n}\n\nexport interface PatternMatchResult {\n readonly pattern: LanguagePattern;\n readonly captured: ReadonlyMap<SemanticRole, SemanticValue>;\n readonly consumedTokens: number;\n readonly confidence: number;\n}\n\nexport interface PatternMatchError {\n readonly message: string;\n readonly position: SourcePosition;\n readonly expectedPatterns?: string[];\n readonly partialMatch?: Partial<PatternMatchResult>;\n}\n","/**\n * Natural Language Renderer\n *\n * Interface and utilities for rendering SemanticNode → human-readable text\n * in any supported language. This is the inverse of parsing: it converts\n * a language-neutral semantic representation back to natural-language syntax.\n *\n * Every domain that supports `translate()` needs a renderer.\n */\n\nimport type { SemanticNode } from '../core/types';\nimport { extractRoleValue } from '../core/types';\nimport type { CommandSchema, RoleSpec } from '../schema';\nimport type { PatternGenLanguageProfile } from './pattern-generator';\n\n// =============================================================================\n// Renderer Interface\n// =============================================================================\n\n/**\n * Renders a SemanticNode to human-readable text in a target language.\n */\nexport interface NaturalLanguageRenderer {\n render(node: SemanticNode, language: string): string;\n}\n\n// =============================================================================\n// Renderer Helpers\n// =============================================================================\n\n/**\n * Keyword table: action → language → translated keyword.\n *\n * @example\n * ```typescript\n * const KEYWORDS: KeywordTable = {\n * select: { en: 'select', ja: '選択', es: 'seleccionar' },\n * insert: { en: 'insert', ja: '挿入', es: 'insertar' },\n * };\n * ```\n */\nexport type KeywordTable = Record<string, Record<string, string>>;\n\n/**\n * Marker table: marker name → language → translated marker.\n *\n * @example\n * ```typescript\n * const MARKERS: MarkerTable = {\n * from: { en: 'from', ja: 'から', es: 'de' },\n * into: { en: 'into', ja: 'に', es: 'en' },\n * };\n * ```\n */\nexport type MarkerTable = Record<string, Record<string, string>>;\n\n/**\n * Configuration for building a renderer from schemas and profiles.\n */\nexport interface RendererConfig {\n /** Command keyword translations per language */\n readonly keywords: KeywordTable;\n\n /** Role marker translations per language (prepositions/particles) */\n readonly markers: MarkerTable;\n\n /** Languages that use SOV word order */\n readonly sovLanguages: ReadonlySet<string>;\n\n /** Languages that use VSO word order (optional, defaults to empty) */\n readonly vsoLanguages?: ReadonlySet<string>;\n}\n\n/**\n * Look up a command keyword in the target language.\n * Falls back to the key itself if no translation found.\n */\nexport function lookupKeyword(keywords: KeywordTable, action: string, language: string): string {\n return keywords[action]?.[language] ?? action;\n}\n\n/**\n * Look up a role marker in the target language.\n * Falls back to the key itself if no translation found.\n */\nexport function lookupMarker(markers: MarkerTable, marker: string, language: string): string {\n return markers[marker]?.[language] ?? marker;\n}\n\n/**\n * Build a phrase from parts, filtering empty strings and joining with space.\n *\n * @example\n * ```typescript\n * buildPhrase('select', '', 'name', 'from', 'users')\n * // → 'select name from users'\n * ```\n */\nexport function buildPhrase(...parts: string[]): string {\n return parts.filter(Boolean).join(' ');\n}\n\n/**\n * Build keyword and marker tables from schemas and language profiles.\n * Extracts translations from the profile's keyword definitions and\n * role marker overrides.\n *\n * @example\n * ```typescript\n * const { keywords, markers } = buildTablesFromProfiles(schemas, profiles);\n * ```\n */\nexport function buildTablesFromProfiles(\n schemas: readonly CommandSchema[],\n profiles: readonly PatternGenLanguageProfile[]\n): { keywords: KeywordTable; markers: MarkerTable } {\n const keywords: KeywordTable = {};\n const markers: MarkerTable = {};\n\n // Build keyword table from profiles\n for (const profile of profiles) {\n for (const [action, kw] of Object.entries(profile.keywords)) {\n if (!keywords[action]) keywords[action] = {};\n keywords[action][profile.code] = kw.primary;\n }\n }\n\n // Build marker table from schema markerOverrides\n for (const schema of schemas) {\n for (const role of schema.roles) {\n if (role.markerOverride) {\n // Use role name as marker key\n const markerKey = role.role;\n if (!markers[markerKey]) markers[markerKey] = {};\n for (const [lang, markerText] of Object.entries(role.markerOverride)) {\n markers[markerKey][lang] = markerText;\n }\n }\n }\n }\n\n // Also extract role markers from profiles\n for (const profile of profiles) {\n if (profile.roleMarkers) {\n for (const [markerKey, markerDef] of Object.entries(profile.roleMarkers)) {\n if (!markers[markerKey]) markers[markerKey] = {};\n markers[markerKey][profile.code] = markerDef.primary;\n }\n }\n }\n\n return { keywords, markers };\n}\n\n/**\n * Detect word order from language profiles.\n * Returns sets of SOV and VSO language codes.\n */\nexport function detectWordOrders(profiles: readonly PatternGenLanguageProfile[]): {\n sovLanguages: Set<string>;\n vsoLanguages: Set<string>;\n} {\n const sovLanguages = new Set<string>();\n const vsoLanguages = new Set<string>();\n\n for (const profile of profiles) {\n if (profile.wordOrder === 'SOV') sovLanguages.add(profile.code);\n if (profile.wordOrder === 'VSO') vsoLanguages.add(profile.code);\n }\n\n return { sovLanguages, vsoLanguages };\n}\n\n/**\n * Create a basic renderer from schemas and profiles.\n *\n * This generates a renderer that handles word-order reordering automatically.\n * For each command, it constructs the output by placing the keyword and\n * role values in the correct order for the target language.\n *\n * For complex domain-specific rendering, implement `NaturalLanguageRenderer`\n * directly instead.\n *\n * @example\n * ```typescript\n * const renderer = createSchemaRenderer(schemas, profiles);\n * renderer.render(node, 'ja'); // → \"users から name 選択\"\n * ```\n */\nexport function createSchemaRenderer(\n schemas: readonly CommandSchema[],\n profiles: readonly PatternGenLanguageProfile[]\n): NaturalLanguageRenderer {\n const { keywords, markers } = buildTablesFromProfiles(schemas, profiles);\n const { sovLanguages } = detectWordOrders(profiles);\n const schemaMap = new Map<string, CommandSchema>();\n for (const s of schemas) schemaMap.set(s.action, s);\n\n return {\n render(node: SemanticNode, language: string): string {\n const schema = schemaMap.get(node.action);\n if (!schema) return node.action;\n\n const keyword = lookupKeyword(keywords, node.action, language);\n const isSOV = sovLanguages.has(language);\n\n // Collect role parts in schema order\n const roleParts: Array<{ marker?: string; value: string; role: RoleSpec }> = [];\n for (const role of schema.roles) {\n const value = extractRoleValue(node, role.role);\n if (!value && !role.required) continue;\n\n const markerText =\n role.markerOverride?.[language] ?? markers[role.role]?.[language] ?? undefined;\n\n roleParts.push({\n ...(markerText != null && { marker: markerText }),\n value: value || '',\n role,\n });\n }\n\n const parts: string[] = [];\n\n if (isSOV) {\n // SOV: roles (with markers after values) then keyword\n for (const rp of roleParts) {\n if (rp.value) parts.push(rp.value);\n if (rp.marker) parts.push(rp.marker);\n }\n parts.push(keyword);\n } else {\n // SVO/VSO: keyword then roles (with markers before values)\n parts.push(keyword);\n for (const rp of roleParts) {\n if (rp.marker) parts.push(rp.marker);\n if (rp.value) parts.push(rp.value);\n }\n }\n\n return buildPhrase(...parts);\n },\n };\n}\n","/**\n * Structured Error Diagnostics\n *\n * Re-exported from @lokascript/intent.\n * This module is the framework's re-export point for the diagnostic types\n * that live in the universal intent package.\n */\n\nexport type {\n DiagnosticSeverity,\n Diagnostic,\n DiagnosticResult,\n DiagnosticSummary,\n DiagnosticCollector,\n DiagnosticOptions,\n} from '@lokascript/intent';\n\nexport { createDiagnosticCollector, fromError, filterBySeverity } from '@lokascript/intent';\n"],"mappings":";AAkCA,IAAM,gBAAiC;AAAA,EACrC,cAAc;AAAA,EACd,yBAAyB;AAC3B;AAUO,SAAS,gBACd,QACA,SACA,SAA0B,eACT;AACjB,QAAM,KAAK,GAAG,OAAO,MAAM,IAAI,QAAQ,IAAI;AAC3C,QAAM,WAAW,OAAO,gBAAgB;AAGxC,QAAM,UAAU,QAAQ,SAAS,OAAO,MAAM;AAC9C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,+BAA+B,OAAO,MAAM,QAAQ,QAAQ,IAAI,EAAE;AAAA,EACpF;AAGA,QAAM,SAAS,YAAY,QAAQ,SAAS,QAAQ,SAAS,QAAQ,YAAY;AAGjF,QAAM,aAAa,qBAAqB,QAAQ,OAAO;AAGvD,QAAM,SAAS,kBAAkB,QAAQ,SAAS,QAAQ,OAAO;AAEjE,SAAO;AAAA,IACL;AAAA,IACA,UAAU,QAAQ;AAAA,IAClB,SAAS,OAAO;AAAA,IAChB;AAAA,IACA,UAAU;AAAA,MACR;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACF;AAKA,SAAS,YACP,QACA,SACA,SACA,cACgB;AAChB,QAAM,SAAyB,CAAC;AAChC,QAAM,eAA6B;AAAA,IACjC,MAAM;AAAA,IACN,OAAO;AAAA,IACP,GAAI,cAAc,UAAU,EAAE,aAAa;AAAA,EAC7C;AAGA,QAAM,cAAc,qBAAqB,OAAO,OAAO,QAAQ,SAAS;AAGxE,MAAI,QAAQ,cAAc,OAAO;AAE/B,WAAO,KAAK,YAAY;AAGxB,eAAW,QAAQ,aAAa;AAC9B,wBAAkB,QAAQ,MAAM,OAAO;AAAA,IACzC;AAAA,EACF,WAES,QAAQ,cAAc,OAAO;AAEpC,eAAW,QAAQ,aAAa;AAC9B,wBAAkB,QAAQ,MAAM,OAAO;AAAA,IACzC;AAGA,WA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S,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;IAC3E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IAChF,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAC3B,MAAM,EACN;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAA;KAAE,CAC5E,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,0DAA0D;IAC1D,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,qDAAqD;IACrD,QAAQ,CAAC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CAC5C;AAOD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,yBAAyB,EAClC,MAAM,GAAE,eAA+B,GACtC,eAAe,CA8BjB;AA4ND;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,yBAAyB,EAClC,MAAM,GAAE,eAA+B,GACtC,eAAe,EAAE,CAUnB"}
|
package/dist/index.cjs
CHANGED
|
@@ -1567,7 +1567,8 @@ function buildFormatString(schema, profile, keyword) {
|
|
|
1567
1567
|
if (profile.wordOrder === "SVO" || profile.wordOrder === "VSO") {
|
|
1568
1568
|
parts.push(keyword);
|
|
1569
1569
|
}
|
|
1570
|
-
|
|
1570
|
+
const sortedRoles = sortRolesByWordOrder(schema.roles, profile.wordOrder);
|
|
1571
|
+
for (const role of sortedRoles) {
|
|
1571
1572
|
const marker = getMarkerForRole(role, profile);
|
|
1572
1573
|
const roleName = `{${role.role}}`;
|
|
1573
1574
|
if (marker) {
|
|
@@ -3010,7 +3011,9 @@ function buildProtocolSection() {
|
|
|
3010
3011
|
3. No spaces around the colon in role:value pairs
|
|
3011
3012
|
4. Strings with spaces must be quoted: \`patient:"hello world"\`
|
|
3012
3013
|
5. Selectors start with \`#\`, \`.\`, \`[\`, \`@\`, or \`*\`
|
|
3013
|
-
6.
|
|
3014
|
+
6. A selector containing a space, a combinator (\`>\` \`+\` \`~\`), or a comma must use a selector literal: \`patient:<ul > li/>\`, \`patient:<.a, .b/>\`
|
|
3015
|
+
7. Inside a structural role (\`body\`, \`then\`, \`else\`, \`condition\`, \`loop-body\`, \`variable\`, \`catch\`, \`finally\`) a \`[...]\` value is always a nested command. Write an attribute selector there as \`condition:<[data-active]/>\`
|
|
3016
|
+
8. Output must be valid bracket syntax: \`[action role:value ...]\``;
|
|
3014
3017
|
return {
|
|
3015
3018
|
id: "protocol",
|
|
3016
3019
|
title: "LSE Protocol",
|
|
@@ -3023,6 +3026,7 @@ function buildValueTypeSection() {
|
|
|
3023
3026
|
|
|
3024
3027
|
| Type | Syntax | Example |
|
|
3025
3028
|
|------|--------|---------|
|
|
3029
|
+
| Selector literal | Delimited by \`<\` and \`/>\` | \`<ul > li/>\`, \`<.a, .b/>\`, \`<[data-id]/>\` |
|
|
3026
3030
|
| Selector | Starts with \`#\` \`.\` \`[\` \`@\` \`*\` | \`#button\`, \`.active\`, \`[data-id]\` |
|
|
3027
3031
|
| String | Quoted with \`"\` or \`'\` | \`"hello world"\`, \`'json'\` |
|
|
3028
3032
|
| Boolean | Exact: \`true\` / \`false\` | \`visible:true\` |
|
|
@@ -5218,7 +5222,39 @@ var _BaseTokenizer = class _BaseTokenizer {
|
|
|
5218
5222
|
pos++;
|
|
5219
5223
|
}
|
|
5220
5224
|
}
|
|
5221
|
-
return new TokenStreamImpl(tokens, this.language);
|
|
5225
|
+
return new TokenStreamImpl(this.mergeColonQualifiedNames(tokens), this.language);
|
|
5226
|
+
}
|
|
5227
|
+
/**
|
|
5228
|
+
* Fuse `name` + `:qualifier` into ONE identifier (`draggable:start`).
|
|
5229
|
+
*
|
|
5230
|
+
* `:name` is hyperscript's local-variable sigil, but a colon IMMEDIATELY
|
|
5231
|
+
* preceded by an identifier is a qualifier (custom event namespace), not a
|
|
5232
|
+
* sigil. The English tokenizer already merges these inside
|
|
5233
|
+
* EnglishKeywordExtractor; this post-pass gives the other 23 languages the
|
|
5234
|
+
* same stream. Strict position adjacency is the discriminator: whitespace
|
|
5235
|
+
* between the tokens (`trigger :start`) breaks `end === start`, so a spaced
|
|
5236
|
+
* local-variable reference survives untouched.
|
|
5237
|
+
*
|
|
5238
|
+
* Self-gating for non-hyperscript tokenizers (domain DSLs): their extractor
|
|
5239
|
+
* sets tokenize `:` as bare punctuation (length 1), which never matches
|
|
5240
|
+
* COLON_QUALIFIER, so this pass is a no-op for them.
|
|
5241
|
+
*/
|
|
5242
|
+
mergeColonQualifiedNames(tokens) {
|
|
5243
|
+
const out = [];
|
|
5244
|
+
for (const tok of tokens) {
|
|
5245
|
+
const prev = out[out.length - 1];
|
|
5246
|
+
if (prev && _BaseTokenizer.ASCII_WORD.test(prev.value) && _BaseTokenizer.COLON_QUALIFIER.test(tok.value) && prev.position.end === tok.position.start) {
|
|
5247
|
+
const merged = prev.value + tok.value;
|
|
5248
|
+
out[out.length - 1] = createToken(
|
|
5249
|
+
merged,
|
|
5250
|
+
this.classifyToken(merged),
|
|
5251
|
+
createPosition(prev.position.start, tok.position.end)
|
|
5252
|
+
);
|
|
5253
|
+
continue;
|
|
5254
|
+
}
|
|
5255
|
+
out.push(tok);
|
|
5256
|
+
}
|
|
5257
|
+
return out;
|
|
5222
5258
|
}
|
|
5223
5259
|
/**
|
|
5224
5260
|
* Classify an unknown character when no extractor matches.
|
|
@@ -5724,6 +5760,14 @@ var _BaseTokenizer = class _BaseTokenizer {
|
|
|
5724
5760
|
return null;
|
|
5725
5761
|
}
|
|
5726
5762
|
};
|
|
5763
|
+
/**
|
|
5764
|
+
* ASCII word of the shape the English word-walker produces. Excludes `:`, so a
|
|
5765
|
+
* token that already carries a qualifier never merges again — `a:b:c` yields
|
|
5766
|
+
* `a:b` + `:c`, byte-matching the English extractor's single-segment merge.
|
|
5767
|
+
*/
|
|
5768
|
+
_BaseTokenizer.ASCII_WORD = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
5769
|
+
/** `:name` — only a variable-ref-style extractor ever emits this token shape. */
|
|
5770
|
+
_BaseTokenizer.COLON_QUALIFIER = /^:[A-Za-z_][A-Za-z0-9_]*$/;
|
|
5727
5771
|
/**
|
|
5728
5772
|
* Configuration for native language time units.
|
|
5729
5773
|
* Maps patterns to their standard suffix (ms, s, m, h).
|