tla-ts 0.0.3-dev.3cf2ad0 → 0.0.3-dev.5e6ab4d
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 +11 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/transfer.cjs +10 -10
- package/dist/transfer.js +10 -10
- package/package.json +1 -1
- package/src/lexer.ts +5 -1
- package/src/parallel-worker.ts +5 -1
- package/src/parser.ts +12 -1
- package/src/symmetry.ts +9 -1
- package/src/tlc-order.ts +17 -3
package/package.json
CHANGED
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
|
-
|
|
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);
|
package/src/parallel-worker.ts
CHANGED
|
@@ -128,7 +128,11 @@ const run = (start: StartMessage, parent: Port) => {
|
|
|
128
128
|
if (isSharedFingerprintsFull(shared.fingerprints)) return "paused";
|
|
129
129
|
const successor = successors[expansion.index];
|
|
130
130
|
if (search.findViolatedActionProperty(state, successor.state)) return undefined;
|
|
131
|
-
if (!search.satisfiesActionConstraints(state, successor.state))
|
|
131
|
+
if (!search.satisfiesActionConstraints(state, successor.state)) {
|
|
132
|
+
// TLC checks the invariants of every successor it has not seen, even outside the model.
|
|
133
|
+
if (search.findViolatedInvariant(successor.state, state)) return undefined;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
132
136
|
if (generatedStates) {
|
|
133
137
|
writeStateFingerprint(successor.state, fingerprint);
|
|
134
138
|
if (!generatedStates.insert(fingerprint[0], fingerprint[1])) continue;
|
package/src/parser.ts
CHANGED
|
@@ -135,6 +135,8 @@ const INFIX_OPERATORS = new Map<string, InfixOperator>([
|
|
|
135
135
|
["^^", createInfix(14, 14, false)],
|
|
136
136
|
]);
|
|
137
137
|
|
|
138
|
+
const NEGATION_PRECEDENCE = 12;
|
|
139
|
+
|
|
138
140
|
const POSTFIX_OPERATORS = new Set(["^+", "^*", "^#"]);
|
|
139
141
|
|
|
140
142
|
const PREFIX_OPERATOR_REFERENCES = new Set(["-", "~", "-."]);
|
|
@@ -977,7 +979,12 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
977
979
|
return { kind: "Apply", operator: "~", args: [parseExpression(5)], location };
|
|
978
980
|
case "-":
|
|
979
981
|
advance();
|
|
980
|
-
return {
|
|
982
|
+
return {
|
|
983
|
+
kind: "Apply",
|
|
984
|
+
operator: "-.",
|
|
985
|
+
args: [parseExpression(NEGATION_PRECEDENCE + 1)],
|
|
986
|
+
location,
|
|
987
|
+
};
|
|
981
988
|
case "[]":
|
|
982
989
|
advance();
|
|
983
990
|
return { kind: "Always", expression: parseExpression(16), location };
|
|
@@ -1054,6 +1061,10 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1054
1061
|
}
|
|
1055
1062
|
}
|
|
1056
1063
|
advance();
|
|
1064
|
+
// SANY reads - after an infix operator as prefix -, and rejects it after one that binds tighter.
|
|
1065
|
+
if (infix.low > NEGATION_PRECEDENCE && isAt("-")) {
|
|
1066
|
+
throw createError(`Precedence conflict between ${token.text} and -`, peek());
|
|
1067
|
+
}
|
|
1057
1068
|
const right = parseExpression(infix.high + 1);
|
|
1058
1069
|
const left = state.left;
|
|
1059
1070
|
if (token.text === "/\\" || token.text === "\\/") {
|
package/src/symmetry.ts
CHANGED
|
@@ -188,7 +188,15 @@ const computePermutedValue = (value: ObjectValue, permutation: Permutation) => {
|
|
|
188
188
|
const domain = permuteElements(functionValue.domain, permutation);
|
|
189
189
|
const range = permuteElements(functionValue.range, permutation) ?? functionValue.range;
|
|
190
190
|
if (domain) {
|
|
191
|
-
|
|
191
|
+
const permuted = createFunction(
|
|
192
|
+
domain.map((key, index): [Value, Value] => [key, range[index]]),
|
|
193
|
+
);
|
|
194
|
+
// A permutation often maps the domain to itself, such as a function over the symmetric set.
|
|
195
|
+
// Sharing the original domain array lets comparisons with other images skip the domain.
|
|
196
|
+
const isSameDomain = permuted.domain.every(
|
|
197
|
+
(key, index) => key === functionValue.domain[index],
|
|
198
|
+
);
|
|
199
|
+
return isSameDomain ? createSortedFunction(functionValue.domain, permuted.range) : permuted;
|
|
192
200
|
}
|
|
193
201
|
return range === functionValue.range
|
|
194
202
|
? functionValue
|
package/src/tlc-order.ts
CHANGED
|
@@ -184,9 +184,18 @@ const isAdjacent = (left: Token, right: Token | undefined) =>
|
|
|
184
184
|
right.line === left.line &&
|
|
185
185
|
right.column === left.column + left.text.length;
|
|
186
186
|
|
|
187
|
+
const STRING_ESCAPES: Record<string, string> = {
|
|
188
|
+
"\\": "\\\\",
|
|
189
|
+
'"': '\\"',
|
|
190
|
+
"\n": "\\n",
|
|
191
|
+
"\t": "\\t",
|
|
192
|
+
"\r": "\\r",
|
|
193
|
+
"\f": "\\f",
|
|
194
|
+
};
|
|
195
|
+
|
|
187
196
|
// The texts SANY interns while parsing, in order. SANY reads a proof step label such as <1>2 and
|
|
188
|
-
// a module header such as ---- MODULE as one token
|
|
189
|
-
// during semantic analysis.
|
|
197
|
+
// a module header such as ---- MODULE as one token. It interns a string literal as written, quotes
|
|
198
|
+
// included, and interns the literal's contents only during semantic analysis.
|
|
190
199
|
const getParsedTexts = (tokens: Token[]) => {
|
|
191
200
|
const texts: string[] = [];
|
|
192
201
|
for (let index = 0; index < tokens.length; index++) {
|
|
@@ -202,7 +211,12 @@ const getParsedTexts = (tokens: Token[]) => {
|
|
|
202
211
|
continue;
|
|
203
212
|
}
|
|
204
213
|
const isHeader = token.text === "MODULE" && tokens[index - 1]?.kind === "Separator";
|
|
205
|
-
if (
|
|
214
|
+
if (isHeader) continue;
|
|
215
|
+
texts.push(
|
|
216
|
+
token.kind === "String"
|
|
217
|
+
? `"${token.text.replace(/[\\"\n\t\r\f]/g, (character) => STRING_ESCAPES[character])}"`
|
|
218
|
+
: token.text,
|
|
219
|
+
);
|
|
206
220
|
}
|
|
207
221
|
return texts;
|
|
208
222
|
};
|