@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.
Files changed (181) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +142 -0
  3. package/dist/aot/aot-orchestrator.d.ts +75 -0
  4. package/dist/aot/aot-orchestrator.d.ts.map +1 -0
  5. package/dist/aot/domain-scanner.d.ts +27 -0
  6. package/dist/aot/domain-scanner.d.ts.map +1 -0
  7. package/dist/aot/index.d.ts +8 -0
  8. package/dist/aot/index.d.ts.map +1 -0
  9. package/dist/aot/types.d.ts +103 -0
  10. package/dist/aot/types.d.ts.map +1 -0
  11. package/dist/api/create-dsl.d.ts +91 -0
  12. package/dist/api/create-dsl.d.ts.map +1 -0
  13. package/dist/api/dispatcher.d.ts +108 -0
  14. package/dist/api/dispatcher.d.ts.map +1 -0
  15. package/dist/api/domain-registry.d.ts +152 -0
  16. package/dist/api/domain-registry.d.ts.map +1 -0
  17. package/dist/api/index.d.ts +7 -0
  18. package/dist/api/index.d.ts.map +1 -0
  19. package/dist/api/index.js +2082 -0
  20. package/dist/api/index.js.map +1 -0
  21. package/dist/core/index.d.ts +7 -0
  22. package/dist/core/index.d.ts.map +1 -0
  23. package/dist/core/index.js +2674 -0
  24. package/dist/core/index.js.map +1 -0
  25. package/dist/core/logger.d.ts +32 -0
  26. package/dist/core/logger.d.ts.map +1 -0
  27. package/dist/core/pattern-matching/index.d.ts +6 -0
  28. package/dist/core/pattern-matching/index.d.ts.map +1 -0
  29. package/dist/core/pattern-matching/index.js +1239 -0
  30. package/dist/core/pattern-matching/index.js.map +1 -0
  31. package/dist/core/pattern-matching/pattern-matcher.d.ts +239 -0
  32. package/dist/core/pattern-matching/pattern-matcher.d.ts.map +1 -0
  33. package/dist/core/pattern-matching/utils/index.d.ts +6 -0
  34. package/dist/core/pattern-matching/utils/index.d.ts.map +1 -0
  35. package/dist/core/pattern-matching/utils/possessive-keywords.d.ts +38 -0
  36. package/dist/core/pattern-matching/utils/possessive-keywords.d.ts.map +1 -0
  37. package/dist/core/pattern-matching/utils/type-validation.d.ts +63 -0
  38. package/dist/core/pattern-matching/utils/type-validation.d.ts.map +1 -0
  39. package/dist/core/tokenization/base-tokenizer.d.ts +344 -0
  40. package/dist/core/tokenization/base-tokenizer.d.ts.map +1 -0
  41. package/dist/core/tokenization/char-classifiers.d.ts +56 -0
  42. package/dist/core/tokenization/char-classifiers.d.ts.map +1 -0
  43. package/dist/core/tokenization/default-extractors.d.ts +48 -0
  44. package/dist/core/tokenization/default-extractors.d.ts.map +1 -0
  45. package/dist/core/tokenization/extractors/index.d.ts +9 -0
  46. package/dist/core/tokenization/extractors/index.d.ts.map +1 -0
  47. package/dist/core/tokenization/extractors/operator.d.ts +23 -0
  48. package/dist/core/tokenization/extractors/operator.d.ts.map +1 -0
  49. package/dist/core/tokenization/extractors/punctuation.d.ts +22 -0
  50. package/dist/core/tokenization/extractors/punctuation.d.ts.map +1 -0
  51. package/dist/core/tokenization/extractors.d.ts +61 -0
  52. package/dist/core/tokenization/extractors.d.ts.map +1 -0
  53. package/dist/core/tokenization/index.d.ts +11 -0
  54. package/dist/core/tokenization/index.d.ts.map +1 -0
  55. package/dist/core/tokenization/index.js +1345 -0
  56. package/dist/core/tokenization/index.js.map +1 -0
  57. package/dist/core/tokenization/morphology/index.d.ts +5 -0
  58. package/dist/core/tokenization/morphology/index.d.ts.map +1 -0
  59. package/dist/core/tokenization/morphology/types.d.ts +110 -0
  60. package/dist/core/tokenization/morphology/types.d.ts.map +1 -0
  61. package/dist/core/tokenization/token-utils.d.ts +111 -0
  62. package/dist/core/tokenization/token-utils.d.ts.map +1 -0
  63. package/dist/core/types.d.ts +382 -0
  64. package/dist/core/types.d.ts.map +1 -0
  65. package/dist/core/types.js +108 -0
  66. package/dist/core/types.js.map +1 -0
  67. package/dist/generation/diagnostics.d.ts +120 -0
  68. package/dist/generation/diagnostics.d.ts.map +1 -0
  69. package/dist/generation/index.d.ts +7 -0
  70. package/dist/generation/index.d.ts.map +1 -0
  71. package/dist/generation/index.js +339 -0
  72. package/dist/generation/index.js.map +1 -0
  73. package/dist/generation/pattern-generator.d.ts +48 -0
  74. package/dist/generation/pattern-generator.d.ts.map +1 -0
  75. package/dist/generation/renderer.d.ts +115 -0
  76. package/dist/generation/renderer.d.ts.map +1 -0
  77. package/dist/grammar/index.d.ts +10 -0
  78. package/dist/grammar/index.d.ts.map +1 -0
  79. package/dist/grammar/index.js +391 -0
  80. package/dist/grammar/index.js.map +1 -0
  81. package/dist/grammar/transformer.d.ts +56 -0
  82. package/dist/grammar/transformer.d.ts.map +1 -0
  83. package/dist/grammar/types.d.ts +236 -0
  84. package/dist/grammar/types.d.ts.map +1 -0
  85. package/dist/index.cjs +4454 -0
  86. package/dist/index.cjs.map +1 -0
  87. package/dist/index.d.ts +46 -0
  88. package/dist/index.d.ts.map +1 -0
  89. package/dist/index.js +4336 -0
  90. package/dist/index.js.map +1 -0
  91. package/dist/interfaces/dictionary.d.ts +82 -0
  92. package/dist/interfaces/dictionary.d.ts.map +1 -0
  93. package/dist/interfaces/index.d.ts +10 -0
  94. package/dist/interfaces/index.d.ts.map +1 -0
  95. package/dist/interfaces/profile-provider.d.ts +67 -0
  96. package/dist/interfaces/profile-provider.d.ts.map +1 -0
  97. package/dist/interfaces/value-extractor.d.ts +168 -0
  98. package/dist/interfaces/value-extractor.d.ts.map +1 -0
  99. package/dist/multilingual/index.d.ts +8 -0
  100. package/dist/multilingual/index.d.ts.map +1 -0
  101. package/dist/multilingual/index.js +1 -0
  102. package/dist/multilingual/index.js.map +1 -0
  103. package/dist/parsing/index.d.ts +8 -0
  104. package/dist/parsing/index.d.ts.map +1 -0
  105. package/dist/parsing/index.js +1415 -0
  106. package/dist/parsing/index.js.map +1 -0
  107. package/dist/parsing/multi-statement.d.ts +265 -0
  108. package/dist/parsing/multi-statement.d.ts.map +1 -0
  109. package/dist/schema/command-schema.d.ts +78 -0
  110. package/dist/schema/command-schema.d.ts.map +1 -0
  111. package/dist/schema/index.d.ts +5 -0
  112. package/dist/schema/index.d.ts.map +1 -0
  113. package/dist/schema/index.js +25 -0
  114. package/dist/schema/index.js.map +1 -0
  115. package/dist/test-setup.d.ts +9 -0
  116. package/dist/test-setup.d.ts.map +1 -0
  117. package/dist/testing/index.d.ts +50 -0
  118. package/dist/testing/index.d.ts.map +1 -0
  119. package/dist/testing/index.js +16969 -0
  120. package/dist/testing/index.js.map +1 -0
  121. package/package.json +122 -0
  122. package/src/__test__/fixtures/sql-dsl.ts +232 -0
  123. package/src/__test__/sql-integration.test.ts +189 -0
  124. package/src/__test__/test-utils.ts +260 -0
  125. package/src/aot/aot-orchestrator.test.ts +413 -0
  126. package/src/aot/aot-orchestrator.ts +238 -0
  127. package/src/aot/domain-scanner.ts +178 -0
  128. package/src/aot/index.ts +8 -0
  129. package/src/aot/types.ts +124 -0
  130. package/src/api/create-dsl.ts +367 -0
  131. package/src/api/dispatcher.test.ts +336 -0
  132. package/src/api/dispatcher.ts +222 -0
  133. package/src/api/domain-registry.test.ts +336 -0
  134. package/src/api/domain-registry.ts +500 -0
  135. package/src/api/index.ts +7 -0
  136. package/src/core/index.ts +7 -0
  137. package/src/core/logger.ts +130 -0
  138. package/src/core/pattern-matching/index.ts +6 -0
  139. package/src/core/pattern-matching/pattern-matcher.test.ts +900 -0
  140. package/src/core/pattern-matching/pattern-matcher.ts +1548 -0
  141. package/src/core/pattern-matching/pattern-matcher.ts.backup +1267 -0
  142. package/src/core/pattern-matching/utils/index.ts +6 -0
  143. package/src/core/pattern-matching/utils/possessive-keywords.ts +55 -0
  144. package/src/core/pattern-matching/utils/type-validation.test.ts +316 -0
  145. package/src/core/pattern-matching/utils/type-validation.ts +134 -0
  146. package/src/core/tokenization/base-tokenizer.ts +916 -0
  147. package/src/core/tokenization/char-classifiers.ts +79 -0
  148. package/src/core/tokenization/create-simple-tokenizer.test.ts +260 -0
  149. package/src/core/tokenization/default-extractors.ts +69 -0
  150. package/src/core/tokenization/extractors/index.ts +9 -0
  151. package/src/core/tokenization/extractors/operator.ts +75 -0
  152. package/src/core/tokenization/extractors/punctuation.ts +39 -0
  153. package/src/core/tokenization/extractors.ts +452 -0
  154. package/src/core/tokenization/index.ts +11 -0
  155. package/src/core/tokenization/morphology/index.ts +5 -0
  156. package/src/core/tokenization/morphology/types.ts +211 -0
  157. package/src/core/tokenization/token-utils.ts +252 -0
  158. package/src/core/types.ts +589 -0
  159. package/src/generation/diagnostics.test.ts +171 -0
  160. package/src/generation/diagnostics.ts +239 -0
  161. package/src/generation/index.ts +7 -0
  162. package/src/generation/pattern-generator.test.ts +430 -0
  163. package/src/generation/pattern-generator.ts +315 -0
  164. package/src/generation/renderer.test.ts +266 -0
  165. package/src/generation/renderer.ts +244 -0
  166. package/src/grammar/index.ts +12 -0
  167. package/src/grammar/transformer.ts +159 -0
  168. package/src/grammar/types.ts +630 -0
  169. package/src/index.ts +157 -0
  170. package/src/interfaces/dictionary.ts +123 -0
  171. package/src/interfaces/index.ts +10 -0
  172. package/src/interfaces/profile-provider.ts +88 -0
  173. package/src/interfaces/value-extractor.ts +435 -0
  174. package/src/multilingual/index.ts +9 -0
  175. package/src/parsing/index.ts +27 -0
  176. package/src/parsing/multi-statement.test.ts +480 -0
  177. package/src/parsing/multi-statement.ts +648 -0
  178. package/src/schema/command-schema.ts +118 -0
  179. package/src/schema/index.ts +5 -0
  180. package/src/test-setup.ts +45 -0
  181. package/src/testing/index.ts +137 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/grammar/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAG9B,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,391 @@
1
+ // src/grammar/types.ts
2
+ var UNIVERSAL_PATTERNS = {
3
+ // on click increment #count
4
+ eventIncrement: {
5
+ name: "event-increment",
6
+ roles: ["event", "action", "patient"],
7
+ english: "on {event} {action} {patient}"
8
+ },
9
+ // put X into Y
10
+ putInto: {
11
+ name: "put-into",
12
+ roles: ["action", "patient", "destination"],
13
+ english: "{action} {patient} into {destination}"
14
+ },
15
+ // add .class to element
16
+ addTo: {
17
+ name: "add-to",
18
+ roles: ["action", "patient", "destination"],
19
+ english: "{action} {patient} to {destination}"
20
+ },
21
+ // toggle .class on element
22
+ toggleOn: {
23
+ name: "toggle-on",
24
+ roles: ["action", "patient", "destination"],
25
+ english: "{action} {patient} on {destination}"
26
+ },
27
+ // wait 2 seconds
28
+ waitDuration: {
29
+ name: "wait-duration",
30
+ roles: ["action", "quantity"],
31
+ english: "{action} {quantity}"
32
+ },
33
+ // if condition then ... end
34
+ conditional: {
35
+ name: "conditional",
36
+ roles: ["action", "condition"],
37
+ english: "{action} {condition} then ... end"
38
+ },
39
+ // fetch URL as type
40
+ fetchAs: {
41
+ name: "fetch-as",
42
+ roles: ["action", "source", "method"],
43
+ english: "{action} {source} as {method}"
44
+ },
45
+ // show element with animation
46
+ showWith: {
47
+ name: "show-with",
48
+ roles: ["action", "patient", "style"],
49
+ english: "{action} {patient} with {style}"
50
+ },
51
+ // transition property over duration
52
+ transitionOver: {
53
+ name: "transition-over",
54
+ roles: ["action", "patient", "duration"],
55
+ english: "{action} {patient} over {duration}"
56
+ }
57
+ };
58
+ var LANGUAGE_FAMILY_DEFAULTS = {
59
+ // Germanic (English, German, Dutch)
60
+ germanic: {
61
+ wordOrder: "SVO",
62
+ adpositionType: "preposition",
63
+ morphology: "fusional",
64
+ direction: "ltr",
65
+ canonicalOrder: [
66
+ "action",
67
+ "patient",
68
+ "source",
69
+ "destination",
70
+ "quantity",
71
+ "duration",
72
+ "method",
73
+ "style"
74
+ ]
75
+ },
76
+ // Romance (Spanish, French, Italian, Portuguese)
77
+ romance: {
78
+ wordOrder: "SVO",
79
+ adpositionType: "preposition",
80
+ morphology: "fusional",
81
+ direction: "ltr",
82
+ canonicalOrder: [
83
+ "action",
84
+ "patient",
85
+ "source",
86
+ "destination",
87
+ "quantity",
88
+ "duration",
89
+ "method",
90
+ "style"
91
+ ]
92
+ },
93
+ // Japonic (Japanese)
94
+ japonic: {
95
+ wordOrder: "SOV",
96
+ adpositionType: "postposition",
97
+ morphology: "agglutinative",
98
+ direction: "ltr",
99
+ canonicalOrder: [
100
+ "patient",
101
+ "source",
102
+ "destination",
103
+ "quantity",
104
+ "duration",
105
+ "method",
106
+ "style",
107
+ "action"
108
+ ]
109
+ },
110
+ // Koreanic (Korean)
111
+ koreanic: {
112
+ wordOrder: "SOV",
113
+ adpositionType: "postposition",
114
+ morphology: "agglutinative",
115
+ direction: "ltr",
116
+ canonicalOrder: [
117
+ "patient",
118
+ "source",
119
+ "destination",
120
+ "quantity",
121
+ "duration",
122
+ "method",
123
+ "style",
124
+ "action"
125
+ ]
126
+ },
127
+ // Turkic (Turkish, Azerbaijani)
128
+ turkic: {
129
+ wordOrder: "SOV",
130
+ adpositionType: "postposition",
131
+ morphology: "agglutinative",
132
+ direction: "ltr",
133
+ canonicalOrder: [
134
+ "patient",
135
+ "source",
136
+ "destination",
137
+ "quantity",
138
+ "duration",
139
+ "method",
140
+ "style",
141
+ "action"
142
+ ]
143
+ },
144
+ // Sinitic (Chinese, Cantonese)
145
+ sinitic: {
146
+ wordOrder: "SVO",
147
+ // Topic-prominent, flexible
148
+ adpositionType: "preposition",
149
+ morphology: "isolating",
150
+ direction: "ltr",
151
+ canonicalOrder: [
152
+ "action",
153
+ "patient",
154
+ "source",
155
+ "destination",
156
+ "quantity",
157
+ "duration",
158
+ "method",
159
+ "style"
160
+ ]
161
+ },
162
+ // Semitic (Arabic, Hebrew)
163
+ semitic: {
164
+ wordOrder: "VSO",
165
+ adpositionType: "preposition",
166
+ morphology: "fusional",
167
+ // Root-pattern system
168
+ direction: "rtl",
169
+ canonicalOrder: [
170
+ "action",
171
+ "agent",
172
+ "patient",
173
+ "destination",
174
+ "source",
175
+ "quantity",
176
+ "duration",
177
+ "method",
178
+ "style"
179
+ ]
180
+ },
181
+ // Austronesian (Indonesian, Tagalog)
182
+ austronesian: {
183
+ wordOrder: "SVO",
184
+ adpositionType: "preposition",
185
+ morphology: "agglutinative",
186
+ direction: "ltr",
187
+ canonicalOrder: [
188
+ "action",
189
+ "patient",
190
+ "source",
191
+ "destination",
192
+ "quantity",
193
+ "duration",
194
+ "method",
195
+ "style"
196
+ ]
197
+ },
198
+ // Quechuan (Quechua)
199
+ quechuan: {
200
+ wordOrder: "SOV",
201
+ adpositionType: "postposition",
202
+ morphology: "agglutinative",
203
+ // Actually polysynthetic but simplified
204
+ direction: "ltr",
205
+ canonicalOrder: [
206
+ "patient",
207
+ "source",
208
+ "destination",
209
+ "quantity",
210
+ "duration",
211
+ "method",
212
+ "style",
213
+ "action"
214
+ ]
215
+ },
216
+ // Bantu (Swahili)
217
+ bantu: {
218
+ wordOrder: "SVO",
219
+ adpositionType: "preposition",
220
+ morphology: "agglutinative",
221
+ direction: "ltr",
222
+ canonicalOrder: [
223
+ "action",
224
+ "patient",
225
+ "source",
226
+ "destination",
227
+ "quantity",
228
+ "duration",
229
+ "method",
230
+ "style"
231
+ ]
232
+ }
233
+ };
234
+ function reorderRoles(roles, targetOrder) {
235
+ const result = [];
236
+ const usedRoles = /* @__PURE__ */ new Set();
237
+ for (const role of targetOrder) {
238
+ const element = roles.get(role);
239
+ if (element) {
240
+ result.push(element);
241
+ usedRoles.add(role);
242
+ }
243
+ }
244
+ for (const [role, element] of roles) {
245
+ if (!usedRoles.has(role)) {
246
+ result.push(element);
247
+ }
248
+ }
249
+ return result;
250
+ }
251
+ function insertMarkers(elements, markers, adpositionType) {
252
+ const result = [];
253
+ for (const element of elements) {
254
+ const marker = markers.find((m) => m.role === element.role);
255
+ if (marker) {
256
+ if (adpositionType === "preposition") {
257
+ if (marker.form) result.push(marker.form);
258
+ result.push(element.translated || element.value);
259
+ } else if (adpositionType === "postposition") {
260
+ result.push(element.translated || element.value);
261
+ if (marker.form) result.push(marker.form);
262
+ } else {
263
+ result.push(element.translated || element.value);
264
+ }
265
+ } else {
266
+ result.push(element.translated || element.value);
267
+ }
268
+ }
269
+ return result;
270
+ }
271
+ function joinTokens(tokens) {
272
+ if (tokens.length === 0) return "";
273
+ let result = "";
274
+ for (let i = 0; i < tokens.length; i++) {
275
+ const token = tokens[i];
276
+ const nextToken = tokens[i + 1];
277
+ const isPrefix = token.endsWith("-");
278
+ const isSuffix = token.startsWith("-");
279
+ let displayToken = token;
280
+ if (isPrefix) displayToken = token.slice(0, -1);
281
+ if (isSuffix) displayToken = token.substring(1);
282
+ result += displayToken;
283
+ if (nextToken) {
284
+ const nextIsSuffix = nextToken.startsWith("-");
285
+ if (!isPrefix && !nextIsSuffix) {
286
+ result += " ";
287
+ }
288
+ }
289
+ }
290
+ return result;
291
+ }
292
+ function transformStatement(parsed, _sourceProfile, targetProfile) {
293
+ const reordered = reorderRoles(parsed.roles, targetProfile.canonicalOrder);
294
+ const withMarkers = insertMarkers(reordered, targetProfile.markers, targetProfile.adpositionType);
295
+ return joinTokens(withMarkers);
296
+ }
297
+
298
+ // src/grammar/transformer.ts
299
+ var GrammarTransformer = class {
300
+ constructor(config) {
301
+ this.dictionary = config.dictionary;
302
+ this.profileProvider = config.profileProvider;
303
+ }
304
+ /**
305
+ * Transform a statement from one language to another.
306
+ *
307
+ * @param input - Statement in source language
308
+ * @param fromLanguage - Source language code
309
+ * @param toLanguage - Target language code
310
+ * @returns Transformed statement in target language
311
+ *
312
+ * @throws Error if profiles not found or translation fails
313
+ */
314
+ transform(input, fromLanguage, toLanguage) {
315
+ const fromProfile = this.profileProvider.getProfile(fromLanguage);
316
+ const toProfile = this.profileProvider.getProfile(toLanguage);
317
+ if (!fromProfile) {
318
+ throw new Error(`No profile found for language: ${fromLanguage}`);
319
+ }
320
+ if (!toProfile) {
321
+ throw new Error(`No profile found for language: ${toLanguage}`);
322
+ }
323
+ const parsed = this.parseStatement(input, fromLanguage, fromProfile);
324
+ const translated = this.translateRoles(parsed, fromLanguage, toLanguage);
325
+ const reordered = reorderRoles(translated, toProfile.canonicalOrder);
326
+ const withMarkers = insertMarkers(reordered, toProfile.markers, toProfile.adpositionType);
327
+ return joinTokens(withMarkers);
328
+ }
329
+ /**
330
+ * Parse statement into semantic roles.
331
+ * This is a simplified generic parser - DSLs can provide custom parsers.
332
+ */
333
+ parseStatement(input, language, profile) {
334
+ const roles = /* @__PURE__ */ new Map();
335
+ const tokens = input.split(/\s+/);
336
+ let i = 0;
337
+ while (i < tokens.length) {
338
+ const token = tokens[i];
339
+ const marker = profile.markers.find((m) => m.form === token);
340
+ if (marker) {
341
+ if (i + 1 < tokens.length) {
342
+ roles.set(marker.role, tokens[i + 1]);
343
+ i += 2;
344
+ } else {
345
+ i++;
346
+ }
347
+ } else {
348
+ const canonical = this.dictionary.lookup(token, language);
349
+ if (canonical) {
350
+ roles.set("action", canonical);
351
+ } else {
352
+ if (token.startsWith("#") || token.startsWith(".")) {
353
+ roles.set("patient", token);
354
+ } else {
355
+ roles.set("patient", token);
356
+ }
357
+ }
358
+ i++;
359
+ }
360
+ }
361
+ return roles;
362
+ }
363
+ /**
364
+ * Translate roles using injected dictionary.
365
+ * Returns a Map of ParsedElement objects expected by reorderRoles.
366
+ */
367
+ translateRoles(roles, _fromLanguage, toLanguage) {
368
+ const result = /* @__PURE__ */ new Map();
369
+ for (const [role, value] of roles) {
370
+ const translated = this.dictionary.translate(value, toLanguage);
371
+ result.set(role, {
372
+ role,
373
+ value,
374
+ // Original value
375
+ translated: translated ?? value
376
+ // Translated value or original if no translation
377
+ });
378
+ }
379
+ return result;
380
+ }
381
+ };
382
+ export {
383
+ GrammarTransformer,
384
+ LANGUAGE_FAMILY_DEFAULTS,
385
+ UNIVERSAL_PATTERNS,
386
+ insertMarkers,
387
+ joinTokens,
388
+ reorderRoles,
389
+ transformStatement
390
+ };
391
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/grammar/types.ts","../../src/grammar/transformer.ts"],"sourcesContent":["/**\n * Generalized Grammar System for Multilingual Hyperscript\n *\n * This system abstracts grammatical patterns across language families,\n * enabling deep multilingual support without per-language hardcoding.\n *\n * Key Linguistic Concepts:\n * - Word Order: SVO, SOV, VSO (and variations)\n * - Adposition Type: Preposition (English) vs Postposition (Japanese/Korean)\n * - Morphology: Isolating (Chinese) vs Agglutinative (Turkish) vs Fusional (Arabic)\n * - Text Direction: LTR vs RTL\n */\n\n// =============================================================================\n// Core Types\n// =============================================================================\n\n/**\n * Semantic roles in hyperscript commands.\n * These are universal across all 13 supported languages - only the surface form changes.\n *\n * ## Core Thematic Roles (from linguistic theory)\n * | Role | Usage | Purpose | Example |\n * |-------------|-------|-----------------------------|---------------------------|\n * | action | 100% | Command verb | toggle, put, fetch |\n * | patient | 90% | What is acted upon | .active, #count |\n * | destination | 40% | Where something goes | into #output, to .class |\n * | source | 13% | Where something comes from | from #input, from URL |\n * | event | 106% | Trigger events | click, keydown, submit |\n * | condition | 8% | Boolean expressions | if x > 5, when visible |\n * | agent | 0% | Who performs action | Reserved for future use |\n * | goal | 1% | Target value/state | to 'red' (in transition) |\n *\n * ## Quantitative Roles (answer \"how much/long\")\n * | Role | Usage | Purpose | Example |\n * |----------|-------|----------------|----------------------|\n * | quantity | 7% | Numeric amount | by 5, 3 times |\n * | duration | 1% | Time span | for 5 seconds, 500ms |\n *\n * ## Adverbial/Modifier Roles (answer \"how/by what means\")\n * | Role | Usage | Purpose | Example |\n * |--------------|-------|---------------------------|-------------------|\n * | style | 2% | Animation/behavior | with fade |\n * | manner | 2% | Insertion position | before, after |\n * | method | 1% | HTTP method/technique | via POST, as GET |\n * | responseType | 1% | Response format | as json, as html |\n *\n * ## Control Flow Roles\n * | Role | Usage | Purpose | Example |\n * |----------|-------|--------------|-----------------------|\n * | loopType | 6% | Loop variant | forever, until, times |\n *\n * ## Design Notes\n * - Low-usage roles (agent, goal, method, responseType) are intentionally kept for:\n * - Linguistic completeness across all 13 languages\n * - Future extensibility (AI agents, server-side execution)\n * - Command-specific semantics (fetch, transition)\n * - Each role has distinct grammatical markers per language (see profiles/index.ts)\n * - Usage percentages based on pattern database analysis\n */\nexport type SemanticRole =\n // Core thematic roles\n | 'action' // The command/verb (increment, put, toggle)\n | 'agent' // Who/what performs action (reserved for future: AI agents, server-side)\n | 'patient' // What is acted upon (the counter, .active)\n | 'source' // Origin (from #input, from URL)\n | 'destination' // Target location (into #output, to .class)\n | 'goal' // Target value/state (to 'red', to 100)\n | 'event' // Trigger (click, input, keydown)\n | 'condition' // Boolean expression (if x > 5)\n // Quantitative roles\n | 'quantity' // Numeric amount (by 5, 3 times)\n | 'duration' // Time span (for 5 seconds, over 500ms)\n // Adverbial roles\n | 'responseType' // Response format (as json, as text, as html)\n | 'method' // HTTP method/technique (via POST, using GET)\n | 'style' // Visual/behavioral manner (with fade, smoothly)\n | 'manner' // Insertion position (before, after)\n // Control flow roles\n | 'loopType' // Loop variant: forever, times, for, while, until, until-event\n // Structural roles (for parser control)\n | 'continues'; // Continuation marker (then-chains)\n\n/**\n * Word order patterns\n * These represent the major typological categories\n */\nexport type WordOrder = 'SVO' | 'SOV' | 'VSO' | 'VOS' | 'OVS' | 'OSV' | 'free';\n\n/**\n * Where grammatical markers appear relative to their noun/verb\n */\nexport type AdpositionType = 'preposition' | 'postposition' | 'circumposition' | 'none';\n\n/**\n * Morphological typology - how words are constructed\n */\nexport type MorphologyType =\n | 'isolating' // Chinese - no inflection, word order matters\n | 'agglutinative' // Turkish, Japanese - morphemes stack predictably\n | 'fusional' // Arabic, Spanish - morphemes blend together\n | 'polysynthetic'; // Quechua - complex words encode full sentences\n\n/**\n * A grammatical marker (particle, case ending, preposition)\n */\nexport interface GrammaticalMarker {\n form: string; // The actual text (を, に, to, 的)\n role: SemanticRole; // What semantic role it marks\n position: AdpositionType; // Where it appears\n required: boolean; // Is it mandatory?\n alternatives?: string[]; // Alternative forms (e.g., 을/를 in Korean)\n}\n\n/**\n * Metadata for preserving line structure during translation.\n * Tracks indentation and blank lines so output maintains the same format.\n */\nexport interface LineMetadata {\n /** Trimmed line content (empty string for blank lines) */\n content: string;\n /** Leading whitespace (tabs/spaces) from original line */\n originalIndent: string;\n /** True if the line was empty or whitespace-only */\n isBlank: boolean;\n}\n\n// =============================================================================\n// Language Profile\n// =============================================================================\n\n/**\n * Complete grammatical profile for a language\n * This captures the essential typological features needed for transformation\n */\nexport interface LanguageProfile {\n code: string; // ISO 639-1 code\n name: string; // Native name\n\n // Typological features\n wordOrder: WordOrder;\n adpositionType: AdpositionType;\n morphology: MorphologyType;\n direction: 'ltr' | 'rtl';\n\n // Grammatical markers for each semantic role\n markers: GrammaticalMarker[];\n\n // Role ordering - which semantic roles come in what order\n // E.g., Japanese: ['patient', 'source', 'destination', 'action']\n // E.g., English: ['action', 'patient', 'source', 'destination']\n canonicalOrder: SemanticRole[];\n\n // Special rules\n rules?: GrammarRule[];\n}\n\n/**\n * Pattern for transforming hyperscript structures\n */\nexport interface GrammarRule {\n name: string;\n description: string;\n\n // Pattern matching (in canonical English form)\n match: PatternMatcher;\n\n // How to transform for this language\n transform: PatternTransform;\n\n // Priority (higher = checked first)\n priority: number;\n}\n\n/**\n * Matches a hyperscript pattern\n */\nexport interface PatternMatcher {\n // Command type(s) this matches\n commands?: string[];\n\n // Required semantic roles\n requiredRoles: SemanticRole[];\n\n // Optional roles\n optionalRoles?: SemanticRole[];\n\n // Custom predicate for complex matching\n predicate?: (parsed: ParsedStatement) => boolean;\n}\n\n/**\n * Defines how to transform a matched pattern\n */\nexport interface PatternTransform {\n // Reorder roles for target language\n roleOrder: SemanticRole[];\n\n // Insert markers between roles\n insertMarkers?: boolean;\n\n // Custom transformation function\n custom?: (parsed: ParsedStatement, profile: LanguageProfile) => string;\n}\n\n// =============================================================================\n// Parsed Structures\n// =============================================================================\n\n/**\n * A parsed hyperscript statement broken into semantic components\n */\nexport interface ParsedStatement {\n type: 'event-handler' | 'command' | 'conditional' | 'loop';\n roles: Map<SemanticRole, ParsedElement>;\n original: string;\n}\n\n/**\n * A single element with its semantic role\n */\nexport interface ParsedElement {\n role: SemanticRole;\n value: string; // Original English value\n translated?: string; // Translated value\n isSelector?: boolean; // CSS selector (don't translate)\n isLiteral?: boolean; // Literal value (don't translate)\n}\n\n// =============================================================================\n// Universal Pattern Templates\n// =============================================================================\n\n/**\n * Universal templates for common hyperscript patterns\n * These define the semantic structure independent of surface form\n */\nexport const UNIVERSAL_PATTERNS = {\n // on click increment #count\n eventIncrement: {\n name: 'event-increment',\n roles: ['event', 'action', 'patient'] as SemanticRole[],\n english: 'on {event} {action} {patient}',\n },\n\n // put X into Y\n putInto: {\n name: 'put-into',\n roles: ['action', 'patient', 'destination'] as SemanticRole[],\n english: '{action} {patient} into {destination}',\n },\n\n // add .class to element\n addTo: {\n name: 'add-to',\n roles: ['action', 'patient', 'destination'] as SemanticRole[],\n english: '{action} {patient} to {destination}',\n },\n\n // toggle .class on element\n toggleOn: {\n name: 'toggle-on',\n roles: ['action', 'patient', 'destination'] as SemanticRole[],\n english: '{action} {patient} on {destination}',\n },\n\n // wait 2 seconds\n waitDuration: {\n name: 'wait-duration',\n roles: ['action', 'quantity'] as SemanticRole[],\n english: '{action} {quantity}',\n },\n\n // if condition then ... end\n conditional: {\n name: 'conditional',\n roles: ['action', 'condition'] as SemanticRole[],\n english: '{action} {condition} then ... end',\n },\n\n // fetch URL as type\n fetchAs: {\n name: 'fetch-as',\n roles: ['action', 'source', 'method'] as SemanticRole[],\n english: '{action} {source} as {method}',\n },\n\n // show element with animation\n showWith: {\n name: 'show-with',\n roles: ['action', 'patient', 'style'] as SemanticRole[],\n english: '{action} {patient} with {style}',\n },\n\n // transition property over duration\n transitionOver: {\n name: 'transition-over',\n roles: ['action', 'patient', 'duration'] as SemanticRole[],\n english: '{action} {patient} over {duration}',\n },\n} as const;\n\n// =============================================================================\n// Language Family Defaults\n// =============================================================================\n\n/**\n * Default profiles for major language families\n * Individual languages inherit and override these\n */\nexport const LANGUAGE_FAMILY_DEFAULTS: Record<string, Partial<LanguageProfile>> = {\n // Germanic (English, German, Dutch)\n germanic: {\n wordOrder: 'SVO',\n adpositionType: 'preposition',\n morphology: 'fusional',\n direction: 'ltr',\n canonicalOrder: [\n 'action',\n 'patient',\n 'source',\n 'destination',\n 'quantity',\n 'duration',\n 'method',\n 'style',\n ],\n },\n\n // Romance (Spanish, French, Italian, Portuguese)\n romance: {\n wordOrder: 'SVO',\n adpositionType: 'preposition',\n morphology: 'fusional',\n direction: 'ltr',\n canonicalOrder: [\n 'action',\n 'patient',\n 'source',\n 'destination',\n 'quantity',\n 'duration',\n 'method',\n 'style',\n ],\n },\n\n // Japonic (Japanese)\n japonic: {\n wordOrder: 'SOV',\n adpositionType: 'postposition',\n morphology: 'agglutinative',\n direction: 'ltr',\n canonicalOrder: [\n 'patient',\n 'source',\n 'destination',\n 'quantity',\n 'duration',\n 'method',\n 'style',\n 'action',\n ],\n },\n\n // Koreanic (Korean)\n koreanic: {\n wordOrder: 'SOV',\n adpositionType: 'postposition',\n morphology: 'agglutinative',\n direction: 'ltr',\n canonicalOrder: [\n 'patient',\n 'source',\n 'destination',\n 'quantity',\n 'duration',\n 'method',\n 'style',\n 'action',\n ],\n },\n\n // Turkic (Turkish, Azerbaijani)\n turkic: {\n wordOrder: 'SOV',\n adpositionType: 'postposition',\n morphology: 'agglutinative',\n direction: 'ltr',\n canonicalOrder: [\n 'patient',\n 'source',\n 'destination',\n 'quantity',\n 'duration',\n 'method',\n 'style',\n 'action',\n ],\n },\n\n // Sinitic (Chinese, Cantonese)\n sinitic: {\n wordOrder: 'SVO', // Topic-prominent, flexible\n adpositionType: 'preposition',\n morphology: 'isolating',\n direction: 'ltr',\n canonicalOrder: [\n 'action',\n 'patient',\n 'source',\n 'destination',\n 'quantity',\n 'duration',\n 'method',\n 'style',\n ],\n },\n\n // Semitic (Arabic, Hebrew)\n semitic: {\n wordOrder: 'VSO',\n adpositionType: 'preposition',\n morphology: 'fusional', // Root-pattern system\n direction: 'rtl',\n canonicalOrder: [\n 'action',\n 'agent',\n 'patient',\n 'destination',\n 'source',\n 'quantity',\n 'duration',\n 'method',\n 'style',\n ],\n },\n\n // Austronesian (Indonesian, Tagalog)\n austronesian: {\n wordOrder: 'SVO',\n adpositionType: 'preposition',\n morphology: 'agglutinative',\n direction: 'ltr',\n canonicalOrder: [\n 'action',\n 'patient',\n 'source',\n 'destination',\n 'quantity',\n 'duration',\n 'method',\n 'style',\n ],\n },\n\n // Quechuan (Quechua)\n quechuan: {\n wordOrder: 'SOV',\n adpositionType: 'postposition',\n morphology: 'agglutinative', // Actually polysynthetic but simplified\n direction: 'ltr',\n canonicalOrder: [\n 'patient',\n 'source',\n 'destination',\n 'quantity',\n 'duration',\n 'method',\n 'style',\n 'action',\n ],\n },\n\n // Bantu (Swahili)\n bantu: {\n wordOrder: 'SVO',\n adpositionType: 'preposition',\n morphology: 'agglutinative',\n direction: 'ltr',\n canonicalOrder: [\n 'action',\n 'patient',\n 'source',\n 'destination',\n 'quantity',\n 'duration',\n 'method',\n 'style',\n ],\n },\n};\n\n// =============================================================================\n// Transformation Utilities\n// =============================================================================\n\n/**\n * Reorder semantic roles according to target language.\n * Includes a safety net to append any roles present in input\n * but missing from the target order, preventing data loss.\n */\nexport function reorderRoles(\n roles: Map<SemanticRole, ParsedElement>,\n targetOrder: SemanticRole[]\n): ParsedElement[] {\n const result: ParsedElement[] = [];\n const usedRoles = new Set<SemanticRole>();\n\n // 1. Add roles that are explicitly in the canonical order\n for (const role of targetOrder) {\n const element = roles.get(role);\n if (element) {\n result.push(element);\n usedRoles.add(role);\n }\n }\n\n // 2. Safety Net: Append any roles present in input but missing from target order\n // This prevents data loss (e.g., if 'manner' or 'instrument' isn't in the profile)\n for (const [role, element] of roles) {\n if (!usedRoles.has(role)) {\n result.push(element);\n }\n }\n\n return result;\n}\n\n/**\n * Insert grammatical markers between elements\n */\nexport function insertMarkers(\n elements: ParsedElement[],\n markers: GrammaticalMarker[],\n adpositionType: AdpositionType\n): string[] {\n const result: string[] = [];\n\n for (const element of elements) {\n const marker = markers.find(m => m.role === element.role);\n\n if (marker) {\n if (adpositionType === 'preposition') {\n // Marker before element: \"to element\"\n if (marker.form) result.push(marker.form);\n result.push(element.translated || element.value);\n } else if (adpositionType === 'postposition') {\n // Marker after element: \"element を\"\n result.push(element.translated || element.value);\n if (marker.form) result.push(marker.form);\n } else {\n result.push(element.translated || element.value);\n }\n } else {\n result.push(element.translated || element.value);\n }\n }\n\n return result;\n}\n\n/**\n * Intelligently joins tokens, handling agglutinative suffixes and prefixes.\n *\n * Rules:\n * 1. If a token ends with '-' (prefix marker), no space after it\n * 2. If a token starts with '-' (suffix marker), no space before it\n * 3. Removes the hyphen indicators from the final output\n *\n * Examples:\n * - ['#count', '-ta'] → '#countta' (Quechua accusative suffix)\n * - ['بـ-', 'الماوس'] → 'بـالماوس' (Arabic prefix attachment)\n * - ['value', 'を'] → 'value を' (Japanese particle, normal spacing)\n */\nexport function joinTokens(tokens: string[]): string {\n if (tokens.length === 0) return '';\n\n let result = '';\n\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i];\n const nextToken = tokens[i + 1];\n\n // Check if current token is a prefix (ends with -)\n const isPrefix = token.endsWith('-');\n // Check if current token is a suffix (starts with -)\n const isSuffix = token.startsWith('-');\n\n // Get the display form (strip hyphen markers)\n let displayToken = token;\n if (isPrefix) displayToken = token.slice(0, -1);\n if (isSuffix) displayToken = token.substring(1);\n\n result += displayToken;\n\n // Determine if we need a space before the next token\n if (nextToken) {\n const nextIsSuffix = nextToken.startsWith('-');\n\n // Don't add space if:\n // - Current token is a prefix (ends with -)\n // - Next token is a suffix (starts with -)\n if (!isPrefix && !nextIsSuffix) {\n result += ' ';\n }\n }\n }\n\n return result;\n}\n\n/**\n * Transform a parsed statement to target language\n */\nexport function transformStatement(\n parsed: ParsedStatement,\n _sourceProfile: LanguageProfile,\n targetProfile: LanguageProfile\n): string {\n // 1. Reorder roles for target language\n const reordered = reorderRoles(parsed.roles, targetProfile.canonicalOrder);\n\n // 2. Insert grammatical markers\n const withMarkers = insertMarkers(reordered, targetProfile.markers, targetProfile.adpositionType);\n\n // 3. Join with intelligent spacing for agglutinative languages\n // (handles suffixes like -ta, prefixes like بـ-, etc.)\n return joinTokens(withMarkers);\n}\n","/**\n * Grammar Transformer - Dependency Injection Architecture\n *\n * Transforms statements between languages using injected dependencies.\n * This makes the transformer completely domain-agnostic.\n */\n\nimport type { LanguageProfile, ParsedElement, SemanticRole } from './types';\nimport { reorderRoles, insertMarkers, joinTokens } from './types';\nimport type { Dictionary } from '../interfaces/dictionary';\nimport type { ProfileProvider } from '../interfaces/profile-provider';\n\n/**\n * Configuration for grammar transformer.\n */\nexport interface TransformerConfig {\n /** Dictionary for keyword translation */\n readonly dictionary: Dictionary;\n\n /** Profile provider for grammar rules */\n readonly profileProvider: ProfileProvider;\n}\n\n/**\n * Generic grammar transformer using dependency injection.\n *\n * @example\n * const transformer = new GrammarTransformer({\n * dictionary: new InMemoryDictionary(translations),\n * profileProvider: new InMemoryProfileProvider(profiles)\n * });\n *\n * const japanese = transformer.transform('select name from users', 'en', 'ja');\n * // → \"users から name を 選択\"\n */\nexport class GrammarTransformer {\n private dictionary: Dictionary;\n private profileProvider: ProfileProvider;\n\n constructor(config: TransformerConfig) {\n this.dictionary = config.dictionary;\n this.profileProvider = config.profileProvider;\n }\n\n /**\n * Transform a statement from one language to another.\n *\n * @param input - Statement in source language\n * @param fromLanguage - Source language code\n * @param toLanguage - Target language code\n * @returns Transformed statement in target language\n *\n * @throws Error if profiles not found or translation fails\n */\n transform(input: string, fromLanguage: string, toLanguage: string): string {\n // Get language profiles\n const fromProfile = this.profileProvider.getProfile(fromLanguage);\n const toProfile = this.profileProvider.getProfile(toLanguage);\n\n if (!fromProfile) {\n throw new Error(`No profile found for language: ${fromLanguage}`);\n }\n if (!toProfile) {\n throw new Error(`No profile found for language: ${toLanguage}`);\n }\n\n // Parse statement to semantic roles\n const parsed = this.parseStatement(input, fromLanguage, fromProfile);\n\n // Translate each word\n const translated = this.translateRoles(parsed, fromLanguage, toLanguage);\n\n // Reorder and insert markers\n const reordered = reorderRoles(translated, toProfile.canonicalOrder);\n\n const withMarkers = insertMarkers(reordered, toProfile.markers, toProfile.adpositionType);\n\n return joinTokens(withMarkers);\n }\n\n /**\n * Parse statement into semantic roles.\n * This is a simplified generic parser - DSLs can provide custom parsers.\n */\n private parseStatement(\n input: string,\n language: string,\n profile: LanguageProfile\n ): Map<SemanticRole, string> {\n const roles = new Map<SemanticRole, string>();\n const tokens = input.split(/\\s+/);\n\n // Simple parsing: extract roles based on markers\n let i = 0;\n while (i < tokens.length) {\n const token = tokens[i];\n\n // Check if token is a marker\n const marker = profile.markers.find(m => m.form === token);\n\n if (marker) {\n // Next token is the value for this role\n if (i + 1 < tokens.length) {\n roles.set(marker.role, tokens[i + 1]);\n i += 2;\n } else {\n i++;\n }\n } else {\n // Look up token in dictionary to find its role\n const canonical = this.dictionary.lookup(token, language);\n\n if (canonical) {\n // Assume it's the action (command keyword)\n roles.set('action', canonical);\n } else {\n // Assume it's a value (selector, identifier, etc.)\n // Try to guess the role based on syntax\n if (token.startsWith('#') || token.startsWith('.')) {\n roles.set('patient', token);\n } else {\n // Default to patient for unknown values\n roles.set('patient', token);\n }\n }\n\n i++;\n }\n }\n\n return roles;\n }\n\n /**\n * Translate roles using injected dictionary.\n * Returns a Map of ParsedElement objects expected by reorderRoles.\n */\n private translateRoles(\n roles: Map<SemanticRole, string>,\n _fromLanguage: string,\n toLanguage: string\n ): Map<SemanticRole, ParsedElement> {\n const result = new Map<SemanticRole, ParsedElement>();\n\n for (const [role, value] of roles) {\n // Translate using dictionary\n const translated = this.dictionary.translate(value, toLanguage);\n\n // Create ParsedElement with role, value, and translated\n result.set(role, {\n role,\n value, // Original value\n translated: translated ?? value, // Translated value or original if no translation\n });\n }\n\n return result;\n }\n}\n"],"mappings":";AA6OO,IAAM,qBAAqB;AAAA;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Y,KAAK,WAAW,OAAO,OAAO,QAAQ;AAExD,YAAI,WAAW;AAEb,gBAAM,IAAI,UAAU,SAAS;AAAA,QAC/B,OAAO;AAGL,cAAI,MAAM,WAAW,GAAG,KAAK,MAAM,WAAW,GAAG,GAAG;AAClD,kBAAM,IAAI,WAAW,KAAK;AAAA,UAC5B,OAAO;AAEL,kBAAM,IAAI,WAAW,KAAK;AAAA,UAC5B;AAAA,QACF;AAEA;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,eACN,OACA,eACA,YACkC;AAClC,UAAM,SAAS,oBAAI,IAAiC;AAEpD,eAAW,CAAC,MAAM,KAAK,KAAK,OAAO;AAEjC,YAAM,aAAa,KAAK,WAAW,UAAU,OAAO,UAAU;AAG9D,aAAO,IAAI,MAAM;AAAA,QACf;AAAA,QACA;AAAA;AAAA,QACA,YAAY,cAAc;AAAA;AAAA,MAC5B,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Grammar Transformer - Dependency Injection Architecture
3
+ *
4
+ * Transforms statements between languages using injected dependencies.
5
+ * This makes the transformer completely domain-agnostic.
6
+ */
7
+ import type { Dictionary } from '../interfaces/dictionary';
8
+ import type { ProfileProvider } from '../interfaces/profile-provider';
9
+ /**
10
+ * Configuration for grammar transformer.
11
+ */
12
+ export interface TransformerConfig {
13
+ /** Dictionary for keyword translation */
14
+ readonly dictionary: Dictionary;
15
+ /** Profile provider for grammar rules */
16
+ readonly profileProvider: ProfileProvider;
17
+ }
18
+ /**
19
+ * Generic grammar transformer using dependency injection.
20
+ *
21
+ * @example
22
+ * const transformer = new GrammarTransformer({
23
+ * dictionary: new InMemoryDictionary(translations),
24
+ * profileProvider: new InMemoryProfileProvider(profiles)
25
+ * });
26
+ *
27
+ * const japanese = transformer.transform('select name from users', 'en', 'ja');
28
+ * // → "users から name を 選択"
29
+ */
30
+ export declare class GrammarTransformer {
31
+ private dictionary;
32
+ private profileProvider;
33
+ constructor(config: TransformerConfig);
34
+ /**
35
+ * Transform a statement from one language to another.
36
+ *
37
+ * @param input - Statement in source language
38
+ * @param fromLanguage - Source language code
39
+ * @param toLanguage - Target language code
40
+ * @returns Transformed statement in target language
41
+ *
42
+ * @throws Error if profiles not found or translation fails
43
+ */
44
+ transform(input: string, fromLanguage: string, toLanguage: string): string;
45
+ /**
46
+ * Parse statement into semantic roles.
47
+ * This is a simplified generic parser - DSLs can provide custom parsers.
48
+ */
49
+ private parseStatement;
50
+ /**
51
+ * Translate roles using injected dictionary.
52
+ * Returns a Map of ParsedElement objects expected by reorderRoles.
53
+ */
54
+ private translateRoles;
55
+ }
56
+ //# sourceMappingURL=transformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../../src/grammar/transformer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,yCAAyC;IACzC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAEhC,yCAAyC;IACzC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;CAC3C;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,eAAe,CAAkB;gBAE7B,MAAM,EAAE,iBAAiB;IAKrC;;;;;;;;;OASG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;IA0B1E;;;OAGG;IACH,OAAO,CAAC,cAAc;IAiDtB;;;OAGG;IACH,OAAO,CAAC,cAAc;CAqBvB"}