@polintpro/proposit-core 0.5.2 → 0.5.6
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/README.md +148 -6
- package/dist/cli/commands/arguments.d.ts.map +1 -1
- package/dist/cli/commands/arguments.js +33 -5
- package/dist/cli/commands/arguments.js.map +1 -1
- package/dist/cli/commands/claims.d.ts +3 -0
- package/dist/cli/commands/claims.d.ts.map +1 -0
- package/dist/cli/commands/claims.js +79 -0
- package/dist/cli/commands/claims.js.map +1 -0
- package/dist/cli/commands/parse.d.ts +3 -0
- package/dist/cli/commands/parse.d.ts.map +1 -0
- package/dist/cli/commands/parse.js +138 -0
- package/dist/cli/commands/parse.js.map +1 -0
- package/dist/cli/commands/sources.d.ts +1 -1
- package/dist/cli/commands/sources.d.ts.map +1 -1
- package/dist/cli/commands/sources.js +79 -94
- package/dist/cli/commands/sources.js.map +1 -1
- package/dist/cli/commands/variables.d.ts.map +1 -1
- package/dist/cli/commands/variables.js +37 -1
- package/dist/cli/commands/variables.js.map +1 -1
- package/dist/cli/config.d.ts +0 -2
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +0 -6
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/engine.d.ts +14 -1
- package/dist/cli/engine.d.ts.map +1 -1
- package/dist/cli/engine.js +51 -35
- package/dist/cli/engine.js.map +1 -1
- package/dist/cli/import.d.ts +9 -1
- package/dist/cli/import.d.ts.map +1 -1
- package/dist/cli/import.js +5 -2
- package/dist/cli/import.js.map +1 -1
- package/dist/cli/llm/index.d.ts +6 -0
- package/dist/cli/llm/index.d.ts.map +1 -0
- package/dist/cli/llm/index.js +26 -0
- package/dist/cli/llm/index.js.map +1 -0
- package/dist/cli/llm/openai.d.ts +4 -0
- package/dist/cli/llm/openai.d.ts.map +1 -0
- package/dist/cli/llm/openai.js +44 -0
- package/dist/cli/llm/openai.js.map +1 -0
- package/dist/cli/llm/types.d.ts +14 -0
- package/dist/cli/llm/types.d.ts.map +1 -0
- package/dist/cli/llm/types.js +2 -0
- package/dist/cli/llm/types.js.map +1 -0
- package/dist/cli/router.d.ts.map +1 -1
- package/dist/cli/router.js +2 -0
- package/dist/cli/router.js.map +1 -1
- package/dist/cli/schemata.d.ts +0 -8
- package/dist/cli/schemata.d.ts.map +1 -1
- package/dist/cli/schemata.js +0 -10
- package/dist/cli/schemata.js.map +1 -1
- package/dist/cli/storage/libraries.d.ts +11 -0
- package/dist/cli/storage/libraries.d.ts.map +1 -0
- package/dist/cli/storage/libraries.js +61 -0
- package/dist/cli/storage/libraries.js.map +1 -0
- package/dist/cli.js +3 -1
- package/dist/cli.js.map +1 -1
- package/dist/extensions/basics/argument-parser.d.ts +12 -0
- package/dist/extensions/basics/argument-parser.d.ts.map +1 -0
- package/dist/extensions/basics/argument-parser.js +27 -0
- package/dist/extensions/basics/argument-parser.js.map +1 -0
- package/dist/extensions/basics/index.d.ts +4 -0
- package/dist/extensions/basics/index.d.ts.map +1 -0
- package/dist/extensions/basics/index.js +3 -0
- package/dist/extensions/basics/index.js.map +1 -0
- package/dist/extensions/basics/schemata.d.ts +31 -0
- package/dist/extensions/basics/schemata.d.ts.map +1 -0
- package/dist/extensions/basics/schemata.js +55 -0
- package/dist/extensions/basics/schemata.js.map +1 -0
- package/dist/lib/consts.d.ts.map +1 -1
- package/dist/lib/consts.js +7 -15
- package/dist/lib/consts.js.map +1 -1
- package/dist/lib/core/argument-engine.d.ts +15 -27
- package/dist/lib/core/argument-engine.d.ts.map +1 -1
- package/dist/lib/core/argument-engine.js +236 -242
- package/dist/lib/core/argument-engine.js.map +1 -1
- package/dist/lib/core/change-collector.d.ts +0 -7
- package/dist/lib/core/change-collector.d.ts.map +1 -1
- package/dist/lib/core/change-collector.js +0 -18
- package/dist/lib/core/change-collector.js.map +1 -1
- package/dist/lib/core/claim-library.d.ts +2 -2
- package/dist/lib/core/claim-library.d.ts.map +1 -1
- package/dist/lib/core/claim-source-library.d.ts +27 -0
- package/dist/lib/core/claim-source-library.d.ts.map +1 -0
- package/dist/lib/core/claim-source-library.js +116 -0
- package/dist/lib/core/claim-source-library.js.map +1 -0
- package/dist/lib/core/diff.d.ts +3 -7
- package/dist/lib/core/diff.d.ts.map +1 -1
- package/dist/lib/core/diff.js +14 -79
- package/dist/lib/core/diff.js.map +1 -1
- package/dist/lib/core/interfaces/argument-engine.interfaces.d.ts +30 -9
- package/dist/lib/core/interfaces/argument-engine.interfaces.d.ts.map +1 -1
- package/dist/lib/core/interfaces/index.d.ts +1 -2
- package/dist/lib/core/interfaces/index.d.ts.map +1 -1
- package/dist/lib/core/interfaces/library.interfaces.d.ts +251 -5
- package/dist/lib/core/interfaces/library.interfaces.d.ts.map +1 -1
- package/dist/lib/core/interfaces/premise-engine.interfaces.d.ts +20 -29
- package/dist/lib/core/interfaces/premise-engine.interfaces.d.ts.map +1 -1
- package/dist/lib/core/parser/formula-gen.js +120 -47
- package/dist/lib/core/premise-engine.d.ts +7 -8
- package/dist/lib/core/premise-engine.d.ts.map +1 -1
- package/dist/lib/core/premise-engine.js +66 -82
- package/dist/lib/core/premise-engine.js.map +1 -1
- package/dist/lib/core/source-library.d.ts +2 -2
- package/dist/lib/core/source-library.d.ts.map +1 -1
- package/dist/lib/core/variable-manager.d.ts +3 -4
- package/dist/lib/core/variable-manager.d.ts.map +1 -1
- package/dist/lib/core/variable-manager.js +11 -1
- package/dist/lib/core/variable-manager.js.map +1 -1
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +3 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/parsing/argument-parser.d.ts +47 -0
- package/dist/lib/parsing/argument-parser.d.ts.map +1 -0
- package/dist/lib/parsing/argument-parser.js +307 -0
- package/dist/lib/parsing/argument-parser.js.map +1 -0
- package/dist/lib/parsing/index.d.ts +7 -0
- package/dist/lib/parsing/index.d.ts.map +1 -0
- package/dist/lib/parsing/index.js +4 -0
- package/dist/lib/parsing/index.js.map +1 -0
- package/dist/lib/parsing/prompt-builder.d.ts +11 -0
- package/dist/lib/parsing/prompt-builder.d.ts.map +1 -0
- package/dist/lib/parsing/prompt-builder.js +178 -0
- package/dist/lib/parsing/prompt-builder.js.map +1 -0
- package/dist/lib/parsing/schemata.d.ts +77 -0
- package/dist/lib/parsing/schemata.d.ts.map +1 -0
- package/dist/lib/parsing/schemata.js +88 -0
- package/dist/lib/parsing/schemata.js.map +1 -0
- package/dist/lib/parsing/types.d.ts +13 -0
- package/dist/lib/parsing/types.d.ts.map +1 -0
- package/dist/lib/parsing/types.js +2 -0
- package/dist/lib/parsing/types.js.map +1 -0
- package/dist/lib/schemata/propositional.d.ts +36 -2
- package/dist/lib/schemata/propositional.d.ts.map +1 -1
- package/dist/lib/schemata/propositional.js +30 -4
- package/dist/lib/schemata/propositional.js.map +1 -1
- package/dist/lib/schemata/source.d.ts +4 -16
- package/dist/lib/schemata/source.d.ts.map +1 -1
- package/dist/lib/schemata/source.js +7 -17
- package/dist/lib/schemata/source.js.map +1 -1
- package/dist/lib/types/checksum.d.ts +2 -4
- package/dist/lib/types/checksum.d.ts.map +1 -1
- package/dist/lib/types/diff.d.ts +1 -5
- package/dist/lib/types/diff.d.ts.map +1 -1
- package/dist/lib/types/evaluation.d.ts +1 -1
- package/dist/lib/types/evaluation.d.ts.map +1 -1
- package/dist/lib/types/mutation.d.ts +0 -3
- package/dist/lib/types/mutation.d.ts.map +1 -1
- package/dist/lib/types/reactive.d.ts +1 -3
- package/dist/lib/types/reactive.d.ts.map +1 -1
- package/package.json +5 -1
- package/dist/cli/storage/sources.d.ts +0 -11
- package/dist/cli/storage/sources.d.ts.map +0 -1
- package/dist/cli/storage/sources.js +0 -105
- package/dist/cli/storage/sources.js.map +0 -1
- package/dist/lib/core/interfaces/source-management.interfaces.d.ts +0 -63
- package/dist/lib/core/interfaces/source-management.interfaces.d.ts.map +0 -1
- package/dist/lib/core/interfaces/source-management.interfaces.js +0 -2
- package/dist/lib/core/interfaces/source-management.interfaces.js.map +0 -1
- package/dist/lib/core/source-manager.d.ts +0 -38
- package/dist/lib/core/source-manager.d.ts.map +0 -1
- package/dist/lib/core/source-manager.js +0 -266
- package/dist/lib/core/source-manager.js.map +0 -1
|
@@ -184,12 +184,17 @@ function peg$parse(input, options) {
|
|
|
184
184
|
const peg$c1 = "->";
|
|
185
185
|
const peg$c2 = "\u2194";
|
|
186
186
|
const peg$c3 = "<->";
|
|
187
|
-
const peg$c4 = "
|
|
188
|
-
const peg$c5 = "
|
|
189
|
-
const peg$c6 = "\
|
|
190
|
-
const peg$c7 = "
|
|
191
|
-
const peg$c8 = "
|
|
192
|
-
const peg$c9 = "
|
|
187
|
+
const peg$c4 = "implies";
|
|
188
|
+
const peg$c5 = "iff";
|
|
189
|
+
const peg$c6 = "\u2228";
|
|
190
|
+
const peg$c7 = "||";
|
|
191
|
+
const peg$c8 = "or";
|
|
192
|
+
const peg$c9 = "\u2227";
|
|
193
|
+
const peg$c10 = "&&";
|
|
194
|
+
const peg$c11 = "and";
|
|
195
|
+
const peg$c12 = "not";
|
|
196
|
+
const peg$c13 = "(";
|
|
197
|
+
const peg$c14 = ")";
|
|
193
198
|
|
|
194
199
|
const peg$r0 = /^[!\xAC]/;
|
|
195
200
|
const peg$r1 = /^[A-Za-z_]/;
|
|
@@ -200,20 +205,25 @@ function peg$parse(input, options) {
|
|
|
200
205
|
const peg$e1 = peg$literalExpectation("->", false);
|
|
201
206
|
const peg$e2 = peg$literalExpectation("\u2194", false);
|
|
202
207
|
const peg$e3 = peg$literalExpectation("<->", false);
|
|
203
|
-
const peg$e4 = peg$literalExpectation("
|
|
204
|
-
const peg$e5 = peg$literalExpectation("
|
|
205
|
-
const peg$e6 = peg$literalExpectation("\
|
|
206
|
-
const peg$e7 = peg$literalExpectation("
|
|
207
|
-
const peg$e8 = peg$
|
|
208
|
-
const peg$e9 = peg$literalExpectation("
|
|
209
|
-
const peg$e10 = peg$literalExpectation("
|
|
210
|
-
const peg$e11 = peg$
|
|
211
|
-
const peg$e12 = peg$classExpectation([
|
|
212
|
-
const peg$e13 = peg$
|
|
208
|
+
const peg$e4 = peg$literalExpectation("implies", true);
|
|
209
|
+
const peg$e5 = peg$literalExpectation("iff", true);
|
|
210
|
+
const peg$e6 = peg$literalExpectation("\u2228", false);
|
|
211
|
+
const peg$e7 = peg$literalExpectation("||", false);
|
|
212
|
+
const peg$e8 = peg$literalExpectation("or", true);
|
|
213
|
+
const peg$e9 = peg$literalExpectation("\u2227", false);
|
|
214
|
+
const peg$e10 = peg$literalExpectation("&&", false);
|
|
215
|
+
const peg$e11 = peg$literalExpectation("and", true);
|
|
216
|
+
const peg$e12 = peg$classExpectation(["!", "\xAC"], false, false, false);
|
|
217
|
+
const peg$e13 = peg$literalExpectation("not", true);
|
|
218
|
+
const peg$e14 = peg$literalExpectation("(", false);
|
|
219
|
+
const peg$e15 = peg$literalExpectation(")", false);
|
|
220
|
+
const peg$e16 = peg$classExpectation([["A", "Z"], ["a", "z"], "_"], false, false, false);
|
|
221
|
+
const peg$e17 = peg$classExpectation([["A", "Z"], ["a", "z"], ["0", "9"], "_"], false, false, false);
|
|
222
|
+
const peg$e18 = peg$classExpectation([" ", "\t", "\n", "\r"], false, false, false);
|
|
213
223
|
|
|
214
224
|
function peg$f0(expr) { return expr; }
|
|
215
225
|
function peg$f1(left, op, right) {
|
|
216
|
-
const type = (op === "→" || op === "->") ? "implies" : "iff";
|
|
226
|
+
const type = (op === "→" || op === "->" || op.toLowerCase() === "implies") ? "implies" : "iff";
|
|
217
227
|
return binaryNode(type, left, right);
|
|
218
228
|
}
|
|
219
229
|
function peg$f2(first, c) { return c; }
|
|
@@ -453,6 +463,24 @@ function peg$parse(input, options) {
|
|
|
453
463
|
s3 = peg$FAILED;
|
|
454
464
|
if (peg$silentFails === 0) { peg$fail(peg$e3); }
|
|
455
465
|
}
|
|
466
|
+
if (s3 === peg$FAILED) {
|
|
467
|
+
s3 = input.substr(peg$currPos, 7);
|
|
468
|
+
if (s3.toLowerCase() === peg$c4) {
|
|
469
|
+
peg$currPos += (7);
|
|
470
|
+
} else {
|
|
471
|
+
s3 = peg$FAILED;
|
|
472
|
+
if (peg$silentFails === 0) { peg$fail(peg$e4); }
|
|
473
|
+
}
|
|
474
|
+
if (s3 === peg$FAILED) {
|
|
475
|
+
s3 = input.substr(peg$currPos, 3);
|
|
476
|
+
if (s3.toLowerCase() === peg$c5) {
|
|
477
|
+
peg$currPos += (3);
|
|
478
|
+
} else {
|
|
479
|
+
s3 = peg$FAILED;
|
|
480
|
+
if (peg$silentFails === 0) { peg$fail(peg$e5); }
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
456
484
|
}
|
|
457
485
|
}
|
|
458
486
|
}
|
|
@@ -491,19 +519,28 @@ function peg$parse(input, options) {
|
|
|
491
519
|
s3 = peg$currPos;
|
|
492
520
|
s4 = peg$parse_();
|
|
493
521
|
if (input.charCodeAt(peg$currPos) === 8744) {
|
|
494
|
-
s5 = peg$
|
|
522
|
+
s5 = peg$c6;
|
|
495
523
|
peg$currPos++;
|
|
496
524
|
} else {
|
|
497
525
|
s5 = peg$FAILED;
|
|
498
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
526
|
+
if (peg$silentFails === 0) { peg$fail(peg$e6); }
|
|
499
527
|
}
|
|
500
528
|
if (s5 === peg$FAILED) {
|
|
501
|
-
if (input.substr(peg$currPos, 2) === peg$
|
|
502
|
-
s5 = peg$
|
|
529
|
+
if (input.substr(peg$currPos, 2) === peg$c7) {
|
|
530
|
+
s5 = peg$c7;
|
|
503
531
|
peg$currPos += 2;
|
|
504
532
|
} else {
|
|
505
533
|
s5 = peg$FAILED;
|
|
506
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
534
|
+
if (peg$silentFails === 0) { peg$fail(peg$e7); }
|
|
535
|
+
}
|
|
536
|
+
if (s5 === peg$FAILED) {
|
|
537
|
+
s5 = input.substr(peg$currPos, 2);
|
|
538
|
+
if (s5.toLowerCase() === peg$c8) {
|
|
539
|
+
peg$currPos += (2);
|
|
540
|
+
} else {
|
|
541
|
+
s5 = peg$FAILED;
|
|
542
|
+
if (peg$silentFails === 0) { peg$fail(peg$e8); }
|
|
543
|
+
}
|
|
507
544
|
}
|
|
508
545
|
}
|
|
509
546
|
if (s5 !== peg$FAILED) {
|
|
@@ -525,19 +562,28 @@ function peg$parse(input, options) {
|
|
|
525
562
|
s3 = peg$currPos;
|
|
526
563
|
s4 = peg$parse_();
|
|
527
564
|
if (input.charCodeAt(peg$currPos) === 8744) {
|
|
528
|
-
s5 = peg$
|
|
565
|
+
s5 = peg$c6;
|
|
529
566
|
peg$currPos++;
|
|
530
567
|
} else {
|
|
531
568
|
s5 = peg$FAILED;
|
|
532
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
569
|
+
if (peg$silentFails === 0) { peg$fail(peg$e6); }
|
|
533
570
|
}
|
|
534
571
|
if (s5 === peg$FAILED) {
|
|
535
|
-
if (input.substr(peg$currPos, 2) === peg$
|
|
536
|
-
s5 = peg$
|
|
572
|
+
if (input.substr(peg$currPos, 2) === peg$c7) {
|
|
573
|
+
s5 = peg$c7;
|
|
537
574
|
peg$currPos += 2;
|
|
538
575
|
} else {
|
|
539
576
|
s5 = peg$FAILED;
|
|
540
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
577
|
+
if (peg$silentFails === 0) { peg$fail(peg$e7); }
|
|
578
|
+
}
|
|
579
|
+
if (s5 === peg$FAILED) {
|
|
580
|
+
s5 = input.substr(peg$currPos, 2);
|
|
581
|
+
if (s5.toLowerCase() === peg$c8) {
|
|
582
|
+
peg$currPos += (2);
|
|
583
|
+
} else {
|
|
584
|
+
s5 = peg$FAILED;
|
|
585
|
+
if (peg$silentFails === 0) { peg$fail(peg$e8); }
|
|
586
|
+
}
|
|
541
587
|
}
|
|
542
588
|
}
|
|
543
589
|
if (s5 !== peg$FAILED) {
|
|
@@ -575,19 +621,28 @@ function peg$parse(input, options) {
|
|
|
575
621
|
s3 = peg$currPos;
|
|
576
622
|
s4 = peg$parse_();
|
|
577
623
|
if (input.charCodeAt(peg$currPos) === 8743) {
|
|
578
|
-
s5 = peg$
|
|
624
|
+
s5 = peg$c9;
|
|
579
625
|
peg$currPos++;
|
|
580
626
|
} else {
|
|
581
627
|
s5 = peg$FAILED;
|
|
582
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
628
|
+
if (peg$silentFails === 0) { peg$fail(peg$e9); }
|
|
583
629
|
}
|
|
584
630
|
if (s5 === peg$FAILED) {
|
|
585
|
-
if (input.substr(peg$currPos, 2) === peg$
|
|
586
|
-
s5 = peg$
|
|
631
|
+
if (input.substr(peg$currPos, 2) === peg$c10) {
|
|
632
|
+
s5 = peg$c10;
|
|
587
633
|
peg$currPos += 2;
|
|
588
634
|
} else {
|
|
589
635
|
s5 = peg$FAILED;
|
|
590
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
636
|
+
if (peg$silentFails === 0) { peg$fail(peg$e10); }
|
|
637
|
+
}
|
|
638
|
+
if (s5 === peg$FAILED) {
|
|
639
|
+
s5 = input.substr(peg$currPos, 3);
|
|
640
|
+
if (s5.toLowerCase() === peg$c11) {
|
|
641
|
+
peg$currPos += (3);
|
|
642
|
+
} else {
|
|
643
|
+
s5 = peg$FAILED;
|
|
644
|
+
if (peg$silentFails === 0) { peg$fail(peg$e11); }
|
|
645
|
+
}
|
|
591
646
|
}
|
|
592
647
|
}
|
|
593
648
|
if (s5 !== peg$FAILED) {
|
|
@@ -609,19 +664,28 @@ function peg$parse(input, options) {
|
|
|
609
664
|
s3 = peg$currPos;
|
|
610
665
|
s4 = peg$parse_();
|
|
611
666
|
if (input.charCodeAt(peg$currPos) === 8743) {
|
|
612
|
-
s5 = peg$
|
|
667
|
+
s5 = peg$c9;
|
|
613
668
|
peg$currPos++;
|
|
614
669
|
} else {
|
|
615
670
|
s5 = peg$FAILED;
|
|
616
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
671
|
+
if (peg$silentFails === 0) { peg$fail(peg$e9); }
|
|
617
672
|
}
|
|
618
673
|
if (s5 === peg$FAILED) {
|
|
619
|
-
if (input.substr(peg$currPos, 2) === peg$
|
|
620
|
-
s5 = peg$
|
|
674
|
+
if (input.substr(peg$currPos, 2) === peg$c10) {
|
|
675
|
+
s5 = peg$c10;
|
|
621
676
|
peg$currPos += 2;
|
|
622
677
|
} else {
|
|
623
678
|
s5 = peg$FAILED;
|
|
624
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
679
|
+
if (peg$silentFails === 0) { peg$fail(peg$e10); }
|
|
680
|
+
}
|
|
681
|
+
if (s5 === peg$FAILED) {
|
|
682
|
+
s5 = input.substr(peg$currPos, 3);
|
|
683
|
+
if (s5.toLowerCase() === peg$c11) {
|
|
684
|
+
peg$currPos += (3);
|
|
685
|
+
} else {
|
|
686
|
+
s5 = peg$FAILED;
|
|
687
|
+
if (peg$silentFails === 0) { peg$fail(peg$e11); }
|
|
688
|
+
}
|
|
625
689
|
}
|
|
626
690
|
}
|
|
627
691
|
if (s5 !== peg$FAILED) {
|
|
@@ -658,7 +722,16 @@ function peg$parse(input, options) {
|
|
|
658
722
|
peg$currPos++;
|
|
659
723
|
} else {
|
|
660
724
|
s1 = peg$FAILED;
|
|
661
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
725
|
+
if (peg$silentFails === 0) { peg$fail(peg$e12); }
|
|
726
|
+
}
|
|
727
|
+
if (s1 === peg$FAILED) {
|
|
728
|
+
s1 = input.substr(peg$currPos, 3);
|
|
729
|
+
if (s1.toLowerCase() === peg$c12) {
|
|
730
|
+
peg$currPos += (3);
|
|
731
|
+
} else {
|
|
732
|
+
s1 = peg$FAILED;
|
|
733
|
+
if (peg$silentFails === 0) { peg$fail(peg$e13); }
|
|
734
|
+
}
|
|
662
735
|
}
|
|
663
736
|
if (s1 !== peg$FAILED) {
|
|
664
737
|
s2 = peg$parse_();
|
|
@@ -686,11 +759,11 @@ function peg$parse(input, options) {
|
|
|
686
759
|
|
|
687
760
|
s0 = peg$currPos;
|
|
688
761
|
if (input.charCodeAt(peg$currPos) === 40) {
|
|
689
|
-
s1 = peg$
|
|
762
|
+
s1 = peg$c13;
|
|
690
763
|
peg$currPos++;
|
|
691
764
|
} else {
|
|
692
765
|
s1 = peg$FAILED;
|
|
693
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
766
|
+
if (peg$silentFails === 0) { peg$fail(peg$e14); }
|
|
694
767
|
}
|
|
695
768
|
if (s1 !== peg$FAILED) {
|
|
696
769
|
s2 = peg$parse_();
|
|
@@ -698,11 +771,11 @@ function peg$parse(input, options) {
|
|
|
698
771
|
if (s3 !== peg$FAILED) {
|
|
699
772
|
s4 = peg$parse_();
|
|
700
773
|
if (input.charCodeAt(peg$currPos) === 41) {
|
|
701
|
-
s5 = peg$
|
|
774
|
+
s5 = peg$c14;
|
|
702
775
|
peg$currPos++;
|
|
703
776
|
} else {
|
|
704
777
|
s5 = peg$FAILED;
|
|
705
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
778
|
+
if (peg$silentFails === 0) { peg$fail(peg$e15); }
|
|
706
779
|
}
|
|
707
780
|
if (s5 !== peg$FAILED) {
|
|
708
781
|
peg$savedPos = s0;
|
|
@@ -742,7 +815,7 @@ function peg$parse(input, options) {
|
|
|
742
815
|
peg$currPos++;
|
|
743
816
|
} else {
|
|
744
817
|
s2 = peg$FAILED;
|
|
745
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
818
|
+
if (peg$silentFails === 0) { peg$fail(peg$e16); }
|
|
746
819
|
}
|
|
747
820
|
if (s2 !== peg$FAILED) {
|
|
748
821
|
s3 = [];
|
|
@@ -751,7 +824,7 @@ function peg$parse(input, options) {
|
|
|
751
824
|
peg$currPos++;
|
|
752
825
|
} else {
|
|
753
826
|
s4 = peg$FAILED;
|
|
754
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
827
|
+
if (peg$silentFails === 0) { peg$fail(peg$e17); }
|
|
755
828
|
}
|
|
756
829
|
while (s4 !== peg$FAILED) {
|
|
757
830
|
s3.push(s4);
|
|
@@ -760,7 +833,7 @@ function peg$parse(input, options) {
|
|
|
760
833
|
peg$currPos++;
|
|
761
834
|
} else {
|
|
762
835
|
s4 = peg$FAILED;
|
|
763
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
836
|
+
if (peg$silentFails === 0) { peg$fail(peg$e17); }
|
|
764
837
|
}
|
|
765
838
|
}
|
|
766
839
|
s2 = [s2, s3];
|
|
@@ -788,7 +861,7 @@ function peg$parse(input, options) {
|
|
|
788
861
|
peg$currPos++;
|
|
789
862
|
} else {
|
|
790
863
|
s1 = peg$FAILED;
|
|
791
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
864
|
+
if (peg$silentFails === 0) { peg$fail(peg$e18); }
|
|
792
865
|
}
|
|
793
866
|
while (s1 !== peg$FAILED) {
|
|
794
867
|
s0.push(s1);
|
|
@@ -797,7 +870,7 @@ function peg$parse(input, options) {
|
|
|
797
870
|
peg$currPos++;
|
|
798
871
|
} else {
|
|
799
872
|
s1 = peg$FAILED;
|
|
800
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
873
|
+
if (peg$silentFails === 0) { peg$fail(peg$e18); }
|
|
801
874
|
}
|
|
802
875
|
}
|
|
803
876
|
peg$silentFails--;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type TCoreArgument, type TCorePremise, type TCorePropositionalExpression, type TCorePropositionalVariable, type TOptionalChecksum } from "../schemata/index.js";
|
|
2
2
|
import type { TCoreExpressionAssignment, TCorePremiseEvaluationResult, TCoreValidationResult } from "../types/evaluation.js";
|
|
3
3
|
import type { TCoreMutationResult } from "../types/mutation.js";
|
|
4
4
|
import type { TLogicEngineOptions } from "./argument-engine.js";
|
|
5
5
|
import type { TExpressionInput, TExpressionManagerSnapshot, TExpressionWithoutPosition, TExpressionUpdate } from "./expression-manager.js";
|
|
6
6
|
import { VariableManager } from "./variable-manager.js";
|
|
7
|
-
import type { SourceManager } from "./source-manager.js";
|
|
8
7
|
import type { TExpressionMutations, TExpressionQueries, TVariableReferences, TPremiseClassification, TPremiseEvaluation, TPremiseLifecycle, TPremiseIdentity, TDisplayable, TChecksummable } from "./interfaces/index.js";
|
|
9
8
|
export type TPremiseEngineSnapshot<TPremise extends TCorePremise = TCorePremise, TExpr extends TCorePropositionalExpression = TCorePropositionalExpression> = {
|
|
10
9
|
premise: TOptionalChecksum<TPremise>;
|
|
@@ -23,15 +22,17 @@ export declare class PremiseEngine<TArg extends TCoreArgument = TCoreArgument, T
|
|
|
23
22
|
private checksumDirty;
|
|
24
23
|
private cachedChecksum;
|
|
25
24
|
private expressionIndex?;
|
|
26
|
-
private sourceManager?;
|
|
27
25
|
private onMutate?;
|
|
26
|
+
private circularityCheck?;
|
|
27
|
+
private emptyBoundPremiseCheck?;
|
|
28
28
|
constructor(premise: TOptionalChecksum<TPremise>, deps: {
|
|
29
29
|
argument: TOptionalChecksum<TArg>;
|
|
30
30
|
variables: VariableManager<TVar>;
|
|
31
31
|
expressionIndex?: Map<string, string>;
|
|
32
|
-
sourceManager?: SourceManager;
|
|
33
32
|
}, config?: TLogicEngineOptions);
|
|
34
33
|
setOnMutate(callback: (() => void) | undefined): void;
|
|
34
|
+
setCircularityCheck(check: ((variableId: string, premiseId: string) => boolean) | undefined): void;
|
|
35
|
+
setEmptyBoundPremiseCheck(check: ((variableId: string) => boolean) | undefined): void;
|
|
35
36
|
deleteExpressionsUsingVariable(variableId: string): TCoreMutationResult<TExpr[], TExpr, TVar, TPremise, TArg>;
|
|
36
37
|
addExpression(expression: TExpressionInput<TExpr>): TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>;
|
|
37
38
|
appendExpression(parentId: string | null, expression: TExpressionWithoutPosition<TExpr>): TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>;
|
|
@@ -41,9 +42,6 @@ export declare class PremiseEngine<TArg extends TCoreArgument = TCoreArgument, T
|
|
|
41
42
|
insertExpression(expression: TExpressionInput<TExpr>, leftNodeId?: string, rightNodeId?: string): TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>;
|
|
42
43
|
wrapExpression(operator: TExpressionWithoutPosition<TExpr>, newSibling: TExpressionWithoutPosition<TExpr>, leftNodeId?: string, rightNodeId?: string): TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>;
|
|
43
44
|
toggleNegation(expressionId: string): TCoreMutationResult<TExpr | null, TExpr, TVar, TPremise, TArg>;
|
|
44
|
-
addExpressionSourceAssociation(sourceId: string, sourceVersion: number, expressionId: string): TCoreMutationResult<TCoreExpressionSourceAssociation, TExpr, TVar, TPremise, TArg>;
|
|
45
|
-
removeExpressionSourceAssociation(associationId: string): TCoreMutationResult<TCoreExpressionSourceAssociation | undefined, TExpr, TVar, TPremise, TArg>;
|
|
46
|
-
getSourceAssociationsForExpression(expressionId: string): TCoreExpressionSourceAssociation[];
|
|
47
45
|
getExpression(id: string): TExpr | undefined;
|
|
48
46
|
getId(): string;
|
|
49
47
|
getExtras(): Record<string, unknown>;
|
|
@@ -59,6 +57,7 @@ export declare class PremiseEngine<TArg extends TCoreArgument = TCoreArgument, T
|
|
|
59
57
|
evaluate(assignment: TCoreExpressionAssignment, options?: {
|
|
60
58
|
strictUnknownKeys?: boolean;
|
|
61
59
|
requireExactCoverage?: boolean;
|
|
60
|
+
resolver?: (variableId: string) => boolean | null;
|
|
62
61
|
}): TCorePremiseEvaluationResult;
|
|
63
62
|
toDisplayString(): string;
|
|
64
63
|
getReferencedVariableIds(): Set<string>;
|
|
@@ -77,7 +76,7 @@ export declare class PremiseEngine<TArg extends TCoreArgument = TCoreArgument, T
|
|
|
77
76
|
private operatorSymbol;
|
|
78
77
|
snapshot(): TPremiseEngineSnapshot<TPremise, TExpr>;
|
|
79
78
|
/** Creates a new PremiseEngine from a previously captured snapshot. */
|
|
80
|
-
static fromSnapshot<TArg extends TCoreArgument = TCoreArgument, TPremise extends TCorePremise = TCorePremise, TExpr extends TCorePropositionalExpression = TCorePropositionalExpression, TVar extends TCorePropositionalVariable = TCorePropositionalVariable>(snapshot: TPremiseEngineSnapshot<TPremise, TExpr>, argument: TOptionalChecksum<TArg>, variables: VariableManager<TVar>, expressionIndex?: Map<string, string
|
|
79
|
+
static fromSnapshot<TArg extends TCoreArgument = TCoreArgument, TPremise extends TCorePremise = TCorePremise, TExpr extends TCorePropositionalExpression = TCorePropositionalExpression, TVar extends TCorePropositionalVariable = TCorePropositionalVariable>(snapshot: TPremiseEngineSnapshot<TPremise, TExpr>, argument: TOptionalChecksum<TArg>, variables: VariableManager<TVar>, expressionIndex?: Map<string, string>): PremiseEngine<TArg, TPremise, TExpr, TVar>;
|
|
81
80
|
private syncExpressionIndex;
|
|
82
81
|
private rebuildVariableIndex;
|
|
83
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"premise-engine.d.ts","sourceRoot":"","sources":["../../../src/lib/core/premise-engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"premise-engine.d.ts","sourceRoot":"","sources":["../../../src/lib/core/premise-engine.ts"],"names":[],"mappings":"AACA,OAAO,EAEH,KAAK,aAAa,EAElB,KAAK,YAAY,EACjB,KAAK,4BAA4B,EACjC,KAAK,0BAA0B,EAC/B,KAAK,iBAAiB,EACzB,MAAM,sBAAsB,CAAA;AAG7B,OAAO,KAAK,EACR,yBAAyB,EACzB,4BAA4B,EAI5B,qBAAqB,EACxB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,mBAAmB,EAAkB,MAAM,sBAAsB,CAAA;AAc/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAI/D,OAAO,KAAK,EACR,gBAAgB,EAChB,0BAA0B,EAC1B,0BAA0B,EAC1B,iBAAiB,EACpB,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EAAE,eA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Q,SAAS,YAAY,GAAG,YAAY,EAC5C,KAAK,SAAS,4BAA4B,GACtC,4BAA4B,EAChC,IAAI,SAAS,0BAA0B,GAAG,0BAA0B,EAEpE,QAAQ,EAAE,sBAAsB,CAAC,QAAQ,EAAE,KAAK,CAAC,EACjD,QAAQ,EAAE,iBAAiB,CAAC,IAAI,CAAC,EACjC,SAAS,EAAE,eAAe,CAAC,IAAI,CAAC,EAChC,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACtC,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC;IAuB7C,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,oBAAoB;CAQ/B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { isPremiseBound, } from "../schemata/index.js";
|
|
2
3
|
import { DefaultMap } from "../utils/default-map.js";
|
|
3
4
|
import { sortedCopyById, sortedUnique } from "../utils/collections.js";
|
|
4
5
|
import { kleeneAnd, kleeneIff, kleeneImplies, kleeneNot, kleeneOr, } from "./evaluation/kleene.js";
|
|
@@ -19,8 +20,9 @@ export class PremiseEngine {
|
|
|
19
20
|
checksumDirty = true;
|
|
20
21
|
cachedChecksum;
|
|
21
22
|
expressionIndex;
|
|
22
|
-
sourceManager;
|
|
23
23
|
onMutate;
|
|
24
|
+
circularityCheck;
|
|
25
|
+
emptyBoundPremiseCheck;
|
|
24
26
|
constructor(premise, deps, config) {
|
|
25
27
|
this.premise = { ...premise };
|
|
26
28
|
this.argument = deps.argument;
|
|
@@ -30,11 +32,16 @@ export class PremiseEngine {
|
|
|
30
32
|
this.expressions = new ExpressionManager(config);
|
|
31
33
|
this.expressionsByVariableId = new DefaultMap(() => new Set());
|
|
32
34
|
this.expressionIndex = deps.expressionIndex;
|
|
33
|
-
this.sourceManager = deps.sourceManager;
|
|
34
35
|
}
|
|
35
36
|
setOnMutate(callback) {
|
|
36
37
|
this.onMutate = callback;
|
|
37
38
|
}
|
|
39
|
+
setCircularityCheck(check) {
|
|
40
|
+
this.circularityCheck = check;
|
|
41
|
+
}
|
|
42
|
+
setEmptyBoundPremiseCheck(check) {
|
|
43
|
+
this.emptyBoundPremiseCheck = check;
|
|
44
|
+
}
|
|
38
45
|
deleteExpressionsUsingVariable(variableId) {
|
|
39
46
|
const expressionIds = this.expressionsByVariableId.get(variableId);
|
|
40
47
|
if (expressionIds.size === 0) {
|
|
@@ -60,12 +67,6 @@ export class PremiseEngine {
|
|
|
60
67
|
collector.removedExpression(e);
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
|
-
if (changes.expressionSourceAssociations) {
|
|
64
|
-
for (const a of changes.expressionSourceAssociations
|
|
65
|
-
.removed) {
|
|
66
|
-
collector.removedExpressionSourceAssociation(a);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
70
|
}
|
|
70
71
|
// Expressions in the collector already have checksums attached
|
|
71
72
|
// (from ExpressionManager which stores expressions with checksums).
|
|
@@ -92,6 +93,11 @@ export class PremiseEngine {
|
|
|
92
93
|
!this.variables.hasVariable(expression.variableId)) {
|
|
93
94
|
throw new Error(`Variable expression "${expression.id}" references non-existent variable "${expression.variableId}".`);
|
|
94
95
|
}
|
|
96
|
+
if (expression.type === "variable" && this.circularityCheck) {
|
|
97
|
+
if (this.circularityCheck(expression.variableId, this.premise.id)) {
|
|
98
|
+
throw new Error(`Circular binding: variable "${expression.variableId}" is bound to this premise (directly or transitively)`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
95
101
|
if (expression.parentId === null) {
|
|
96
102
|
if (this.rootExpressionId !== undefined) {
|
|
97
103
|
throw new Error(`Premise "${this.premise.id}" already has a root expression.`);
|
|
@@ -135,6 +141,11 @@ export class PremiseEngine {
|
|
|
135
141
|
!this.variables.hasVariable(expression.variableId)) {
|
|
136
142
|
throw new Error(`Variable expression "${expression.id}" references non-existent variable "${expression.variableId}".`);
|
|
137
143
|
}
|
|
144
|
+
if (expression.type === "variable" && this.circularityCheck) {
|
|
145
|
+
if (this.circularityCheck(expression.variableId, this.premise.id)) {
|
|
146
|
+
throw new Error(`Circular binding: variable "${expression.variableId}" is bound to this premise (directly or transitively)`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
138
149
|
if (parentId === null) {
|
|
139
150
|
if (this.rootExpressionId !== undefined) {
|
|
140
151
|
throw new Error(`Premise "${this.premise.id}" already has a root expression.`);
|
|
@@ -176,6 +187,11 @@ export class PremiseEngine {
|
|
|
176
187
|
!this.variables.hasVariable(expression.variableId)) {
|
|
177
188
|
throw new Error(`Variable expression "${expression.id}" references non-existent variable "${expression.variableId}".`);
|
|
178
189
|
}
|
|
190
|
+
if (expression.type === "variable" && this.circularityCheck) {
|
|
191
|
+
if (this.circularityCheck(expression.variableId, this.premise.id)) {
|
|
192
|
+
throw new Error(`Circular binding: variable "${expression.variableId}" is bound to this premise (directly or transitively)`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
179
195
|
if (!this.expressions.getExpression(siblingId)) {
|
|
180
196
|
throw new Error(`Expression "${siblingId}" not found in this premise.`);
|
|
181
197
|
}
|
|
@@ -279,18 +295,6 @@ export class PremiseEngine {
|
|
|
279
295
|
}
|
|
280
296
|
this.syncRootExpressionId();
|
|
281
297
|
this.markDirty();
|
|
282
|
-
// Cascade: remove source associations for all removed expressions
|
|
283
|
-
if (this.sourceManager) {
|
|
284
|
-
const removedExprs = collector.toChangeset().expressions;
|
|
285
|
-
if (removedExprs) {
|
|
286
|
-
for (const expr of removedExprs.removed) {
|
|
287
|
-
const sourceResult = this.sourceManager.removeAssociationsForExpression(expr.id);
|
|
288
|
-
for (const assoc of sourceResult.removedExpressionAssociations) {
|
|
289
|
-
collector.removedExpressionSourceAssociation(assoc);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
298
|
const changes = collector.toChangeset();
|
|
295
299
|
this.syncExpressionIndex(changes);
|
|
296
300
|
this.onMutate?.();
|
|
@@ -309,6 +313,11 @@ export class PremiseEngine {
|
|
|
309
313
|
!this.variables.hasVariable(expression.variableId)) {
|
|
310
314
|
throw new Error(`Variable expression "${expression.id}" references non-existent variable "${expression.variableId}".`);
|
|
311
315
|
}
|
|
316
|
+
if (expression.type === "variable" && this.circularityCheck) {
|
|
317
|
+
if (this.circularityCheck(expression.variableId, this.premise.id)) {
|
|
318
|
+
throw new Error(`Circular binding: variable "${expression.variableId}" is bound to this premise (directly or transitively)`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
312
321
|
const collector = new ChangeCollector();
|
|
313
322
|
this.expressions.setCollector(collector);
|
|
314
323
|
try {
|
|
@@ -339,6 +348,11 @@ export class PremiseEngine {
|
|
|
339
348
|
!this.variables.hasVariable(newSibling.variableId)) {
|
|
340
349
|
throw new Error(`Variable expression "${newSibling.id}" references non-existent variable "${newSibling.variableId}".`);
|
|
341
350
|
}
|
|
351
|
+
if (newSibling.type === "variable" && this.circularityCheck) {
|
|
352
|
+
if (this.circularityCheck(newSibling.variableId, this.premise.id)) {
|
|
353
|
+
throw new Error(`Circular binding: variable "${newSibling.variableId}" is bound to this premise (directly or transitively)`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
342
356
|
const collector = new ChangeCollector();
|
|
343
357
|
this.expressions.setCollector(collector);
|
|
344
358
|
try {
|
|
@@ -414,65 +428,6 @@ export class PremiseEngine {
|
|
|
414
428
|
this.expressions.setCollector(null);
|
|
415
429
|
}
|
|
416
430
|
}
|
|
417
|
-
// -------------------------------------------------------------------------
|
|
418
|
-
// Source association convenience methods
|
|
419
|
-
// -------------------------------------------------------------------------
|
|
420
|
-
addExpressionSourceAssociation(sourceId, sourceVersion, expressionId) {
|
|
421
|
-
if (!this.sourceManager) {
|
|
422
|
-
throw new Error("No SourceManager available.");
|
|
423
|
-
}
|
|
424
|
-
if (!this.expressions.getExpression(expressionId)) {
|
|
425
|
-
throw new Error(`Expression "${expressionId}" does not exist in premise "${this.premise.id}".`);
|
|
426
|
-
}
|
|
427
|
-
const assoc = {
|
|
428
|
-
id: randomUUID(),
|
|
429
|
-
sourceId,
|
|
430
|
-
sourceVersion,
|
|
431
|
-
expressionId,
|
|
432
|
-
premiseId: this.premise.id,
|
|
433
|
-
argumentId: this.argument.id,
|
|
434
|
-
argumentVersion: this.argument.version,
|
|
435
|
-
checksum: "",
|
|
436
|
-
};
|
|
437
|
-
const fields = this.checksumConfig?.expressionSourceAssociationFields ??
|
|
438
|
-
DEFAULT_CHECKSUM_CONFIG.expressionSourceAssociationFields;
|
|
439
|
-
const assocWithChecksum = {
|
|
440
|
-
...assoc,
|
|
441
|
-
checksum: entityChecksum(assoc, fields),
|
|
442
|
-
};
|
|
443
|
-
this.sourceManager.addExpressionSourceAssociation(assocWithChecksum);
|
|
444
|
-
const collector = new ChangeCollector();
|
|
445
|
-
collector.addedExpressionSourceAssociation(assocWithChecksum);
|
|
446
|
-
this.markDirty();
|
|
447
|
-
this.onMutate?.();
|
|
448
|
-
return { result: assocWithChecksum, changes: collector.toChangeset() };
|
|
449
|
-
}
|
|
450
|
-
removeExpressionSourceAssociation(associationId) {
|
|
451
|
-
if (!this.sourceManager) {
|
|
452
|
-
return { result: undefined, changes: {} };
|
|
453
|
-
}
|
|
454
|
-
const allExprAssocs = this.sourceManager.getAllExpressionSourceAssociations();
|
|
455
|
-
if (!allExprAssocs.some((a) => a.id === associationId)) {
|
|
456
|
-
return { result: undefined, changes: {} };
|
|
457
|
-
}
|
|
458
|
-
const removalResult = this.sourceManager.removeExpressionSourceAssociation(associationId);
|
|
459
|
-
const collector = new ChangeCollector();
|
|
460
|
-
for (const assoc of removalResult.removedExpressionAssociations) {
|
|
461
|
-
collector.removedExpressionSourceAssociation(assoc);
|
|
462
|
-
}
|
|
463
|
-
this.markDirty();
|
|
464
|
-
this.onMutate?.();
|
|
465
|
-
return {
|
|
466
|
-
result: removalResult.removedExpressionAssociations[0],
|
|
467
|
-
changes: collector.toChangeset(),
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
getSourceAssociationsForExpression(expressionId) {
|
|
471
|
-
if (!this.sourceManager) {
|
|
472
|
-
return [];
|
|
473
|
-
}
|
|
474
|
-
return this.sourceManager.getAssociationsForExpression(expressionId);
|
|
475
|
-
}
|
|
476
431
|
getExpression(id) {
|
|
477
432
|
return this.expressions.getExpression(id);
|
|
478
433
|
}
|
|
@@ -576,6 +531,15 @@ export class PremiseEngine {
|
|
|
576
531
|
variableId: expr.variableId,
|
|
577
532
|
}));
|
|
578
533
|
}
|
|
534
|
+
if (expr.type === "variable" &&
|
|
535
|
+
this.emptyBoundPremiseCheck?.(expr.variableId)) {
|
|
536
|
+
issues.push({
|
|
537
|
+
code: "EXPR_BOUND_PREMISE_EMPTY",
|
|
538
|
+
severity: "warning",
|
|
539
|
+
message: `Variable "${expr.variableId}" is bound to a premise with no expression tree`,
|
|
540
|
+
expressionId: expr.id,
|
|
541
|
+
});
|
|
542
|
+
}
|
|
579
543
|
if (expr.type !== "operator" && expr.type !== "formula") {
|
|
580
544
|
continue;
|
|
581
545
|
}
|
|
@@ -661,7 +625,20 @@ export class PremiseEngine {
|
|
|
661
625
|
return false;
|
|
662
626
|
}
|
|
663
627
|
if (expression.type === "variable") {
|
|
664
|
-
|
|
628
|
+
let value;
|
|
629
|
+
if (options?.resolver) {
|
|
630
|
+
const variable = this.variables.getVariable(expression.variableId);
|
|
631
|
+
if (variable && isPremiseBound(variable)) {
|
|
632
|
+
value = options.resolver(expression.variableId);
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
value =
|
|
636
|
+
assignment.variables[expression.variableId] ?? null;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
else {
|
|
640
|
+
value = assignment.variables[expression.variableId] ?? null;
|
|
641
|
+
}
|
|
665
642
|
expressionValues[expression.id] = value;
|
|
666
643
|
return value;
|
|
667
644
|
}
|
|
@@ -701,6 +678,13 @@ export class PremiseEngine {
|
|
|
701
678
|
const rootValue = evaluateExpression(rootExpressionId);
|
|
702
679
|
const variableValues = {};
|
|
703
680
|
for (const variableId of referencedVariableIds) {
|
|
681
|
+
if (options?.resolver) {
|
|
682
|
+
const variable = this.variables.getVariable(variableId);
|
|
683
|
+
if (variable && isPremiseBound(variable)) {
|
|
684
|
+
variableValues[variableId] = options.resolver(variableId);
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
704
688
|
variableValues[variableId] =
|
|
705
689
|
assignment.variables[variableId] ?? null;
|
|
706
690
|
}
|
|
@@ -895,8 +879,8 @@ export class PremiseEngine {
|
|
|
895
879
|
};
|
|
896
880
|
}
|
|
897
881
|
/** Creates a new PremiseEngine from a previously captured snapshot. */
|
|
898
|
-
static fromSnapshot(snapshot, argument, variables, expressionIndex
|
|
899
|
-
const pe = new PremiseEngine(snapshot.premise, { argument, variables, expressionIndex
|
|
882
|
+
static fromSnapshot(snapshot, argument, variables, expressionIndex) {
|
|
883
|
+
const pe = new PremiseEngine(snapshot.premise, { argument, variables, expressionIndex }, snapshot.config);
|
|
900
884
|
// Restore expressions from the snapshot
|
|
901
885
|
pe.expressions = ExpressionManager.fromSnapshot(snapshot.expressions);
|
|
902
886
|
// Restore rootExpressionId from snapshot
|