tla-ts 0.0.8-dev.d9bffda → 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.
- package/README.md +30 -0
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +15 -15
- package/dist/deciders.js +40 -40
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +80 -10
- package/dist/index.d.ts +80 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +116 -36
- package/dist/prove.js +116 -36
- package/dist/run.cjs +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +1 -1
- package/dist/transfer.cjs +128 -103
- package/dist/transfer.js +128 -103
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +7 -21
- package/src/bags.ts +99 -99
- package/src/builtins.ts +44 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +605 -311
- package/src/cli/options.ts +12 -3
- package/src/cli/run.ts +2 -2
- package/src/cli/runtime-invariants.ts +135 -0
- package/src/cli/shared.ts +20 -9
- package/src/cli/tlc-arguments.ts +646 -0
- package/src/cli/tlc-usage.ts +362 -0
- package/src/cli/tlc.ts +571 -185
- package/src/cli/typescript.ts +26 -0
- package/src/cli/xml-exporter.ts +4 -10
- package/src/codegen.ts +190 -46
- package/src/config.ts +101 -68
- package/src/coverage.ts +855 -0
- package/src/dependencies.ts +20 -28
- package/src/dfid.ts +636 -0
- package/src/environment.ts +266 -98
- package/src/errors.ts +142 -45
- package/src/evaluate.ts +632 -298
- package/src/exit-codes.ts +37 -1
- package/src/index.ts +3 -0
- package/src/instances.ts +85 -9
- package/src/java-overrides.ts +2 -12
- package/src/json-reader.ts +456 -0
- package/src/json.ts +262 -139
- package/src/levels.ts +2 -3
- package/src/lexer.ts +17 -26
- package/src/liveness-checker.ts +10 -18
- package/src/liveness.ts +121 -49
- package/src/parallel-worker.ts +14 -10
- package/src/parallel.ts +41 -17
- package/src/parser.ts +436 -90
- package/src/pcal/ast.ts +7 -28
- package/src/pcal/parse.ts +11 -39
- package/src/pcal/tokenize.ts +4 -20
- package/src/pcal/translate.ts +10 -42
- package/src/pcal/validate.ts +3 -21
- package/src/pretty-print.ts +1 -2
- package/src/prover/smt/solver/solver.ts +31 -27
- package/src/randomization.ts +84 -35
- package/src/resolve.ts +18 -60
- package/src/runtime.ts +11 -4
- package/src/sany/builtins.ts +3 -4
- package/src/sany/generator.ts +128 -176
- package/src/sany/levels.ts +6 -30
- package/src/sany/lexer.ts +7 -23
- package/src/sany/linter.ts +31 -29
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +4 -28
- package/src/sany/parse-error.ts +44 -100
- package/src/sany/report.ts +25 -40
- package/src/sany/selectors.ts +8 -22
- package/src/sany/source.ts +8 -15
- package/src/sany/xml.ts +11 -42
- package/src/search.ts +547 -144
- package/src/simulate.ts +694 -0
- package/src/spec-description.ts +166 -48
- package/src/standard-definitions.ts +2 -3
- package/src/standard-modules.ts +264 -68
- package/src/state-graph.ts +51 -18
- package/src/subexpressions.ts +31 -5
- package/src/successors.ts +267 -77
- package/src/symmetry.ts +31 -8
- package/src/tableau.ts +1 -2
- package/src/tlc/fingerprint.ts +183 -61
- package/src/tlc/jar-data.ts +113 -6
- package/src/tlc/messages.ts +122 -37
- package/src/tlc/order.ts +33 -38
- package/src/tlc/random.ts +16 -16
- package/src/tlc/replay.ts +563 -211
- package/src/tlc/summary.ts +2 -4
- package/src/tlc/tlc-operators.ts +81 -36
- package/src/tlc/tlcext-operators.ts +138 -117
- package/src/tlc/trace-spec.ts +273 -0
- package/src/tlc/value-stream.ts +143 -0
- package/src/tlc/version.ts +2 -4
- package/src/typescript/actions.ts +494 -0
- package/src/typescript/collections.ts +615 -0
- package/src/typescript/compile.ts +70 -0
- package/src/typescript/context.ts +106 -0
- package/src/typescript/emit.ts +122 -0
- package/src/typescript/expressions.ts +508 -0
- package/src/typescript/formula.ts +160 -0
- package/src/typescript/functions.ts +295 -0
- package/src/typescript/model.ts +164 -0
- package/src/typescript/names.ts +116 -0
- package/src/typescript/program.ts +51 -0
- package/src/typescript/properties.ts +148 -0
- package/src/typescript/scope.ts +117 -0
- package/src/typescript/steps.ts +175 -0
- package/src/typescript/types.ts +178 -0
- package/src/values.ts +832 -255
package/src/sany/parse-error.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { createSanyLexer, escapeLexeme, getKind, type SanyToken } from "./lexer";
|
|
2
2
|
import { SANY_OPERATOR_SYNONYMS } from "../tlc/jar-data";
|
|
3
3
|
|
|
4
|
-
//
|
|
5
|
-
// the
|
|
6
|
-
// their lookahead specifications, and the semantic actions that steer parsing or set the
|
|
7
|
-
// `expecting` message. TLAplusParser.msgStackToString prints that message, the token the parser
|
|
8
|
-
// failed at, and the productions it was in, so the interpreter must fail at the same token, in the
|
|
9
|
-
// same productions, and must look as far ahead as JavaCC's jj_rescan_token does.
|
|
4
|
+
// Interprets the grammar of javacc/tla+.jj as JavaCC's generated parser runs it, so that it fails
|
|
5
|
+
// at the same token, in the same productions, after the same lookahead as SANY's parser.
|
|
10
6
|
|
|
11
7
|
type Predicate = (state: ParserState) => boolean;
|
|
12
8
|
|
|
@@ -35,14 +31,12 @@ interface RepeatUnit {
|
|
|
35
31
|
body: SequenceUnit;
|
|
36
32
|
}
|
|
37
33
|
|
|
38
|
-
// Java code in a production, which may throw a ParseException with a message.
|
|
39
34
|
interface ActionUnit {
|
|
40
35
|
type: "action";
|
|
41
36
|
run: (state: ParserState) => string | undefined;
|
|
42
37
|
}
|
|
43
38
|
|
|
44
|
-
//
|
|
45
|
-
// whether to take that expansion. Elsewhere, JavaCC checks only its semantic part.
|
|
39
|
+
// Elsewhere than first in an alternative or a loop's body, JavaCC checks only its semantic part.
|
|
46
40
|
interface LookaheadUnit {
|
|
47
41
|
type: "lookahead";
|
|
48
42
|
amount: number;
|
|
@@ -59,11 +53,8 @@ type Unit =
|
|
|
59
53
|
| ActionUnit
|
|
60
54
|
| LookaheadUnit;
|
|
61
55
|
|
|
62
|
-
// A token kind in angle brackets, a production's name, or a unit.
|
|
63
56
|
type Part = Unit | string;
|
|
64
57
|
|
|
65
|
-
// A SyntaxTreeNode: a token, or what a production matched, which spans from its first token to
|
|
66
|
-
// its last.
|
|
67
58
|
interface SyntaxNode {
|
|
68
59
|
kind: string;
|
|
69
60
|
heirs: SyntaxNode[];
|
|
@@ -71,18 +62,14 @@ interface SyntaxNode {
|
|
|
71
62
|
last: SanyToken;
|
|
72
63
|
}
|
|
73
64
|
|
|
74
|
-
// The production being parsed: the nodes of what it has matched, and the node it returns if that
|
|
75
|
-
// is not a node of its own kind over them.
|
|
76
65
|
interface Frame {
|
|
77
66
|
heirs: SyntaxNode[];
|
|
78
67
|
node: SyntaxNode | undefined;
|
|
79
68
|
}
|
|
80
69
|
|
|
81
70
|
interface Production {
|
|
82
|
-
// The name TLAplusParser.bpa pushes on the message stack, if the production calls it.
|
|
83
71
|
message: string | undefined;
|
|
84
72
|
body: SequenceUnit;
|
|
85
|
-
// Java code that runs after the production's epa.
|
|
86
73
|
exit: ((frame: Frame, state: ParserState) => string | void) | undefined;
|
|
87
74
|
}
|
|
88
75
|
|
|
@@ -95,7 +82,6 @@ interface Operator {
|
|
|
95
82
|
fix: "prefix" | "postfix" | "infix" | "nfix";
|
|
96
83
|
}
|
|
97
84
|
|
|
98
|
-
// An OSelement of OperatorStack: an operand, or an operator with its node.
|
|
99
85
|
interface StackElement {
|
|
100
86
|
node: SyntaxNode;
|
|
101
87
|
operator: Operator | undefined;
|
|
@@ -107,7 +93,6 @@ interface Analysis {
|
|
|
107
93
|
hasSemanticStart: boolean;
|
|
108
94
|
}
|
|
109
95
|
|
|
110
|
-
// A jj_2 call, which jj_rescan_token scans again if it looked past the current token: JJCalls.
|
|
111
96
|
interface LookaheadCall {
|
|
112
97
|
generation: number;
|
|
113
98
|
first: SanyToken;
|
|
@@ -134,7 +119,6 @@ interface ParserState {
|
|
|
134
119
|
readToken: () => SanyToken;
|
|
135
120
|
lexicalError: string | undefined;
|
|
136
121
|
token: SanyToken;
|
|
137
|
-
// jj_gen, which counts consumed tokens, and its value at the last failed jj_ntk switch.
|
|
138
122
|
generation: number;
|
|
139
123
|
failedSwitchGeneration: number;
|
|
140
124
|
scanPosition: SanyToken;
|
|
@@ -146,15 +130,14 @@ interface ParserState {
|
|
|
146
130
|
calls: Map<SequenceUnit, LookaheadCall[]>;
|
|
147
131
|
expecting: string;
|
|
148
132
|
messages: StackMessage[];
|
|
133
|
+
pushedErrors: string[];
|
|
149
134
|
moduleName: string | undefined;
|
|
150
135
|
junctions: Junction[];
|
|
151
136
|
frames: Frame[];
|
|
152
|
-
// OperatorStack's stack of stacks, one for each Expression being parsed.
|
|
153
137
|
operatorStacks: StackElement[][];
|
|
154
138
|
lastOperator: Operator | undefined;
|
|
155
139
|
proofLevels: number[];
|
|
156
140
|
isTerminalProof: boolean;
|
|
157
|
-
// Whether FairnessHook is set, which it is if the last NoOpExtension ended with arguments.
|
|
158
141
|
isFairnessHooked: boolean;
|
|
159
142
|
isFairnessParenthesized: boolean[];
|
|
160
143
|
report: string | undefined;
|
|
@@ -174,7 +157,6 @@ const getKindRange = (first: string, last: string) =>
|
|
|
174
157
|
(_, offset) => getKind(first) + offset,
|
|
175
158
|
);
|
|
176
159
|
|
|
177
|
-
// TLAplusParser.isOp, isInfixOp, isPostfixOp, and isFieldNameToken.
|
|
178
160
|
const OPERATOR_KINDS = new Set(getKindRange("op_57", "op_119"));
|
|
179
161
|
const INFIX_KINDS = new Set(getKindRange("op_1", "op_119"));
|
|
180
162
|
const POSTFIX_KINDS = new Set(getKindRange("op_57", "op_70"));
|
|
@@ -294,15 +276,12 @@ const CANONICAL_OPERATORS = new Map([
|
|
|
294
276
|
...createOperators("infix", 10, 10, false, "=>"),
|
|
295
277
|
]);
|
|
296
278
|
|
|
297
|
-
// Operators.getOperator, which knows an operator by its name or a synonym.
|
|
298
279
|
const OPERATORS = new Map([
|
|
299
280
|
...CANONICAL_OPERATORS,
|
|
300
281
|
...SANY_OPERATOR_SYNONYMS.flatMap((synonyms) =>
|
|
301
282
|
synonyms.slice(1).map((synonym) => [synonym, CANONICAL_OPERATORS.get(synonyms[0])] as const),
|
|
302
283
|
),
|
|
303
284
|
]);
|
|
304
|
-
// OperatorStack's fcnOp, which a function application's "[" pushes, and Operator.VoidOperator,
|
|
305
|
-
// which OperatorStack.finalReduce pushes to reduce the whole stack.
|
|
306
285
|
const FCN_OPERATOR = OPERATORS.get("[");
|
|
307
286
|
const VOID_OPERATOR: Operator = {
|
|
308
287
|
name: "$$_void",
|
|
@@ -355,8 +334,7 @@ const getNext = (state: ParserState, token: SanyToken) => {
|
|
|
355
334
|
return token.next;
|
|
356
335
|
};
|
|
357
336
|
|
|
358
|
-
//
|
|
359
|
-
// during a scan.
|
|
337
|
+
// Counts from the scan position while a semantic lookahead runs during a scan.
|
|
360
338
|
const getToken = (state: ParserState, index: number) => {
|
|
361
339
|
let token = state.isLookingAhead ? state.scanPosition : state.token;
|
|
362
340
|
for (let count = 0; count < index; count++) token = getNext(state, token);
|
|
@@ -368,7 +346,6 @@ const isNextKind = (...names: string[]) => {
|
|
|
368
346
|
return (state: ParserState) => kinds.includes(getToken(state, 1).kind);
|
|
369
347
|
};
|
|
370
348
|
|
|
371
|
-
// JunctionListContext.isAboveCurrent, for the next token by default, and isNewBullet.
|
|
372
349
|
const isAboveCurrent = (state: ParserState, column = getToken(state, 1).beginColumn) => {
|
|
373
350
|
const junction = state.junctions.at(-1);
|
|
374
351
|
return junction === undefined || junction.column < column;
|
|
@@ -380,17 +357,14 @@ const isNewBullet = (state: ParserState) => {
|
|
|
380
357
|
return junction?.column === token.beginColumn && junction.kind === token.kind;
|
|
381
358
|
};
|
|
382
359
|
|
|
383
|
-
// TLAplusParser.caseSep.
|
|
384
360
|
const isCaseSeparator = (state: ParserState) =>
|
|
385
361
|
isNextKind("CASESEP")(state) && isAboveCurrent(state);
|
|
386
362
|
|
|
387
|
-
// The Java code that lets a keyword name a module or a record field.
|
|
388
363
|
const setFieldName = (state: ParserState) => {
|
|
389
364
|
const token = getToken(state, 1);
|
|
390
365
|
if (FIELD_NAME_KINDS.has(token.kind)) token.kind = IDENTIFIER;
|
|
391
366
|
};
|
|
392
367
|
|
|
393
|
-
// SyntaxTreeNode.getLocation for the tokens first to last, as Location.toString prints it.
|
|
394
368
|
const formatLocation = (state: ParserState, first: SanyToken, last = first) =>
|
|
395
369
|
`line ${first.beginLine}, col ${first.beginColumn} to line ${last.beginLine}, col ${last.beginColumn + last.image.length - 1} of module ${state.moduleName}`;
|
|
396
370
|
|
|
@@ -401,7 +375,6 @@ const createNode = (kind: string, heirs: SyntaxNode[]) => ({
|
|
|
401
375
|
last: heirs[heirs.length - 1].last,
|
|
402
376
|
});
|
|
403
377
|
|
|
404
|
-
// The node offset nodes back among those of what the production being parsed has matched.
|
|
405
378
|
const getHeir = (state: ParserState, offset: number) => {
|
|
406
379
|
const heirs = state.frames[state.frames.length - 1].heirs;
|
|
407
380
|
return heirs[heirs.length - offset];
|
|
@@ -410,16 +383,12 @@ const getHeir = (state: ParserState, offset: number) => {
|
|
|
410
383
|
const getOperatorStack = (state: ParserState) =>
|
|
411
384
|
state.operatorStacks[state.operatorStacks.length - 1];
|
|
412
385
|
|
|
413
|
-
// Operator.succ and Operator.prec: whether left binds tighter than right, or looser.
|
|
414
386
|
const isTighter = (left: Operator, right: Operator) => left.low > right.high;
|
|
415
387
|
const isLooser = (left: Operator, right: Operator) => left.high < right.low;
|
|
416
388
|
|
|
417
|
-
// Operators.getMixfix, which turns "-" into the prefix "-.".
|
|
418
389
|
const getMixfix = (operator: Operator) =>
|
|
419
390
|
operator.fix === "prefix" ? operator : OPERATORS.get(`${operator.name}.`);
|
|
420
391
|
|
|
421
|
-
// OperatorStack.reducePostfix: replaces the operand and postfix operator below index top with
|
|
422
|
-
// their expression.
|
|
423
392
|
const reducePostfix = (stack: StackElement[], top: number) => {
|
|
424
393
|
const operand = stack[top - 2].node;
|
|
425
394
|
const postfix = stack[top - 1];
|
|
@@ -432,8 +401,6 @@ const reducePostfix = (stack: StackElement[], top: number) => {
|
|
|
432
401
|
});
|
|
433
402
|
};
|
|
434
403
|
|
|
435
|
-
// OperatorStack.reducePrefix and reduceInfix: replace the operator below the top of the stack and
|
|
436
|
-
// its operands with their expression.
|
|
437
404
|
const reduceOperator = (stack: StackElement[], operator: Operator) => {
|
|
438
405
|
const top = stack.length - 1;
|
|
439
406
|
if (operator.fix !== "infix" && operator.fix !== "nfix") {
|
|
@@ -455,11 +422,8 @@ const reduceOperator = (stack: StackElement[], operator: Operator) => {
|
|
|
455
422
|
});
|
|
456
423
|
};
|
|
457
424
|
|
|
458
|
-
//
|
|
459
|
-
//
|
|
460
|
-
// or two operands follow each other. The grammar pushes an infix or postfix operator only after an
|
|
461
|
-
// operand, except for a "-" that Expression takes for a prefix one, so the checks that reject
|
|
462
|
-
// other orders never fail and are left out.
|
|
425
|
+
// The grammar pushes an infix or postfix operator only after an operand, except a "-" that
|
|
426
|
+
// Expression takes for a prefix one, so the checks that reject other orders are left out.
|
|
463
427
|
const reduceStack = (state: ParserState): string | undefined => {
|
|
464
428
|
const stack = getOperatorStack(state);
|
|
465
429
|
const top = stack.length - 1;
|
|
@@ -514,8 +478,6 @@ const reduceStack = (state: ParserState): string | undefined => {
|
|
|
514
478
|
: `\n Illegal combination of operators ${operator.name} in block ${location} and ${right.operator.name}.`;
|
|
515
479
|
};
|
|
516
480
|
|
|
517
|
-
// OperatorStack.pushOnStack for the node of the production just parsed: an operand, or, if
|
|
518
|
-
// isOperator holds of it, an operator, which reduceStack reduces with what is below it.
|
|
519
481
|
const pushOnStack = (isOperator: (node: SyntaxNode) => boolean) =>
|
|
520
482
|
action((state) => {
|
|
521
483
|
const stack = getOperatorStack(state);
|
|
@@ -530,30 +492,27 @@ const pushOnStack = (isOperator: (node: SyntaxNode) => boolean) =>
|
|
|
530
492
|
const PUSH_OPERAND = pushOnStack(() => false);
|
|
531
493
|
const PUSH_OPERATOR = pushOnStack(() => true);
|
|
532
494
|
|
|
533
|
-
// TLAplusParser's lastOp, which the productions of operators set.
|
|
534
495
|
const SET_LAST_OPERATOR = action((state) => {
|
|
535
496
|
state.lastOperator = OPERATORS.get(state.token.image);
|
|
536
497
|
});
|
|
537
498
|
|
|
538
|
-
// The OpArgs node that a PrimitiveExp's heirs end with, directly or in their last "!" extension.
|
|
539
499
|
const getArguments = (heirs: SyntaxNode[]) => {
|
|
540
500
|
const last = heirs[heirs.length - 1];
|
|
541
501
|
const node = last.kind === "BangExt" ? last.heirs[last.heirs.length - 1] : last;
|
|
542
502
|
return node.kind === "OpArgs" ? node : undefined;
|
|
543
503
|
};
|
|
544
504
|
|
|
545
|
-
//
|
|
505
|
+
// SANY also takes A!B!lbl(x) for a label, its bug tlaplus/tlaplus#885.
|
|
546
506
|
const isLabel = (node: SyntaxNode) => {
|
|
547
507
|
if (node.kind === "GeneralId") return true;
|
|
548
|
-
const opArgs =
|
|
508
|
+
const opArgs =
|
|
509
|
+
node.kind === "OpApplication" && node.heirs.length === 2 ? getArguments(node.heirs) : undefined;
|
|
549
510
|
return (
|
|
550
511
|
opArgs !== undefined &&
|
|
551
512
|
opArgs.heirs.every((argument, index) => index % 2 === 0 || argument.kind === "GeneralId")
|
|
552
513
|
);
|
|
553
514
|
};
|
|
554
515
|
|
|
555
|
-
// The first node below node, stopping at junction lists, that does not start to the right of the
|
|
556
|
-
// current junction list's bullet: what TLAplusParser.checkIndentation reports.
|
|
557
516
|
const getMisindentedNode = (state: ParserState, node: SyntaxNode): SyntaxNode | undefined => {
|
|
558
517
|
for (const child of node.heirs) {
|
|
559
518
|
if (child.kind === "Junctions") continue;
|
|
@@ -564,9 +523,7 @@ const getMisindentedNode = (state: ParserState, node: SyntaxNode): SyntaxNode |
|
|
|
564
523
|
return undefined;
|
|
565
524
|
};
|
|
566
525
|
|
|
567
|
-
// TLAplusParser.belchDEF
|
|
568
|
-
// definition. It reverses the links of the tokens it walks over, so that `next` leads back toward
|
|
569
|
-
// the definition's start, and restores them when done.
|
|
526
|
+
// TLAplusParser.belchDEF reverses the links of the tokens it walks over and restores them after.
|
|
570
527
|
const belchDef = (state: ParserState) => {
|
|
571
528
|
const stops = ["EOF", "THEOREM", "PROPOSITION", "ASSUMPTION", "END_MODULE"].map(getKind);
|
|
572
529
|
const isKind = (token: SanyToken, ...names: string[]) =>
|
|
@@ -627,8 +584,6 @@ const belchDef = (state: ParserState) => {
|
|
|
627
584
|
current.next = next;
|
|
628
585
|
};
|
|
629
586
|
|
|
630
|
-
// TLAplusParser.matchFcnConst: whether the next tokens are "<< ... >> \in" or a list of
|
|
631
|
-
// identifiers followed by \in.
|
|
632
587
|
const matchFcnConst = (state: ParserState) => {
|
|
633
588
|
let token = getToken(state, 1);
|
|
634
589
|
if (token.kind === getKind("LAB")) {
|
|
@@ -651,13 +606,11 @@ const matchFcnConst = (state: ParserState) => {
|
|
|
651
606
|
return token.kind === getKind("IN");
|
|
652
607
|
};
|
|
653
608
|
|
|
654
|
-
// TLAplusParser.levelOfProofStepLexeme: -1 for <*> and -2 for <+>.
|
|
655
609
|
const getStepLevel = (token: SanyToken) => {
|
|
656
610
|
if (token.image[1] === "*") return -1;
|
|
657
611
|
return token.image[1] === "+" ? -2 : Number.parseInt(token.image.slice(1));
|
|
658
612
|
};
|
|
659
613
|
|
|
660
|
-
// TLAplusParser.getProofLevel. TLAplusParser's proofDepth is the length of proofLevels less 1.
|
|
661
614
|
const getProofLevel = (state: ParserState) => state.proofLevels.at(-1) ?? -1;
|
|
662
615
|
|
|
663
616
|
const beginsProof = (state: ParserState) => {
|
|
@@ -679,7 +632,7 @@ const beginsProof = (state: ParserState) => {
|
|
|
679
632
|
return isNextKind("BY", "PROOF", "OBVIOUS", "OMITTED")(state);
|
|
680
633
|
};
|
|
681
634
|
|
|
682
|
-
//
|
|
635
|
+
// Also sets the level of a proof from its first step.
|
|
683
636
|
const isCorrectLevel = (state: ParserState, token: SanyToken) => {
|
|
684
637
|
const level = getStepLevel(token);
|
|
685
638
|
const depth = state.proofLevels.length - 1;
|
|
@@ -725,8 +678,7 @@ const STEP_START = tokens(
|
|
|
725
678
|
].map(getKind),
|
|
726
679
|
);
|
|
727
680
|
|
|
728
|
-
//
|
|
729
|
-
// separate lookahead site, as in the generated parser.
|
|
681
|
+
// Each use is a separate lookahead site, as in the generated parser.
|
|
730
682
|
const getPrefixOperators = () =>
|
|
731
683
|
zeroOrMore(
|
|
732
684
|
lookahead({ expansion: [choice(PREFIX_OPERATOR, "<op_77>")], semantic: isAboveCurrent }),
|
|
@@ -777,7 +729,6 @@ const setTerminalProof = (isTerminalProof: boolean) =>
|
|
|
777
729
|
state.isTerminalProof = isTerminalProof;
|
|
778
730
|
});
|
|
779
731
|
|
|
780
|
-
// An alternative of OperatorOrFunctionDefinition: a left-hand side, then "==", then a body.
|
|
781
732
|
const definition = (expecting: string, ...parts: Part[]) =>
|
|
782
733
|
sequence(
|
|
783
734
|
...parts.slice(0, -1),
|
|
@@ -1513,7 +1464,14 @@ const PRODUCTIONS: Record<string, Production> = {
|
|
|
1513
1464
|
]),
|
|
1514
1465
|
ExceptComponent: production("Except Component", [
|
|
1515
1466
|
choice(
|
|
1516
|
-
sequence(
|
|
1467
|
+
sequence(
|
|
1468
|
+
"<DOT>",
|
|
1469
|
+
action(setFieldName),
|
|
1470
|
+
"Identifier",
|
|
1471
|
+
action((state) => {
|
|
1472
|
+
if (state.token.image === "@") state.pushedErrors.push("@ used in !.@");
|
|
1473
|
+
}),
|
|
1474
|
+
),
|
|
1517
1475
|
sequence("<LSB>", "Expression", zeroOrMore("<COMMA>", "Expression"), "<RSB>"),
|
|
1518
1476
|
),
|
|
1519
1477
|
]),
|
|
@@ -1599,18 +1557,13 @@ const PRODUCTIONS: Record<string, Production> = {
|
|
|
1599
1557
|
state.junctions.pop();
|
|
1600
1558
|
}),
|
|
1601
1559
|
]),
|
|
1602
|
-
JuncItem: production(
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
item &&
|
|
1610
|
-
`Item at ${formatLocation(state, item.first, item.last)} is not properly indented inside conjunction or disjunction list item at ${formatLocation(state, frame.heirs[0].first, frame.heirs[1].last)}`
|
|
1611
|
-
);
|
|
1612
|
-
},
|
|
1613
|
-
),
|
|
1560
|
+
JuncItem: production("Junction Item", [choice("<OR>", "<AND>"), "Expression"], (frame, state) => {
|
|
1561
|
+
const item = getMisindentedNode(state, frame.heirs[1]);
|
|
1562
|
+
return (
|
|
1563
|
+
item &&
|
|
1564
|
+
`Item at ${formatLocation(state, item.first, item.last)} is not properly indented inside conjunction or disjunction list item at ${formatLocation(state, frame.heirs[0].first, frame.heirs[1].last)}`
|
|
1565
|
+
);
|
|
1566
|
+
}),
|
|
1614
1567
|
UnboundOrBoundChoose: production("(Un)Bounded Choose", [
|
|
1615
1568
|
"<CHOOSE>",
|
|
1616
1569
|
choice("Identifier", "IdentifierTuple"),
|
|
@@ -1637,8 +1590,8 @@ const PRODUCTIONS: Record<string, Production> = {
|
|
|
1637
1590
|
getPrefixOperators(),
|
|
1638
1591
|
getOperand(),
|
|
1639
1592
|
],
|
|
1640
|
-
// OperatorStack.finalReduce
|
|
1641
|
-
//
|
|
1593
|
+
// OperatorStack.finalReduce pushes an operator that binds looser than any other, whose node,
|
|
1594
|
+
// null in Java, is never printed.
|
|
1642
1595
|
(frame, state) => {
|
|
1643
1596
|
const stack = getOperatorStack(state);
|
|
1644
1597
|
stack.push({ node: frame.heirs[0], operator: VOID_OPERATOR });
|
|
@@ -1653,7 +1606,6 @@ const PRODUCTIONS: Record<string, Production> = {
|
|
|
1653
1606
|
sequence(
|
|
1654
1607
|
lookahead({
|
|
1655
1608
|
expansion: [choice("<AND>", "<OR>")],
|
|
1656
|
-
// OperatorStack.preInEmptyTop.
|
|
1657
1609
|
semantic: (state) => {
|
|
1658
1610
|
const top = state.operatorStacks.at(-1)?.at(-1);
|
|
1659
1611
|
return (
|
|
@@ -1698,7 +1650,6 @@ const PRODUCTIONS: Record<string, Production> = {
|
|
|
1698
1650
|
lookahead({ expansion: ["<LSB>"], semantic: isAboveCurrent }),
|
|
1699
1651
|
expect("function argument"),
|
|
1700
1652
|
"SBracketCases",
|
|
1701
|
-
// TLAplusParser.isGenOp, which holds of a function application.
|
|
1702
1653
|
pushOnStack((node) => node.kind === "FcnAppl"),
|
|
1703
1654
|
),
|
|
1704
1655
|
),
|
|
@@ -1724,7 +1675,6 @@ const PRODUCTIONS: Record<string, Production> = {
|
|
|
1724
1675
|
return undefined;
|
|
1725
1676
|
}),
|
|
1726
1677
|
"Expression",
|
|
1727
|
-
// TLAplusParser.labelDoesNotChangeParse, given the operator parsed last.
|
|
1728
1678
|
action((state) => {
|
|
1729
1679
|
const stack = getOperatorStack(state);
|
|
1730
1680
|
const labeled = getHeir(state, 1);
|
|
@@ -1851,9 +1801,6 @@ const PRODUCTIONS: Record<string, Production> = {
|
|
|
1851
1801
|
|
|
1852
1802
|
const analyses = new Map<Unit, Analysis>();
|
|
1853
1803
|
|
|
1854
|
-
// What JavaCC's ParseEngine.genFirstSet and Semanticize.emptyExpansionExists compute: the tokens
|
|
1855
|
-
// an expansion can start with, whether it can match nothing, and whether its start passes a
|
|
1856
|
-
// semantic lookahead, which makes JavaCC decide by a jj_2 call instead of a switch (jj2LA).
|
|
1857
1804
|
const analyze = (unit: Unit): Analysis => {
|
|
1858
1805
|
const cached = analyses.get(unit);
|
|
1859
1806
|
if (cached) return cached;
|
|
@@ -1893,8 +1840,7 @@ const evaluateSemantic = (state: ParserState, semantic: Predicate) => {
|
|
|
1893
1840
|
return isPassed;
|
|
1894
1841
|
};
|
|
1895
1842
|
|
|
1896
|
-
//
|
|
1897
|
-
// length of the longest token sequence the ParseException expects.
|
|
1843
|
+
// Also records how far past the current token jj_rescan_token scans.
|
|
1898
1844
|
const scanToken = (state: ParserState, kinds: Set<number>): ScanResult => {
|
|
1899
1845
|
if (state.scanPosition === state.lastPosition) {
|
|
1900
1846
|
state.remaining--;
|
|
@@ -1915,8 +1861,8 @@ const scanToken = (state: ParserState, kinds: Set<number>): ScanResult => {
|
|
|
1915
1861
|
return state.remaining === 0 && state.scanPosition === state.lastPosition ? "done" : "matched";
|
|
1916
1862
|
};
|
|
1917
1863
|
|
|
1918
|
-
//
|
|
1919
|
-
//
|
|
1864
|
+
// A loop or option skips its body's lookahead, but a choice checks the semantic part of each
|
|
1865
|
+
// alternative's.
|
|
1920
1866
|
const scan = (state: ParserState, unit: Unit): ScanResult => {
|
|
1921
1867
|
if (unit.type === "tokens") return scanToken(state, unit.kinds);
|
|
1922
1868
|
if (unit.type === "call") return scan(state, PRODUCTIONS[unit.name].body);
|
|
@@ -1965,8 +1911,8 @@ const scan = (state: ParserState, unit: Unit): ScanResult => {
|
|
|
1965
1911
|
}
|
|
1966
1912
|
};
|
|
1967
1913
|
|
|
1968
|
-
//
|
|
1969
|
-
//
|
|
1914
|
+
// Saves the call for jj_rescan_token as jj_save does, over a call of the same site that can't be
|
|
1915
|
+
// rescanned.
|
|
1970
1916
|
const scanAhead = (state: ParserState, amount: number, expansion: SequenceUnit) => {
|
|
1971
1917
|
state.remaining = amount;
|
|
1972
1918
|
state.scanPosition = state.token;
|
|
@@ -1985,9 +1931,8 @@ const scanAhead = (state: ParserState, amount: number, expansion: SequenceUnit)
|
|
|
1985
1931
|
return isMatched;
|
|
1986
1932
|
};
|
|
1987
1933
|
|
|
1988
|
-
//
|
|
1989
|
-
//
|
|
1990
|
-
// tokens are needed, a jj_ntk switch where one token decides, and a jj_2 call otherwise.
|
|
1934
|
+
// A check is the semantic lookahead alone where no tokens are needed, a jj_ntk switch where one
|
|
1935
|
+
// token decides, and a jj_2 call otherwise.
|
|
1991
1936
|
const decide = (state: ParserState, alternatives: SequenceUnit[]) =>
|
|
1992
1937
|
alternatives.findIndex((alternative) => {
|
|
1993
1938
|
const head = alternative.units[0];
|
|
@@ -2005,8 +1950,7 @@ const decide = (state: ParserState, alternatives: SequenceUnit[]) =>
|
|
|
2005
1950
|
return scanAhead(state, amount, expansion) && (semantic === undefined || semantic(state));
|
|
2006
1951
|
});
|
|
2007
1952
|
|
|
2008
|
-
//
|
|
2009
|
-
// builds, which shows as many tokens as the longest token sequence it expects. A rescan that
|
|
1953
|
+
// Shows as many tokens as the longest token sequence the ParseException expects. A rescan that
|
|
2010
1954
|
// finishes its lookahead ends the rescans of its site.
|
|
2011
1955
|
const getEncountered = (state: ParserState) => {
|
|
2012
1956
|
state.isRescanning = true;
|
|
@@ -2038,7 +1982,6 @@ const getEncountered = (state: ParserState) => {
|
|
|
2038
1982
|
return `Encountered "${images.join(" ")}" at line ${next.beginLine}, column ${next.beginColumn} and token "${escapeLexeme(state.token.image)}" `;
|
|
2039
1983
|
};
|
|
2040
1984
|
|
|
2041
|
-
// Records TLAplusParser.msgStackToString's report, without its "***Parse Error***" heading.
|
|
2042
1985
|
const fail = (state: ParserState, message?: string) => {
|
|
2043
1986
|
const expecting = state.expecting === "" ? "" : `Was expecting "${state.expecting}"\n`;
|
|
2044
1987
|
const stack = state.messages
|
|
@@ -2070,7 +2013,6 @@ const consume = (state: ParserState, kinds: Set<number>) => {
|
|
|
2070
2013
|
return true;
|
|
2071
2014
|
};
|
|
2072
2015
|
|
|
2073
|
-
// Parses a production, and adds the node it returns to those of the production that called it.
|
|
2074
2016
|
const parseProduction = (state: ParserState, name: string) => {
|
|
2075
2017
|
const production = PRODUCTIONS[name];
|
|
2076
2018
|
if (production.message !== undefined) {
|
|
@@ -2092,8 +2034,6 @@ const parseProduction = (state: ParserState, name: string) => {
|
|
|
2092
2034
|
return true;
|
|
2093
2035
|
};
|
|
2094
2036
|
|
|
2095
|
-
// Runs the parse-mode code JavaCC generates for unit. It returns false once a ParseException's
|
|
2096
|
-
// report is recorded.
|
|
2097
2037
|
const parse = (state: ParserState, unit: Unit): boolean => {
|
|
2098
2038
|
if (unit.type === "tokens") return consume(state, unit.kinds);
|
|
2099
2039
|
if (unit.type === "call") return parseProduction(state, unit.name);
|
|
@@ -2120,7 +2060,6 @@ const parse = (state: ParserState, unit: Unit): boolean => {
|
|
|
2120
2060
|
return true;
|
|
2121
2061
|
};
|
|
2122
2062
|
|
|
2123
|
-
// What SANY reports for a module its lexer or parser rejects, or undefined if it accepts the module.
|
|
2124
2063
|
export const getSanyParseError = (source: string) => {
|
|
2125
2064
|
const readToken = createSanyLexer(source);
|
|
2126
2065
|
const start: SanyToken = { kind: EOF, image: "", beginLine: 0, beginColumn: 0, next: undefined };
|
|
@@ -2144,6 +2083,7 @@ export const getSanyParseError = (source: string) => {
|
|
|
2144
2083
|
calls: new Map(),
|
|
2145
2084
|
expecting: "nothing",
|
|
2146
2085
|
messages: [],
|
|
2086
|
+
pushedErrors: [],
|
|
2147
2087
|
moduleName: undefined,
|
|
2148
2088
|
junctions: [],
|
|
2149
2089
|
frames: [],
|
|
@@ -2157,5 +2097,9 @@ export const getSanyParseError = (source: string) => {
|
|
|
2157
2097
|
};
|
|
2158
2098
|
const isParsed = parse(state, { type: "call", name: "CompilationUnit" });
|
|
2159
2099
|
if (state.lexicalError !== undefined) return state.lexicalError;
|
|
2160
|
-
|
|
2100
|
+
const errors = [
|
|
2101
|
+
...state.pushedErrors,
|
|
2102
|
+
...(isParsed || state.report === undefined ? [] : [`***Parse Error***\n${state.report}`]),
|
|
2103
|
+
];
|
|
2104
|
+
return errors.length === 0 ? undefined : errors.join("\n");
|
|
2161
2105
|
};
|