tla-ts 0.0.3-dev.eba78ea → 0.0.3-dev.eed6eb1
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/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +150 -8
- package/dist/index.d.ts +150 -8
- 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 +1351 -20
- package/dist/run-cli.js +1351 -20
- package/dist/transfer.cjs +86 -28
- package/dist/transfer.js +86 -28
- package/package.json +5 -1
- package/src/ast.ts +57 -6
- package/src/bags.ts +4 -7
- package/src/builtins.ts +29 -11
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1365 -216
- package/src/cli.ts +8 -1
- package/src/codegen.ts +68 -18
- package/src/config.ts +254 -181
- package/src/environment.ts +457 -132
- package/src/errors.ts +217 -3
- package/src/evaluate.ts +723 -116
- package/src/exit-codes.ts +5 -4
- package/src/index.ts +1 -0
- package/src/instances.ts +4 -2
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +183 -37
- package/src/lexer.ts +122 -29
- package/src/live-check.ts +220 -102
- package/src/liveness.ts +216 -52
- package/src/obligation-expression.ts +2 -2
- package/src/obligation-source.ts +2 -0
- package/src/parallel-worker.ts +8 -3
- package/src/parallel.ts +56 -5
- package/src/parser.ts +445 -147
- package/src/pcal-ast.ts +770 -0
- package/src/pcal-parse.ts +1523 -0
- package/src/pcal-tokenize.ts +516 -0
- package/src/pcal-translate.ts +1230 -0
- package/src/pcal-validate.ts +454 -0
- package/src/randomization.ts +24 -7
- package/src/resolve.ts +1465 -411
- package/src/run-cli.ts +1179 -155
- package/src/runtime.ts +16 -0
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3128 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +545 -0
- package/src/sany-linter.ts +122 -0
- package/src/sany-modules.ts +1398 -0
- package/src/sany-nodes.ts +463 -0
- package/src/sany-parse-error.ts +2161 -0
- package/src/sany-report.ts +356 -0
- package/src/sany-selectors.ts +738 -0
- package/src/sany-source.ts +248 -0
- package/src/sany-xml.ts +1017 -0
- package/src/spec-description.ts +26 -7
- package/src/standard-modules.ts +203 -146
- package/src/standard-ranges.ts +116 -0
- package/src/state-graph.ts +29 -6
- package/src/subexpressions.ts +221 -161
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +160 -105
- package/src/symmetry.ts +180 -52
- package/src/tableau.ts +54 -25
- package/src/tlc-ext.ts +13 -17
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +46 -18
- package/src/tlc-order.ts +56 -6
- package/src/tlc-random.ts +37 -9
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-summary.ts +20 -5
- package/src/tlc-version.ts +18 -0
- package/src/transfer.ts +15 -3
- package/src/value-sources.ts +29 -0
- package/src/values.ts +696 -178
package/src/lexer.ts
CHANGED
|
@@ -12,9 +12,11 @@ type TokenKind =
|
|
|
12
12
|
| "ModuleEnd"
|
|
13
13
|
| "End";
|
|
14
14
|
|
|
15
|
+
// spelling holds the text of an operator written as a synonym, such as (+) for \oplus.
|
|
15
16
|
export interface Token {
|
|
16
17
|
kind: TokenKind;
|
|
17
18
|
text: string;
|
|
19
|
+
spelling?: string;
|
|
18
20
|
line: number;
|
|
19
21
|
column: number;
|
|
20
22
|
endColumn: number;
|
|
@@ -232,38 +234,84 @@ const SYMBOL_OPERATORS = [
|
|
|
232
234
|
"?",
|
|
233
235
|
];
|
|
234
236
|
|
|
237
|
+
// The Unicode forms of the operators SANY's grammar, javacc/tla+.jj, reads, as their ASCII forms.
|
|
235
238
|
const UNICODE_OPERATORS = new Map([
|
|
239
|
+
["∃", "\\E"],
|
|
240
|
+
["∀", "\\A"],
|
|
241
|
+
["∷", "::"],
|
|
242
|
+
["≜", "=="],
|
|
243
|
+
["⟨", "<<"],
|
|
244
|
+
["⟩_", ">>_"],
|
|
245
|
+
["⟩", ">>"],
|
|
246
|
+
["→", "->"],
|
|
247
|
+
["←", "<-"],
|
|
248
|
+
["↦", "|->"],
|
|
249
|
+
["⁺", "^+"],
|
|
250
|
+
["¬", "~"],
|
|
251
|
+
["□", "[]"],
|
|
252
|
+
["◇", "<>"],
|
|
236
253
|
["∧", "/\\"],
|
|
237
254
|
["∨", "\\/"],
|
|
238
|
-
["
|
|
239
|
-
["
|
|
240
|
-
["
|
|
255
|
+
["∈", "\\in"],
|
|
256
|
+
["≈", "\\approx"],
|
|
257
|
+
["≔", ":="],
|
|
258
|
+
["≍", "\\asymp"],
|
|
259
|
+
["◯", "\\bigcirc"],
|
|
260
|
+
["⩴", "::="],
|
|
261
|
+
["●", "\\bullet"],
|
|
262
|
+
["∩", "\\cap"],
|
|
263
|
+
["⋅", "\\cdot"],
|
|
264
|
+
["∘", "\\o"],
|
|
265
|
+
["≅", "\\cong"],
|
|
266
|
+
["∪", "\\cup"],
|
|
267
|
+
["÷", "\\div"],
|
|
268
|
+
["≐", "\\doteq"],
|
|
269
|
+
["‥", ".."],
|
|
270
|
+
["…", "..."],
|
|
241
271
|
["≡", "<=>"],
|
|
272
|
+
["‼", "!!"],
|
|
273
|
+
["≥", ">="],
|
|
274
|
+
["≫", "\\gg"],
|
|
242
275
|
["⇔", "<=>"],
|
|
243
|
-
["
|
|
276
|
+
["⇒", "=>"],
|
|
277
|
+
["⫤", "=|"],
|
|
278
|
+
["↝", "~>"],
|
|
279
|
+
["≤", "<="],
|
|
280
|
+
["≪", "\\ll"],
|
|
281
|
+
["⊣", "-|"],
|
|
282
|
+
["≠", "#"],
|
|
244
283
|
["∉", "\\notin"],
|
|
245
|
-
["
|
|
284
|
+
["⊙", "\\odot"],
|
|
285
|
+
["⊖", "\\ominus"],
|
|
286
|
+
["⊕", "\\oplus"],
|
|
287
|
+
["⊘", "\\oslash"],
|
|
288
|
+
["⊗", "\\otimes"],
|
|
289
|
+
["⇸", "-+->"],
|
|
290
|
+
["≺", "\\prec"],
|
|
291
|
+
["⪯", "\\preceq"],
|
|
292
|
+
["∝", "\\propto"],
|
|
293
|
+
["⁇", "??"],
|
|
294
|
+
["⊨", "|="],
|
|
295
|
+
["⊢", "|-"],
|
|
296
|
+
["∼", "\\sim"],
|
|
297
|
+
["≃", "\\simeq"],
|
|
298
|
+
["⊓", "\\sqcap"],
|
|
299
|
+
["⊔", "\\sqcup"],
|
|
300
|
+
["⊏", "\\sqsubset"],
|
|
301
|
+
["⊑", "\\sqsubseteq"],
|
|
302
|
+
["⊐", "\\sqsupset"],
|
|
303
|
+
["⊒", "\\sqsupseteq"],
|
|
304
|
+
["⋆", "\\star"],
|
|
246
305
|
["⊂", "\\subset"],
|
|
247
|
-
["
|
|
306
|
+
["⊆", "\\subseteq"],
|
|
307
|
+
["≻", "\\succ"],
|
|
308
|
+
["⪰", "\\succeq"],
|
|
248
309
|
["⊃", "\\supset"],
|
|
249
|
-
["
|
|
250
|
-
["∩", "\\cap"],
|
|
310
|
+
["⊇", "\\supseteq"],
|
|
251
311
|
["×", "\\X"],
|
|
252
|
-
["
|
|
253
|
-
["
|
|
254
|
-
["
|
|
255
|
-
["≤", "<="],
|
|
256
|
-
["≥", ">="],
|
|
257
|
-
["↦", "|->"],
|
|
258
|
-
["→", "->"],
|
|
259
|
-
["⟨", "<<"],
|
|
260
|
-
["⟩", ">>"],
|
|
261
|
-
["□", "[]"],
|
|
262
|
-
["◇", "<>"],
|
|
263
|
-
["≜", "=="],
|
|
264
|
-
["′", "'"],
|
|
265
|
-
["∘", "\\o"],
|
|
266
|
-
["⋅", "\\cdot"],
|
|
312
|
+
["⊎", "\\uplus"],
|
|
313
|
+
["‖", "||"],
|
|
314
|
+
["≀", "\\wr"],
|
|
267
315
|
]);
|
|
268
316
|
|
|
269
317
|
const BASED_NUMBER = /^\\([bB][01]+|[oO][0-7]+|[hH][0-9a-fA-F]+)/;
|
|
@@ -301,13 +349,27 @@ export const matchOperator = (source: string, index: number): OperatorMatch | un
|
|
|
301
349
|
const operator = BACKSLASH_OPERATORS.get(word.slice(0, length.value));
|
|
302
350
|
return { text: operator ?? "\\", length: operator === undefined ? 1 : length.value + 1 };
|
|
303
351
|
}
|
|
304
|
-
const
|
|
305
|
-
|
|
352
|
+
const unicodeSymbol = [source.slice(index, index + 2), character].find((candidate) =>
|
|
353
|
+
UNICODE_OPERATORS.has(candidate),
|
|
354
|
+
);
|
|
355
|
+
if (unicodeSymbol !== undefined) {
|
|
356
|
+
return { text: UNICODE_OPERATORS.get(unicodeSymbol) ?? "", length: unicodeSymbol.length };
|
|
357
|
+
}
|
|
306
358
|
const symbol = SYMBOL_OPERATORS.find((candidate) => source.startsWith(candidate, index));
|
|
307
359
|
if (symbol) return { text: SYMBOL_ALIASES.get(symbol) ?? symbol, length: symbol.length };
|
|
308
360
|
return character === "\\" ? { text: "\\", length: 1 } : undefined;
|
|
309
361
|
};
|
|
310
362
|
|
|
363
|
+
// TLC's configuration parser reads its tokens with SANY's lexer, so it reads a Unicode operator, or
|
|
364
|
+
// ℕ, ℤ, or ℝ, as one token, which it compares as written with the words it expects.
|
|
365
|
+
const UNICODE_NAMES = new Set(["ℕ", "ℤ", "ℝ"]);
|
|
366
|
+
export const matchUnicodeToken = (source: string, index: number): OperatorMatch | undefined => {
|
|
367
|
+
const token = [source.slice(index, index + 2), source[index]].find(
|
|
368
|
+
(candidate) => UNICODE_OPERATORS.has(candidate) || UNICODE_NAMES.has(candidate),
|
|
369
|
+
);
|
|
370
|
+
return token === undefined ? undefined : { text: token, length: token.length };
|
|
371
|
+
};
|
|
372
|
+
|
|
311
373
|
const isDigit = (character: string | undefined) =>
|
|
312
374
|
character !== undefined && character >= "0" && character <= "9";
|
|
313
375
|
|
|
@@ -335,6 +397,10 @@ const matchStep = (source: string, index: number) => {
|
|
|
335
397
|
);
|
|
336
398
|
};
|
|
337
399
|
|
|
400
|
+
// SANY's lexer reads @ as an identifier, which stands for the value an EXCEPT changes only alone.
|
|
401
|
+
export const readAtAsIdentifier = (token: Token): Token =>
|
|
402
|
+
token.kind === "Operator" && token.text === "@" ? { ...token, kind: "Identifier" } : token;
|
|
403
|
+
|
|
338
404
|
const TAB_SIZE = 8;
|
|
339
405
|
|
|
340
406
|
const getWidthAfter = (width: number, character: string | undefined) =>
|
|
@@ -367,9 +433,16 @@ export const tokenize = (source: string): Token[] => {
|
|
|
367
433
|
}
|
|
368
434
|
return getWidthAfter(scan.width, source[cursor.index]);
|
|
369
435
|
};
|
|
370
|
-
const pushToken = (kind: TokenKind, text: string, length: number) => {
|
|
436
|
+
const pushToken = (kind: TokenKind, text: string, length: number, spelling?: string) => {
|
|
371
437
|
const column = getColumn();
|
|
372
|
-
tokens.push({
|
|
438
|
+
tokens.push({
|
|
439
|
+
kind,
|
|
440
|
+
text,
|
|
441
|
+
spelling,
|
|
442
|
+
line: cursor.line,
|
|
443
|
+
column,
|
|
444
|
+
endColumn: column + length - 1,
|
|
445
|
+
});
|
|
373
446
|
cursor.index += length;
|
|
374
447
|
};
|
|
375
448
|
const advanceOver = (length: number) => {
|
|
@@ -442,11 +515,14 @@ export const tokenize = (source: string): Token[] => {
|
|
|
442
515
|
const characters: string[] = [];
|
|
443
516
|
advanceOver(1);
|
|
444
517
|
while (source[cursor.index] !== '"') {
|
|
445
|
-
if (cursor.index >= source.length || source[cursor.index]
|
|
518
|
+
if (cursor.index >= source.length || "\n\r".includes(source[cursor.index])) {
|
|
446
519
|
throw createError("Unterminated string");
|
|
447
520
|
}
|
|
448
521
|
if (source[cursor.index] === "\\") {
|
|
449
522
|
const escaped = source[cursor.index + 1];
|
|
523
|
+
if (escaped === undefined || !'ntrf\\"'.includes(escaped)) {
|
|
524
|
+
throw createError("Invalid escape in string");
|
|
525
|
+
}
|
|
450
526
|
characters.push({ n: "\n", t: "\t", r: "\r", f: "\f" }[escaped] ?? escaped);
|
|
451
527
|
advanceOver(2);
|
|
452
528
|
continue;
|
|
@@ -479,6 +555,12 @@ export const tokenize = (source: string): Token[] => {
|
|
|
479
555
|
pushToken(number.includes(".") ? "Decimal" : "Number", number, number.length);
|
|
480
556
|
continue;
|
|
481
557
|
}
|
|
558
|
+
// A word needs a letter to be a name, so SANY reads one without as underscores and numbers.
|
|
559
|
+
const part = /^(_|\d+)/.exec(word)?.[0];
|
|
560
|
+
if (part !== undefined && !/[A-Za-z]/.test(word)) {
|
|
561
|
+
pushToken(part === "_" ? "Operator" : "Number", part, part.length);
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
482
564
|
if (word.startsWith("WF_") || word.startsWith("SF_")) {
|
|
483
565
|
pushToken("Keyword", word.slice(0, 3), 3);
|
|
484
566
|
continue;
|
|
@@ -488,6 +570,11 @@ export const tokenize = (source: string): Token[] => {
|
|
|
488
570
|
pushToken(KEYWORDS.has(word) ? "Keyword" : "Identifier", name, word.length);
|
|
489
571
|
continue;
|
|
490
572
|
}
|
|
573
|
+
if ("ℕℤℝ".includes(character)) {
|
|
574
|
+
pushToken("Identifier", names.get(character) ?? character, 1);
|
|
575
|
+
names.set(character, character);
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
491
578
|
const stepLength = matchStep(source, cursor.index);
|
|
492
579
|
if (stepLength > 0) {
|
|
493
580
|
pushToken("Step", source.slice(cursor.index, cursor.index + stepLength), stepLength);
|
|
@@ -495,7 +582,13 @@ export const tokenize = (source: string): Token[] => {
|
|
|
495
582
|
}
|
|
496
583
|
const operator = matchOperator(source, cursor.index);
|
|
497
584
|
if (operator) {
|
|
498
|
-
|
|
585
|
+
const spelling = source.slice(cursor.index, cursor.index + operator.length);
|
|
586
|
+
pushToken(
|
|
587
|
+
"Operator",
|
|
588
|
+
operator.text,
|
|
589
|
+
operator.length,
|
|
590
|
+
spelling === operator.text ? undefined : spelling,
|
|
591
|
+
);
|
|
499
592
|
continue;
|
|
500
593
|
}
|
|
501
594
|
throw createError(`Unexpected character ${JSON.stringify(character)}`);
|