dirac-lang 0.1.17 → 0.1.19
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-OB7IXRFP.js → chunk-GR6KWGCI.js} +14 -13
- package/dist/{chunk-3FECP4IA.js → chunk-QMFCOZ5D.js} +1 -1
- package/dist/cli.js +3 -3
- package/dist/index.js +2 -2
- package/dist/{interpreter-Y465JGHU.js → interpreter-JTOTDC46.js} +1 -1
- package/dist/test-runner.js +1 -1
- package/examples/scope-test-nested.di +60 -0
- package/examples/scope-test.di +55 -0
- package/package.json +1 -1
- package/src/tags/call.ts +2 -2
- package/src/tags/defvar.ts +2 -1
- package/tests/subroutine-nested-calls.test.di +32 -0
- package/tests/subroutine-sequential-calls.test.di +36 -0
- package/tests/tag-check.test.di +1 -1
|
@@ -85,7 +85,8 @@ async function executeDefvar(session, element) {
|
|
|
85
85
|
const valueAttr = element.attributes.value;
|
|
86
86
|
const visibleAttr = element.attributes.visible || "false";
|
|
87
87
|
const literal = "literal" in element.attributes;
|
|
88
|
-
const
|
|
88
|
+
const trimAttr = element.attributes.trim;
|
|
89
|
+
const trim = trimAttr !== "false";
|
|
89
90
|
if (!name) {
|
|
90
91
|
throw new Error("<defvar> requires name attribute");
|
|
91
92
|
}
|
|
@@ -310,8 +311,8 @@ async function executeCallInternal(session, subroutine, callElement, isExtendExe
|
|
|
310
311
|
} finally {
|
|
311
312
|
session.skipSubroutineRegistration = oldSkipFlag;
|
|
312
313
|
popParameters(session);
|
|
313
|
-
session.varBoundary = oldBoundary;
|
|
314
314
|
cleanToBoundary(session);
|
|
315
|
+
session.varBoundary = oldBoundary;
|
|
315
316
|
session.isReturn = wasReturn;
|
|
316
317
|
}
|
|
317
318
|
}
|
|
@@ -396,12 +397,12 @@ async function executeIf(session, element) {
|
|
|
396
397
|
const condition = await evaluatePredicate(session, conditionElement);
|
|
397
398
|
if (condition) {
|
|
398
399
|
if (thenElement) {
|
|
399
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
400
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-JTOTDC46.js");
|
|
400
401
|
await integrateChildren2(session, thenElement);
|
|
401
402
|
}
|
|
402
403
|
} else {
|
|
403
404
|
if (elseElement) {
|
|
404
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
405
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-JTOTDC46.js");
|
|
405
406
|
await integrateChildren2(session, elseElement);
|
|
406
407
|
}
|
|
407
408
|
}
|
|
@@ -414,7 +415,7 @@ async function evaluatePredicate(session, predicateElement) {
|
|
|
414
415
|
return await evaluateCondition(session, predicateElement);
|
|
415
416
|
}
|
|
416
417
|
const outputLengthBefore = session.output.length;
|
|
417
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
418
|
+
const { integrate: integrate2 } = await import("./interpreter-JTOTDC46.js");
|
|
418
419
|
await integrate2(session, predicateElement);
|
|
419
420
|
const newOutputChunks = session.output.slice(outputLengthBefore);
|
|
420
421
|
const result = newOutputChunks.join("").trim();
|
|
@@ -437,11 +438,11 @@ async function evaluateCondition(session, condElement) {
|
|
|
437
438
|
}
|
|
438
439
|
const outputLengthBefore = session.output.length;
|
|
439
440
|
const args = [];
|
|
440
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
441
|
+
const { integrate: integrate2 } = await import("./interpreter-JTOTDC46.js");
|
|
441
442
|
for (const child of condElement.children) {
|
|
442
443
|
if (child.tag.toLowerCase() === "arg") {
|
|
443
444
|
const argOutputStart = session.output.length;
|
|
444
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
445
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-JTOTDC46.js");
|
|
445
446
|
await integrateChildren2(session, child);
|
|
446
447
|
const newChunks = session.output.slice(argOutputStart);
|
|
447
448
|
const argValue = newChunks.join("");
|
|
@@ -1244,7 +1245,7 @@ async function executeTagCheck(session, element) {
|
|
|
1244
1245
|
const executeTag = correctedTag || tagName;
|
|
1245
1246
|
console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
|
|
1246
1247
|
const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
|
|
1247
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
1248
|
+
const { integrate: integrate2 } = await import("./interpreter-JTOTDC46.js");
|
|
1248
1249
|
await integrate2(session, elementToExecute);
|
|
1249
1250
|
}
|
|
1250
1251
|
}
|
|
@@ -1253,7 +1254,7 @@ async function executeTagCheck(session, element) {
|
|
|
1253
1254
|
// src/tags/throw.ts
|
|
1254
1255
|
async function executeThrow(session, element) {
|
|
1255
1256
|
const exceptionName = element.attributes?.name || "exception";
|
|
1256
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1257
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-JTOTDC46.js");
|
|
1257
1258
|
const exceptionDom = {
|
|
1258
1259
|
tag: "exception-content",
|
|
1259
1260
|
attributes: { name: exceptionName },
|
|
@@ -1266,7 +1267,7 @@ async function executeThrow(session, element) {
|
|
|
1266
1267
|
// src/tags/try.ts
|
|
1267
1268
|
async function executeTry(session, element) {
|
|
1268
1269
|
setExceptionBoundary(session);
|
|
1269
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1270
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-JTOTDC46.js");
|
|
1270
1271
|
await integrateChildren2(session, element);
|
|
1271
1272
|
unsetExceptionBoundary(session);
|
|
1272
1273
|
}
|
|
@@ -1276,7 +1277,7 @@ async function executeCatch(session, element) {
|
|
|
1276
1277
|
const exceptionName = element.attributes?.name || "exception";
|
|
1277
1278
|
const caughtCount = lookupException(session, exceptionName);
|
|
1278
1279
|
if (caughtCount > 0) {
|
|
1279
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1280
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-JTOTDC46.js");
|
|
1280
1281
|
await integrateChildren2(session, element);
|
|
1281
1282
|
}
|
|
1282
1283
|
flushCurrentException(session);
|
|
@@ -1285,7 +1286,7 @@ async function executeCatch(session, element) {
|
|
|
1285
1286
|
// src/tags/exception.ts
|
|
1286
1287
|
async function executeException(session, element) {
|
|
1287
1288
|
const exceptions = getCurrentExceptions(session);
|
|
1288
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1289
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-JTOTDC46.js");
|
|
1289
1290
|
for (const exceptionDom of exceptions) {
|
|
1290
1291
|
await integrateChildren2(session, exceptionDom);
|
|
1291
1292
|
}
|
|
@@ -1425,7 +1426,7 @@ async function executeForeach(session, element) {
|
|
|
1425
1426
|
const parser2 = new DiracParser2();
|
|
1426
1427
|
try {
|
|
1427
1428
|
const fromElement = parser2.parse(fromAttr);
|
|
1428
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
1429
|
+
const { integrate: integrate2 } = await import("./interpreter-JTOTDC46.js");
|
|
1429
1430
|
await integrate2(session, fromElement);
|
|
1430
1431
|
} catch (e) {
|
|
1431
1432
|
session.output = savedOutput;
|
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-QMFCOZ5D.js";
|
|
5
|
+
import "./chunk-GR6KWGCI.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.19",
|
|
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-QMFCOZ5D.js";
|
|
6
6
|
import {
|
|
7
7
|
integrate
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-GR6KWGCI.js";
|
|
9
9
|
import {
|
|
10
10
|
DiracParser
|
|
11
11
|
} from "./chunk-HRHAMPOB.js";
|
package/dist/test-runner.js
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<!-- Test nested subroutine calls with variable scope -->
|
|
2
|
+
<dirac>
|
|
3
|
+
<output>
|
|
4
|
+
============ Test: Nested Subroutine Calls with Variable Scope ============
|
|
5
|
+
</output>
|
|
6
|
+
|
|
7
|
+
<!-- Define main scope variables -->
|
|
8
|
+
<eval name="a">return "value-a"</eval>
|
|
9
|
+
<eval name="b">return "value-b"</eval>
|
|
10
|
+
<eval name="c">return "value-c"</eval>
|
|
11
|
+
|
|
12
|
+
<output>
|
|
13
|
+
Main scope: a=<variable name="a" />, b=<variable name="b" />, c=<variable name="c" />
|
|
14
|
+
</output>
|
|
15
|
+
|
|
16
|
+
<!-- Subroutine that calls another subroutine -->
|
|
17
|
+
<subroutine name="outer-sub" param-x="type:string:" param-y="type:string:">
|
|
18
|
+
<output> Outer subroutine - x: <variable name="x" />, y: <variable name="y" /></output>
|
|
19
|
+
|
|
20
|
+
<!-- Define local variable in outer sub -->
|
|
21
|
+
<eval name="outer_local">return "outer-value"</eval>
|
|
22
|
+
<output> Outer local: <variable name="outer_local" /></output>
|
|
23
|
+
|
|
24
|
+
<!-- Call inner subroutine -->
|
|
25
|
+
<call name="inner-sub" p="$x" q="$y"/>
|
|
26
|
+
|
|
27
|
+
<!-- Check outer variables still exist after inner call -->
|
|
28
|
+
<output> After inner call - x: <variable name="x" />, y: <variable name="y" />, outer_local: <variable name="outer_local" /></output>
|
|
29
|
+
</subroutine>
|
|
30
|
+
|
|
31
|
+
<!-- Inner subroutine -->
|
|
32
|
+
<subroutine name="inner-sub" param-p="type:string:" param-q="type:string:">
|
|
33
|
+
<output> Inner subroutine - p: <variable name="p" />, q: <variable name="q" /></output>
|
|
34
|
+
<eval name="inner_local">return "inner-value"</eval>
|
|
35
|
+
<output> Inner local: <variable name="inner_local" /></output>
|
|
36
|
+
</subroutine>
|
|
37
|
+
|
|
38
|
+
<output>
|
|
39
|
+
Calling outer-sub with a and b...
|
|
40
|
+
</output>
|
|
41
|
+
<call name="outer-sub" x="$a" y="$b"/>
|
|
42
|
+
|
|
43
|
+
<output>
|
|
44
|
+
After outer-sub, checking main scope:
|
|
45
|
+
a=<variable name="a" />, b=<variable name="b" />, c=<variable name="c" />
|
|
46
|
+
</output>
|
|
47
|
+
|
|
48
|
+
<!-- Call outer-sub again to ensure no cumulative scope pollution -->
|
|
49
|
+
<output>
|
|
50
|
+
Calling outer-sub AGAIN with b and c...
|
|
51
|
+
</output>
|
|
52
|
+
<call name="outer-sub" x="$b" y="$c"/>
|
|
53
|
+
|
|
54
|
+
<output>
|
|
55
|
+
After second outer-sub call:
|
|
56
|
+
a=<variable name="a" />, b=<variable name="b" />, c=<variable name="c" />
|
|
57
|
+
|
|
58
|
+
============ Test Complete ============
|
|
59
|
+
</output>
|
|
60
|
+
</dirac>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<dirac>
|
|
2
|
+
<!-- Test library with two simple subroutines -->
|
|
3
|
+
<subroutine name="first-sub"
|
|
4
|
+
param-x="string"
|
|
5
|
+
param-y="string">
|
|
6
|
+
<output>First subroutine - x: <variable name="x" />, y: <variable name="y" /></output>
|
|
7
|
+
</subroutine>
|
|
8
|
+
|
|
9
|
+
<subroutine name="second-sub"
|
|
10
|
+
param-x="string"
|
|
11
|
+
param-y="string"
|
|
12
|
+
param-z="string">
|
|
13
|
+
<output>Second subroutine - x: <variable name="x" />, y: <variable name="y" />, z: <variable name="z" /></output>
|
|
14
|
+
</subroutine>
|
|
15
|
+
|
|
16
|
+
<!-- Main execution -->
|
|
17
|
+
<output>============ Test: Sequential Subroutine Calls ============</output>
|
|
18
|
+
<output></output>
|
|
19
|
+
|
|
20
|
+
<!-- Define variables in main scope -->
|
|
21
|
+
<defvar name="x">value-x</defvar>
|
|
22
|
+
<defvar name="y">value-y</defvar>
|
|
23
|
+
<defvar name="z">value-z</defvar>
|
|
24
|
+
|
|
25
|
+
<output>Variables defined in main scope:</output>
|
|
26
|
+
<output> x = <variable name="x" /></output>
|
|
27
|
+
<output> y = <variable name="y" /></output>
|
|
28
|
+
<output> z = <variable name="z" /></output>
|
|
29
|
+
<output></output>
|
|
30
|
+
|
|
31
|
+
<!-- Call first subroutine -->
|
|
32
|
+
<output>Calling first-sub with x="$x" y="$y"</output>
|
|
33
|
+
<first-sub x="$x" y="$y" />
|
|
34
|
+
<output></output>
|
|
35
|
+
|
|
36
|
+
<!-- Check if variables still exist after first call -->
|
|
37
|
+
<output>After first-sub, checking main scope variables:</output>
|
|
38
|
+
<output> x = <variable name="x" /></output>
|
|
39
|
+
<output> y = <variable name="y" /></output>
|
|
40
|
+
<output> z = <variable name="z" /></output>
|
|
41
|
+
<output></output>
|
|
42
|
+
|
|
43
|
+
<!-- Call second subroutine -->
|
|
44
|
+
<output>Calling second-sub with x="$x" y="$y" z="$z"</output>
|
|
45
|
+
<second-sub x="$x" y="$y" z="$z" />
|
|
46
|
+
<output></output>
|
|
47
|
+
|
|
48
|
+
<output>After second-sub, checking main scope variables:</output>
|
|
49
|
+
<output> x = <variable name="x" /></output>
|
|
50
|
+
<output> y = <variable name="y" /></output>
|
|
51
|
+
<output> z = <variable name="z" /></output>
|
|
52
|
+
<output></output>
|
|
53
|
+
|
|
54
|
+
<output>============ Test Complete ============</output>
|
|
55
|
+
</dirac>
|
package/package.json
CHANGED
package/src/tags/call.ts
CHANGED
|
@@ -200,9 +200,9 @@ async function executeCallInternal(
|
|
|
200
200
|
// Pop parameter stack
|
|
201
201
|
popParameters(session);
|
|
202
202
|
|
|
203
|
-
// Clean up scope (keep visible variables)
|
|
204
|
-
session.varBoundary = oldBoundary;
|
|
203
|
+
// Clean up scope (keep visible variables) BEFORE restoring boundary
|
|
205
204
|
cleanToBoundary(session);
|
|
205
|
+
session.varBoundary = oldBoundary;
|
|
206
206
|
session.isReturn = wasReturn;
|
|
207
207
|
}
|
|
208
208
|
}
|
package/src/tags/defvar.ts
CHANGED
|
@@ -14,7 +14,8 @@ export async function executeDefvar(session: DiracSession, element: DiracElement
|
|
|
14
14
|
const valueAttr = element.attributes.value;
|
|
15
15
|
const visibleAttr = element.attributes.visible || 'false';
|
|
16
16
|
const literal = 'literal' in element.attributes;
|
|
17
|
-
const
|
|
17
|
+
const trimAttr = element.attributes.trim;
|
|
18
|
+
const trim = trimAttr !== 'false'; // Trim by default unless explicitly set to false
|
|
18
19
|
|
|
19
20
|
if (!name) {
|
|
20
21
|
throw new Error('<defvar> requires name attribute');
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<!-- TEST: subroutine_nested_calls_preserve_scope -->
|
|
2
|
+
<!-- EXPECT: main: a=x b=y c=z
|
|
3
|
+
outer: p=x q=y
|
|
4
|
+
inner: r=x s=y
|
|
5
|
+
outer after inner: p=x q=y
|
|
6
|
+
main after outer: a=x b=y c=z -->
|
|
7
|
+
<dirac>
|
|
8
|
+
<!-- Inner subroutine -->
|
|
9
|
+
<subroutine name="inner" param-r="string" param-s="string">
|
|
10
|
+
<output>inner: r=<variable name="r" /> s=<variable name="s" /></output>
|
|
11
|
+
</subroutine>
|
|
12
|
+
|
|
13
|
+
<!-- Outer subroutine that calls inner -->
|
|
14
|
+
<subroutine name="outer" param-p="string" param-q="string">
|
|
15
|
+
<output>outer: p=<variable name="p" /> q=<variable name="q" /></output>
|
|
16
|
+
<inner r="$p" s="$q" />
|
|
17
|
+
<output>outer after inner: p=<variable name="p" /> q=<variable name="q" /></output>
|
|
18
|
+
</subroutine>
|
|
19
|
+
|
|
20
|
+
<!-- Define main scope variables -->
|
|
21
|
+
<defvar name="a">x</defvar>
|
|
22
|
+
<defvar name="b">y</defvar>
|
|
23
|
+
<defvar name="c">z</defvar>
|
|
24
|
+
|
|
25
|
+
<output>main: a=<variable name="a" /> b=<variable name="b" /> c=<variable name="c" /></output>
|
|
26
|
+
|
|
27
|
+
<!-- Call outer which calls inner -->
|
|
28
|
+
<outer p="$a" q="$b" />
|
|
29
|
+
|
|
30
|
+
<!-- Verify main scope variables preserved -->
|
|
31
|
+
<output>main after outer: a=<variable name="a" /> b=<variable name="b" /> c=<variable name="c" /></output>
|
|
32
|
+
</dirac>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<!-- TEST: subroutine_sequential_calls_preserve_scope -->
|
|
2
|
+
<!-- EXPECT: x=a y=b z=c
|
|
3
|
+
first: x=a y=b
|
|
4
|
+
x=a y=b z=c
|
|
5
|
+
second: x=a y=b z=c
|
|
6
|
+
x=a y=b z=c -->
|
|
7
|
+
<dirac>
|
|
8
|
+
<!-- Define subroutines -->
|
|
9
|
+
<subroutine name="first-sub" param-x="string" param-y="string">
|
|
10
|
+
<output>first: x=<variable name="x" /> y=<variable name="y" /></output>
|
|
11
|
+
</subroutine>
|
|
12
|
+
|
|
13
|
+
<subroutine name="second-sub" param-x="string" param-y="string" param-z="string">
|
|
14
|
+
<output>second: x=<variable name="x" /> y=<variable name="y" /> z=<variable name="z" /></output>
|
|
15
|
+
</subroutine>
|
|
16
|
+
|
|
17
|
+
<!-- Define main scope variables -->
|
|
18
|
+
<defvar name="x">a</defvar>
|
|
19
|
+
<defvar name="y">b</defvar>
|
|
20
|
+
<defvar name="z">c</defvar>
|
|
21
|
+
|
|
22
|
+
<!-- Verify initial state -->
|
|
23
|
+
<output>x=<variable name="x" /> y=<variable name="y" /> z=<variable name="z" /></output>
|
|
24
|
+
|
|
25
|
+
<!-- First call -->
|
|
26
|
+
<first-sub x="$x" y="$y" />
|
|
27
|
+
|
|
28
|
+
<!-- Verify variables still exist after first call -->
|
|
29
|
+
<output>x=<variable name="x" /> y=<variable name="y" /> z=<variable name="z" /></output>
|
|
30
|
+
|
|
31
|
+
<!-- Second call - this would fail with the bug -->
|
|
32
|
+
<second-sub x="$x" y="$y" z="$z" />
|
|
33
|
+
|
|
34
|
+
<!-- Verify variables still exist after second call -->
|
|
35
|
+
<output>x=<variable name="x" /> y=<variable name="y" /> z=<variable name="z" /></output>
|
|
36
|
+
</dirac>
|
package/tests/tag-check.test.di
CHANGED
|
@@ -18,7 +18,7 @@ Color changed to: red -->
|
|
|
18
18
|
</subroutine>
|
|
19
19
|
|
|
20
20
|
<!-- Test: tag-check should auto-correct similar tag names and execute -->
|
|
21
|
-
<defvar name="result"
|
|
21
|
+
<defvar name="result">
|
|
22
22
|
<tag-check execute="true" autocorrect="true">
|
|
23
23
|
<background-set color="red" />
|
|
24
24
|
</tag-check>
|