tla-ts 0.0.3-dev.fe239f8 → 0.0.4-dev.2be6058
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 +12 -12
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/run-cli.cjs +32 -1337
- package/dist/run-cli.js +30 -1335
- package/dist/transfer.cjs +1335 -30
- package/dist/transfer.js +1335 -30
- package/package.json +1 -1
- package/src/ast.ts +4 -2
- package/src/config.ts +2 -2
- package/src/environment.ts +22 -3
- package/src/evaluate.ts +25 -24
- package/src/lexer.ts +90 -25
- package/src/live-check.ts +43 -4
- package/src/parser.ts +48 -65
- package/src/resolve.ts +131 -40
- package/src/run-cli.ts +25 -13
- package/src/sany-generator.ts +36 -20
- package/src/sany-report.ts +2 -0
- package/src/tlc-modules.ts +4 -0
- package/src/tlc-order.ts +5 -1
- package/src/values.ts +17 -1
package/package.json
CHANGED
package/src/ast.ts
CHANGED
|
@@ -34,10 +34,11 @@ export interface StringExpression {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// selectorRanges holds the range of each part of a name such as foo!lab, where SANY reports an
|
|
37
|
-
// error in selecting that part.
|
|
37
|
+
// error in selecting that part. spelling holds the text of an operator written as a synonym.
|
|
38
38
|
export interface IdentifierExpression {
|
|
39
39
|
kind: "Identifier";
|
|
40
40
|
name: string;
|
|
41
|
+
spelling?: string;
|
|
41
42
|
selectorRanges?: SourceRange[];
|
|
42
43
|
location: SourceLocation;
|
|
43
44
|
resolution?: LocalResolution;
|
|
@@ -53,7 +54,8 @@ export interface ApplyExpression {
|
|
|
53
54
|
// The number of args each part of a name like F(x)!l(y) takes, when a part before the last takes
|
|
54
55
|
// some.
|
|
55
56
|
argumentCounts?: number[];
|
|
56
|
-
// The range of the parenthesized arguments of a named operator,
|
|
57
|
+
// The range of the parenthesized arguments of a named operator, or of the whole name when its
|
|
58
|
+
// last part takes none, where SANY reports their count.
|
|
57
59
|
argumentsRange?: SourceRange;
|
|
58
60
|
selectorRanges?: SourceRange[];
|
|
59
61
|
// The range of the arguments of each part of a name like F(x)!l(y), for a part that takes some.
|
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/environment.ts
CHANGED
|
@@ -57,6 +57,8 @@ import {
|
|
|
57
57
|
type Symbols,
|
|
58
58
|
} from "./resolve";
|
|
59
59
|
import { createRuntime } from "./runtime";
|
|
60
|
+
import { getSanyStandardModules } from "./sany-modules";
|
|
61
|
+
import { USER_STANDARD_MODULES } from "./tlc-modules";
|
|
60
62
|
import { getSanyParseError } from "./sany-parse-error";
|
|
61
63
|
import {
|
|
62
64
|
CORE_OPERATORS,
|
|
@@ -381,6 +383,9 @@ export const createEnvironment = (
|
|
|
381
383
|
};
|
|
382
384
|
|
|
383
385
|
const getStandardSymbols = (name: string) => {
|
|
386
|
+
// SANY reads a module from the user's directories before its standard modules.
|
|
387
|
+
if (USER_STANDARD_MODULES.has(name) && options.loadModule?.(name) !== undefined)
|
|
388
|
+
return undefined;
|
|
384
389
|
const symbols = addStandardModule(name);
|
|
385
390
|
const dependencies = STANDARD_DEPENDENCIES.get(name) ?? [];
|
|
386
391
|
if (symbols) useModule(name, dependencies);
|
|
@@ -472,6 +477,17 @@ export const createEnvironment = (
|
|
|
472
477
|
return cached;
|
|
473
478
|
}
|
|
474
479
|
const top = linkTopLevel(loadModule(name, importer));
|
|
480
|
+
// TLC replaces each definition of a module that has a standard module's name with the Java
|
|
481
|
+
// method of that name, so a user's Bags.tla keeps the definitions that Bags has no method for.
|
|
482
|
+
const standardModule = getSanyStandardModules(runtime.version).has(name)
|
|
483
|
+
? getStandardModule(name, options.print, runtime, options.files, builtins)
|
|
484
|
+
: undefined;
|
|
485
|
+
standardModule?.operators.forEach((operator) => {
|
|
486
|
+
const symbol = top.linked.visible.get(operator.name);
|
|
487
|
+
if (symbol?.kind !== "Definition" || symbol.arity !== operator.arity) return;
|
|
488
|
+
builtins.set(symbol.key, operator);
|
|
489
|
+
definitions.delete(symbol.key);
|
|
490
|
+
});
|
|
475
491
|
linkedModules.set(name, top.linked);
|
|
476
492
|
dependencies.set(name, top.closure);
|
|
477
493
|
useModule(name, top.closure);
|
|
@@ -912,9 +928,9 @@ export const createEnvironment = (
|
|
|
912
928
|
reports,
|
|
913
929
|
warnings: scope.warnings,
|
|
914
930
|
});
|
|
931
|
+
// SANY keeps the first of two symbols of a name.
|
|
915
932
|
const getSymbolsBefore = (location: SourceLocation): Symbols =>
|
|
916
|
-
|
|
917
|
-
...visible,
|
|
933
|
+
[
|
|
918
934
|
...declarations
|
|
919
935
|
.filter((declaration) => isBefore(declaration.location, location))
|
|
920
936
|
.map((declaration): [string, ModuleSymbol] => [
|
|
@@ -927,7 +943,10 @@ export const createEnvironment = (
|
|
|
927
943
|
definition.name,
|
|
928
944
|
getDefinitionSymbol(definition),
|
|
929
945
|
]),
|
|
930
|
-
]
|
|
946
|
+
].reduce(
|
|
947
|
+
(symbols, [name, symbol]) => (symbols.has(name) ? symbols : symbols.set(name, symbol)),
|
|
948
|
+
new Map(visible),
|
|
949
|
+
);
|
|
931
950
|
// Generator.generateModule reports the errors of a nested module and goes on, and then
|
|
932
951
|
// SymbolTable.addModule reports a module already defined.
|
|
933
952
|
const linkNested = (nested: Module) => {
|
package/src/evaluate.ts
CHANGED
|
@@ -578,15 +578,19 @@ interface LazyFunction {
|
|
|
578
578
|
scope: Scope | undefined;
|
|
579
579
|
}
|
|
580
580
|
|
|
581
|
-
|
|
581
|
+
// The function keeps its parameters, body and scope itself, since a WeakMap entry for each
|
|
582
|
+
// short-lived function makes every garbage collection slower.
|
|
583
|
+
interface KeptLazyFunctionValue extends LazyFunctionValue {
|
|
584
|
+
lambda: LazyFunction;
|
|
585
|
+
}
|
|
582
586
|
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
};
|
|
587
|
+
const isKeptLazyFunction = (value: Value): value is KeptLazyFunctionValue =>
|
|
588
|
+
typeof value === "object" && value.kind === "LazyFunction" && "lambda" in value;
|
|
589
|
+
|
|
590
|
+
const keepLambda = (lambda: LazyFunction) => Object.assign(lambda.value, { lambda });
|
|
587
591
|
|
|
588
592
|
export const getLazyFunction = (value: Value) =>
|
|
589
|
-
|
|
593
|
+
isKeptLazyFunction(value) ? value.lambda : undefined;
|
|
590
594
|
|
|
591
595
|
// Tool.getFcnContext: the scope of a lazy function's body for the arguments of an application. It
|
|
592
596
|
// ignores arguments beyond the parameters.
|
|
@@ -1375,9 +1379,14 @@ const isStateCached = (expression: Expression, environment: Environment) =>
|
|
|
1375
1379
|
getReadVariables(expression, environment) !== undefined &&
|
|
1376
1380
|
!hasFreeLocals(expression, NO_BOUND_NAMES);
|
|
1377
1381
|
|
|
1378
|
-
//
|
|
1382
|
+
// A set filter TLC evaluates lazily, with how to rebuild it so that its predicate runs in another
|
|
1379
1383
|
// environment.
|
|
1380
|
-
|
|
1384
|
+
interface RebindableFilteredSet extends FilteredSetValue {
|
|
1385
|
+
rebind: (environment: Environment) => Value;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
const isRebindableFilteredSet = (value: Value): value is RebindableFilteredSet =>
|
|
1389
|
+
typeof value === "object" && value.kind === "FilteredSet" && "rebind" in value;
|
|
1381
1390
|
|
|
1382
1391
|
// TLC's CallStackTool rebinds the lazy values its evaluations return, so their later evaluation
|
|
1383
1392
|
// records its call stack too.
|
|
@@ -1398,11 +1407,7 @@ const traceEvaluator =
|
|
|
1398
1407
|
setTrace.callStack = callStack;
|
|
1399
1408
|
try {
|
|
1400
1409
|
const computed = evaluator(context);
|
|
1401
|
-
const rebind
|
|
1402
|
-
typeof computed === "object" && computed.kind === "FilteredSet"
|
|
1403
|
-
? filteredSetRebinders.get(computed)
|
|
1404
|
-
: undefined;
|
|
1405
|
-
const value = rebind ? rebind(environment) : computed;
|
|
1410
|
+
const value = isRebindableFilteredSet(computed) ? computed.rebind(environment) : computed;
|
|
1406
1411
|
callStack.values.set(expression, value);
|
|
1407
1412
|
if (typeof value === "object" && value.kind !== "FilteredSet" && isSourced(expression)) {
|
|
1408
1413
|
callStack.sources.set(value, expression);
|
|
@@ -2069,22 +2074,18 @@ const compileSetComprehension = (
|
|
|
2069
2074
|
base: Value,
|
|
2070
2075
|
context: Context,
|
|
2071
2076
|
evaluator: Evaluator,
|
|
2072
|
-
):
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
};
|
|
2079
|
-
filteredSetRebinders.set(filtered, (tracing) =>
|
|
2077
|
+
): RebindableFilteredSet => ({
|
|
2078
|
+
kind: "FilteredSet",
|
|
2079
|
+
base,
|
|
2080
|
+
test: createTest(evaluator, context),
|
|
2081
|
+
source,
|
|
2082
|
+
rebind: (tracing) =>
|
|
2080
2083
|
createFiltered(
|
|
2081
2084
|
base,
|
|
2082
2085
|
{ ...context, environment: tracing },
|
|
2083
2086
|
getEvaluator(expression.predicate, tracing),
|
|
2084
2087
|
),
|
|
2085
|
-
|
|
2086
|
-
return filtered;
|
|
2087
|
-
};
|
|
2088
|
+
});
|
|
2088
2089
|
return (context) => {
|
|
2089
2090
|
const base = set(context);
|
|
2090
2091
|
// TLC filters any value it can't enumerate lazily, and fails only when it uses the result.
|
package/src/lexer.ts
CHANGED
|
@@ -234,38 +234,84 @@ 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.
|
|
237
238
|
const UNICODE_OPERATORS = new Map([
|
|
239
|
+
["∃", "\\E"],
|
|
240
|
+
["∀", "\\A"],
|
|
241
|
+
["∷", "::"],
|
|
242
|
+
["≜", "=="],
|
|
243
|
+
["⟨", "<<"],
|
|
244
|
+
["⟩_", ">>_"],
|
|
245
|
+
["⟩", ">>"],
|
|
246
|
+
["→", "->"],
|
|
247
|
+
["←", "<-"],
|
|
248
|
+
["↦", "|->"],
|
|
249
|
+
["⁺", "^+"],
|
|
250
|
+
["¬", "~"],
|
|
251
|
+
["□", "[]"],
|
|
252
|
+
["◇", "<>"],
|
|
238
253
|
["∧", "/\\"],
|
|
239
254
|
["∨", "\\/"],
|
|
240
|
-
["
|
|
241
|
-
["
|
|
242
|
-
["
|
|
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
|
+
["…", "..."],
|
|
243
271
|
["≡", "<=>"],
|
|
272
|
+
["‼", "!!"],
|
|
273
|
+
["≥", ">="],
|
|
274
|
+
["≫", "\\gg"],
|
|
244
275
|
["⇔", "<=>"],
|
|
245
|
-
["
|
|
276
|
+
["⇒", "=>"],
|
|
277
|
+
["⫤", "=|"],
|
|
278
|
+
["↝", "~>"],
|
|
279
|
+
["≤", "<="],
|
|
280
|
+
["≪", "\\ll"],
|
|
281
|
+
["⊣", "-|"],
|
|
282
|
+
["≠", "#"],
|
|
246
283
|
["∉", "\\notin"],
|
|
247
|
-
["
|
|
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"],
|
|
248
305
|
["⊂", "\\subset"],
|
|
249
|
-
["
|
|
306
|
+
["⊆", "\\subseteq"],
|
|
307
|
+
["≻", "\\succ"],
|
|
308
|
+
["⪰", "\\succeq"],
|
|
250
309
|
["⊃", "\\supset"],
|
|
251
|
-
["
|
|
252
|
-
["∩", "\\cap"],
|
|
310
|
+
["⊇", "\\supseteq"],
|
|
253
311
|
["×", "\\X"],
|
|
254
|
-
["
|
|
255
|
-
["
|
|
256
|
-
["
|
|
257
|
-
["≤", "<="],
|
|
258
|
-
["≥", ">="],
|
|
259
|
-
["↦", "|->"],
|
|
260
|
-
["→", "->"],
|
|
261
|
-
["⟨", "<<"],
|
|
262
|
-
["⟩", ">>"],
|
|
263
|
-
["□", "[]"],
|
|
264
|
-
["◇", "<>"],
|
|
265
|
-
["≜", "=="],
|
|
266
|
-
["′", "'"],
|
|
267
|
-
["∘", "\\o"],
|
|
268
|
-
["⋅", "\\cdot"],
|
|
312
|
+
["⊎", "\\uplus"],
|
|
313
|
+
["‖", "||"],
|
|
314
|
+
["≀", "\\wr"],
|
|
269
315
|
]);
|
|
270
316
|
|
|
271
317
|
const BASED_NUMBER = /^\\([bB][01]+|[oO][0-7]+|[hH][0-9a-fA-F]+)/;
|
|
@@ -303,13 +349,27 @@ export const matchOperator = (source: string, index: number): OperatorMatch | un
|
|
|
303
349
|
const operator = BACKSLASH_OPERATORS.get(word.slice(0, length.value));
|
|
304
350
|
return { text: operator ?? "\\", length: operator === undefined ? 1 : length.value + 1 };
|
|
305
351
|
}
|
|
306
|
-
const
|
|
307
|
-
|
|
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
|
+
}
|
|
308
358
|
const symbol = SYMBOL_OPERATORS.find((candidate) => source.startsWith(candidate, index));
|
|
309
359
|
if (symbol) return { text: SYMBOL_ALIASES.get(symbol) ?? symbol, length: symbol.length };
|
|
310
360
|
return character === "\\" ? { text: "\\", length: 1 } : undefined;
|
|
311
361
|
};
|
|
312
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
|
+
|
|
313
373
|
const isDigit = (character: string | undefined) =>
|
|
314
374
|
character !== undefined && character >= "0" && character <= "9";
|
|
315
375
|
|
|
@@ -510,6 +570,11 @@ export const tokenize = (source: string): Token[] => {
|
|
|
510
570
|
pushToken(KEYWORDS.has(word) ? "Keyword" : "Identifier", name, word.length);
|
|
511
571
|
continue;
|
|
512
572
|
}
|
|
573
|
+
if ("ℕℤℝ".includes(character)) {
|
|
574
|
+
pushToken("Identifier", names.get(character) ?? character, 1);
|
|
575
|
+
names.set(character, character);
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
513
578
|
const stepLength = matchStep(source, cursor.index);
|
|
514
579
|
if (stepLength > 0) {
|
|
515
580
|
pushToken("Step", source.slice(cursor.index, cursor.index + stepLength), stepLength);
|
package/src/live-check.ts
CHANGED
|
@@ -83,6 +83,7 @@ interface Check {
|
|
|
83
83
|
firstNodes: Pool<Int32Array>;
|
|
84
84
|
lastNodes: Pool<Int32Array>;
|
|
85
85
|
nextSiblings: number[];
|
|
86
|
+
nodeIds: NodeTable;
|
|
86
87
|
isDone: boolean[];
|
|
87
88
|
errorNode: number | undefined;
|
|
88
89
|
}
|
|
@@ -140,6 +141,26 @@ const writeToPool = <Data extends Int32Array | Uint8Array>(
|
|
|
140
141
|
|
|
141
142
|
const NO_NODE = -1;
|
|
142
143
|
|
|
144
|
+
// A Map holds at most 2^24 entries, so each tableau node of a state finds its node in an
|
|
145
|
+
// open-addressing table of (state plus one, tableau node, node) triples.
|
|
146
|
+
interface NodeTable {
|
|
147
|
+
slots: Int32Array;
|
|
148
|
+
size: number;
|
|
149
|
+
shift: number;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const getNodeSlot = (table: NodeTable, state: number, tableauNode: number) => {
|
|
153
|
+
const mask = table.slots.length / 3 - 1;
|
|
154
|
+
const hash = Math.imul(Math.imul(state, 0x9e3779b1) ^ tableauNode, 0x85ebca6b) >>> table.shift;
|
|
155
|
+
for (let index = hash; ; index = (index + 1) & mask) {
|
|
156
|
+
const slot = index * 3;
|
|
157
|
+
const stored = table.slots[slot];
|
|
158
|
+
if (stored === 0 || (stored === state + 1 && table.slots[slot + 1] === tableauNode)) {
|
|
159
|
+
return slot;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
143
164
|
const createNodes = (length: number) => new Int32Array(length).fill(NO_NODE);
|
|
144
165
|
|
|
145
166
|
const UNWRITTEN = -1;
|
|
@@ -227,6 +248,7 @@ export const createLivenessChecker = (
|
|
|
227
248
|
firstNodes: createPool(createNodes),
|
|
228
249
|
lastNodes: createPool(createNodes),
|
|
229
250
|
nextSiblings: [],
|
|
251
|
+
nodeIds: { slots: new Int32Array(3 << 10), size: 0, shift: 22 },
|
|
230
252
|
isDone: [],
|
|
231
253
|
errorNode: undefined,
|
|
232
254
|
}));
|
|
@@ -322,12 +344,29 @@ export const createLivenessChecker = (
|
|
|
322
344
|
model.infinitelyOftenActions.length === 0,
|
|
323
345
|
);
|
|
324
346
|
|
|
325
|
-
const getNodeId = (check: Check, state: number, tableauNode: number) =>
|
|
326
|
-
check.solution.tableau
|
|
327
|
-
|
|
328
|
-
|
|
347
|
+
const getNodeId = (check: Check, state: number, tableauNode: number) => {
|
|
348
|
+
if (!check.solution.tableau) return state;
|
|
349
|
+
const slots = check.nodeIds.slots;
|
|
350
|
+
const slot = getNodeSlot(check.nodeIds, state, tableauNode);
|
|
351
|
+
return slots[slot] === 0 ? undefined : slots[slot + 2];
|
|
352
|
+
};
|
|
329
353
|
const recordNode = (check: Check, state: number, tableauNode: number) => {
|
|
330
354
|
const node = pushNode(check, state, tableauNode);
|
|
355
|
+
const table = check.nodeIds;
|
|
356
|
+
if (++table.size * 2 > table.slots.length / 3) {
|
|
357
|
+
const old = table.slots;
|
|
358
|
+
table.slots = new Int32Array(old.length * 2);
|
|
359
|
+
table.shift--;
|
|
360
|
+
for (let slot = 0; slot < old.length; slot += 3) {
|
|
361
|
+
if (old[slot] !== 0) {
|
|
362
|
+
table.slots.set(
|
|
363
|
+
old.subarray(slot, slot + 3),
|
|
364
|
+
getNodeSlot(table, old[slot] - 1, old[slot + 1]),
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
table.slots.set([state + 1, tableauNode, node], getNodeSlot(table, state, tableauNode));
|
|
331
370
|
const last = check.lastNodes.data[state] ?? NO_NODE;
|
|
332
371
|
if (last === NO_NODE) writeToPool(check.firstNodes, state, [node]);
|
|
333
372
|
else check.nextSiblings[last] = node;
|
package/src/parser.ts
CHANGED
|
@@ -356,9 +356,6 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
356
356
|
const factNames = new Set<string>();
|
|
357
357
|
// The NEW, TAKE, and PICK names in scope, which a DEF clause cannot cite.
|
|
358
358
|
const proofScopes: Set<string>[] = [];
|
|
359
|
-
// A fact or an operator argument may cite an operator of a parameterized instance without the
|
|
360
|
-
// instance's arguments, as with Op <- I!Op in a substitution.
|
|
361
|
-
const factStart = { index: -1 };
|
|
362
359
|
// SANY reports a location in a nested module as one in the module of its file.
|
|
363
360
|
const openModules: Module[] = [];
|
|
364
361
|
|
|
@@ -703,7 +700,7 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
703
700
|
const location = getLocation(token);
|
|
704
701
|
if (POSTFIX_OPERATORS.has(token.text)) {
|
|
705
702
|
return withRange(
|
|
706
|
-
{ kind: "OperatorReference", operator: token.text, location },
|
|
703
|
+
{ kind: "OperatorReference", operator: token.text, spelling: token.spelling, location },
|
|
707
704
|
cursor.index - 1,
|
|
708
705
|
);
|
|
709
706
|
}
|
|
@@ -736,15 +733,9 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
736
733
|
start,
|
|
737
734
|
);
|
|
738
735
|
}
|
|
739
|
-
|
|
740
|
-
// SANY reads an argument that only names an operator of a parameterized instance, such as
|
|
741
|
-
// I!Op, as that operator, which takes the arguments of the instance too.
|
|
742
|
-
if (argument.kind === "Identifier") missingArguments.delete(argument);
|
|
743
|
-
return argument;
|
|
736
|
+
return parseExpression();
|
|
744
737
|
};
|
|
745
738
|
|
|
746
|
-
const missingArguments = new Map<Expression, { location: string; message: string }>();
|
|
747
|
-
|
|
748
739
|
const lastArguments: { range: SourceRange | undefined } = { range: undefined };
|
|
749
740
|
|
|
750
741
|
const parseArguments = () =>
|
|
@@ -966,7 +957,6 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
966
957
|
|
|
967
958
|
const parsePrimary = (preceding?: Precedence): Expression => {
|
|
968
959
|
const start = cursor.index;
|
|
969
|
-
const isFactStart = start === factStart.index;
|
|
970
960
|
const token = advance();
|
|
971
961
|
const location = getLocation(token);
|
|
972
962
|
if (isTlapm && token.kind === "Keyword" && token.text === "LAMBDA") {
|
|
@@ -1023,20 +1013,6 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
1023
1013
|
? { kind: "Apply", operator: name, args, argumentsRange: lastArguments.range, location }
|
|
1024
1014
|
: { kind: "Identifier", name, location };
|
|
1025
1015
|
}
|
|
1026
|
-
const instance = openModules
|
|
1027
|
-
.flatMap((module) => module.instances)
|
|
1028
|
-
.find((candidate) => candidate.name === name);
|
|
1029
|
-
const isMissingArguments =
|
|
1030
|
-
instance !== undefined &&
|
|
1031
|
-
mode === "tlc" &&
|
|
1032
|
-
!isFactStart &&
|
|
1033
|
-
instance.params.length !== args.length;
|
|
1034
|
-
if (isMissingArguments && args.length > 0) {
|
|
1035
|
-
throw createError(
|
|
1036
|
-
`The operator ${name} requires ${instance.params.length} arguments`,
|
|
1037
|
-
token,
|
|
1038
|
-
);
|
|
1039
|
-
}
|
|
1040
1016
|
const selectors: Selector[] = [{ kind: "Name", name, args }];
|
|
1041
1017
|
const selectorRanges = [getRange(start, start)];
|
|
1042
1018
|
while (isSelectorAhead()) {
|
|
@@ -1056,46 +1032,44 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
1056
1032
|
const argumentCounts = selectors.map((selector) =>
|
|
1057
1033
|
"args" in selector ? selector.args.length : 0,
|
|
1058
1034
|
);
|
|
1059
|
-
const argumentsRange = argumentRanges.
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
:
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
};
|
|
1085
|
-
if (isMissingArguments) {
|
|
1086
|
-
missingArguments.set(reference, {
|
|
1087
|
-
location: formatRange(getRange(start)),
|
|
1088
|
-
message: `The operator ${name} requires ${instance.params.length} arguments.`,
|
|
1089
|
-
});
|
|
1090
|
-
}
|
|
1091
|
-
return reference;
|
|
1035
|
+
const argumentsRange = argumentRanges.at(-1) ?? getRange(start);
|
|
1036
|
+
return names.length < selectors.length
|
|
1037
|
+
? { kind: "Subexpression", selectors, selectorRanges, argumentRanges, location }
|
|
1038
|
+
: qualifiedArgs.length === 0
|
|
1039
|
+
? { kind: "Identifier", name: operator, selectorRanges, location }
|
|
1040
|
+
: argumentCounts.slice(0, -1).some((count) => count > 0)
|
|
1041
|
+
? {
|
|
1042
|
+
kind: "Apply",
|
|
1043
|
+
operator,
|
|
1044
|
+
args: qualifiedArgs,
|
|
1045
|
+
argumentCounts,
|
|
1046
|
+
argumentsRange,
|
|
1047
|
+
selectorRanges,
|
|
1048
|
+
argumentRanges,
|
|
1049
|
+
location,
|
|
1050
|
+
}
|
|
1051
|
+
: {
|
|
1052
|
+
kind: "Apply",
|
|
1053
|
+
operator,
|
|
1054
|
+
args: qualifiedArgs,
|
|
1055
|
+
argumentsRange,
|
|
1056
|
+
selectorRanges,
|
|
1057
|
+
argumentRanges,
|
|
1058
|
+
location,
|
|
1059
|
+
};
|
|
1092
1060
|
}
|
|
1093
1061
|
// SANY reads an infix or postfix operator as a primary expression, with or without arguments.
|
|
1094
1062
|
if (token.kind === "Operator" && isOperatorName(token.text) && isAt("(")) {
|
|
1095
|
-
return {
|
|
1063
|
+
return {
|
|
1064
|
+
kind: "Apply",
|
|
1065
|
+
operator: token.text,
|
|
1066
|
+
spelling: token.spelling,
|
|
1067
|
+
args: parseArguments(),
|
|
1068
|
+
location,
|
|
1069
|
+
};
|
|
1096
1070
|
}
|
|
1097
1071
|
if (token.kind === "Operator" && isOperatorName(token.text) && !isTlapm) {
|
|
1098
|
-
return { kind: "Identifier", name: token.text, location };
|
|
1072
|
+
return { kind: "Identifier", name: token.text, spelling: token.spelling, location };
|
|
1099
1073
|
}
|
|
1100
1074
|
switch (token.text) {
|
|
1101
1075
|
case "(": {
|
|
@@ -1263,7 +1237,13 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
1263
1237
|
advance();
|
|
1264
1238
|
operators.last = POSTFIX_PRECEDENCE;
|
|
1265
1239
|
state.left = withRange(
|
|
1266
|
-
{
|
|
1240
|
+
{
|
|
1241
|
+
kind: "Apply",
|
|
1242
|
+
operator: token.text,
|
|
1243
|
+
spelling: token.spelling,
|
|
1244
|
+
args: [state.left],
|
|
1245
|
+
location,
|
|
1246
|
+
},
|
|
1267
1247
|
start,
|
|
1268
1248
|
);
|
|
1269
1249
|
continue;
|
|
@@ -1607,7 +1587,6 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
1607
1587
|
// start of an expression.
|
|
1608
1588
|
const parseFact = (): Fact => {
|
|
1609
1589
|
const start = cursor.index;
|
|
1610
|
-
factStart.index = start;
|
|
1611
1590
|
const token = peek();
|
|
1612
1591
|
if (
|
|
1613
1592
|
token.kind === "Operator" &&
|
|
@@ -1616,7 +1595,12 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
1616
1595
|
) {
|
|
1617
1596
|
cursor.index++;
|
|
1618
1597
|
return withRange(
|
|
1619
|
-
{
|
|
1598
|
+
{
|
|
1599
|
+
kind: "OperatorReference",
|
|
1600
|
+
operator: token.text,
|
|
1601
|
+
spelling: token.spelling,
|
|
1602
|
+
location: getLocation(token),
|
|
1603
|
+
},
|
|
1620
1604
|
start,
|
|
1621
1605
|
);
|
|
1622
1606
|
}
|
|
@@ -2006,7 +1990,6 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
2006
1990
|
start: { line: location.line, column: location.column },
|
|
2007
1991
|
end: { line: token.line, column: token.endColumn },
|
|
2008
1992
|
};
|
|
2009
|
-
if (missingArguments.size > 0) throw createSanyError([...missingArguments.values()]);
|
|
2010
1993
|
openModules.pop();
|
|
2011
1994
|
recursiveScopes.pop();
|
|
2012
1995
|
return module;
|