tla-ts 0.0.3-dev.6a30eee → 0.0.3-dev.6d0aeb6
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 +5 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +58 -22
- package/dist/index.d.ts +58 -22
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +20 -18
- package/dist/run-cli.js +22 -20
- package/dist/transfer.cjs +40 -15
- package/dist/transfer.js +40 -15
- package/package.json +1 -1
- package/src/ast.ts +101 -1
- package/src/builtins.ts +9 -3
- package/src/check.ts +473 -100
- package/src/cli-options.ts +11 -5
- package/src/codegen.ts +15 -22
- package/src/config.ts +224 -170
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +158 -49
- package/src/errors.ts +93 -3
- package/src/evaluate.ts +214 -147
- package/src/exit-codes.ts +21 -14
- package/src/fingerprints.ts +2 -1
- package/src/instances.ts +16 -15
- package/src/levels.ts +181 -45
- package/src/live-check.ts +132 -70
- package/src/liveness.ts +118 -24
- package/src/parallel-worker.ts +2 -2
- package/src/parallel.ts +5 -2
- package/src/parser.ts +71 -19
- package/src/resolve.ts +490 -95
- package/src/run-cli.ts +104 -18
- package/src/runtime.ts +2 -0
- package/src/sany-lexer.ts +615 -0
- package/src/sany-parse-error.ts +3143 -0
- package/src/spec-description.ts +19 -8
- package/src/standard-modules.ts +54 -45
- package/src/state-graph.ts +157 -0
- package/src/subexpressions.ts +35 -23
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +176 -36
- package/src/symmetry.ts +16 -6
- package/src/tableau.ts +51 -24
- package/src/tlc-ext.ts +29 -12
- package/src/tlc-module.ts +14 -33
- package/src/tlc-modules.ts +4 -0
- package/src/tlc-order.ts +8 -4
- package/src/tlc-random.ts +9 -6
- package/src/tlc-summary.ts +20 -5
- package/src/value-sources.ts +29 -0
- package/src/values.ts +242 -61
package/src/parser.ts
CHANGED
|
@@ -22,7 +22,7 @@ import type {
|
|
|
22
22
|
StepBody,
|
|
23
23
|
UseOrHide,
|
|
24
24
|
} from "./ast";
|
|
25
|
-
import { TlaSyntaxError } from "./errors";
|
|
25
|
+
import { createSanyError, formatRange, TlaSyntaxError } from "./errors";
|
|
26
26
|
import { getNumeralValue, tokenize, type Token } from "./lexer";
|
|
27
27
|
|
|
28
28
|
interface InfixOperator {
|
|
@@ -329,8 +329,7 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
329
329
|
const tokenEnds: SourceLocation[] = [];
|
|
330
330
|
const tokenRanges: SourceRange[] = [];
|
|
331
331
|
|
|
332
|
-
const getRange = (startIndex: number) => {
|
|
333
|
-
const endIndex = cursor.index - 1;
|
|
332
|
+
const getRange = (startIndex: number, endIndex = cursor.index - 1) => {
|
|
334
333
|
const cached = startIndex === endIndex ? tokenRanges[startIndex] : undefined;
|
|
335
334
|
if (cached) return cached;
|
|
336
335
|
const last = tokens[endIndex];
|
|
@@ -628,14 +627,24 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
628
627
|
const body = parseExpression();
|
|
629
628
|
return withRange({ kind: "Lambda", params, body, location: getLocation(token) }, start);
|
|
630
629
|
}
|
|
631
|
-
|
|
630
|
+
const argument = parseExpression();
|
|
631
|
+
// SANY reads an argument that only names an operator of a parameterized instance, such as
|
|
632
|
+
// I!Op, as that operator, which takes the arguments of the instance too.
|
|
633
|
+
if (argument.kind === "Identifier") missingArguments.delete(argument);
|
|
634
|
+
return argument;
|
|
632
635
|
};
|
|
633
636
|
|
|
637
|
+
const missingArguments = new Map<Expression, { location: string; message: string }>();
|
|
638
|
+
|
|
639
|
+
const lastArguments: { range: SourceRange | undefined } = { range: undefined };
|
|
640
|
+
|
|
634
641
|
const parseArguments = () =>
|
|
635
642
|
withoutOffside(() => {
|
|
643
|
+
const start = cursor.index;
|
|
636
644
|
expect("(");
|
|
637
645
|
const args = parseSeparated(parseArgument);
|
|
638
646
|
expect(")");
|
|
647
|
+
lastArguments.range = getRange(start);
|
|
639
648
|
return args;
|
|
640
649
|
});
|
|
641
650
|
|
|
@@ -662,9 +671,12 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
662
671
|
if (peek().kind === "Identifier" && (isAt("|->", 1) || isAt(":", 1))) {
|
|
663
672
|
const kind = isAt("|->", 1) ? "Record" : "RecordSet";
|
|
664
673
|
const fields = parseSeparated(() => {
|
|
674
|
+
const fieldStart = cursor.index;
|
|
675
|
+
const fieldLocation = getLocation(peek());
|
|
665
676
|
const name = expectIdentifier();
|
|
677
|
+
fieldLocation.range = getRange(fieldStart);
|
|
666
678
|
expect(kind === "Record" ? "|->" : ":");
|
|
667
|
-
return { name, value: parseExpression() };
|
|
679
|
+
return { name, value: parseExpression(), location: fieldLocation };
|
|
668
680
|
});
|
|
669
681
|
expect("]");
|
|
670
682
|
return { kind, fields, location };
|
|
@@ -823,7 +835,8 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
823
835
|
};
|
|
824
836
|
|
|
825
837
|
const parsePrimary = (): Expression => {
|
|
826
|
-
const
|
|
838
|
+
const start = cursor.index;
|
|
839
|
+
const isFactStart = start === factStart.index;
|
|
827
840
|
const token = advance();
|
|
828
841
|
const location = getLocation(token);
|
|
829
842
|
if (isTlapm && token.kind === "Keyword" && token.text === "LAMBDA") {
|
|
@@ -856,38 +869,71 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
856
869
|
const args = hasArguments ? parseArguments() : [];
|
|
857
870
|
if (!isSelectorAhead()) {
|
|
858
871
|
return hasArguments
|
|
859
|
-
? { kind: "Apply", operator: name, args, location }
|
|
872
|
+
? { kind: "Apply", operator: name, args, argumentsRange: lastArguments.range, location }
|
|
860
873
|
: { kind: "Identifier", name, location };
|
|
861
874
|
}
|
|
862
875
|
const instance = openModules
|
|
863
876
|
.flatMap((module) => module.instances)
|
|
864
877
|
.find((candidate) => candidate.name === name);
|
|
865
|
-
|
|
878
|
+
const isMissingArguments =
|
|
879
|
+
instance !== undefined &&
|
|
880
|
+
!isFactStart &&
|
|
881
|
+
!isTlapm &&
|
|
882
|
+
instance.params.length !== args.length;
|
|
883
|
+
if (isMissingArguments && args.length > 0) {
|
|
866
884
|
throw createError(
|
|
867
885
|
`The operator ${name} requires ${instance.params.length} arguments`,
|
|
868
886
|
token,
|
|
869
887
|
);
|
|
870
888
|
}
|
|
871
889
|
const selectors: Selector[] = [{ kind: "Name", name, args }];
|
|
890
|
+
const selectorRanges = [getRange(start, start)];
|
|
872
891
|
while (isSelectorAhead()) {
|
|
873
892
|
advance();
|
|
893
|
+
selectorRanges.push(getRange(cursor.index, cursor.index));
|
|
874
894
|
selectors.push(parseSelector());
|
|
875
895
|
}
|
|
876
896
|
const names = selectors.flatMap((selector) =>
|
|
877
897
|
selector.kind === "Name" ? [selector.name] : [],
|
|
878
898
|
);
|
|
879
|
-
if (names.length < selectors.length) return { kind: "Subexpression", selectors, location };
|
|
880
899
|
const operator = names.join("!");
|
|
881
900
|
const qualifiedArgs = selectors.flatMap((selector) =>
|
|
882
901
|
"args" in selector ? selector.args : [],
|
|
883
902
|
);
|
|
884
|
-
if (qualifiedArgs.length === 0) return { kind: "Identifier", name: operator, location };
|
|
885
903
|
const argumentCounts = selectors.map((selector) =>
|
|
886
904
|
"args" in selector ? selector.args.length : 0,
|
|
887
905
|
);
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
906
|
+
const argumentsRange = lastArguments.range;
|
|
907
|
+
const reference: Expression =
|
|
908
|
+
names.length < selectors.length
|
|
909
|
+
? { kind: "Subexpression", selectors, selectorRanges, location }
|
|
910
|
+
: qualifiedArgs.length === 0
|
|
911
|
+
? { kind: "Identifier", name: operator, selectorRanges, location }
|
|
912
|
+
: argumentCounts.slice(0, -1).some((count) => count > 0)
|
|
913
|
+
? {
|
|
914
|
+
kind: "Apply",
|
|
915
|
+
operator,
|
|
916
|
+
args: qualifiedArgs,
|
|
917
|
+
argumentCounts,
|
|
918
|
+
argumentsRange,
|
|
919
|
+
selectorRanges,
|
|
920
|
+
location,
|
|
921
|
+
}
|
|
922
|
+
: {
|
|
923
|
+
kind: "Apply",
|
|
924
|
+
operator,
|
|
925
|
+
args: qualifiedArgs,
|
|
926
|
+
argumentsRange,
|
|
927
|
+
selectorRanges,
|
|
928
|
+
location,
|
|
929
|
+
};
|
|
930
|
+
if (isMissingArguments) {
|
|
931
|
+
missingArguments.set(reference, {
|
|
932
|
+
location: formatRange(getRange(start)),
|
|
933
|
+
message: `The operator ${name} requires ${instance.params.length} arguments.`,
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
return reference;
|
|
891
937
|
}
|
|
892
938
|
if (token.kind === "Operator" && isOperatorName(token.text) && isAt("("))
|
|
893
939
|
return { kind: "Apply", operator: token.text, args: parseArguments(), location };
|
|
@@ -1423,11 +1469,14 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1423
1469
|
location: getLocation(keyword),
|
|
1424
1470
|
};
|
|
1425
1471
|
const invalid =
|
|
1426
|
-
use.kind === "Hide" && !isTlapm ? use.facts.
|
|
1427
|
-
if (invalid) {
|
|
1428
|
-
throw
|
|
1429
|
-
|
|
1430
|
-
|
|
1472
|
+
use.kind === "Hide" && !isTlapm ? use.facts.filter((fact) => !isHideFact(fact)) : [];
|
|
1473
|
+
if (invalid.length > 0) {
|
|
1474
|
+
throw createSanyError(
|
|
1475
|
+
invalid.map((fact) => ({
|
|
1476
|
+
location: formatRange(fact.location.range ?? getRange(start)),
|
|
1477
|
+
message:
|
|
1478
|
+
"The only expression allowed as a fact in a HIDE is \nthe name of a theorem, assumption, or step.",
|
|
1479
|
+
})),
|
|
1431
1480
|
);
|
|
1432
1481
|
}
|
|
1433
1482
|
return withRange(use, start);
|
|
@@ -1563,10 +1612,12 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1563
1612
|
const parseStep = (): ProofStep => {
|
|
1564
1613
|
const start = cursor.index;
|
|
1565
1614
|
const step = parseStepStart(isAt("QED", 1));
|
|
1615
|
+
const statementStart = cursor.index;
|
|
1566
1616
|
const scope = new Set<string>();
|
|
1567
1617
|
proofScopes.push(scope);
|
|
1568
1618
|
const body: StepBody = accept("QED") ? { kind: "Qed" } : parseStepBody();
|
|
1569
1619
|
const head = getRange(start);
|
|
1620
|
+
const statement = getRange(statementStart);
|
|
1570
1621
|
const hasProof = isProofStart(peek());
|
|
1571
1622
|
if (hasProof && !PROVABLE_STEPS.has(body.kind)) {
|
|
1572
1623
|
throw createError("Proof of a step that does not take a proof");
|
|
@@ -1574,7 +1625,7 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1574
1625
|
const proof = hasProof ? parseProof() : undefined;
|
|
1575
1626
|
proofScopes.pop();
|
|
1576
1627
|
if (body.kind !== "Assert" || body.isSuffices) scope.forEach(declareProofSymbol);
|
|
1577
|
-
return withRange({ ...step, body, head, proof }, start);
|
|
1628
|
+
return withRange({ ...step, body, head, statement, proof }, start);
|
|
1578
1629
|
};
|
|
1579
1630
|
|
|
1580
1631
|
const parseProofBody = (): Proof => {
|
|
@@ -1705,6 +1756,7 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1705
1756
|
end: { line: token.line, column: token.endColumn },
|
|
1706
1757
|
};
|
|
1707
1758
|
}
|
|
1759
|
+
if (missingArguments.size > 0) throw createSanyError([...missingArguments.values()]);
|
|
1708
1760
|
openModules.pop();
|
|
1709
1761
|
recursiveScopes.pop();
|
|
1710
1762
|
return module;
|