tla-ts 0.0.3-dev.a50fc89 → 0.0.3-dev.b0f84e8

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/src/instances.ts CHANGED
@@ -1,16 +1,17 @@
1
- import type {
2
- Bound,
3
- BoundPattern,
4
- Definition,
5
- Expression,
6
- Instance,
7
- Module,
8
- OperatorParam,
9
- SourceLocation,
10
- Theorem,
1
+ import {
2
+ getChildren,
3
+ isLocallyResolved,
4
+ type Bound,
5
+ type BoundPattern,
6
+ type Definition,
7
+ type Expression,
8
+ type Instance,
9
+ type Module,
10
+ type OperatorParam,
11
+ type SourceLocation,
12
+ type Theorem,
11
13
  } from "./ast";
12
14
  import { TlaSyntaxError } from "./errors";
13
- import { getChildren, isLocallyResolved } from "./evaluate";
14
15
  import { getArity, getBoundNames, getPatternNames, isBefore } from "./resolve";
15
16
 
16
17
  export const substitutedExpressions = new WeakSet<Expression>();
@@ -218,7 +219,7 @@ interface Instantiation {
218
219
  variables: Set<string>;
219
220
  getDefinition: (key: string) => Definition | undefined;
220
221
  isParameterized: (key: string) => boolean;
221
- addDefinition: (name: string, create: (key: string) => Definition) => string;
222
+ addDefinition: (source: string, name: string, create: (key: string) => Definition) => string;
222
223
  createName: (name: string) => string;
223
224
  }
224
225
 
@@ -639,7 +640,7 @@ const copyDefinition = (rewrite: Rewrite, key: string): string => {
639
640
  const instantiation = rewrite.instantiation;
640
641
  const definition = instantiation.getDefinition(key);
641
642
  if (!definition) return key;
642
- return instantiation.addDefinition(definition.name, (copyKey) => {
643
+ return instantiation.addDefinition(key, definition.name, (copyKey) => {
643
644
  rewrite.copies.set(key, copyKey);
644
645
  const rename = createRenamer(rewrite);
645
646
  const mapped = renameParams(
@@ -678,7 +679,7 @@ export const createInstantiation = (instantiation: Instantiation) => {
678
679
  if (copy !== undefined) return copy;
679
680
  const definition = instantiation.getDefinition(key);
680
681
  if (!definition) return key;
681
- return instantiation.addDefinition(definition.name, () =>
682
+ return instantiation.addDefinition(key, definition.name, () =>
682
683
  withInstanceParams(definition, instantiation.params, definition.location),
683
684
  );
684
685
  },
package/src/levels.ts CHANGED
@@ -1,13 +1,13 @@
1
- import type {
2
- AssumeProve,
3
- Definition,
4
- Expression,
5
- Module,
6
- OperatorParam,
7
- SourceLocation,
1
+ import {
2
+ getChildren,
3
+ type AssumeProve,
4
+ type Definition,
5
+ type Expression,
6
+ type Module,
7
+ type OperatorParam,
8
+ type SourceLocation,
8
9
  } from "./ast";
9
10
  import { TlaSyntaxError } from "./errors";
10
- import { getChildren } from "./evaluate";
11
11
  import { mapChildren } from "./instances";
12
12
  import { getBoundNames, getPatternNames } from "./resolve";
13
13
  import { STANDARD_LEVELS } from "./standard-levels";
package/src/lexer.ts CHANGED
@@ -345,6 +345,8 @@ export const tokenize = (source: string): Token[] => {
345
345
  if (!headerMatch)
346
346
  throw new TlaSyntaxError("Expected a module header such as ---- MODULE Name ----");
347
347
  const tokens: Token[] = [];
348
+ // Each name is one string object, so looking a name up in a scope compares pointers.
349
+ const names = new Map<string, string>();
348
350
  const prefixLines = source.slice(0, headerMatch.index).split("\n");
349
351
  const cursor = {
350
352
  index: headerMatch.index,
@@ -481,7 +483,9 @@ export const tokenize = (source: string): Token[] => {
481
483
  pushToken("Keyword", word.slice(0, 3), 3);
482
484
  continue;
483
485
  }
484
- pushToken(KEYWORDS.has(word) ? "Keyword" : "Identifier", word, word.length);
486
+ const name = names.get(word) ?? word;
487
+ names.set(name, name);
488
+ pushToken(KEYWORDS.has(word) ? "Keyword" : "Identifier", name, word.length);
485
489
  continue;
486
490
  }
487
491
  const stepLength = matchStep(source, cursor.index);