tla-ts 0.0.8 → 0.0.9-dev.0dd11f695

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.
Files changed (119) hide show
  1. package/README.md +30 -0
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +15 -15
  5. package/dist/deciders.js +40 -40
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +98 -19
  8. package/dist/index.d.ts +98 -19
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +116 -36
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +143 -31
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +1 -1
  20. package/dist/transfer.cjs +128 -106
  21. package/dist/transfer.js +128 -106
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +3 -1
  25. package/src/ast.ts +7 -21
  26. package/src/bags.ts +99 -99
  27. package/src/builtins.ts +44 -75
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +605 -311
  30. package/src/cli/options.ts +12 -3
  31. package/src/cli/run.ts +2 -2
  32. package/src/cli/runtime-invariants.ts +135 -0
  33. package/src/cli/shared.ts +20 -9
  34. package/src/cli/tlc-arguments.ts +646 -0
  35. package/src/cli/tlc-usage.ts +362 -0
  36. package/src/cli/tlc.ts +571 -185
  37. package/src/cli/typescript.ts +26 -0
  38. package/src/cli/xml-exporter.ts +4 -10
  39. package/src/codegen.ts +190 -51
  40. package/src/config.ts +101 -68
  41. package/src/coverage.ts +855 -0
  42. package/src/dependencies.ts +340 -24
  43. package/src/dfid.ts +636 -0
  44. package/src/environment.ts +289 -109
  45. package/src/errors.ts +142 -45
  46. package/src/evaluate.ts +734 -980
  47. package/src/exit-codes.ts +37 -1
  48. package/src/index.ts +3 -0
  49. package/src/instances.ts +85 -9
  50. package/src/java-overrides.ts +2 -12
  51. package/src/json-reader.ts +456 -0
  52. package/src/json.ts +262 -139
  53. package/src/levels.ts +2 -3
  54. package/src/lexer.ts +150 -70
  55. package/src/liveness-checker.ts +10 -18
  56. package/src/liveness.ts +122 -64
  57. package/src/parallel-worker.ts +14 -10
  58. package/src/parallel.ts +41 -17
  59. package/src/parser.ts +436 -90
  60. package/src/pcal/ast.ts +7 -28
  61. package/src/pcal/parse.ts +11 -39
  62. package/src/pcal/tokenize.ts +4 -20
  63. package/src/pcal/translate.ts +10 -42
  64. package/src/pcal/validate.ts +3 -21
  65. package/src/pretty-print.ts +1 -2
  66. package/src/prover/smt/solver/solver.ts +31 -27
  67. package/src/randomization.ts +84 -35
  68. package/src/resolve.ts +18 -60
  69. package/src/runtime.ts +11 -4
  70. package/src/sany/builtins.ts +3 -4
  71. package/src/sany/generator.ts +128 -176
  72. package/src/sany/levels.ts +6 -30
  73. package/src/sany/lexer.ts +7 -23
  74. package/src/sany/linter.ts +31 -29
  75. package/src/sany/modules.ts +1 -5
  76. package/src/sany/nodes.ts +4 -28
  77. package/src/sany/parse-error.ts +44 -100
  78. package/src/sany/report.ts +25 -40
  79. package/src/sany/selectors.ts +8 -22
  80. package/src/sany/source.ts +8 -15
  81. package/src/sany/xml.ts +11 -42
  82. package/src/search.ts +550 -150
  83. package/src/simulate.ts +694 -0
  84. package/src/spec-description.ts +167 -49
  85. package/src/standard-definitions.ts +2 -3
  86. package/src/standard-modules.ts +264 -68
  87. package/src/state-graph.ts +51 -18
  88. package/src/subexpressions.ts +31 -5
  89. package/src/successors.ts +269 -85
  90. package/src/symmetry.ts +59 -147
  91. package/src/tableau.ts +1 -2
  92. package/src/tlc/fingerprint.ts +226 -151
  93. package/src/tlc/jar-data.ts +113 -6
  94. package/src/tlc/messages.ts +122 -37
  95. package/src/tlc/order.ts +56 -82
  96. package/src/tlc/random.ts +16 -16
  97. package/src/tlc/replay.ts +564 -212
  98. package/src/tlc/summary.ts +2 -4
  99. package/src/tlc/tlc-operators.ts +81 -36
  100. package/src/tlc/tlcext-operators.ts +138 -117
  101. package/src/tlc/trace-spec.ts +273 -0
  102. package/src/tlc/value-stream.ts +143 -0
  103. package/src/tlc/version.ts +2 -4
  104. package/src/typescript/actions.ts +494 -0
  105. package/src/typescript/collections.ts +615 -0
  106. package/src/typescript/compile.ts +70 -0
  107. package/src/typescript/context.ts +106 -0
  108. package/src/typescript/emit.ts +122 -0
  109. package/src/typescript/expressions.ts +508 -0
  110. package/src/typescript/formula.ts +160 -0
  111. package/src/typescript/functions.ts +295 -0
  112. package/src/typescript/model.ts +164 -0
  113. package/src/typescript/names.ts +116 -0
  114. package/src/typescript/program.ts +51 -0
  115. package/src/typescript/properties.ts +148 -0
  116. package/src/typescript/scope.ts +117 -0
  117. package/src/typescript/steps.ts +175 -0
  118. package/src/typescript/types.ts +178 -0
  119. package/src/values.ts +910 -318
package/src/lexer.ts CHANGED
@@ -234,7 +234,6 @@ const SYMBOL_OPERATORS = [
234
234
  "?",
235
235
  ];
236
236
 
237
- // The Unicode forms of the operators SANY's grammar, javacc/tla+.jj, reads, as their ASCII forms.
238
237
  const UNICODE_OPERATORS = new Map([
239
238
  ["∃", "\\E"],
240
239
  ["∀", "\\A"],
@@ -314,33 +313,103 @@ const UNICODE_OPERATORS = new Map([
314
313
  ["≀", "\\wr"],
315
314
  ]);
316
315
 
317
- const BASED_NUMBER = /^\\([bB][01]+|[oO][0-7]+|[hH][0-9a-fA-F]+)/;
318
-
319
316
  const NUMBER_BASES = new Map([
320
317
  ["b", 2],
321
318
  ["o", 8],
322
319
  ["h", 16],
323
320
  ]);
324
321
 
325
- // A numeral token keeps its text as typed, such as \hFF, so errors can quote it as TLC does.
322
+ // A numeral token keeps its text, such as \hFF, so errors can quote it as TLC does.
326
323
  export const getNumeralValue = (text: string) =>
327
324
  text.startsWith("\\")
328
325
  ? parseInt(text.slice(2), NUMBER_BASES.get(text[1].toLowerCase()))
329
326
  : Number(text);
330
327
 
331
- const MODULE_HEADER = /-{4,}[ \t]*MODULE\b/;
328
+ const MODULE_HEADER = /-{4,} *MODULE\b/;
329
+
330
+ const CODE_TAB = 9;
331
+ const CODE_NEWLINE = 10;
332
+ const CODE_RETURN = 13;
333
+ const CODE_SPACE = 32;
334
+ const CODE_QUOTE = 34;
335
+ const CODE_OPEN_PAREN = 40;
336
+ const CODE_STAR = 42;
337
+ const CODE_DASH = 45;
338
+ const CODE_DOT = 46;
339
+ const CODE_LESS_THAN = 60;
340
+ const CODE_EQUALS = 61;
341
+ const CODE_BACKSLASH = 92;
342
+ const CODE_UNDERSCORE = 95;
343
+
344
+ const DIGIT = 1;
345
+ const LETTER = 2;
346
+ const UNDERSCORE = 4;
347
+ const BINARY_DIGIT = 8;
348
+ const OCTAL_DIGIT = 16;
349
+ const HEX_DIGIT = 32;
350
+ const IDENTIFIER = DIGIT | LETTER | UNDERSCORE;
351
+
352
+ const LOWERCASE = "abcdefghijklmnopqrstuvwxyz";
353
+
354
+ const CHARACTER_CLASSES = new Uint8Array(128);
355
+ new Map([
356
+ ["0123456789", DIGIT | HEX_DIGIT],
357
+ [LOWERCASE + LOWERCASE.toUpperCase(), LETTER],
358
+ ["_", UNDERSCORE],
359
+ ["01", BINARY_DIGIT],
360
+ ["01234567", OCTAL_DIGIT],
361
+ ["abcdefABCDEF", HEX_DIGIT],
362
+ ]).forEach((characterClass, characters) => {
363
+ for (const character of characters) {
364
+ CHARACTER_CLASSES[character.charCodeAt(0)] |= characterClass;
365
+ }
366
+ });
367
+
368
+ // charCodeAt past the end of a source gives NaN, which is in no class.
369
+ const isInClass = (code: number, characterClass: number) =>
370
+ code < 128 && (CHARACTER_CLASSES[code] & characterClass) !== 0;
332
371
 
333
- const isIdentifierCharacter = (character: string) => /[A-Za-z0-9_]/.test(character);
372
+ const skipClass = (source: string, index: number, characterClass: number) => {
373
+ let end = index;
374
+ while (isInClass(source.charCodeAt(end), characterClass)) end++;
375
+ return end;
376
+ };
334
377
 
335
378
  interface OperatorMatch {
336
379
  text: string;
337
380
  length: number;
338
381
  }
339
382
 
383
+ // In the order of SYMBOL_OPERATORS, which lists a longer operator before its prefixes.
384
+ const SYMBOL_OPERATORS_BY_START = new Map<number, string[]>();
385
+ SYMBOL_OPERATORS.forEach((symbol) => {
386
+ const start = symbol.charCodeAt(0);
387
+ const candidates = SYMBOL_OPERATORS_BY_START.get(start) ?? [];
388
+ candidates.push(symbol);
389
+ SYMBOL_OPERATORS_BY_START.set(start, candidates);
390
+ });
391
+
392
+ const matchSymbolOperator = (source: string, index: number) => {
393
+ const candidates = SYMBOL_OPERATORS_BY_START.get(source.charCodeAt(index));
394
+ if (candidates === undefined) return undefined;
395
+ for (let position = 0; position < candidates.length; position++) {
396
+ if (source.startsWith(candidates[position], index)) return candidates[position];
397
+ }
398
+ return undefined;
399
+ };
400
+
401
+ const matchUnicodeOperator = (source: string, index: number) => {
402
+ if (source.charCodeAt(index) < 128) return undefined;
403
+ const pair = source.slice(index, index + 2);
404
+ if (UNICODE_OPERATORS.has(pair)) return pair;
405
+ const single = source[index];
406
+ return UNICODE_OPERATORS.has(single) ? single : undefined;
407
+ };
408
+
340
409
  export const matchOperator = (source: string, index: number): OperatorMatch | undefined => {
341
- const character = source[index];
342
- if (character === "\\" && /[A-Za-z]/.test(source[index + 1] ?? "")) {
343
- const word = /^[A-Za-z]+/.exec(source.slice(index + 1))?.[0] ?? "";
410
+ const code = source.charCodeAt(index);
411
+ if (code === CODE_BACKSLASH && isInClass(source.charCodeAt(index + 1), LETTER)) {
412
+ const word = source.slice(index + 1, skipClass(source, index + 1, LETTER));
344
413
  // Like SANY, read the longest operator that the word starts with, so S\used is S \ used.
345
414
  const length = { value: word.length };
346
415
  while (length.value > 0 && !BACKSLASH_OPERATORS.has(word.slice(0, length.value))) {
@@ -349,19 +418,16 @@ export const matchOperator = (source: string, index: number): OperatorMatch | un
349
418
  const operator = BACKSLASH_OPERATORS.get(word.slice(0, length.value));
350
419
  return { text: operator ?? "\\", length: operator === undefined ? 1 : length.value + 1 };
351
420
  }
352
- const unicodeSymbol = [source.slice(index, index + 2), character].find((candidate) =>
353
- UNICODE_OPERATORS.has(candidate),
354
- );
421
+ const unicodeSymbol = matchUnicodeOperator(source, index);
355
422
  if (unicodeSymbol !== undefined) {
356
423
  return { text: UNICODE_OPERATORS.get(unicodeSymbol) ?? "", length: unicodeSymbol.length };
357
424
  }
358
- const symbol = SYMBOL_OPERATORS.find((candidate) => source.startsWith(candidate, index));
425
+ const symbol = matchSymbolOperator(source, index);
359
426
  if (symbol) return { text: SYMBOL_ALIASES.get(symbol) ?? symbol, length: symbol.length };
360
- return character === "\\" ? { text: "\\", length: 1 } : undefined;
427
+ return code === CODE_BACKSLASH ? { text: "\\", length: 1 } : undefined;
361
428
  };
362
429
 
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.
430
+ // TLC's config parser reads ℕ, ℤ, ℝ, or a Unicode operator as one token, compared as written.
365
431
  const UNICODE_NAMES = new Set(["ℕ", "ℤ", "ℝ"]);
366
432
  export const matchUnicodeToken = (source: string, index: number): OperatorMatch | undefined => {
367
433
  const token = [source.slice(index, index + 2), source[index]].find(
@@ -370,9 +436,6 @@ export const matchUnicodeToken = (source: string, index: number): OperatorMatch
370
436
  return token === undefined ? undefined : { text: token, length: token.length };
371
437
  };
372
438
 
373
- const isDigit = (character: string | undefined) =>
374
- character !== undefined && character >= "0" && character <= "9";
375
-
376
439
  export const skipWhile = (
377
440
  source: string,
378
441
  index: number,
@@ -383,15 +446,15 @@ export const skipWhile = (
383
446
  return end.value;
384
447
  };
385
448
 
386
- // The length of a step number such as <1>a., <+>, or <2>*., which SANY reads as one token wherever
387
- // it appears.
388
- const matchStep = (source: string, index: number) => {
389
- if (source[index] !== "<") return 0;
449
+ // SANY reads a step number as one token anywhere, and tlapm reads no name after <*> or <+>.
450
+ const matchStep = (source: string, index: number, isTlapm: boolean) => {
390
451
  const isImplicit = source[index + 1] === "+" || source[index + 1] === "*";
391
- const levelEnd = isImplicit ? index + 2 : skipWhile(source, index + 1, isDigit);
452
+ const levelEnd = isImplicit ? index + 2 : skipClass(source, index + 1, DIGIT);
392
453
  if (levelEnd === index + 1 || source[levelEnd] !== ">") return 0;
393
- const nameEnd = skipWhile(source, levelEnd + 1, isIdentifierCharacter);
394
- const isDash = nameEnd === levelEnd + 1 && (source[nameEnd] === "*" || source[nameEnd] === "-");
454
+ const isNamed = !isImplicit || !isTlapm;
455
+ const nameEnd = isNamed ? skipClass(source, levelEnd + 1, IDENTIFIER) : levelEnd + 1;
456
+ const isDash =
457
+ isNamed && nameEnd === levelEnd + 1 && (source[nameEnd] === "*" || source[nameEnd] === "-");
395
458
  return (
396
459
  skipWhile(source, isDash ? nameEnd + 1 : nameEnd, (character) => character === ".") - index
397
460
  );
@@ -403,10 +466,26 @@ export const readAtAsIdentifier = (token: Token): Token =>
403
466
 
404
467
  const TAB_SIZE = 8;
405
468
 
406
- const getWidthAfter = (width: number, character: string | undefined) =>
407
- character === "\t" ? width + TAB_SIZE - (width % TAB_SIZE) : width + 1;
469
+ const STRING_ESCAPES: Record<string, string> = { n: "\n", t: "\t", r: "\r", f: "\f" };
470
+
471
+ const getWidthAfter = (width: number, code: number) =>
472
+ code === CODE_TAB ? width + TAB_SIZE - (width % TAB_SIZE) : width + 1;
473
+
474
+ const BASED_NUMBER_DIGITS = new Map([
475
+ ["b", BINARY_DIGIT],
476
+ ["o", OCTAL_DIGIT],
477
+ ["h", HEX_DIGIT],
478
+ ]);
479
+
480
+ export const matchBasedNumber = (source: string, index: number) => {
481
+ if (source.charCodeAt(index) !== CODE_BACKSLASH) return 0;
482
+ const digits = BASED_NUMBER_DIGITS.get(source.charAt(index + 1).toLowerCase());
483
+ if (digits === undefined) return 0;
484
+ const end = skipClass(source, index + 2, digits);
485
+ return end === index + 2 ? 0 : end - index;
486
+ };
408
487
 
409
- export const tokenize = (source: string): Token[] => {
488
+ export const tokenize = (source: string, isTlapm = false): Token[] => {
410
489
  const headerMatch = MODULE_HEADER.exec(source);
411
490
  if (!headerMatch)
412
491
  throw new TlaSyntaxError("Expected a module header such as ---- MODULE Name ----");
@@ -429,9 +508,9 @@ export const tokenize = (source: string): Token[] => {
429
508
  scan.width = 0;
430
509
  }
431
510
  for (; scan.position < cursor.index; scan.position++) {
432
- scan.width = getWidthAfter(scan.width, source[scan.position]);
511
+ scan.width = getWidthAfter(scan.width, source.charCodeAt(scan.position));
433
512
  }
434
- return getWidthAfter(scan.width, source[cursor.index]);
513
+ return getWidthAfter(scan.width, source.charCodeAt(cursor.index));
435
514
  };
436
515
  const pushToken = (kind: TokenKind, text: string, length: number, spelling?: string) => {
437
516
  const column = getColumn();
@@ -447,7 +526,7 @@ export const tokenize = (source: string): Token[] => {
447
526
  };
448
527
  const advanceOver = (length: number) => {
449
528
  for (let offset = 0; offset < length; offset++) {
450
- if (source[cursor.index] === "\n") {
529
+ if (source.charCodeAt(cursor.index) === CODE_NEWLINE) {
451
530
  cursor.line++;
452
531
  cursor.lineStart = cursor.index + 1;
453
532
  }
@@ -463,18 +542,18 @@ export const tokenize = (source: string): Token[] => {
463
542
  });
464
543
 
465
544
  while (cursor.index < source.length) {
466
- const character = source[cursor.index];
545
+ const code = source.charCodeAt(cursor.index);
467
546
 
468
- if (character === "\n" || character === " " || character === "\t" || character === "\r") {
547
+ if (code === CODE_NEWLINE || code === CODE_SPACE || code === CODE_TAB || code === CODE_RETURN) {
469
548
  advanceOver(1);
470
549
  continue;
471
550
  }
472
- if (source.startsWith("\\*", cursor.index)) {
473
- const lineEnd = source.indexOf("\n", cursor.index);
474
- advanceOver((lineEnd === -1 ? source.length : lineEnd) - cursor.index);
551
+ if (code === CODE_BACKSLASH && source.charCodeAt(cursor.index + 1) === CODE_STAR) {
552
+ const lineEnd = skipWhile(source, cursor.index, (next) => next !== "\n" && next !== "\r");
553
+ advanceOver(lineEnd - cursor.index);
475
554
  continue;
476
555
  }
477
- if (source.startsWith("(*", cursor.index)) {
556
+ if (code === CODE_OPEN_PAREN && source.charCodeAt(cursor.index + 1) === CODE_STAR) {
478
557
  const depth = { value: 0 };
479
558
  do {
480
559
  if (cursor.index >= source.length) throw createError("Unterminated comment");
@@ -490,40 +569,36 @@ export const tokenize = (source: string): Token[] => {
490
569
  } while (depth.value > 0);
491
570
  continue;
492
571
  }
493
- if (source.startsWith("----", cursor.index)) {
572
+ if (code === CODE_DASH && source.startsWith("----", cursor.index)) {
494
573
  const length = skipWhile(source, cursor.index, (next) => next === "-") - cursor.index;
495
- if (
496
- source
497
- .slice(cursor.index + length)
498
- .trimStart()
499
- .startsWith("MODULE")
500
- )
501
- cursor.moduleDepth++;
574
+ const keyword = skipWhile(source, cursor.index + length, (next) => next === " ");
575
+ if (source.startsWith("MODULE", keyword)) cursor.moduleDepth++;
502
576
  pushToken("Separator", "----", length);
503
577
  continue;
504
578
  }
505
- if (source.startsWith("====", cursor.index)) {
579
+ if (code === CODE_EQUALS && source.startsWith("====", cursor.index)) {
506
580
  const length = skipWhile(source, cursor.index, (next) => next === "=") - cursor.index;
507
581
  pushToken("ModuleEnd", "====", length);
508
582
  cursor.moduleDepth--;
509
583
  if (cursor.moduleDepth <= 0) break;
510
584
  continue;
511
585
  }
512
- if (character === '"') {
586
+ if (code === CODE_QUOTE) {
513
587
  const line = cursor.line;
514
588
  const column = getColumn();
515
589
  const characters: string[] = [];
516
590
  advanceOver(1);
517
- while (source[cursor.index] !== '"') {
518
- if (cursor.index >= source.length || "\n\r".includes(source[cursor.index])) {
591
+ while (source.charCodeAt(cursor.index) !== CODE_QUOTE) {
592
+ const next = source.charCodeAt(cursor.index);
593
+ if (cursor.index >= source.length || next === CODE_NEWLINE || next === CODE_RETURN) {
519
594
  throw createError("Unterminated string");
520
595
  }
521
- if (source[cursor.index] === "\\") {
596
+ if (next === CODE_BACKSLASH) {
522
597
  const escaped = source[cursor.index + 1];
523
598
  if (escaped === undefined || !'ntrf\\"'.includes(escaped)) {
524
599
  throw createError("Invalid escape in string");
525
600
  }
526
- characters.push({ n: "\n", t: "\t", r: "\r", f: "\f" }[escaped] ?? escaped);
601
+ characters.push(STRING_ESCAPES[escaped] ?? escaped);
527
602
  advanceOver(2);
528
603
  continue;
529
604
  }
@@ -540,24 +615,26 @@ export const tokenize = (source: string): Token[] => {
540
615
  });
541
616
  continue;
542
617
  }
543
- const basedNumber = BASED_NUMBER.exec(source.slice(cursor.index, cursor.index + 64));
544
- if (basedNumber) {
545
- pushToken("Number", basedNumber[0], basedNumber[0].length);
618
+ const basedLength = matchBasedNumber(source, cursor.index);
619
+ if (basedLength > 0) {
620
+ pushToken("Number", source.slice(cursor.index, cursor.index + basedLength), basedLength);
546
621
  continue;
547
622
  }
548
- if (isIdentifierCharacter(character)) {
549
- const word = source.slice(
550
- cursor.index,
551
- skipWhile(source, cursor.index, isIdentifierCharacter),
552
- );
553
- if (/^\d+$/.test(word)) {
554
- const number = /^\d+(\.\d+)?/.exec(source.slice(cursor.index))?.[0] ?? word;
555
- pushToken(number.includes(".") ? "Decimal" : "Number", number, number.length);
623
+ if (isInClass(code, IDENTIFIER)) {
624
+ const wordEnd = skipClass(source, cursor.index, IDENTIFIER);
625
+ const word = source.slice(cursor.index, wordEnd);
626
+ const digitsEnd = skipClass(source, cursor.index, DIGIT);
627
+ if (digitsEnd === wordEnd) {
628
+ const fractionEnd =
629
+ source.charCodeAt(wordEnd) === CODE_DOT ? skipClass(source, wordEnd + 1, DIGIT) : wordEnd;
630
+ const isDecimal = fractionEnd > wordEnd + 1;
631
+ const number = isDecimal ? source.slice(cursor.index, fractionEnd) : word;
632
+ pushToken(isDecimal ? "Decimal" : "Number", number, number.length);
556
633
  continue;
557
634
  }
558
635
  // 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)) {
636
+ if (!/[A-Za-z]/.test(word)) {
637
+ const part = code === CODE_UNDERSCORE ? "_" : source.slice(cursor.index, digitsEnd);
561
638
  pushToken(part === "_" ? "Operator" : "Number", part, part.length);
562
639
  continue;
563
640
  }
@@ -570,15 +647,18 @@ export const tokenize = (source: string): Token[] => {
570
647
  pushToken(KEYWORDS.has(word) ? "Keyword" : "Identifier", name, word.length);
571
648
  continue;
572
649
  }
573
- if ("ℕℤℝ".includes(character)) {
650
+ const character = source[cursor.index];
651
+ if (code >= 128 && UNICODE_NAMES.has(character)) {
574
652
  pushToken("Identifier", names.get(character) ?? character, 1);
575
653
  names.set(character, character);
576
654
  continue;
577
655
  }
578
- const stepLength = matchStep(source, cursor.index);
579
- if (stepLength > 0) {
580
- pushToken("Step", source.slice(cursor.index, cursor.index + stepLength), stepLength);
581
- continue;
656
+ if (code === CODE_LESS_THAN) {
657
+ const stepLength = matchStep(source, cursor.index, isTlapm);
658
+ if (stepLength > 0) {
659
+ pushToken("Step", source.slice(cursor.index, cursor.index + stepLength), stepLength);
660
+ continue;
661
+ }
582
662
  }
583
663
  const operator = matchOperator(source, cursor.index);
584
664
  if (operator) {
@@ -1,7 +1,6 @@
1
1
  import { TlaEvaluationError } from "./errors";
2
2
  import { hasRepeatedEffects, type Environment } from "./evaluate";
3
3
  import {
4
- createTautologyError,
5
4
  evaluateLive,
6
5
  evaluateOnLasso,
7
6
  toLiveExpression,
@@ -28,8 +27,8 @@ export interface LiveSuccessor {
28
27
  export interface Lasso {
29
28
  prefix: number[];
30
29
  cycle: number[];
31
- // Whether the solution that the lasso violates constrains the cycle, as a liveness property does.
32
- // TLC warns that a stuttering counterexample to one may come from a missing fairness constraint.
30
+ // TLC warns that a stuttering counterexample to a liveness property may come from a missing
31
+ // fairness constraint.
33
32
  isCycleConstrained: boolean;
34
33
  }
35
34
 
@@ -62,10 +61,8 @@ interface Pool<Data extends Int32Array | Uint8Array> {
62
61
  create: (length: number) => Data;
63
62
  }
64
63
 
65
- // TLC's behavior graph for one solution: a node per state, or per state and tableau node.
66
64
  interface BehaviorGraph {
67
65
  solution: Solution;
68
- // One id per distinct action check across the solutions.
69
66
  actionIds: Int32Array;
70
67
  nodeStates: number[];
71
68
  nodeTableaux: number[];
@@ -104,7 +101,6 @@ const containsAlways = (expression: LiveExpression): boolean => {
104
101
  }
105
102
  };
106
103
 
107
- // TLC's OrderOfSolution#hasEmptyPEMAndBoxFreePromises, negated.
108
104
  const isCycleConstrained = (solution: Solution) =>
109
105
  solution.promises.some((promise) => containsAlways(promise.body)) ||
110
106
  solution.models.some(
@@ -178,7 +174,6 @@ const getStateResult = (behavior: BehaviorGraph, node: number, position: number)
178
174
  behavior.nodeStates[node] * behavior.solution.stateChecks.length + position
179
175
  ] === 1;
180
176
 
181
- // A node owns one entry in each per-node array of its graph.
182
177
  const pushNode = (behavior: BehaviorGraph, state: number, tableauNode: number) => {
183
178
  behavior.nodeStates.push(state);
184
179
  behavior.nodeTableaux.push(tableauNode);
@@ -225,9 +220,6 @@ export const createLivenessChecker = (
225
220
  const formula =
226
221
  fairness.length === 0 ? violation : createJunction("And", [...fairness, violation]);
227
222
  const solutions = getSolutions(formula);
228
- if (solutions.length === 0) {
229
- throw createTautologyError();
230
- }
231
223
  const actionIds = new Map<string, number>();
232
224
  const behaviors = solutions.map((solution): BehaviorGraph => ({
233
225
  solution,
@@ -268,11 +260,14 @@ export const createLivenessChecker = (
268
260
  return cache;
269
261
  };
270
262
  // TLCGet("level") reads the level of the state whose successors the checks run on.
263
+ // A check that fails leaves no source, so the failure's trace reads the levels of the search.
271
264
  const evaluateFrom = <Result>(source: number | undefined, evaluate: () => Result) => {
272
265
  environment.runtime.setLivenessSource(source);
273
- const result = evaluate();
274
- environment.runtime.setLivenessSource(undefined);
275
- return result;
266
+ try {
267
+ return evaluate();
268
+ } finally {
269
+ environment.runtime.setLivenessSource(undefined);
270
+ }
276
271
  };
277
272
  const evaluateState = (predicate: LiveExpression, state: Value[]) =>
278
273
  evaluateLive(
@@ -439,7 +434,6 @@ export const createLivenessChecker = (
439
434
  return table.slots.filter((entry): entry is LiveSuccessor => entry !== undefined);
440
435
  };
441
436
 
442
- // TLC's TableauLiveChecker#addNextState for a node it finds after it expanded the node's state.
443
437
  const expandLate = (
444
438
  behavior: BehaviorGraph,
445
439
  tableau: Tableau,
@@ -551,7 +545,6 @@ export const createLivenessChecker = (
551
545
  writeNode(behavior, index, successors, actions, stateResults);
552
546
  };
553
547
 
554
- // The shortest path from an initial node to the node, last node first, as TLC's getPath finds it.
555
548
  const getPath = (behavior: BehaviorGraph, target: number) => {
556
549
  if (behavior.initial.includes(target)) return [target];
557
550
  const parents = new Map<number, number>();
@@ -635,8 +628,8 @@ export const createLivenessChecker = (
635
628
  return getLasso(root, members, membersByState);
636
629
  };
637
630
 
638
- // TLC's LiveWorker#printTrace: a prefix to the root, a greedy walk through the component
639
- // until it satisfies every check, and a breadth-first path back to the root.
631
+ // TLC's LiveWorker#printTrace: a prefix to the root, a greedy walk through the component until it
632
+ // satisfies every check, and a breadth-first path back to the root.
640
633
  const getLasso = (
641
634
  root: number,
642
635
  members: Set<number>,
@@ -733,7 +726,6 @@ export const createLivenessChecker = (
733
726
  };
734
727
  };
735
728
 
736
- // TLC's LiveWorker#bfsPostFix, the states from the walk's end back to the root, last first.
737
729
  const getClosingPath = (
738
730
  root: number,
739
731
  end: number,