@lokascript/framework 2.0.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/LICENSE +20 -0
- package/README.md +142 -0
- package/dist/aot/aot-orchestrator.d.ts +75 -0
- package/dist/aot/aot-orchestrator.d.ts.map +1 -0
- package/dist/aot/domain-scanner.d.ts +27 -0
- package/dist/aot/domain-scanner.d.ts.map +1 -0
- package/dist/aot/index.d.ts +8 -0
- package/dist/aot/index.d.ts.map +1 -0
- package/dist/aot/types.d.ts +103 -0
- package/dist/aot/types.d.ts.map +1 -0
- package/dist/api/create-dsl.d.ts +91 -0
- package/dist/api/create-dsl.d.ts.map +1 -0
- package/dist/api/dispatcher.d.ts +108 -0
- package/dist/api/dispatcher.d.ts.map +1 -0
- package/dist/api/domain-registry.d.ts +152 -0
- package/dist/api/domain-registry.d.ts.map +1 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +2082 -0
- package/dist/api/index.js.map +1 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +2674 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/logger.d.ts +32 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/pattern-matching/index.d.ts +6 -0
- package/dist/core/pattern-matching/index.d.ts.map +1 -0
- package/dist/core/pattern-matching/index.js +1239 -0
- package/dist/core/pattern-matching/index.js.map +1 -0
- package/dist/core/pattern-matching/pattern-matcher.d.ts +239 -0
- package/dist/core/pattern-matching/pattern-matcher.d.ts.map +1 -0
- package/dist/core/pattern-matching/utils/index.d.ts +6 -0
- package/dist/core/pattern-matching/utils/index.d.ts.map +1 -0
- package/dist/core/pattern-matching/utils/possessive-keywords.d.ts +38 -0
- package/dist/core/pattern-matching/utils/possessive-keywords.d.ts.map +1 -0
- package/dist/core/pattern-matching/utils/type-validation.d.ts +63 -0
- package/dist/core/pattern-matching/utils/type-validation.d.ts.map +1 -0
- package/dist/core/tokenization/base-tokenizer.d.ts +344 -0
- package/dist/core/tokenization/base-tokenizer.d.ts.map +1 -0
- package/dist/core/tokenization/char-classifiers.d.ts +56 -0
- package/dist/core/tokenization/char-classifiers.d.ts.map +1 -0
- package/dist/core/tokenization/default-extractors.d.ts +48 -0
- package/dist/core/tokenization/default-extractors.d.ts.map +1 -0
- package/dist/core/tokenization/extractors/index.d.ts +9 -0
- package/dist/core/tokenization/extractors/index.d.ts.map +1 -0
- package/dist/core/tokenization/extractors/operator.d.ts +23 -0
- package/dist/core/tokenization/extractors/operator.d.ts.map +1 -0
- package/dist/core/tokenization/extractors/punctuation.d.ts +22 -0
- package/dist/core/tokenization/extractors/punctuation.d.ts.map +1 -0
- package/dist/core/tokenization/extractors.d.ts +61 -0
- package/dist/core/tokenization/extractors.d.ts.map +1 -0
- package/dist/core/tokenization/index.d.ts +11 -0
- package/dist/core/tokenization/index.d.ts.map +1 -0
- package/dist/core/tokenization/index.js +1345 -0
- package/dist/core/tokenization/index.js.map +1 -0
- package/dist/core/tokenization/morphology/index.d.ts +5 -0
- package/dist/core/tokenization/morphology/index.d.ts.map +1 -0
- package/dist/core/tokenization/morphology/types.d.ts +110 -0
- package/dist/core/tokenization/morphology/types.d.ts.map +1 -0
- package/dist/core/tokenization/token-utils.d.ts +111 -0
- package/dist/core/tokenization/token-utils.d.ts.map +1 -0
- package/dist/core/types.d.ts +382 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +108 -0
- package/dist/core/types.js.map +1 -0
- package/dist/generation/diagnostics.d.ts +120 -0
- package/dist/generation/diagnostics.d.ts.map +1 -0
- package/dist/generation/index.d.ts +7 -0
- package/dist/generation/index.d.ts.map +1 -0
- package/dist/generation/index.js +339 -0
- package/dist/generation/index.js.map +1 -0
- package/dist/generation/pattern-generator.d.ts +48 -0
- package/dist/generation/pattern-generator.d.ts.map +1 -0
- package/dist/generation/renderer.d.ts +115 -0
- package/dist/generation/renderer.d.ts.map +1 -0
- package/dist/grammar/index.d.ts +10 -0
- package/dist/grammar/index.d.ts.map +1 -0
- package/dist/grammar/index.js +391 -0
- package/dist/grammar/index.js.map +1 -0
- package/dist/grammar/transformer.d.ts +56 -0
- package/dist/grammar/transformer.d.ts.map +1 -0
- package/dist/grammar/types.d.ts +236 -0
- package/dist/grammar/types.d.ts.map +1 -0
- package/dist/index.cjs +4454 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4336 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/dictionary.d.ts +82 -0
- package/dist/interfaces/dictionary.d.ts.map +1 -0
- package/dist/interfaces/index.d.ts +10 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/profile-provider.d.ts +67 -0
- package/dist/interfaces/profile-provider.d.ts.map +1 -0
- package/dist/interfaces/value-extractor.d.ts +168 -0
- package/dist/interfaces/value-extractor.d.ts.map +1 -0
- package/dist/multilingual/index.d.ts +8 -0
- package/dist/multilingual/index.d.ts.map +1 -0
- package/dist/multilingual/index.js +1 -0
- package/dist/multilingual/index.js.map +1 -0
- package/dist/parsing/index.d.ts +8 -0
- package/dist/parsing/index.d.ts.map +1 -0
- package/dist/parsing/index.js +1415 -0
- package/dist/parsing/index.js.map +1 -0
- package/dist/parsing/multi-statement.d.ts +265 -0
- package/dist/parsing/multi-statement.d.ts.map +1 -0
- package/dist/schema/command-schema.d.ts +78 -0
- package/dist/schema/command-schema.d.ts.map +1 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +25 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/test-setup.d.ts +9 -0
- package/dist/test-setup.d.ts.map +1 -0
- package/dist/testing/index.d.ts +50 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +16969 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +122 -0
- package/src/__test__/fixtures/sql-dsl.ts +232 -0
- package/src/__test__/sql-integration.test.ts +189 -0
- package/src/__test__/test-utils.ts +260 -0
- package/src/aot/aot-orchestrator.test.ts +413 -0
- package/src/aot/aot-orchestrator.ts +238 -0
- package/src/aot/domain-scanner.ts +178 -0
- package/src/aot/index.ts +8 -0
- package/src/aot/types.ts +124 -0
- package/src/api/create-dsl.ts +367 -0
- package/src/api/dispatcher.test.ts +336 -0
- package/src/api/dispatcher.ts +222 -0
- package/src/api/domain-registry.test.ts +336 -0
- package/src/api/domain-registry.ts +500 -0
- package/src/api/index.ts +7 -0
- package/src/core/index.ts +7 -0
- package/src/core/logger.ts +130 -0
- package/src/core/pattern-matching/index.ts +6 -0
- package/src/core/pattern-matching/pattern-matcher.test.ts +900 -0
- package/src/core/pattern-matching/pattern-matcher.ts +1548 -0
- package/src/core/pattern-matching/pattern-matcher.ts.backup +1267 -0
- package/src/core/pattern-matching/utils/index.ts +6 -0
- package/src/core/pattern-matching/utils/possessive-keywords.ts +55 -0
- package/src/core/pattern-matching/utils/type-validation.test.ts +316 -0
- package/src/core/pattern-matching/utils/type-validation.ts +134 -0
- package/src/core/tokenization/base-tokenizer.ts +916 -0
- package/src/core/tokenization/char-classifiers.ts +79 -0
- package/src/core/tokenization/create-simple-tokenizer.test.ts +260 -0
- package/src/core/tokenization/default-extractors.ts +69 -0
- package/src/core/tokenization/extractors/index.ts +9 -0
- package/src/core/tokenization/extractors/operator.ts +75 -0
- package/src/core/tokenization/extractors/punctuation.ts +39 -0
- package/src/core/tokenization/extractors.ts +452 -0
- package/src/core/tokenization/index.ts +11 -0
- package/src/core/tokenization/morphology/index.ts +5 -0
- package/src/core/tokenization/morphology/types.ts +211 -0
- package/src/core/tokenization/token-utils.ts +252 -0
- package/src/core/types.ts +589 -0
- package/src/generation/diagnostics.test.ts +171 -0
- package/src/generation/diagnostics.ts +239 -0
- package/src/generation/index.ts +7 -0
- package/src/generation/pattern-generator.test.ts +430 -0
- package/src/generation/pattern-generator.ts +315 -0
- package/src/generation/renderer.test.ts +266 -0
- package/src/generation/renderer.ts +244 -0
- package/src/grammar/index.ts +12 -0
- package/src/grammar/transformer.ts +159 -0
- package/src/grammar/types.ts +630 -0
- package/src/index.ts +157 -0
- package/src/interfaces/dictionary.ts +123 -0
- package/src/interfaces/index.ts +10 -0
- package/src/interfaces/profile-provider.ts +88 -0
- package/src/interfaces/value-extractor.ts +435 -0
- package/src/multilingual/index.ts +9 -0
- package/src/parsing/index.ts +27 -0
- package/src/parsing/multi-statement.test.ts +480 -0
- package/src/parsing/multi-statement.ts +648 -0
- package/src/schema/command-schema.ts +118 -0
- package/src/schema/index.ts +5 -0
- package/src/test-setup.ts +45 -0
- package/src/testing/index.ts +137 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lokascript/framework - Generic framework for building multilingual DSLs
|
|
3
|
+
*
|
|
4
|
+
* This framework provides the building blocks for creating domain-specific languages
|
|
5
|
+
* that work across multiple human languages (English, Japanese, Spanish, etc.) with
|
|
6
|
+
* semantic parsing and grammar transformation.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { createMultilingualDSL } from '@lokascript/framework';
|
|
11
|
+
*
|
|
12
|
+
* const myDSL = createMultilingualDSL({
|
|
13
|
+
* schemas: [{ action: 'select', roles: [...] }],
|
|
14
|
+
* languages: [{ code: 'en', profile: {...}, tokenizer: {...} }],
|
|
15
|
+
* codeGenerator: (node) => generateSQL(node)
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* myDSL.parse('select name from users', 'en');
|
|
19
|
+
* myDSL.translate('select name from users', 'en', 'ja');
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// Main API
|
|
24
|
+
export * from './api';
|
|
25
|
+
|
|
26
|
+
// AOT (generalized ahead-of-time compilation)
|
|
27
|
+
export * from './aot';
|
|
28
|
+
|
|
29
|
+
// Interfaces (for dependency injection)
|
|
30
|
+
export * from './interfaces';
|
|
31
|
+
|
|
32
|
+
// Core modules
|
|
33
|
+
export * from './schema';
|
|
34
|
+
export * from './generation';
|
|
35
|
+
|
|
36
|
+
// Grammar exports - explicitly list to avoid PatternMatcher conflict with core
|
|
37
|
+
export { GrammarTransformer } from './grammar/transformer';
|
|
38
|
+
export type { TransformerConfig } from './grammar/transformer';
|
|
39
|
+
export { reorderRoles, insertMarkers, joinTokens } from './grammar/types';
|
|
40
|
+
export type {
|
|
41
|
+
LanguageProfile,
|
|
42
|
+
PatternTransform,
|
|
43
|
+
ParsedElement,
|
|
44
|
+
WordOrder,
|
|
45
|
+
GrammaticalMarker,
|
|
46
|
+
AdpositionType,
|
|
47
|
+
} from './grammar/types';
|
|
48
|
+
|
|
49
|
+
// Core - export classes and utilities
|
|
50
|
+
export * from './core';
|
|
51
|
+
|
|
52
|
+
// Re-export key types for convenience
|
|
53
|
+
export type {
|
|
54
|
+
ActionType,
|
|
55
|
+
SemanticRole as SemanticRoleType,
|
|
56
|
+
SemanticValue,
|
|
57
|
+
SemanticNode,
|
|
58
|
+
CommandSemanticNode,
|
|
59
|
+
EventHandlerSemanticNode,
|
|
60
|
+
ConditionalSemanticNode,
|
|
61
|
+
CompoundSemanticNode,
|
|
62
|
+
LoopSemanticNode,
|
|
63
|
+
LiteralValue,
|
|
64
|
+
SelectorValue,
|
|
65
|
+
ReferenceValue,
|
|
66
|
+
PropertyPathValue,
|
|
67
|
+
ExpressionValue,
|
|
68
|
+
SemanticMetadata,
|
|
69
|
+
SourcePosition,
|
|
70
|
+
LanguageToken,
|
|
71
|
+
TokenStream,
|
|
72
|
+
LanguageTokenizer,
|
|
73
|
+
LanguagePattern,
|
|
74
|
+
} from './core/types';
|
|
75
|
+
|
|
76
|
+
export type { CommandSchema, RoleSpec } from './schema';
|
|
77
|
+
|
|
78
|
+
// Renderer
|
|
79
|
+
export type {
|
|
80
|
+
NaturalLanguageRenderer,
|
|
81
|
+
KeywordTable,
|
|
82
|
+
MarkerTable,
|
|
83
|
+
RendererConfig,
|
|
84
|
+
} from './generation/renderer';
|
|
85
|
+
export {
|
|
86
|
+
lookupKeyword,
|
|
87
|
+
lookupMarker,
|
|
88
|
+
buildPhrase,
|
|
89
|
+
buildTablesFromProfiles,
|
|
90
|
+
detectWordOrders,
|
|
91
|
+
createSchemaRenderer,
|
|
92
|
+
} from './generation/renderer';
|
|
93
|
+
|
|
94
|
+
// Diagnostics
|
|
95
|
+
export type {
|
|
96
|
+
DiagnosticSeverity,
|
|
97
|
+
Diagnostic,
|
|
98
|
+
DiagnosticResult,
|
|
99
|
+
DiagnosticSummary,
|
|
100
|
+
DiagnosticCollector,
|
|
101
|
+
DiagnosticOptions,
|
|
102
|
+
} from './generation/diagnostics';
|
|
103
|
+
export { createDiagnosticCollector, fromError, filterBySeverity } from './generation/diagnostics';
|
|
104
|
+
|
|
105
|
+
export type {
|
|
106
|
+
LanguageConfig,
|
|
107
|
+
DSLConfig,
|
|
108
|
+
MultilingualDSL,
|
|
109
|
+
CodeGenerator,
|
|
110
|
+
ValidationResult,
|
|
111
|
+
CompileResult,
|
|
112
|
+
DomainDescriptor,
|
|
113
|
+
MCPToolDefinition,
|
|
114
|
+
MCPToolResponse,
|
|
115
|
+
DispatchResult,
|
|
116
|
+
CompositeParseResult,
|
|
117
|
+
CompositeStatement,
|
|
118
|
+
CompositeError,
|
|
119
|
+
DispatcherOptions,
|
|
120
|
+
} from './api';
|
|
121
|
+
|
|
122
|
+
export { DomainRegistry, CrossDomainDispatcher } from './api';
|
|
123
|
+
|
|
124
|
+
// Re-export helper functions
|
|
125
|
+
export {
|
|
126
|
+
createLiteral,
|
|
127
|
+
createSelector,
|
|
128
|
+
createReference,
|
|
129
|
+
createPropertyPath,
|
|
130
|
+
createExpression,
|
|
131
|
+
createCommandNode,
|
|
132
|
+
createEventHandlerNode,
|
|
133
|
+
createConditionalNode,
|
|
134
|
+
createCompoundNode,
|
|
135
|
+
createLoopNode,
|
|
136
|
+
extractValue,
|
|
137
|
+
extractRoleValue,
|
|
138
|
+
} from './core/types';
|
|
139
|
+
|
|
140
|
+
export { defineCommand, defineRole } from './schema';
|
|
141
|
+
export { createSimpleTokenizer } from './core/tokenization/base-tokenizer';
|
|
142
|
+
export type { SimpleTokenizerConfig } from './core/tokenization/base-tokenizer';
|
|
143
|
+
|
|
144
|
+
// Multi-statement parser
|
|
145
|
+
export { createMultiStatementParser, accumulateBlocks } from './parsing/multi-statement';
|
|
146
|
+
export type {
|
|
147
|
+
MultiStatementParser,
|
|
148
|
+
MultiStatementConfig,
|
|
149
|
+
MultiStatementResult,
|
|
150
|
+
ParsedStatement,
|
|
151
|
+
StatementError,
|
|
152
|
+
StatementBlock,
|
|
153
|
+
BlockConfig,
|
|
154
|
+
BlockResult,
|
|
155
|
+
KeywordMap,
|
|
156
|
+
WordOrderHint,
|
|
157
|
+
} from './parsing/multi-statement';
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dictionary Interface - Keyword Translation
|
|
3
|
+
*
|
|
4
|
+
* Provides keyword translations between languages.
|
|
5
|
+
* DSLs implement this to provide their domain-specific translations.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Dictionary provides keyword translations between languages.
|
|
10
|
+
*/
|
|
11
|
+
export interface Dictionary {
|
|
12
|
+
/**
|
|
13
|
+
* Look up canonical form from localized keyword.
|
|
14
|
+
*
|
|
15
|
+
* @param localizedWord - Word in target language (e.g., 'トグル', 'alternar')
|
|
16
|
+
* @param language - Language code
|
|
17
|
+
* @returns Canonical form (e.g., 'toggle') or undefined
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* dictionary.lookup('トグル', 'ja') // → 'toggle'
|
|
21
|
+
* dictionary.lookup('alternar', 'es') // → 'toggle'
|
|
22
|
+
*/
|
|
23
|
+
lookup(localizedWord: string, language: string): string | undefined;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Translate canonical keyword to target language.
|
|
27
|
+
*
|
|
28
|
+
* @param canonical - Canonical form (e.g., 'toggle')
|
|
29
|
+
* @param targetLanguage - Target language code
|
|
30
|
+
* @returns Localized form or undefined
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* dictionary.translate('toggle', 'ja') // → 'トグル'
|
|
34
|
+
* dictionary.translate('toggle', 'es') // → 'alternar'
|
|
35
|
+
*/
|
|
36
|
+
translate(canonical: string, targetLanguage: string): string | undefined;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Get all translations of a word across all supported languages.
|
|
40
|
+
*
|
|
41
|
+
* @param word - Word to translate
|
|
42
|
+
* @param sourceLanguage - Source language
|
|
43
|
+
* @returns Map of language code to translation
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* dictionary.getAllTranslations('toggle', 'en')
|
|
47
|
+
* // → { ja: 'トグル', es: 'alternar', ko: '토글', ... }
|
|
48
|
+
*/
|
|
49
|
+
getAllTranslations(word: string, sourceLanguage: string): Record<string, string>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Optional: Find what category a word belongs to.
|
|
53
|
+
* Useful for organizing translations by domain (commands, modifiers, events, etc.).
|
|
54
|
+
*/
|
|
55
|
+
getCategory?(word: string, language: string): string | undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Simple in-memory dictionary implementation.
|
|
60
|
+
* Suitable for small DSLs or prototyping.
|
|
61
|
+
*/
|
|
62
|
+
export class InMemoryDictionary implements Dictionary {
|
|
63
|
+
/**
|
|
64
|
+
* @param translations - Map of language code to canonical→localized mappings
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* new InMemoryDictionary({
|
|
68
|
+
* en: { select: 'select', insert: 'insert' },
|
|
69
|
+
* es: { select: 'seleccionar', insert: 'insertar' },
|
|
70
|
+
* ja: { select: '選択', insert: '挿入' }
|
|
71
|
+
* })
|
|
72
|
+
*/
|
|
73
|
+
constructor(private translations: Record<string, Record<string, string>>) {}
|
|
74
|
+
|
|
75
|
+
lookup(word: string, language: string): string | undefined {
|
|
76
|
+
const langDict = this.translations[language];
|
|
77
|
+
if (!langDict) return undefined;
|
|
78
|
+
|
|
79
|
+
// Reverse lookup: find key where value = word
|
|
80
|
+
const wordLower = word.toLowerCase();
|
|
81
|
+
for (const [canonical, localized] of Object.entries(langDict)) {
|
|
82
|
+
if (localized.toLowerCase() === wordLower) {
|
|
83
|
+
return canonical;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
translate(canonical: string, targetLanguage: string): string | undefined {
|
|
90
|
+
return this.translations[targetLanguage]?.[canonical];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getAllTranslations(word: string, sourceLanguage: string): Record<string, string> {
|
|
94
|
+
const canonical = this.lookup(word, sourceLanguage);
|
|
95
|
+
if (!canonical) return {};
|
|
96
|
+
|
|
97
|
+
const result: Record<string, string> = {};
|
|
98
|
+
for (const [lang, dict] of Object.entries(this.translations)) {
|
|
99
|
+
const translation = dict[canonical];
|
|
100
|
+
if (translation) {
|
|
101
|
+
result[lang] = translation;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Null dictionary - no translations (useful for single-language DSLs).
|
|
110
|
+
*/
|
|
111
|
+
export class NullDictionary implements Dictionary {
|
|
112
|
+
lookup(word: string, _language: string): string | undefined {
|
|
113
|
+
return word; // Identity: word is its own canonical form
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
translate(canonical: string, _targetLanguage: string): string | undefined {
|
|
117
|
+
return canonical; // Identity: no translation
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
getAllTranslations(word: string, _sourceLanguage: string): Record<string, string> {
|
|
121
|
+
return { en: word }; // Only source language
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core interfaces for dependency injection
|
|
3
|
+
*
|
|
4
|
+
* These interfaces define pluggable components that DSLs can implement
|
|
5
|
+
* to customize framework behavior.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export * from './dictionary';
|
|
9
|
+
export * from './profile-provider';
|
|
10
|
+
export * from './value-extractor';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profile Provider Interface - Language Profile Access
|
|
3
|
+
*
|
|
4
|
+
* Provides language profiles for grammar transformation.
|
|
5
|
+
* DSLs implement this to provide their domain-specific profiles.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { LanguageProfile } from '../grammar';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Provides language profiles for transformation.
|
|
12
|
+
*/
|
|
13
|
+
export interface ProfileProvider {
|
|
14
|
+
/**
|
|
15
|
+
* Get language profile by code.
|
|
16
|
+
*
|
|
17
|
+
* @param language - ISO 639-1 code (e.g., 'en', 'ja', 'es')
|
|
18
|
+
* @returns Language profile or undefined if not supported
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const profile = provider.getProfile('ja');
|
|
22
|
+
* console.log(profile.wordOrder); // 'SOV'
|
|
23
|
+
*/
|
|
24
|
+
getProfile(language: string): LanguageProfile | undefined;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get all supported language codes.
|
|
28
|
+
*
|
|
29
|
+
* @returns Array of ISO 639-1 codes
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* provider.getSupportedLanguages() // → ['en', 'ja', 'es', 'ko']
|
|
33
|
+
*/
|
|
34
|
+
getSupportedLanguages(): string[];
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Check if a language is supported.
|
|
38
|
+
*
|
|
39
|
+
* @param language - Language code to check
|
|
40
|
+
* @returns True if language is supported
|
|
41
|
+
*/
|
|
42
|
+
hasLanguage(language: string): boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Simple in-memory profile provider.
|
|
47
|
+
*/
|
|
48
|
+
export class InMemoryProfileProvider implements ProfileProvider {
|
|
49
|
+
/**
|
|
50
|
+
* @param profiles - Map of language code to profile
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* new InMemoryProfileProvider({
|
|
54
|
+
* en: { code: 'en', wordOrder: 'SVO', ... },
|
|
55
|
+
* ja: { code: 'ja', wordOrder: 'SOV', ... }
|
|
56
|
+
* })
|
|
57
|
+
*/
|
|
58
|
+
constructor(private profiles: Record<string, LanguageProfile>) {}
|
|
59
|
+
|
|
60
|
+
getProfile(language: string): LanguageProfile | undefined {
|
|
61
|
+
return this.profiles[language];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getSupportedLanguages(): string[] {
|
|
65
|
+
return Object.keys(this.profiles);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
hasLanguage(language: string): boolean {
|
|
69
|
+
return language in this.profiles;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Null profile provider - for DSLs that don't need grammar transformation.
|
|
75
|
+
*/
|
|
76
|
+
export class NullProfileProvider implements ProfileProvider {
|
|
77
|
+
getProfile(_language: string): LanguageProfile | undefined {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getSupportedLanguages(): string[] {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
hasLanguage(_language: string): boolean {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|