tla-ts 0.0.3-dev.b4e335d → 0.0.3-dev.baa5e34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tla-ts",
3
- "version": "0.0.3-dev.b4e335d",
3
+ "version": "0.0.3-dev.baa5e34",
4
4
  "description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
5
5
  "keywords": [
6
6
  "formal verification",
package/src/config.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { TlaConfigError } from "./errors";
2
- import { matchOperator } from "./lexer";
2
+ import { matchOperator, matchUnicodeToken } from "./lexer";
3
3
  import { formatLexicalError } from "./sany-lexer";
4
4
  import type { TlcVersion } from "./tlc-version";
5
5
 
@@ -168,7 +168,7 @@ const tokenizeConfig = (source: string) => {
168
168
  skip(symbol);
169
169
  continue;
170
170
  }
171
- const operator = matchOperator(source, cursor.index);
171
+ const operator = matchUnicodeToken(source, cursor.index) ?? matchOperator(source, cursor.index);
172
172
  if (!operator) {
173
173
  addLexicalError(cursor.index, "");
174
174
  return tokens;
package/src/lexer.ts CHANGED
@@ -360,6 +360,16 @@ export const matchOperator = (source: string, index: number): OperatorMatch | un
360
360
  return character === "\\" ? { text: "\\", length: 1 } : undefined;
361
361
  };
362
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
+
363
373
  const isDigit = (character: string | undefined) =>
364
374
  character !== undefined && character >= "0" && character <= "9";
365
375
 
@@ -164,6 +164,9 @@ export interface SanySpecification {
164
164
  export interface SanyGenerationOptions {
165
165
  // The name of the root module's file, which SANY requires to match the module's name.
166
166
  rootFileName?: string;
167
+ // The path of the root module's file as SANY's caller gives it, which SANY names when it cannot
168
+ // parse the file, rather than the file name it gives the other modules.
169
+ rootFilePath?: string;
167
170
  // Called before SANY parses the file of each module, and before it analyzes each external
168
171
  // module, in its order.
169
172
  onParse?: (name: string) => void;
@@ -482,12 +485,9 @@ export const generateSanySpecification = (
482
485
  const sources = new Map<string, { file: SourceFile; module: Module }>();
483
486
 
484
487
  const parseSource = (name: string, text: string) => {
488
+ const file = (name === options.rootFileName && options.rootFilePath) || `${name}.tla`;
485
489
  const getParseFailure = (parseError: string) =>
486
- new TlaSanyFatalError(
487
- `Could not parse module ${name} from file ${name}.tla`,
488
- name,
489
- parseError,
490
- );
490
+ new TlaSanyFatalError(`Could not parse module ${name} from file ${file}`, name, parseError);
491
491
  const lexicalError = options.version === "1.7.4" ? getSany174LexicalError(text) : undefined;
492
492
  if (lexicalError !== undefined) throw getParseFailure(lexicalError);
493
493
  // HACK: the parser's errors are not SANY's, so a module that fails to parse gets the report
@@ -265,6 +265,8 @@ export const getSanyReport = (
265
265
  loadValidatedModule(rootName, source);
266
266
  return generateSanySpecification(source, loadSource, {
267
267
  rootFileName: rootName,
268
+ // XMLExporter gives SANY the file it is asked for, and TLC the name of the module.
269
+ rootFilePath: options.isXmlExport ? `${name.replace(/\.tla$/, "")}.tla` : undefined,
268
270
  version: options.version,
269
271
  rootExtendees: options.rootExtendees,
270
272
  onParse: (moduleName) => {
package/src/values.ts CHANGED
@@ -489,8 +489,24 @@ export const markStreamedSet = <Streamed extends UnionValue | SetOperationValue>
489
489
  return value;
490
490
  };
491
491
 
492
+ // The sets that stream their elements apart from the normalized set until TLC caches them.
493
+ const STREAMING_KINDS = new Set<ObjectValue["kind"]>([
494
+ "Union",
495
+ "SetOperation",
496
+ "FilteredSet",
497
+ "ProductSet",
498
+ "RecordSet",
499
+ "FunctionSet",
500
+ ]);
501
+
492
502
  const cacheSet = (value: Value) => {
493
- if (streamedSetPresence.isPresent && typeof value === "object") cachedSets.add(value);
503
+ if (
504
+ streamedSetPresence.isPresent &&
505
+ typeof value === "object" &&
506
+ STREAMING_KINDS.has(value.kind)
507
+ ) {
508
+ cachedSets.add(value);
509
+ }
494
510
  };
495
511
 
496
512
  // FcnLambdaValue#fingerPrint caches the FcnRcdValue the function enumerates to, which applies it