dirac-lang 0.1.22 → 0.1.23
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/{chunk-XGR3IHWY.js → chunk-APWJJXNI.js} +32 -18
- package/dist/{chunk-7X5JYLMO.js → chunk-RGS2XK6T.js} +1 -1
- package/dist/cli.js +3 -3
- package/dist/index.js +2 -2
- package/dist/{interpreter-WUPTTWCU.js → interpreter-UZDVASAW.js} +1 -1
- package/dist/test-runner.js +67 -9
- package/package.json +1 -1
- package/src/tags/input.ts +30 -7
- package/src/test-runner.ts +83 -9
- package/tests/input-stdin-all.test.di +8 -0
- package/tests/input-stdin-all.txt +1 -0
|
@@ -419,12 +419,12 @@ async function executeIf(session, element) {
|
|
|
419
419
|
const condition = await evaluatePredicate(session, conditionElement);
|
|
420
420
|
if (condition) {
|
|
421
421
|
if (thenElement) {
|
|
422
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
422
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-UZDVASAW.js");
|
|
423
423
|
await integrateChildren2(session, thenElement);
|
|
424
424
|
}
|
|
425
425
|
} else {
|
|
426
426
|
if (elseElement) {
|
|
427
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
427
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-UZDVASAW.js");
|
|
428
428
|
await integrateChildren2(session, elseElement);
|
|
429
429
|
}
|
|
430
430
|
}
|
|
@@ -437,7 +437,7 @@ async function evaluatePredicate(session, predicateElement) {
|
|
|
437
437
|
return await evaluateCondition(session, predicateElement);
|
|
438
438
|
}
|
|
439
439
|
const outputLengthBefore = session.output.length;
|
|
440
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
440
|
+
const { integrate: integrate2 } = await import("./interpreter-UZDVASAW.js");
|
|
441
441
|
await integrate2(session, predicateElement);
|
|
442
442
|
const newOutputChunks = session.output.slice(outputLengthBefore);
|
|
443
443
|
const result = newOutputChunks.join("").trim();
|
|
@@ -460,11 +460,11 @@ async function evaluateCondition(session, condElement) {
|
|
|
460
460
|
}
|
|
461
461
|
const outputLengthBefore = session.output.length;
|
|
462
462
|
const args = [];
|
|
463
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
463
|
+
const { integrate: integrate2 } = await import("./interpreter-UZDVASAW.js");
|
|
464
464
|
for (const child of condElement.children) {
|
|
465
465
|
if (child.tag.toLowerCase() === "arg") {
|
|
466
466
|
const argOutputStart = session.output.length;
|
|
467
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
467
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-UZDVASAW.js");
|
|
468
468
|
await integrateChildren2(session, child);
|
|
469
469
|
const newChunks = session.output.slice(argOutputStart);
|
|
470
470
|
const argValue = newChunks.join("");
|
|
@@ -1282,7 +1282,7 @@ async function executeTagCheck(session, element) {
|
|
|
1282
1282
|
const executeTag = correctedTag || tagName;
|
|
1283
1283
|
console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
|
|
1284
1284
|
const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
|
|
1285
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
1285
|
+
const { integrate: integrate2 } = await import("./interpreter-UZDVASAW.js");
|
|
1286
1286
|
await integrate2(session, elementToExecute);
|
|
1287
1287
|
}
|
|
1288
1288
|
}
|
|
@@ -1291,7 +1291,7 @@ async function executeTagCheck(session, element) {
|
|
|
1291
1291
|
// src/tags/throw.ts
|
|
1292
1292
|
async function executeThrow(session, element) {
|
|
1293
1293
|
const exceptionName = element.attributes?.name || "exception";
|
|
1294
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1294
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-UZDVASAW.js");
|
|
1295
1295
|
const exceptionDom = {
|
|
1296
1296
|
tag: "exception-content",
|
|
1297
1297
|
attributes: { name: exceptionName },
|
|
@@ -1304,7 +1304,7 @@ async function executeThrow(session, element) {
|
|
|
1304
1304
|
// src/tags/try.ts
|
|
1305
1305
|
async function executeTry(session, element) {
|
|
1306
1306
|
setExceptionBoundary(session);
|
|
1307
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1307
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-UZDVASAW.js");
|
|
1308
1308
|
await integrateChildren2(session, element);
|
|
1309
1309
|
unsetExceptionBoundary(session);
|
|
1310
1310
|
}
|
|
@@ -1314,7 +1314,7 @@ async function executeCatch(session, element) {
|
|
|
1314
1314
|
const exceptionName = element.attributes?.name || "exception";
|
|
1315
1315
|
const caughtCount = lookupException(session, exceptionName);
|
|
1316
1316
|
if (caughtCount > 0) {
|
|
1317
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1317
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-UZDVASAW.js");
|
|
1318
1318
|
await integrateChildren2(session, element);
|
|
1319
1319
|
}
|
|
1320
1320
|
flushCurrentException(session);
|
|
@@ -1323,7 +1323,7 @@ async function executeCatch(session, element) {
|
|
|
1323
1323
|
// src/tags/exception.ts
|
|
1324
1324
|
async function executeException(session, element) {
|
|
1325
1325
|
const exceptions = getCurrentExceptions(session);
|
|
1326
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1326
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-UZDVASAW.js");
|
|
1327
1327
|
for (const exceptionDom of exceptions) {
|
|
1328
1328
|
await integrateChildren2(session, exceptionDom);
|
|
1329
1329
|
}
|
|
@@ -1463,7 +1463,7 @@ async function executeForeach(session, element) {
|
|
|
1463
1463
|
const parser2 = new DiracParser2();
|
|
1464
1464
|
try {
|
|
1465
1465
|
const fromElement = parser2.parse(fromAttr);
|
|
1466
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
1466
|
+
const { integrate: integrate2 } = await import("./interpreter-UZDVASAW.js");
|
|
1467
1467
|
await integrate2(session, fromElement);
|
|
1468
1468
|
} catch (e) {
|
|
1469
1469
|
session.output = savedOutput;
|
|
@@ -1644,17 +1644,31 @@ async function executeInput(session, element) {
|
|
|
1644
1644
|
emit(session, value);
|
|
1645
1645
|
}
|
|
1646
1646
|
async function readAllStdin() {
|
|
1647
|
+
process.stdin.removeAllListeners("data");
|
|
1648
|
+
process.stdin.removeAllListeners("end");
|
|
1649
|
+
process.stdin.removeAllListeners("error");
|
|
1647
1650
|
return new Promise((resolve2, reject) => {
|
|
1648
1651
|
const chunks = [];
|
|
1649
|
-
|
|
1652
|
+
const onData = (chunk) => {
|
|
1650
1653
|
chunks.push(chunk);
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1654
|
+
};
|
|
1655
|
+
const onEnd = () => {
|
|
1656
|
+
const result = Buffer.concat(chunks).toString("utf-8");
|
|
1657
|
+
process.stdin.removeListener("data", onData);
|
|
1658
|
+
process.stdin.removeListener("end", onEnd);
|
|
1659
|
+
process.stdin.removeListener("error", onError);
|
|
1660
|
+
resolve2(result);
|
|
1661
|
+
};
|
|
1662
|
+
const onError = (err) => {
|
|
1663
|
+
process.stdin.removeListener("data", onData);
|
|
1664
|
+
process.stdin.removeListener("end", onEnd);
|
|
1665
|
+
process.stdin.removeListener("error", onError);
|
|
1656
1666
|
reject(err);
|
|
1657
|
-
}
|
|
1667
|
+
};
|
|
1668
|
+
process.stdin.on("data", onData);
|
|
1669
|
+
process.stdin.on("end", onEnd);
|
|
1670
|
+
process.stdin.on("error", onError);
|
|
1671
|
+
process.stdin.resume();
|
|
1658
1672
|
});
|
|
1659
1673
|
}
|
|
1660
1674
|
var stdinReader = null;
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
execute
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-RGS2XK6T.js";
|
|
5
|
+
import "./chunk-APWJJXNI.js";
|
|
6
6
|
import "./chunk-HRHAMPOB.js";
|
|
7
7
|
import "./chunk-E7PWEMZA.js";
|
|
8
8
|
import "./chunk-52ED23DR.js";
|
|
@@ -13,7 +13,7 @@ import "dotenv/config";
|
|
|
13
13
|
// package.json
|
|
14
14
|
var package_default = {
|
|
15
15
|
name: "dirac-lang",
|
|
16
|
-
version: "0.1.
|
|
16
|
+
version: "0.1.23",
|
|
17
17
|
description: "LLM-Augmented Declarative Execution",
|
|
18
18
|
type: "module",
|
|
19
19
|
main: "dist/index.js",
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
createLLMAdapter,
|
|
3
3
|
execute,
|
|
4
4
|
executeUserCommand
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-RGS2XK6T.js";
|
|
6
6
|
import {
|
|
7
7
|
integrate
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-APWJJXNI.js";
|
|
9
9
|
import {
|
|
10
10
|
DiracParser
|
|
11
11
|
} from "./chunk-HRHAMPOB.js";
|
package/dist/test-runner.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
integrate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-APWJJXNI.js";
|
|
4
4
|
import {
|
|
5
5
|
DiracParser
|
|
6
6
|
} from "./chunk-HRHAMPOB.js";
|
|
@@ -55,17 +55,75 @@ var TestRunner = class {
|
|
|
55
55
|
passed: false
|
|
56
56
|
};
|
|
57
57
|
try {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
const stdinFile = filePath.replace(".test.di", ".txt");
|
|
59
|
+
let stdinData;
|
|
60
|
+
if (fs.existsSync(stdinFile)) {
|
|
61
|
+
stdinData = fs.readFileSync(stdinFile, "utf-8");
|
|
62
|
+
}
|
|
63
|
+
if (stdinData !== void 0) {
|
|
64
|
+
const originalOn = process.stdin.on.bind(process.stdin);
|
|
65
|
+
const originalResume = process.stdin.resume.bind(process.stdin);
|
|
66
|
+
const originalRemoveAllListeners = process.stdin.removeAllListeners.bind(process.stdin);
|
|
67
|
+
const originalRemoveListener = process.stdin.removeListener.bind(process.stdin);
|
|
68
|
+
const listeners = {};
|
|
69
|
+
process.stdin.on = function(event, callback) {
|
|
70
|
+
if (!listeners[event]) listeners[event] = [];
|
|
71
|
+
listeners[event].push(callback);
|
|
72
|
+
return this;
|
|
73
|
+
};
|
|
74
|
+
process.stdin.removeAllListeners = function(event) {
|
|
75
|
+
if (event) {
|
|
76
|
+
delete listeners[event];
|
|
77
|
+
} else {
|
|
78
|
+
Object.keys(listeners).forEach((k) => delete listeners[k]);
|
|
79
|
+
}
|
|
80
|
+
return this;
|
|
81
|
+
};
|
|
82
|
+
process.stdin.removeListener = function(event, callback) {
|
|
83
|
+
if (listeners[event]) {
|
|
84
|
+
listeners[event] = listeners[event].filter((fn) => fn !== callback);
|
|
85
|
+
}
|
|
86
|
+
return this;
|
|
87
|
+
};
|
|
88
|
+
process.stdin.resume = function() {
|
|
89
|
+
setImmediate(() => {
|
|
90
|
+
if (listeners["data"]) {
|
|
91
|
+
listeners["data"].forEach((fn) => fn(Buffer.from(stdinData, "utf-8")));
|
|
92
|
+
}
|
|
93
|
+
setImmediate(() => {
|
|
94
|
+
if (listeners["end"]) {
|
|
95
|
+
listeners["end"].forEach((fn) => fn());
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
return this;
|
|
100
|
+
};
|
|
101
|
+
try {
|
|
102
|
+
const parser = new DiracParser();
|
|
103
|
+
const ast = parser.parse(cleanContent);
|
|
104
|
+
const session = createSession({ ...this.config, filePath });
|
|
105
|
+
await integrate(session, ast);
|
|
106
|
+
const output = getOutput(session);
|
|
107
|
+
result.actualOutput = output;
|
|
108
|
+
} finally {
|
|
109
|
+
process.stdin.on = originalOn;
|
|
110
|
+
process.stdin.resume = originalResume;
|
|
111
|
+
process.stdin.removeAllListeners = originalRemoveAllListeners;
|
|
112
|
+
process.stdin.removeListener = originalRemoveListener;
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
const parser = new DiracParser();
|
|
116
|
+
const ast = parser.parse(cleanContent);
|
|
117
|
+
const session = createSession({ ...this.config, filePath });
|
|
118
|
+
await integrate(session, ast);
|
|
119
|
+
const output = getOutput(session);
|
|
120
|
+
result.actualOutput = output;
|
|
121
|
+
}
|
|
64
122
|
if (metadata.expectError) {
|
|
65
123
|
result.passed = false;
|
|
66
|
-
result.error = `Expected error but test succeeded. Output: ${
|
|
124
|
+
result.error = `Expected error but test succeeded. Output: ${result.actualOutput}`;
|
|
67
125
|
} else if (metadata.expected !== void 0) {
|
|
68
|
-
const normalizedActual =
|
|
126
|
+
const normalizedActual = result.actualOutput.replace(/\s+/g, " ").trim();
|
|
69
127
|
const normalizedExpected = metadata.expected.replace(/\s+/g, " ").trim();
|
|
70
128
|
if (normalizedActual === normalizedExpected) {
|
|
71
129
|
result.passed = true;
|
package/package.json
CHANGED
package/src/tags/input.ts
CHANGED
|
@@ -65,20 +65,43 @@ export async function executeInput(session: DiracSession, element: DiracElement)
|
|
|
65
65
|
* Read all stdin content at once
|
|
66
66
|
*/
|
|
67
67
|
async function readAllStdin(): Promise<string> {
|
|
68
|
+
// Remove any existing listeners to avoid conflicts
|
|
69
|
+
process.stdin.removeAllListeners('data');
|
|
70
|
+
process.stdin.removeAllListeners('end');
|
|
71
|
+
process.stdin.removeAllListeners('error');
|
|
72
|
+
|
|
68
73
|
return new Promise((resolve, reject) => {
|
|
69
74
|
const chunks: Buffer[] = [];
|
|
70
75
|
|
|
71
|
-
|
|
76
|
+
const onData = (chunk: Buffer) => {
|
|
72
77
|
chunks.push(chunk);
|
|
73
|
-
}
|
|
78
|
+
};
|
|
74
79
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
80
|
+
const onEnd = () => {
|
|
81
|
+
const result = Buffer.concat(chunks).toString('utf-8');
|
|
82
|
+
|
|
83
|
+
// Clean up listeners
|
|
84
|
+
process.stdin.removeListener('data', onData);
|
|
85
|
+
process.stdin.removeListener('end', onEnd);
|
|
86
|
+
process.stdin.removeListener('error', onError);
|
|
87
|
+
|
|
88
|
+
resolve(result);
|
|
89
|
+
};
|
|
78
90
|
|
|
79
|
-
|
|
91
|
+
const onError = (err: Error) => {
|
|
92
|
+
// Clean up listeners
|
|
93
|
+
process.stdin.removeListener('data', onData);
|
|
94
|
+
process.stdin.removeListener('end', onEnd);
|
|
95
|
+
process.stdin.removeListener('error', onError);
|
|
96
|
+
|
|
80
97
|
reject(err);
|
|
81
|
-
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
process.stdin.on('data', onData);
|
|
101
|
+
process.stdin.on('end', onEnd);
|
|
102
|
+
process.stdin.on('error', onError);
|
|
103
|
+
|
|
104
|
+
process.stdin.resume();
|
|
82
105
|
});
|
|
83
106
|
}
|
|
84
107
|
|
package/src/test-runner.ts
CHANGED
|
@@ -81,22 +81,96 @@ export class TestRunner {
|
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
try {
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
// Check if there's a stdin input file for this test
|
|
85
|
+
const stdinFile = filePath.replace('.test.di', '.txt');
|
|
86
|
+
let stdinData: string | undefined;
|
|
87
|
+
if (fs.existsSync(stdinFile)) {
|
|
88
|
+
stdinData = fs.readFileSync(stdinFile, 'utf-8');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// If stdin data exists, we need to mock stdin
|
|
92
|
+
// Since we can't replace process.stdin directly, we'll use a workaround:
|
|
93
|
+
// temporarily store data in a place the input tag can access it
|
|
94
|
+
if (stdinData !== undefined) {
|
|
95
|
+
// Save original methods
|
|
96
|
+
const originalOn = process.stdin.on.bind(process.stdin);
|
|
97
|
+
const originalResume = process.stdin.resume.bind(process.stdin);
|
|
98
|
+
const originalRemoveAllListeners = process.stdin.removeAllListeners.bind(process.stdin);
|
|
99
|
+
const originalRemoveListener = process.stdin.removeListener.bind(process.stdin);
|
|
100
|
+
|
|
101
|
+
// Mock stdin methods
|
|
102
|
+
const listeners: { [key: string]: Function[] } = {};
|
|
103
|
+
|
|
104
|
+
(process.stdin as any).on = function(event: string, callback: Function) {
|
|
105
|
+
if (!listeners[event]) listeners[event] = [];
|
|
106
|
+
listeners[event].push(callback);
|
|
107
|
+
return this;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
(process.stdin as any).removeAllListeners = function(event?: string) {
|
|
111
|
+
if (event) {
|
|
112
|
+
delete listeners[event];
|
|
113
|
+
} else {
|
|
114
|
+
Object.keys(listeners).forEach(k => delete listeners[k]);
|
|
115
|
+
}
|
|
116
|
+
return this;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
(process.stdin as any).removeListener = function(event: string, callback: Function) {
|
|
120
|
+
if (listeners[event]) {
|
|
121
|
+
listeners[event] = listeners[event].filter(fn => fn !== callback);
|
|
122
|
+
}
|
|
123
|
+
return this;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
(process.stdin as any).resume = function() {
|
|
127
|
+
// Simulate data event
|
|
128
|
+
setImmediate(() => {
|
|
129
|
+
if (listeners['data']) {
|
|
130
|
+
listeners['data'].forEach(fn => fn(Buffer.from(stdinData!, 'utf-8')));
|
|
131
|
+
}
|
|
132
|
+
// Simulate end event
|
|
133
|
+
setImmediate(() => {
|
|
134
|
+
if (listeners['end']) {
|
|
135
|
+
listeners['end'].forEach(fn => fn());
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
return this;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
const parser = new DiracParser();
|
|
144
|
+
const ast = parser.parse(cleanContent);
|
|
145
|
+
const session = createSession({ ...this.config, filePath });
|
|
146
|
+
await integrate(session, ast);
|
|
147
|
+
const output = getOutput(session);
|
|
148
|
+
result.actualOutput = output;
|
|
149
|
+
} finally {
|
|
150
|
+
// Restore original methods
|
|
151
|
+
(process.stdin as any).on = originalOn;
|
|
152
|
+
(process.stdin as any).resume = originalResume;
|
|
153
|
+
(process.stdin as any).removeAllListeners = originalRemoveAllListeners;
|
|
154
|
+
(process.stdin as any).removeListener = originalRemoveListener;
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
// Normal test without stdin
|
|
158
|
+
const parser = new DiracParser();
|
|
159
|
+
const ast = parser.parse(cleanContent);
|
|
160
|
+
const session = createSession({ ...this.config, filePath });
|
|
161
|
+
await integrate(session, ast);
|
|
162
|
+
const output = getOutput(session);
|
|
163
|
+
result.actualOutput = output;
|
|
164
|
+
}
|
|
91
165
|
|
|
92
166
|
if (metadata.expectError) {
|
|
93
167
|
// Expected an error but got success
|
|
94
168
|
result.passed = false;
|
|
95
|
-
result.error = `Expected error but test succeeded. Output: ${
|
|
169
|
+
result.error = `Expected error but test succeeded. Output: ${result.actualOutput}`;
|
|
96
170
|
} else if (metadata.expected !== undefined) {
|
|
97
171
|
// Check if output matches expected
|
|
98
172
|
// Normalize whitespace for comparison (collapse multiple spaces/newlines)
|
|
99
|
-
const normalizedActual =
|
|
173
|
+
const normalizedActual = result.actualOutput!.replace(/\s+/g, ' ').trim();
|
|
100
174
|
const normalizedExpected = metadata.expected.replace(/\s+/g, ' ').trim();
|
|
101
175
|
|
|
102
176
|
if (normalizedActual === normalizedExpected) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hello from stdin
|