tla-ts 0.0.3 → 0.0.4-dev.0be9567

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.
Files changed (86) hide show
  1. package/README.md +32 -12
  2. package/dist/cli.cjs +1 -1
  3. package/dist/cli.js +1 -1
  4. package/dist/index.cjs +1 -1
  5. package/dist/index.d.cts +162 -8
  6. package/dist/index.d.ts +162 -8
  7. package/dist/index.js +1 -1
  8. package/dist/parallel-worker.cjs +2 -2
  9. package/dist/parallel-worker.js +2 -2
  10. package/dist/parallel.cjs +1 -1
  11. package/dist/parallel.js +2 -2
  12. package/dist/run-cli.cjs +45 -18
  13. package/dist/run-cli.js +45 -18
  14. package/dist/transfer.cjs +1393 -18
  15. package/dist/transfer.js +1393 -18
  16. package/package.json +5 -1
  17. package/src/ast.ts +147 -6
  18. package/src/bags.ts +4 -7
  19. package/src/builtins.ts +29 -11
  20. package/src/bundled-modules.ts +3 -3
  21. package/src/canonical.ts +4 -3
  22. package/src/check.ts +1539 -235
  23. package/src/cli-options.ts +11 -5
  24. package/src/cli.ts +8 -1
  25. package/src/codegen.ts +98 -39
  26. package/src/config.ts +254 -181
  27. package/src/dependencies.ts +2 -2
  28. package/src/environment.ts +540 -140
  29. package/src/errors.ts +224 -3
  30. package/src/evaluate.ts +994 -279
  31. package/src/exit-codes.ts +22 -43
  32. package/src/fingerprints.ts +46 -11
  33. package/src/index.ts +1 -0
  34. package/src/instances.ts +19 -16
  35. package/src/java-overrides.ts +104 -25
  36. package/src/levels.ts +191 -45
  37. package/src/lexer.ts +127 -30
  38. package/src/live-check.ts +867 -0
  39. package/src/liveness.ts +218 -572
  40. package/src/obligation-expression.ts +2 -2
  41. package/src/obligation-source.ts +2 -0
  42. package/src/parallel-worker.ts +174 -213
  43. package/src/parallel.ts +131 -39
  44. package/src/parser.ts +456 -147
  45. package/src/pcal-ast.ts +770 -0
  46. package/src/pcal-parse.ts +1523 -0
  47. package/src/pcal-tokenize.ts +516 -0
  48. package/src/pcal-translate.ts +1230 -0
  49. package/src/pcal-validate.ts +454 -0
  50. package/src/randomization.ts +24 -7
  51. package/src/resolve.ts +1481 -426
  52. package/src/run-cli.ts +1212 -143
  53. package/src/runtime.ts +19 -1
  54. package/src/sany-builtins.ts +147 -0
  55. package/src/sany-generator.ts +3128 -0
  56. package/src/sany-levels.ts +1208 -0
  57. package/src/sany-lexer.ts +545 -0
  58. package/src/sany-linter.ts +122 -0
  59. package/src/sany-modules.ts +1398 -0
  60. package/src/sany-nodes.ts +463 -0
  61. package/src/sany-parse-error.ts +2161 -0
  62. package/src/sany-report.ts +356 -0
  63. package/src/sany-selectors.ts +738 -0
  64. package/src/sany-source.ts +248 -0
  65. package/src/sany-xml.ts +1017 -0
  66. package/src/spec-description.ts +42 -11
  67. package/src/standard-modules.ts +203 -148
  68. package/src/standard-ranges.ts +116 -0
  69. package/src/state-graph.ts +180 -0
  70. package/src/subexpressions.ts +231 -171
  71. package/src/substitution-levels.ts +38 -17
  72. package/src/successors.ts +220 -108
  73. package/src/symmetry.ts +194 -54
  74. package/src/tableau.ts +54 -25
  75. package/src/tlc-ext.ts +42 -29
  76. package/src/tlc-messages.ts +329 -0
  77. package/src/tlc-module.ts +52 -43
  78. package/src/tlc-modules.ts +4 -0
  79. package/src/tlc-order.ts +78 -10
  80. package/src/tlc-random.ts +37 -9
  81. package/src/tlc-replay.ts +655 -0
  82. package/src/tlc-summary.ts +20 -5
  83. package/src/tlc-version.ts +18 -0
  84. package/src/transfer.ts +15 -3
  85. package/src/value-sources.ts +29 -0
  86. package/src/values.ts +743 -189
package/src/config.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { TlaConfigError } from "./errors";
2
- import { matchOperator } from "./lexer";
2
+ import { matchOperator, matchUnicodeToken } 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 KEYWORDS = new Set([
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
- const SYMBOLS = ["<-", "<<", ">>", "=", "{", "}", ",", "[", "]", "(", ")"];
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
- cursor.line += whitespace.split("\n").length - 1;
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
- cursor.index += lineEnd === -1 ? rest.length : lineEnd;
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) throw new TlaConfigError(`Unterminated comment at line ${cursor.line}`);
96
- cursor.line += rest.slice(0, end).split("\n").length - 1;
97
- cursor.index += end + 2;
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: cursor.line });
103
- cursor.index += number.length;
142
+ tokens.push({ kind: "Number", text: number, line });
143
+ skip(number);
104
144
  continue;
105
145
  }
106
- const word = /^[A-Za-z0-9_!]+/.exec(rest)?.[0];
146
+ const word = /^[A-Za-z0-9_]+/.exec(rest)?.[0];
107
147
  if (word) {
108
- tokens.push({ kind: "Word", text: word, line: cursor.line });
109
- cursor.index += word.length;
148
+ tokens.push({ kind: "Word", text: word, line });
149
+ skip(word);
110
150
  continue;
111
151
  }
112
- const string = /^"((?:[^"\\]|\\.)*)"/.exec(rest);
113
- if (string) {
114
- tokens.push({ kind: "String", text: string[1], line: cursor.line });
115
- cursor.index += string[0].length;
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: cursor.line });
121
- cursor.index += symbol.length;
167
+ tokens.push({ kind: "Symbol", text: symbol, line });
168
+ skip(symbol);
122
169
  continue;
123
170
  }
124
- const operator = matchOperator(source, cursor.index);
125
- if (!operator)
126
- throw new TlaConfigError(
127
- `Unexpected character ${JSON.stringify(rest[0])} at line ${cursor.line}`,
128
- );
129
- tokens.push({ kind: "Word", text: operator.text, line: cursor.line });
130
- cursor.index += operator.length;
171
+ const operator = matchUnicodeToken(source, cursor.index) ?? matchOperator(source, 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
- export const parseConfig = (source: string): ModelConfig => {
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 peek = () => tokens[cursor.index];
161
- const advance = () => tokens[cursor.index++];
162
- const isKeyword = (token: ConfigToken) => token.kind === "Word" && KEYWORDS.has(token.text);
163
- const expect = (text: string) => {
164
- const token = advance();
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
- if (peek().text !== "}") elements.push(parseValue());
211
- while (peek().text === ",") {
212
- advance();
213
- elements.push(parseValue());
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 === "Word" && !isKeyword(token)) return { kind: "ModelValue", name: token.text };
219
- throw new TlaConfigError(
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
- const parseModuleScope = () => {
225
- if (peek().text !== "[") return undefined;
226
- advance();
227
- const module = expectName();
228
- expect("]");
229
- return module;
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
- const parseConstants = () => {
233
- while (isNameAhead()) {
234
- const name = advance().text;
235
- if (peek().text === "(") {
236
- advance();
237
- const args: ConfigValue[] = [];
238
- while (peek().text !== ")") {
239
- args.push(parseValue());
240
- if (peek().text !== ")") expect(",");
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
- advance();
243
- expect("=");
244
- const module = parseModuleScope();
245
- config.constants.push({ name, value: parseValue(), args, ...(module && { module }) });
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
- if (peek().text === "<-") {
249
- advance();
250
- const module = parseModuleScope();
251
- config.substitutions.push({ name, target: expectName(), ...(module && { module }) });
252
- continue;
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
- expect("=");
255
- const module = parseModuleScope();
256
- config.constants.push({ name, value: parseValue(), ...(module && { module }) });
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
- while (peek().kind !== "End") {
261
- const token = advance();
262
- switch (token.text) {
263
- case "CONSTANT":
264
- case "CONSTANTS":
265
- parseConstants();
266
- break;
267
- case "INIT":
268
- setSingle("init", token.text);
269
- break;
270
- case "NEXT":
271
- setSingle("next", token.text);
272
- break;
273
- case "SPECIFICATION":
274
- setSingle("specification", token.text);
275
- break;
276
- case "SYMMETRY":
277
- setSingle("symmetry", token.text);
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
- default:
327
- throw new TlaConfigError(`Unexpected ${JSON.stringify(token.text)} at line ${token.line}`);
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
- if (
331
- config.specification !== undefined &&
332
- (config.init !== undefined || config.next !== undefined)
333
- ) {
334
- throw new TlaConfigError("SPECIFICATION cannot be combined with INIT or NEXT");
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
  };
@@ -1,5 +1,5 @@
1
- import type { Definition, Expression } from "./ast";
2
- import { getChildren, isImpureBuiltin, type Environment } from "./evaluate";
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",