tla-ts 0.0.3-dev.6979965 → 0.0.3-dev.6ac5593
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 +16 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +72 -22
- package/dist/index.d.ts +72 -22
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +2 -2
- 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 -17
- package/dist/run-cli.js +22 -19
- package/dist/transfer.cjs +46 -16
- package/dist/transfer.js +46 -16
- package/package.json +1 -1
- package/src/ast.ts +121 -4
- package/src/builtins.ts +9 -3
- package/src/check.ts +521 -105
- 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 +410 -130
- package/src/errors.ts +109 -3
- package/src/evaluate.ts +443 -194
- package/src/exit-codes.ts +39 -42
- package/src/fingerprints.ts +2 -1
- package/src/instances.ts +17 -16
- package/src/levels.ts +185 -44
- package/src/lexer.ts +5 -1
- package/src/live-check.ts +772 -0
- package/src/liveness.ts +120 -543
- package/src/parallel-worker.ts +102 -115
- package/src/parallel.ts +34 -23
- package/src/parser.ts +184 -54
- package/src/resolve.ts +1378 -420
- package/src/run-cli.ts +115 -20
- package/src/runtime.ts +3 -1
- 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/standard-ranges.ts +116 -0
- package/src/state-graph.ts +157 -0
- package/src/subexpressions.ts +231 -171
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +184 -40
- package/src/symmetry.ts +123 -43
- 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 +25 -7
- 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 +249 -65
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 {
|
|
@@ -135,6 +135,8 @@ const INFIX_OPERATORS = new Map<string, InfixOperator>([
|
|
|
135
135
|
["^^", createInfix(14, 14, false)],
|
|
136
136
|
]);
|
|
137
137
|
|
|
138
|
+
const NEGATION_PRECEDENCE = 12;
|
|
139
|
+
|
|
138
140
|
const POSTFIX_OPERATORS = new Set(["^+", "^*", "^#"]);
|
|
139
141
|
|
|
140
142
|
const PREFIX_OPERATOR_REFERENCES = new Set(["-", "~", "-."]);
|
|
@@ -313,6 +315,7 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
313
315
|
const proofScopes: Set<string>[] = [];
|
|
314
316
|
// A fact may cite an operator of a parameterized instance without the instance's arguments.
|
|
315
317
|
const factStart = { index: -1 };
|
|
318
|
+
// SANY reports a location in a nested module as one in the module of its file.
|
|
316
319
|
const openModules: Module[] = [];
|
|
317
320
|
|
|
318
321
|
const isRecursiveName = (name: string) => recursiveScopes[recursiveScopes.length - 1].has(name);
|
|
@@ -327,15 +330,14 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
327
330
|
const tokenEnds: SourceLocation[] = [];
|
|
328
331
|
const tokenRanges: SourceRange[] = [];
|
|
329
332
|
|
|
330
|
-
const getRange = (startIndex: number) => {
|
|
331
|
-
const endIndex = cursor.index - 1;
|
|
333
|
+
const getRange = (startIndex: number, endIndex = cursor.index - 1) => {
|
|
332
334
|
const cached = startIndex === endIndex ? tokenRanges[startIndex] : undefined;
|
|
333
335
|
if (cached) return cached;
|
|
334
336
|
const last = tokens[endIndex];
|
|
335
337
|
tokenStarts[startIndex] ??= getLocation(tokens[startIndex]);
|
|
336
338
|
tokenEnds[endIndex] ??= { line: last.line, column: last.endColumn };
|
|
337
339
|
const range = {
|
|
338
|
-
module: openModules[
|
|
340
|
+
module: openModules[0].name,
|
|
339
341
|
start: tokenStarts[startIndex],
|
|
340
342
|
end: tokenEnds[endIndex],
|
|
341
343
|
};
|
|
@@ -470,6 +472,16 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
470
472
|
return token.text;
|
|
471
473
|
};
|
|
472
474
|
|
|
475
|
+
const expectName = () => {
|
|
476
|
+
const start = cursor.index;
|
|
477
|
+
return { name: expectIdentifier(), range: getRange(start) };
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
const getNames = (names: { name: string; range: SourceRange }[]) => ({
|
|
481
|
+
names: names.map((item) => item.name),
|
|
482
|
+
ranges: names.map((item) => item.range),
|
|
483
|
+
});
|
|
484
|
+
|
|
473
485
|
const withoutOffside = <Result>(parse: () => Result) => {
|
|
474
486
|
cursor.offsideColumns.push(NO_OFFSIDE);
|
|
475
487
|
const result = parse();
|
|
@@ -512,10 +524,13 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
512
524
|
};
|
|
513
525
|
|
|
514
526
|
const parsePattern = (): BoundPattern => {
|
|
515
|
-
if (!accept("<<"))
|
|
516
|
-
|
|
527
|
+
if (!accept("<<")) {
|
|
528
|
+
const named = expectName();
|
|
529
|
+
return { kind: "Name", name: named.name, ranges: [named.range] };
|
|
530
|
+
}
|
|
531
|
+
const names = getNames(parseSeparated(expectName));
|
|
517
532
|
expect(">>");
|
|
518
|
-
return { kind: "Tuple", names };
|
|
533
|
+
return { kind: "Tuple", names: names.names, ranges: names.ranges };
|
|
519
534
|
};
|
|
520
535
|
|
|
521
536
|
const parseBounds = () =>
|
|
@@ -621,19 +636,38 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
621
636
|
if (isAt("LAMBDA")) {
|
|
622
637
|
const start = cursor.index;
|
|
623
638
|
advance();
|
|
624
|
-
const params = parseSeparated(
|
|
639
|
+
const params = getNames(parseSeparated(expectName));
|
|
625
640
|
expect(":");
|
|
626
641
|
const body = parseExpression();
|
|
627
|
-
return withRange(
|
|
642
|
+
return withRange(
|
|
643
|
+
{
|
|
644
|
+
kind: "Lambda",
|
|
645
|
+
params: params.names,
|
|
646
|
+
paramRanges: params.ranges,
|
|
647
|
+
body,
|
|
648
|
+
location: getLocation(token),
|
|
649
|
+
},
|
|
650
|
+
start,
|
|
651
|
+
);
|
|
628
652
|
}
|
|
629
|
-
|
|
653
|
+
const argument = parseExpression();
|
|
654
|
+
// SANY reads an argument that only names an operator of a parameterized instance, such as
|
|
655
|
+
// I!Op, as that operator, which takes the arguments of the instance too.
|
|
656
|
+
if (argument.kind === "Identifier") missingArguments.delete(argument);
|
|
657
|
+
return argument;
|
|
630
658
|
};
|
|
631
659
|
|
|
660
|
+
const missingArguments = new Map<Expression, { location: string; message: string }>();
|
|
661
|
+
|
|
662
|
+
const lastArguments: { range: SourceRange | undefined } = { range: undefined };
|
|
663
|
+
|
|
632
664
|
const parseArguments = () =>
|
|
633
665
|
withoutOffside(() => {
|
|
666
|
+
const start = cursor.index;
|
|
634
667
|
expect("(");
|
|
635
668
|
const args = parseSeparated(parseArgument);
|
|
636
669
|
expect(")");
|
|
670
|
+
lastArguments.range = getRange(start);
|
|
637
671
|
return args;
|
|
638
672
|
});
|
|
639
673
|
|
|
@@ -660,9 +694,12 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
660
694
|
if (peek().kind === "Identifier" && (isAt("|->", 1) || isAt(":", 1))) {
|
|
661
695
|
const kind = isAt("|->", 1) ? "Record" : "RecordSet";
|
|
662
696
|
const fields = parseSeparated(() => {
|
|
697
|
+
const fieldStart = cursor.index;
|
|
698
|
+
const fieldLocation = getLocation(peek());
|
|
663
699
|
const name = expectIdentifier();
|
|
700
|
+
fieldLocation.range = getRange(fieldStart);
|
|
664
701
|
expect(kind === "Record" ? "|->" : ":");
|
|
665
|
-
return { name, value: parseExpression() };
|
|
702
|
+
return { name, value: parseExpression(), location: fieldLocation };
|
|
666
703
|
});
|
|
667
704
|
expect("]");
|
|
668
705
|
return { kind, fields, location };
|
|
@@ -761,12 +798,13 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
761
798
|
expect(":");
|
|
762
799
|
return { kind, bounds, body: parseExpression(), location };
|
|
763
800
|
}
|
|
764
|
-
const names = parseSeparated(
|
|
801
|
+
const names = getNames(parseSeparated(expectName));
|
|
765
802
|
expect(":");
|
|
766
803
|
return {
|
|
767
804
|
kind: "UnboundedQuantifier",
|
|
768
805
|
quantifier: start.text === "\\A" || start.text === "\\AA" ? "Forall" : "Exists",
|
|
769
|
-
names,
|
|
806
|
+
names: names.names,
|
|
807
|
+
nameRanges: names.ranges,
|
|
770
808
|
body: parseExpression(),
|
|
771
809
|
isTemporal,
|
|
772
810
|
location,
|
|
@@ -821,7 +859,8 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
821
859
|
};
|
|
822
860
|
|
|
823
861
|
const parsePrimary = (): Expression => {
|
|
824
|
-
const
|
|
862
|
+
const start = cursor.index;
|
|
863
|
+
const isFactStart = start === factStart.index;
|
|
825
864
|
const token = advance();
|
|
826
865
|
const location = getLocation(token);
|
|
827
866
|
if (isTlapm && token.kind === "Keyword" && token.text === "LAMBDA") {
|
|
@@ -845,47 +884,92 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
845
884
|
if (token.kind === "Identifier" || isStep) {
|
|
846
885
|
const name = isStep ? (getStepName(token) ?? token.text) : token.text;
|
|
847
886
|
if (isLabelAhead()) {
|
|
848
|
-
const params = accept("(") ? parseSeparated(
|
|
849
|
-
if (params.length > 0) expect(")");
|
|
887
|
+
const params = getNames(accept("(") ? parseSeparated(expectName) : []);
|
|
888
|
+
if (params.names.length > 0) expect(")");
|
|
850
889
|
expect("::");
|
|
851
|
-
return {
|
|
890
|
+
return {
|
|
891
|
+
kind: "Label",
|
|
892
|
+
name,
|
|
893
|
+
params: params.names,
|
|
894
|
+
paramRanges: params.ranges,
|
|
895
|
+
body: parseExpression(),
|
|
896
|
+
location,
|
|
897
|
+
};
|
|
852
898
|
}
|
|
853
899
|
const hasArguments = isAt("(");
|
|
854
900
|
const args = hasArguments ? parseArguments() : [];
|
|
901
|
+
const argumentRanges = [hasArguments ? lastArguments.range : undefined];
|
|
855
902
|
if (!isSelectorAhead()) {
|
|
856
903
|
return hasArguments
|
|
857
|
-
? { kind: "Apply", operator: name, args, location }
|
|
904
|
+
? { kind: "Apply", operator: name, args, argumentsRange: lastArguments.range, location }
|
|
858
905
|
: { kind: "Identifier", name, location };
|
|
859
906
|
}
|
|
860
907
|
const instance = openModules
|
|
861
908
|
.flatMap((module) => module.instances)
|
|
862
909
|
.find((candidate) => candidate.name === name);
|
|
863
|
-
|
|
910
|
+
const isMissingArguments =
|
|
911
|
+
instance !== undefined &&
|
|
912
|
+
!isFactStart &&
|
|
913
|
+
!isTlapm &&
|
|
914
|
+
instance.params.length !== args.length;
|
|
915
|
+
if (isMissingArguments && args.length > 0) {
|
|
864
916
|
throw createError(
|
|
865
917
|
`The operator ${name} requires ${instance.params.length} arguments`,
|
|
866
918
|
token,
|
|
867
919
|
);
|
|
868
920
|
}
|
|
869
921
|
const selectors: Selector[] = [{ kind: "Name", name, args }];
|
|
922
|
+
const selectorRanges = [getRange(start, start)];
|
|
870
923
|
while (isSelectorAhead()) {
|
|
871
924
|
advance();
|
|
925
|
+
selectorRanges.push(getRange(cursor.index, cursor.index));
|
|
926
|
+
lastArguments.range = undefined;
|
|
872
927
|
selectors.push(parseSelector());
|
|
928
|
+
argumentRanges.push(lastArguments.range);
|
|
873
929
|
}
|
|
874
930
|
const names = selectors.flatMap((selector) =>
|
|
875
931
|
selector.kind === "Name" ? [selector.name] : [],
|
|
876
932
|
);
|
|
877
|
-
if (names.length < selectors.length) return { kind: "Subexpression", selectors, location };
|
|
878
933
|
const operator = names.join("!");
|
|
879
934
|
const qualifiedArgs = selectors.flatMap((selector) =>
|
|
880
935
|
"args" in selector ? selector.args : [],
|
|
881
936
|
);
|
|
882
|
-
if (qualifiedArgs.length === 0) return { kind: "Identifier", name: operator, location };
|
|
883
937
|
const argumentCounts = selectors.map((selector) =>
|
|
884
938
|
"args" in selector ? selector.args.length : 0,
|
|
885
939
|
);
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
940
|
+
const argumentsRange = argumentRanges.findLast((range) => range !== undefined);
|
|
941
|
+
const reference: Expression =
|
|
942
|
+
names.length < selectors.length
|
|
943
|
+
? { kind: "Subexpression", selectors, selectorRanges, argumentRanges, location }
|
|
944
|
+
: qualifiedArgs.length === 0
|
|
945
|
+
? { kind: "Identifier", name: operator, selectorRanges, location }
|
|
946
|
+
: argumentCounts.slice(0, -1).some((count) => count > 0)
|
|
947
|
+
? {
|
|
948
|
+
kind: "Apply",
|
|
949
|
+
operator,
|
|
950
|
+
args: qualifiedArgs,
|
|
951
|
+
argumentCounts,
|
|
952
|
+
argumentsRange,
|
|
953
|
+
selectorRanges,
|
|
954
|
+
argumentRanges,
|
|
955
|
+
location,
|
|
956
|
+
}
|
|
957
|
+
: {
|
|
958
|
+
kind: "Apply",
|
|
959
|
+
operator,
|
|
960
|
+
args: qualifiedArgs,
|
|
961
|
+
argumentsRange,
|
|
962
|
+
selectorRanges,
|
|
963
|
+
argumentRanges,
|
|
964
|
+
location,
|
|
965
|
+
};
|
|
966
|
+
if (isMissingArguments) {
|
|
967
|
+
missingArguments.set(reference, {
|
|
968
|
+
location: formatRange(getRange(start)),
|
|
969
|
+
message: `The operator ${name} requires ${instance.params.length} arguments.`,
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
return reference;
|
|
889
973
|
}
|
|
890
974
|
if (token.kind === "Operator" && isOperatorName(token.text) && isAt("("))
|
|
891
975
|
return { kind: "Apply", operator: token.text, args: parseArguments(), location };
|
|
@@ -977,7 +1061,12 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
977
1061
|
return { kind: "Apply", operator: "~", args: [parseExpression(5)], location };
|
|
978
1062
|
case "-":
|
|
979
1063
|
advance();
|
|
980
|
-
return {
|
|
1064
|
+
return {
|
|
1065
|
+
kind: "Apply",
|
|
1066
|
+
operator: "-.",
|
|
1067
|
+
args: [parseExpression(NEGATION_PRECEDENCE + 1)],
|
|
1068
|
+
location,
|
|
1069
|
+
};
|
|
981
1070
|
case "[]":
|
|
982
1071
|
advance();
|
|
983
1072
|
return { kind: "Always", expression: parseExpression(16), location };
|
|
@@ -1054,6 +1143,10 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1054
1143
|
}
|
|
1055
1144
|
}
|
|
1056
1145
|
advance();
|
|
1146
|
+
// SANY reads - after an infix operator as prefix -, and rejects it after one that binds tighter.
|
|
1147
|
+
if (infix.low > NEGATION_PRECEDENCE && isAt("-")) {
|
|
1148
|
+
throw createError(`Precedence conflict between ${token.text} and -`, peek());
|
|
1149
|
+
}
|
|
1057
1150
|
const right = parseExpression(infix.high + 1);
|
|
1058
1151
|
const left = state.left;
|
|
1059
1152
|
if (token.text === "/\\" || token.text === "\\/") {
|
|
@@ -1088,7 +1181,7 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1088
1181
|
const body = parseExpression();
|
|
1089
1182
|
const last = tokens[cursor.index - 1];
|
|
1090
1183
|
const end = { line: last.line, column: last.endColumn };
|
|
1091
|
-
return { body, bodyRange: { module: openModules[
|
|
1184
|
+
return { body, bodyRange: { module: openModules[0].name, start, end } };
|
|
1092
1185
|
};
|
|
1093
1186
|
|
|
1094
1187
|
const parseDefinition = (isLocal: boolean): Definition | Instance => {
|
|
@@ -1096,6 +1189,16 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1096
1189
|
return withRange(parseDefinitionUnit(isLocal), start);
|
|
1097
1190
|
};
|
|
1098
1191
|
|
|
1192
|
+
const toParam = (named: { name: string; range: SourceRange }): OperatorParam => ({
|
|
1193
|
+
name: named.name,
|
|
1194
|
+
arity: 0,
|
|
1195
|
+
location: {
|
|
1196
|
+
line: named.range.start.line,
|
|
1197
|
+
column: named.range.start.column,
|
|
1198
|
+
range: named.range,
|
|
1199
|
+
},
|
|
1200
|
+
});
|
|
1201
|
+
|
|
1099
1202
|
const parseDefinitionUnit = (isLocal: boolean): Definition | Instance => {
|
|
1100
1203
|
const token = peek();
|
|
1101
1204
|
const location = getLocation(token);
|
|
@@ -1115,24 +1218,22 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1115
1218
|
peek(2).kind === "Identifier" &&
|
|
1116
1219
|
isAt("==", 3)
|
|
1117
1220
|
) {
|
|
1118
|
-
const left =
|
|
1221
|
+
const left = expectName();
|
|
1119
1222
|
const operator = advance().text;
|
|
1120
|
-
const right =
|
|
1223
|
+
const right = expectName();
|
|
1121
1224
|
expect("==");
|
|
1122
|
-
return parseOperator(operator, [
|
|
1123
|
-
{ name: left, arity: 0 },
|
|
1124
|
-
{ name: right, arity: 0 },
|
|
1125
|
-
]);
|
|
1225
|
+
return parseOperator(operator, [toParam(left), toParam(right)]);
|
|
1126
1226
|
}
|
|
1127
1227
|
const isPrefixDefinition = token.kind === "Operator" && token.text === "-.";
|
|
1128
1228
|
const isPostfixDefinition =
|
|
1129
1229
|
token.kind === "Identifier" && POSTFIX_OPERATORS.has(peek(1).text) && isAt("==", 2);
|
|
1130
1230
|
if (isPrefixDefinition || isPostfixDefinition) {
|
|
1131
1231
|
const operator = isPrefixDefinition ? token.text : peek(1).text;
|
|
1132
|
-
|
|
1133
|
-
const param =
|
|
1232
|
+
if (isPrefixDefinition) advance();
|
|
1233
|
+
const param = expectName();
|
|
1234
|
+
if (isPostfixDefinition) advance();
|
|
1134
1235
|
expect("==");
|
|
1135
|
-
return parseOperator(operator, [
|
|
1236
|
+
return parseOperator(operator, [toParam(param)]);
|
|
1136
1237
|
}
|
|
1137
1238
|
const name = expectIdentifier();
|
|
1138
1239
|
if (accept("[")) {
|
|
@@ -1170,9 +1271,11 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1170
1271
|
const module = expectIdentifier();
|
|
1171
1272
|
const substitutions = accept("WITH")
|
|
1172
1273
|
? parseSeparated(() => {
|
|
1274
|
+
const targetStart = cursor.index;
|
|
1173
1275
|
const target = advance().text;
|
|
1276
|
+
const nameRange = getRange(targetStart);
|
|
1174
1277
|
expect("<-");
|
|
1175
|
-
return { name: target, expression: parseArgument() };
|
|
1278
|
+
return { name: target, nameRange, expression: parseArgument() };
|
|
1176
1279
|
})
|
|
1177
1280
|
: [];
|
|
1178
1281
|
return {
|
|
@@ -1188,6 +1291,11 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1188
1291
|
};
|
|
1189
1292
|
|
|
1190
1293
|
const parseDeclaration = (): Declaration => {
|
|
1294
|
+
const start = cursor.index;
|
|
1295
|
+
return withRange(parseDeclarationUnit(), start);
|
|
1296
|
+
};
|
|
1297
|
+
|
|
1298
|
+
const parseDeclarationUnit = (): Declaration => {
|
|
1191
1299
|
const location = getLocation(peek());
|
|
1192
1300
|
if (isAt("_") && peek(1).kind === "Operator") {
|
|
1193
1301
|
advance();
|
|
@@ -1412,11 +1520,14 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1412
1520
|
location: getLocation(keyword),
|
|
1413
1521
|
};
|
|
1414
1522
|
const invalid =
|
|
1415
|
-
use.kind === "Hide" && !isTlapm ? use.facts.
|
|
1416
|
-
if (invalid) {
|
|
1417
|
-
throw
|
|
1418
|
-
|
|
1419
|
-
|
|
1523
|
+
use.kind === "Hide" && !isTlapm ? use.facts.filter((fact) => !isHideFact(fact)) : [];
|
|
1524
|
+
if (invalid.length > 0) {
|
|
1525
|
+
throw createSanyError(
|
|
1526
|
+
invalid.map((fact) => ({
|
|
1527
|
+
location: formatRange(fact.location.range ?? getRange(start)),
|
|
1528
|
+
message:
|
|
1529
|
+
"The only expression allowed as a fact in a HIDE is \nthe name of a theorem, assumption, or step.",
|
|
1530
|
+
})),
|
|
1420
1531
|
);
|
|
1421
1532
|
}
|
|
1422
1533
|
return withRange(use, start);
|
|
@@ -1432,10 +1543,18 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1432
1543
|
}
|
|
1433
1544
|
if (level !== undefined) advance();
|
|
1434
1545
|
if (level === "Variable") {
|
|
1435
|
-
const
|
|
1436
|
-
declareProofSymbol(name);
|
|
1546
|
+
const named = expectName();
|
|
1547
|
+
declareProofSymbol(named.name);
|
|
1437
1548
|
return withRange(
|
|
1438
|
-
{
|
|
1549
|
+
{
|
|
1550
|
+
kind: "NewSymbol",
|
|
1551
|
+
name: named.name,
|
|
1552
|
+
arity: 0,
|
|
1553
|
+
level,
|
|
1554
|
+
set: undefined,
|
|
1555
|
+
nameRange: named.range,
|
|
1556
|
+
location,
|
|
1557
|
+
},
|
|
1439
1558
|
start,
|
|
1440
1559
|
);
|
|
1441
1560
|
}
|
|
@@ -1453,6 +1572,7 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1453
1572
|
arity: declaration.arity,
|
|
1454
1573
|
level: level ?? "Constant",
|
|
1455
1574
|
set: isBounded ? parseExpression() : undefined,
|
|
1575
|
+
nameRange: declaration.location.range,
|
|
1456
1576
|
location,
|
|
1457
1577
|
},
|
|
1458
1578
|
start,
|
|
@@ -1495,7 +1615,8 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1495
1615
|
const token = peek();
|
|
1496
1616
|
if (isAt("USE") || isAt("HIDE")) return parseUseOrHide();
|
|
1497
1617
|
if (isAt("INSTANCE")) {
|
|
1498
|
-
|
|
1618
|
+
const start = cursor.index;
|
|
1619
|
+
return withRange(parseInstance(undefined, [], false, getLocation(token)), start);
|
|
1499
1620
|
}
|
|
1500
1621
|
if (isAt("DEFINE") || isDefinitionStart()) {
|
|
1501
1622
|
const start = cursor.index;
|
|
@@ -1508,21 +1629,27 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1508
1629
|
if (accept("HAVE")) return { kind: "Have", expression: parseExpression() };
|
|
1509
1630
|
if (accept("TAKE")) {
|
|
1510
1631
|
const isBounded = isBoundAhead();
|
|
1511
|
-
const names = isBounded ? [] : parseSeparated(
|
|
1632
|
+
const names = getNames(isBounded ? [] : parseSeparated(expectName));
|
|
1512
1633
|
const bounds = isBounded ? parseBounds() : [];
|
|
1513
|
-
declareProofSymbols(names, bounds);
|
|
1514
|
-
return { kind: "Take", names, bounds };
|
|
1634
|
+
declareProofSymbols(names.names, bounds);
|
|
1635
|
+
return { kind: "Take", names: names.names, nameRanges: names.ranges, bounds };
|
|
1515
1636
|
}
|
|
1516
1637
|
if (accept("WITNESS")) {
|
|
1517
1638
|
return { kind: "Witness", expressions: parseSeparated(() => parseExpression()) };
|
|
1518
1639
|
}
|
|
1519
1640
|
if (accept("PICK")) {
|
|
1520
1641
|
const isNames = isNameListAhead(":");
|
|
1521
|
-
const names = isNames ? parseSeparated(
|
|
1642
|
+
const names = getNames(isNames ? parseSeparated(expectName) : []);
|
|
1522
1643
|
const bounds = isNames ? [] : parseBounds();
|
|
1523
|
-
declareProofSymbols(names, bounds);
|
|
1644
|
+
declareProofSymbols(names.names, bounds);
|
|
1524
1645
|
expect(":");
|
|
1525
|
-
return {
|
|
1646
|
+
return {
|
|
1647
|
+
kind: "Pick",
|
|
1648
|
+
names: names.names,
|
|
1649
|
+
nameRanges: names.ranges,
|
|
1650
|
+
bounds,
|
|
1651
|
+
body: parseExpression(),
|
|
1652
|
+
};
|
|
1526
1653
|
}
|
|
1527
1654
|
if (accept("CASE")) return { kind: "Case", expression: parseExpression() };
|
|
1528
1655
|
return {
|
|
@@ -1552,10 +1679,12 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1552
1679
|
const parseStep = (): ProofStep => {
|
|
1553
1680
|
const start = cursor.index;
|
|
1554
1681
|
const step = parseStepStart(isAt("QED", 1));
|
|
1682
|
+
const statementStart = cursor.index;
|
|
1555
1683
|
const scope = new Set<string>();
|
|
1556
1684
|
proofScopes.push(scope);
|
|
1557
1685
|
const body: StepBody = accept("QED") ? { kind: "Qed" } : parseStepBody();
|
|
1558
1686
|
const head = getRange(start);
|
|
1687
|
+
const statement = getRange(statementStart);
|
|
1559
1688
|
const hasProof = isProofStart(peek());
|
|
1560
1689
|
if (hasProof && !PROVABLE_STEPS.has(body.kind)) {
|
|
1561
1690
|
throw createError("Proof of a step that does not take a proof");
|
|
@@ -1563,7 +1692,7 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1563
1692
|
const proof = hasProof ? parseProof() : undefined;
|
|
1564
1693
|
proofScopes.pop();
|
|
1565
1694
|
if (body.kind !== "Assert" || body.isSuffices) scope.forEach(declareProofSymbol);
|
|
1566
|
-
return withRange({ ...step, body, head, proof }, start);
|
|
1695
|
+
return withRange({ ...step, body, head, statement, proof }, start);
|
|
1567
1696
|
};
|
|
1568
1697
|
|
|
1569
1698
|
const parseProofBody = (): Proof => {
|
|
@@ -1689,11 +1818,12 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1689
1818
|
if (token.kind === "ModuleEnd" || token.kind === "End") {
|
|
1690
1819
|
if (token.kind === "ModuleEnd") {
|
|
1691
1820
|
location.range = {
|
|
1692
|
-
module: name,
|
|
1821
|
+
module: openModules[0].name,
|
|
1693
1822
|
start: { line: location.line, column: location.column },
|
|
1694
1823
|
end: { line: token.line, column: token.endColumn },
|
|
1695
1824
|
};
|
|
1696
1825
|
}
|
|
1826
|
+
if (missingArguments.size > 0) throw createSanyError([...missingArguments.values()]);
|
|
1697
1827
|
openModules.pop();
|
|
1698
1828
|
recursiveScopes.pop();
|
|
1699
1829
|
return module;
|
|
@@ -1775,7 +1905,7 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1775
1905
|
);
|
|
1776
1906
|
continue;
|
|
1777
1907
|
}
|
|
1778
|
-
addDefinitionUnit(module,
|
|
1908
|
+
addDefinitionUnit(module, withRange(parseDefinitionUnit(true), tokenIndex));
|
|
1779
1909
|
continue;
|
|
1780
1910
|
}
|
|
1781
1911
|
}
|