tla-ts 0.0.3-dev.3cf2ad0 → 0.0.3-dev.3ef4193
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 +16 -2
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +158 -8
- package/dist/index.d.ts +158 -8
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +1351 -19
- package/dist/run-cli.js +1351 -19
- package/dist/transfer.cjs +88 -18
- package/dist/transfer.js +88 -18
- package/package.json +5 -1
- package/src/ast.ts +146 -6
- package/src/bags.ts +4 -7
- package/src/builtins.ts +29 -11
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1539 -235
- package/src/cli-options.ts +11 -5
- package/src/cli.ts +8 -1
- package/src/codegen.ts +77 -37
- package/src/config.ts +252 -179
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +524 -140
- package/src/errors.ts +224 -3
- package/src/evaluate.ts +796 -246
- package/src/exit-codes.ts +22 -43
- package/src/index.ts +1 -0
- package/src/instances.ts +19 -16
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +191 -45
- package/src/lexer.ts +37 -5
- package/src/live-check.ts +828 -0
- package/src/liveness.ts +218 -572
- package/src/obligation-expression.ts +2 -2
- package/src/obligation-source.ts +2 -0
- package/src/parallel-worker.ts +13 -4
- package/src/parallel.ts +73 -6
- package/src/parser.ts +436 -144
- package/src/pcal-ast.ts +770 -0
- package/src/pcal-parse.ts +1523 -0
- package/src/pcal-tokenize.ts +516 -0
- package/src/pcal-translate.ts +1230 -0
- package/src/pcal-validate.ts +454 -0
- package/src/randomization.ts +24 -7
- package/src/resolve.ts +1424 -415
- package/src/run-cli.ts +1200 -143
- package/src/runtime.ts +19 -1
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3112 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +545 -0
- package/src/sany-linter.ts +122 -0
- package/src/sany-modules.ts +1398 -0
- package/src/sany-nodes.ts +463 -0
- package/src/sany-parse-error.ts +2161 -0
- package/src/sany-report.ts +354 -0
- package/src/sany-selectors.ts +738 -0
- package/src/sany-source.ts +248 -0
- package/src/sany-xml.ts +1017 -0
- package/src/spec-description.ts +42 -11
- package/src/standard-modules.ts +200 -148
- package/src/standard-ranges.ts +116 -0
- package/src/state-graph.ts +180 -0
- package/src/subexpressions.ts +231 -171
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +219 -107
- package/src/symmetry.ts +189 -53
- package/src/tableau.ts +54 -25
- package/src/tlc-ext.ts +42 -29
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +52 -43
- package/src/tlc-order.ts +73 -9
- package/src/tlc-random.ts +37 -9
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-summary.ts +20 -5
- package/src/tlc-version.ts +18 -0
- package/src/transfer.ts +15 -3
- package/src/value-sources.ts +29 -0
- package/src/values.ts +708 -180
package/src/config.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { TlaConfigError } from "./errors";
|
|
2
2
|
import { matchOperator } from "./lexer";
|
|
3
|
+
import { formatLexicalError } from "./sany-lexer";
|
|
4
|
+
import type { TlcVersion } from "./tlc-version";
|
|
3
5
|
|
|
4
6
|
export type ConfigValue =
|
|
5
7
|
| { kind: "Number"; value: number }
|
|
@@ -42,12 +44,12 @@ export interface ModelConfig {
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
interface ConfigToken {
|
|
45
|
-
kind: "Word" | "Number" | "String" | "Symbol" | "End";
|
|
47
|
+
kind: "Word" | "Number" | "String" | "Symbol" | "End" | "Error";
|
|
46
48
|
text: string;
|
|
47
49
|
line: number;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
const
|
|
52
|
+
const SHARED_KEYWORDS = [
|
|
51
53
|
"CONSTANT",
|
|
52
54
|
"CONSTANTS",
|
|
53
55
|
"INIT",
|
|
@@ -64,6 +66,10 @@ const KEYWORDS = new Set([
|
|
|
64
66
|
"SYMMETRY",
|
|
65
67
|
"VIEW",
|
|
66
68
|
"CHECK_DEADLOCK",
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
const KEYWORDS = new Set([
|
|
72
|
+
...SHARED_KEYWORDS,
|
|
67
73
|
"ALIAS",
|
|
68
74
|
"POSTCONDITION",
|
|
69
75
|
"POSTCONDITIONS",
|
|
@@ -72,68 +78,149 @@ const KEYWORDS = new Set([
|
|
|
72
78
|
"_RL_REWARD",
|
|
73
79
|
]);
|
|
74
80
|
|
|
75
|
-
|
|
81
|
+
// TLC 1.7.4 reads a TYPE and a TYPE_CONSTRAINT, which it doesn't check, and none of the keywords
|
|
82
|
+
// that came after it.
|
|
83
|
+
const TYPE_KEYWORDS = ["TYPE", "TYPE_CONSTRAINT"];
|
|
84
|
+
const KEYWORDS_174 = new Set([...SHARED_KEYWORDS, ...TYPE_KEYWORDS]);
|
|
76
85
|
|
|
86
|
+
const SYMBOLS = ["<-", "<<", ">>", "=", "{", "}", ",", "[", "]", "(", ")", "!"];
|
|
87
|
+
|
|
88
|
+
// TLC reads a configuration file with the TLA+ lexer. A lexical error ends the tokens; TLC reports
|
|
89
|
+
// it only when it reads that far.
|
|
77
90
|
const tokenizeConfig = (source: string) => {
|
|
78
91
|
const tokens: ConfigToken[] = [];
|
|
79
|
-
const cursor = { index: 0, line: 1 };
|
|
92
|
+
const cursor = { index: 0, line: 1, lineStart: 0 };
|
|
93
|
+
const addLexicalError = (index: number, after: string) => {
|
|
94
|
+
tokens.push({
|
|
95
|
+
kind: "Error",
|
|
96
|
+
text: formatLexicalError(cursor.line, index - cursor.lineStart + 1, source[index], after),
|
|
97
|
+
line: cursor.line,
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
// TLC appends a newline to the file. JavaCC reports a token that the end of the input cuts off,
|
|
101
|
+
// that newline included, at the start of the line after it.
|
|
102
|
+
const addEndOfInputError = (after: string) => {
|
|
103
|
+
tokens.push({
|
|
104
|
+
kind: "Error",
|
|
105
|
+
text: formatLexicalError(cursor.line + 1, 0, undefined, after),
|
|
106
|
+
line: cursor.line,
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
const skip = (text: string) => {
|
|
110
|
+
const lines = text.split("\n");
|
|
111
|
+
if (lines.length > 1) {
|
|
112
|
+
cursor.line += lines.length - 1;
|
|
113
|
+
cursor.lineStart = cursor.index + text.length - lines[lines.length - 1].length;
|
|
114
|
+
}
|
|
115
|
+
cursor.index += text.length;
|
|
116
|
+
};
|
|
80
117
|
while (cursor.index < source.length) {
|
|
81
118
|
const rest = source.slice(cursor.index);
|
|
82
119
|
const whitespace = /^\s+/.exec(rest)?.[0];
|
|
83
120
|
if (whitespace) {
|
|
84
|
-
|
|
85
|
-
cursor.index += whitespace.length;
|
|
121
|
+
skip(whitespace);
|
|
86
122
|
continue;
|
|
87
123
|
}
|
|
88
124
|
if (rest.startsWith("\\*")) {
|
|
89
125
|
const lineEnd = rest.indexOf("\n");
|
|
90
|
-
|
|
126
|
+
skip(lineEnd === -1 ? rest : rest.slice(0, lineEnd));
|
|
91
127
|
continue;
|
|
92
128
|
}
|
|
93
129
|
if (rest.startsWith("(*")) {
|
|
94
130
|
const end = rest.indexOf("*)");
|
|
95
|
-
if (end === -1)
|
|
96
|
-
|
|
97
|
-
|
|
131
|
+
if (end === -1) {
|
|
132
|
+
skip(rest);
|
|
133
|
+
addEndOfInputError("");
|
|
134
|
+
return tokens;
|
|
135
|
+
}
|
|
136
|
+
skip(rest.slice(0, end + 2));
|
|
98
137
|
continue;
|
|
99
138
|
}
|
|
139
|
+
const line = cursor.line;
|
|
100
140
|
const number = /^\d+(?![A-Za-z_])/.exec(rest)?.[0];
|
|
101
141
|
if (number) {
|
|
102
|
-
tokens.push({ kind: "Number", text: number, line
|
|
103
|
-
|
|
142
|
+
tokens.push({ kind: "Number", text: number, line });
|
|
143
|
+
skip(number);
|
|
104
144
|
continue;
|
|
105
145
|
}
|
|
106
|
-
const word = /^[A-Za-z0-9_
|
|
146
|
+
const word = /^[A-Za-z0-9_]+/.exec(rest)?.[0];
|
|
107
147
|
if (word) {
|
|
108
|
-
tokens.push({ kind: "Word", text: word, line
|
|
109
|
-
|
|
148
|
+
tokens.push({ kind: "Word", text: word, line });
|
|
149
|
+
skip(word);
|
|
110
150
|
continue;
|
|
111
151
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
152
|
+
if (rest.startsWith('"')) {
|
|
153
|
+
const string = /^"((?:[^"\\\n]|\\[^\n])*)("?)/.exec(rest);
|
|
154
|
+
const text = string?.[0] ?? '"';
|
|
155
|
+
if (string?.[2] !== '"') {
|
|
156
|
+
skip(text);
|
|
157
|
+
if (cursor.index === source.length) addEndOfInputError(`${text}\n`);
|
|
158
|
+
else addLexicalError(cursor.index, text);
|
|
159
|
+
return tokens;
|
|
160
|
+
}
|
|
161
|
+
tokens.push({ kind: "String", text: string[1], line });
|
|
162
|
+
skip(text);
|
|
116
163
|
continue;
|
|
117
164
|
}
|
|
118
165
|
const symbol = SYMBOLS.find((candidate) => rest.startsWith(candidate));
|
|
119
166
|
if (symbol) {
|
|
120
|
-
tokens.push({ kind: "Symbol", text: symbol, line
|
|
121
|
-
|
|
167
|
+
tokens.push({ kind: "Symbol", text: symbol, line });
|
|
168
|
+
skip(symbol);
|
|
122
169
|
continue;
|
|
123
170
|
}
|
|
124
171
|
const operator = matchOperator(source, cursor.index);
|
|
125
|
-
if (!operator)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
tokens.push({ kind: "Word", text: operator.text, line
|
|
130
|
-
cursor.index
|
|
172
|
+
if (!operator) {
|
|
173
|
+
addLexicalError(cursor.index, "");
|
|
174
|
+
return tokens;
|
|
175
|
+
}
|
|
176
|
+
tokens.push({ kind: "Word", text: operator.text, line });
|
|
177
|
+
skip(source.slice(cursor.index, cursor.index + operator.length));
|
|
131
178
|
}
|
|
132
179
|
tokens.push({ kind: "End", text: "", line: cursor.line });
|
|
133
180
|
return tokens;
|
|
134
181
|
};
|
|
135
182
|
|
|
136
|
-
|
|
183
|
+
// TLC's messages for a configuration file it can't read, from ModelConfig.parse.
|
|
184
|
+
const createSyntaxError = (line: number, problem: string) =>
|
|
185
|
+
new TlaConfigError(`TLC found an error in the configuration file at line ${line}\n${problem}`);
|
|
186
|
+
|
|
187
|
+
const createDuplicateKeywordError = (line: number, keyword: string) =>
|
|
188
|
+
createSyntaxError(line, `The keyword ${keyword} appeared twice.`);
|
|
189
|
+
|
|
190
|
+
const SINGLE_KEYWORDS = new Map<
|
|
191
|
+
string,
|
|
192
|
+
"init" | "next" | "specification" | "view" | "symmetry" | "alias" | "periodic" | "rlReward"
|
|
193
|
+
>([
|
|
194
|
+
["INIT", "init"],
|
|
195
|
+
["NEXT", "next"],
|
|
196
|
+
["SPECIFICATION", "specification"],
|
|
197
|
+
["VIEW", "view"],
|
|
198
|
+
["SYMMETRY", "symmetry"],
|
|
199
|
+
["ALIAS", "alias"],
|
|
200
|
+
["_PERIODIC", "periodic"],
|
|
201
|
+
["_RL_REWARD", "rlReward"],
|
|
202
|
+
]);
|
|
203
|
+
|
|
204
|
+
const LIST_KEYWORDS = new Map<
|
|
205
|
+
string,
|
|
206
|
+
"invariants" | "properties" | "constraints" | "actionConstraints" | "postconditions" | "possible"
|
|
207
|
+
>([
|
|
208
|
+
["INVARIANT", "invariants"],
|
|
209
|
+
["INVARIANTS", "invariants"],
|
|
210
|
+
["PROPERTY", "properties"],
|
|
211
|
+
["PROPERTIES", "properties"],
|
|
212
|
+
["CONSTRAINT", "constraints"],
|
|
213
|
+
["CONSTRAINTS", "constraints"],
|
|
214
|
+
["ACTION_CONSTRAINT", "actionConstraints"],
|
|
215
|
+
["ACTION_CONSTRAINTS", "actionConstraints"],
|
|
216
|
+
["POSTCONDITION", "postconditions"],
|
|
217
|
+
["POSTCONDITIONS", "postconditions"],
|
|
218
|
+
["_POSSIBLE", "possible"],
|
|
219
|
+
]);
|
|
220
|
+
|
|
221
|
+
// A port of TLC's ModelConfig.parse, which takes any token where it expects a name or a value.
|
|
222
|
+
export const parseConfig = (source: string, version: TlcVersion = "master"): ModelConfig => {
|
|
223
|
+
const keywords = version === "1.7.4" ? KEYWORDS_174 : KEYWORDS;
|
|
137
224
|
const tokens = tokenizeConfig(source);
|
|
138
225
|
const cursor = { index: 0 };
|
|
139
226
|
const config: ModelConfig = {
|
|
@@ -155,183 +242,169 @@ export const parseConfig = (source: string): ModelConfig => {
|
|
|
155
242
|
periodic: undefined,
|
|
156
243
|
rlReward: undefined,
|
|
157
244
|
};
|
|
158
|
-
|
|
159
245
|
const deadlock = { isSet: false };
|
|
160
|
-
const
|
|
161
|
-
const advance = () =>
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (token.text !== text) {
|
|
166
|
-
throw new TlaConfigError(
|
|
167
|
-
`Expected ${JSON.stringify(text)} but found ${JSON.stringify(token.text)} at line ${token.line}`,
|
|
168
|
-
);
|
|
246
|
+
const types = new Set<string>();
|
|
247
|
+
const advance = () => {
|
|
248
|
+
const token = tokens[Math.min(cursor.index++, tokens.length - 1)];
|
|
249
|
+
if (token.kind === "Error") {
|
|
250
|
+
throw new TlaConfigError(`TLC found an error in the configuration file:\n${token.text}`);
|
|
169
251
|
}
|
|
170
|
-
|
|
171
|
-
const expectName = () => {
|
|
172
|
-
const token = advance();
|
|
173
|
-
if (token.kind !== "Word" || isKeyword(token)) {
|
|
174
|
-
throw new TlaConfigError(
|
|
175
|
-
`Expected a name but found ${JSON.stringify(token.text)} at line ${token.line}`,
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
return token.text;
|
|
179
|
-
};
|
|
180
|
-
const isNameAhead = () => peek().kind === "Word" && !isKeyword(peek());
|
|
181
|
-
const parseNames = () => {
|
|
182
|
-
const names: string[] = [];
|
|
183
|
-
while (isNameAhead()) names.push(advance().text);
|
|
184
|
-
return names;
|
|
185
|
-
};
|
|
186
|
-
const setSingle = (
|
|
187
|
-
key:
|
|
188
|
-
| "init"
|
|
189
|
-
| "next"
|
|
190
|
-
| "specification"
|
|
191
|
-
| "symmetry"
|
|
192
|
-
| "view"
|
|
193
|
-
| "alias"
|
|
194
|
-
| "periodic"
|
|
195
|
-
| "rlReward",
|
|
196
|
-
keyword: string,
|
|
197
|
-
) => {
|
|
198
|
-
if (config[key] !== undefined) throw new TlaConfigError(`The keyword ${keyword} appears twice`);
|
|
199
|
-
config[key] = expectName();
|
|
252
|
+
return token;
|
|
200
253
|
};
|
|
201
254
|
|
|
202
|
-
const parseValue = (): ConfigValue => {
|
|
203
|
-
const token = advance();
|
|
255
|
+
const parseValue = (token: ConfigToken): ConfigValue => {
|
|
204
256
|
if (token.kind === "Number") return { kind: "Number", value: Number(token.text) };
|
|
205
257
|
if (token.kind === "String") return { kind: "String", value: token.text };
|
|
206
258
|
if (token.text === "TRUE" || token.text === "FALSE")
|
|
207
259
|
return { kind: "Boolean", value: token.text === "TRUE" };
|
|
208
260
|
if (token.text === "{") {
|
|
209
261
|
const elements: ConfigValue[] = [];
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
262
|
+
const current = { token: advance() };
|
|
263
|
+
if (current.token.text !== "}") {
|
|
264
|
+
while (true) {
|
|
265
|
+
elements.push(parseValue(current.token));
|
|
266
|
+
current.token = advance();
|
|
267
|
+
if (current.token.text !== ",") break;
|
|
268
|
+
current.token = advance();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (current.token.text !== "}") {
|
|
272
|
+
throw createSyntaxError(current.token.line, "It was expecting }, but did not find it.");
|
|
214
273
|
}
|
|
215
|
-
expect("}");
|
|
216
274
|
return { kind: "Set", elements };
|
|
217
275
|
}
|
|
218
|
-
if (token.kind
|
|
219
|
-
throw
|
|
220
|
-
`Expected a value but found ${JSON.stringify(token.text)} at line ${token.line}`,
|
|
221
|
-
);
|
|
276
|
+
if (token.kind !== "End") return { kind: "ModelValue", name: token.text };
|
|
277
|
+
throw createSyntaxError(token.line, "It was expecting a value, but did not find it.");
|
|
222
278
|
};
|
|
223
279
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
advance();
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
280
|
+
// A module name in brackets after = or <-, which applies the assignment in that module.
|
|
281
|
+
const parseModuleScope = (operator: string) => {
|
|
282
|
+
const name = advance();
|
|
283
|
+
if (name.kind === "End") {
|
|
284
|
+
throw createSyntaxError(name.line, `Expected an identifier after ${operator}[.`);
|
|
285
|
+
}
|
|
286
|
+
const close = advance();
|
|
287
|
+
if (close.text !== "]") {
|
|
288
|
+
throw createSyntaxError(close.line, "It was expecting ], but did not find it.");
|
|
289
|
+
}
|
|
290
|
+
return name.text;
|
|
230
291
|
};
|
|
231
292
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
293
|
+
// TLC reports a malformed argument list at the line of the CONSTANT keyword.
|
|
294
|
+
const parseConstants = (keywordLine: number) => {
|
|
295
|
+
while (true) {
|
|
296
|
+
const first = advance();
|
|
297
|
+
if (first.kind === "End" || keywords.has(first.text)) return first;
|
|
298
|
+
const current = { token: advance(), name: first.text };
|
|
299
|
+
while (current.token.text === "!") {
|
|
300
|
+
current.name = `${current.name}!${advance().text}`;
|
|
301
|
+
current.token = advance();
|
|
302
|
+
}
|
|
303
|
+
const name = current.name;
|
|
304
|
+
if (current.token.text === "<-") {
|
|
305
|
+
current.token = advance();
|
|
306
|
+
if (current.token.text === "[") {
|
|
307
|
+
const module = parseModuleScope("<-");
|
|
308
|
+
const target = advance();
|
|
309
|
+
if (target.kind === "End") {
|
|
310
|
+
throw createSyntaxError(target.line, "Expected an identifier after <-[mod].");
|
|
311
|
+
}
|
|
312
|
+
config.substitutions.push({ name, target: target.text, module });
|
|
313
|
+
continue;
|
|
241
314
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
config.
|
|
315
|
+
if (current.token.kind === "End") {
|
|
316
|
+
throw createSyntaxError(current.token.line, "Expected an identifier after <-.");
|
|
317
|
+
}
|
|
318
|
+
config.substitutions.push({ name, target: current.token.text });
|
|
246
319
|
continue;
|
|
247
320
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
321
|
+
const args: ConfigValue[] = [];
|
|
322
|
+
const hasArgs = current.token.text === "(";
|
|
323
|
+
if (hasArgs) {
|
|
324
|
+
while (true) {
|
|
325
|
+
args.push(parseValue(advance()));
|
|
326
|
+
current.token = advance();
|
|
327
|
+
if (current.token.text !== ",") break;
|
|
328
|
+
}
|
|
329
|
+
if (current.token.text !== ")") {
|
|
330
|
+
throw createSyntaxError(keywordLine, "");
|
|
331
|
+
}
|
|
332
|
+
current.token = advance();
|
|
333
|
+
}
|
|
334
|
+
if (current.token.text !== "=") {
|
|
335
|
+
throw createSyntaxError(
|
|
336
|
+
current.token.line,
|
|
337
|
+
"It was expecting = or <-, but did not find it.",
|
|
338
|
+
);
|
|
253
339
|
}
|
|
254
|
-
|
|
255
|
-
const module = parseModuleScope();
|
|
256
|
-
|
|
340
|
+
current.token = advance();
|
|
341
|
+
const module = current.token.text === "[" ? parseModuleScope("=") : undefined;
|
|
342
|
+
const value = parseValue(module === undefined ? current.token : advance());
|
|
343
|
+
config.constants.push({
|
|
344
|
+
name,
|
|
345
|
+
value,
|
|
346
|
+
...(hasArgs && { args }),
|
|
347
|
+
...(module !== undefined && { module }),
|
|
348
|
+
});
|
|
257
349
|
}
|
|
258
350
|
};
|
|
259
351
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
break;
|
|
279
|
-
case "VIEW":
|
|
280
|
-
setSingle("view", token.text);
|
|
281
|
-
break;
|
|
282
|
-
case "INVARIANT":
|
|
283
|
-
case "INVARIANTS":
|
|
284
|
-
config.invariants.push(...parseNames());
|
|
285
|
-
break;
|
|
286
|
-
case "PROPERTY":
|
|
287
|
-
case "PROPERTIES":
|
|
288
|
-
config.properties.push(...parseNames());
|
|
289
|
-
break;
|
|
290
|
-
case "CONSTRAINT":
|
|
291
|
-
case "CONSTRAINTS":
|
|
292
|
-
config.constraints.push(...parseNames());
|
|
293
|
-
break;
|
|
294
|
-
case "ACTION_CONSTRAINT":
|
|
295
|
-
case "ACTION_CONSTRAINTS":
|
|
296
|
-
config.actionConstraints.push(...parseNames());
|
|
297
|
-
break;
|
|
298
|
-
case "ALIAS":
|
|
299
|
-
setSingle("alias", token.text);
|
|
300
|
-
break;
|
|
301
|
-
case "POSTCONDITION":
|
|
302
|
-
case "POSTCONDITIONS":
|
|
303
|
-
config.postconditions.push(...parseNames());
|
|
304
|
-
break;
|
|
305
|
-
case "_POSSIBLE":
|
|
306
|
-
config.possible.push(...parseNames());
|
|
307
|
-
break;
|
|
308
|
-
case "_PERIODIC":
|
|
309
|
-
setSingle("periodic", token.text);
|
|
310
|
-
break;
|
|
311
|
-
case "_RL_REWARD":
|
|
312
|
-
setSingle("rlReward", token.text);
|
|
313
|
-
break;
|
|
314
|
-
case "CHECK_DEADLOCK": {
|
|
315
|
-
if (deadlock.isSet) throw new TlaConfigError("The keyword CHECK_DEADLOCK appears twice");
|
|
316
|
-
deadlock.isSet = true;
|
|
317
|
-
const value = advance().text;
|
|
318
|
-
if (value !== "TRUE" && value !== "FALSE") {
|
|
319
|
-
throw new TlaConfigError(
|
|
320
|
-
`CHECK_DEADLOCK expects TRUE or FALSE but found ${JSON.stringify(value)}`,
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
config.checkDeadlock = value === "TRUE";
|
|
324
|
-
break;
|
|
352
|
+
const parseNames = (names: string[]) => {
|
|
353
|
+
while (true) {
|
|
354
|
+
const token = advance();
|
|
355
|
+
if (token.kind === "End" || keywords.has(token.text)) return token;
|
|
356
|
+
names.push(token.text);
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
const current = { token: advance() };
|
|
361
|
+
while (current.token.kind !== "End") {
|
|
362
|
+
const keyword = current.token.text;
|
|
363
|
+
const line = current.token.line;
|
|
364
|
+
const singleKey = keywords.has(keyword) ? SINGLE_KEYWORDS.get(keyword) : undefined;
|
|
365
|
+
const listKey = keywords.has(keyword) ? LIST_KEYWORDS.get(keyword) : undefined;
|
|
366
|
+
const advanceToArgument = () => {
|
|
367
|
+
const argument = advance();
|
|
368
|
+
if (argument.kind === "End") {
|
|
369
|
+
throw createSyntaxError(line, `The keyword ${keyword} was not followed by an identifier.`);
|
|
325
370
|
}
|
|
326
|
-
|
|
327
|
-
|
|
371
|
+
return argument;
|
|
372
|
+
};
|
|
373
|
+
if (singleKey !== undefined) {
|
|
374
|
+
const name = advanceToArgument();
|
|
375
|
+
if (config[singleKey] !== undefined) {
|
|
376
|
+
throw createDuplicateKeywordError(line, keyword);
|
|
377
|
+
}
|
|
378
|
+
config[singleKey] = name.text;
|
|
379
|
+
current.token = advance();
|
|
380
|
+
continue;
|
|
328
381
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
382
|
+
if (listKey !== undefined) {
|
|
383
|
+
current.token = parseNames(config[listKey]);
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
if (keyword === "CONSTANT" || keyword === "CONSTANTS") {
|
|
387
|
+
current.token = parseConstants(line);
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (keyword === "CHECK_DEADLOCK") {
|
|
391
|
+
const value = advanceToArgument();
|
|
392
|
+
if (value.text !== "TRUE" && value.text !== "FALSE") {
|
|
393
|
+
throw createSyntaxError(value.line, "It was expecting TRUE or FALSE, but did not find it.");
|
|
394
|
+
}
|
|
395
|
+
if (deadlock.isSet) throw createDuplicateKeywordError(line, keyword);
|
|
396
|
+
deadlock.isSet = true;
|
|
397
|
+
config.checkDeadlock = value.text === "TRUE";
|
|
398
|
+
current.token = advance();
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
if (!keywords.has(keyword) || !TYPE_KEYWORDS.includes(keyword)) {
|
|
402
|
+
throw createSyntaxError(line, "It was expecting a keyword, but did not find it.");
|
|
403
|
+
}
|
|
404
|
+
advanceToArgument();
|
|
405
|
+
if (types.has(keyword)) throw createDuplicateKeywordError(line, keyword);
|
|
406
|
+
types.add(keyword);
|
|
407
|
+
current.token = advance();
|
|
335
408
|
}
|
|
336
409
|
return config;
|
|
337
410
|
};
|
package/src/dependencies.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
1
|
+
import { getChildren, type Definition, type Expression } from "./ast";
|
|
2
|
+
import { isImpureBuiltin, type Environment } from "./evaluate";
|
|
3
3
|
|
|
4
4
|
const STATE_INDEPENDENT_KINDS = new Set([
|
|
5
5
|
"Prime",
|