tla-ts 0.0.3-dev.3c70a97 → 0.0.3-dev.3ce2f00
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 +5 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +53 -22
- package/dist/index.d.ts +53 -22
- 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 +19 -17
- package/dist/run-cli.js +20 -18
- package/dist/transfer.cjs +33 -17
- package/dist/transfer.js +33 -17
- package/package.json +1 -1
- package/src/ast.ts +3 -0
- package/src/builtins.ts +9 -3
- package/src/check.ts +455 -93
- package/src/cli-options.ts +11 -5
- package/src/codegen.ts +6 -3
- package/src/config.ts +224 -170
- package/src/environment.ts +115 -19
- package/src/errors.ts +78 -1
- package/src/evaluate.ts +182 -26
- package/src/exit-codes.ts +22 -3
- package/src/fingerprints.ts +2 -1
- package/src/instances.ts +4 -4
- package/src/levels.ts +82 -36
- package/src/live-check.ts +132 -70
- package/src/liveness.ts +117 -22
- package/src/parallel-worker.ts +2 -2
- package/src/parallel.ts +5 -2
- package/src/parser.ts +57 -16
- package/src/resolve.ts +106 -29
- package/src/run-cli.ts +103 -18
- package/src/runtime.ts +2 -0
- package/src/spec-description.ts +12 -6
- package/src/standard-modules.ts +54 -45
- package/src/state-graph.ts +157 -0
- package/src/substitution-levels.ts +35 -11
- package/src/successors.ts +169 -33
- package/src/symmetry.ts +16 -6
- package/src/tableau.ts +51 -24
- package/src/tlc-ext.ts +27 -2
- package/src/tlc-module.ts +14 -33
- package/src/tlc-modules.ts +4 -0
- package/src/tlc-order.ts +8 -4
- package/src/tlc-random.ts +9 -6
- package/src/tlc-summary.ts +20 -5
- package/src/value-sources.ts +29 -0
- package/src/values.ts +242 -61
package/src/cli-options.ts
CHANGED
|
@@ -2,6 +2,8 @@ export interface OptionSpec {
|
|
|
2
2
|
flag: string;
|
|
3
3
|
isRequired?: boolean;
|
|
4
4
|
isRepeatable?: boolean;
|
|
5
|
+
// How many of the arguments after the flag the option takes, when that depends on them.
|
|
6
|
+
getArity?: (rest: string[]) => number;
|
|
5
7
|
}
|
|
6
8
|
|
|
7
9
|
export interface ParsedOption {
|
|
@@ -29,27 +31,31 @@ export const defineCommand = (usage: string, specs: OptionSpec[]) => {
|
|
|
29
31
|
const arities = new Map(
|
|
30
32
|
specs.map((spec) => {
|
|
31
33
|
const [name, ...values] = spec.flag.split(" ");
|
|
32
|
-
return [name, values.length];
|
|
34
|
+
return [name, spec.getArity ?? (() => values.length)];
|
|
33
35
|
}),
|
|
34
36
|
);
|
|
35
37
|
const parse = (args: string[]): ParsedArgs => {
|
|
36
38
|
const options: ParsedOption[] = [];
|
|
37
39
|
const positionals: string[] = [];
|
|
38
40
|
const unknown: string[] = [];
|
|
41
|
+
const incomplete: ParsedOption[] = [];
|
|
39
42
|
for (let index = 0; index < args.length; index++) {
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
43
|
+
const getArity = arities.get(args[index]);
|
|
44
|
+
if (getArity === undefined) {
|
|
42
45
|
(args[index].startsWith("-") ? unknown : positionals).push(args[index]);
|
|
43
46
|
continue;
|
|
44
47
|
}
|
|
45
|
-
|
|
48
|
+
const arity = getArity(args.slice(index + 1));
|
|
49
|
+
const option = { name: args[index], values: args.slice(index + 1, index + 1 + arity) };
|
|
50
|
+
options.push(option);
|
|
51
|
+
if (option.values.length < arity) incomplete.push(option);
|
|
46
52
|
index += arity;
|
|
47
53
|
}
|
|
48
54
|
return {
|
|
49
55
|
options,
|
|
50
56
|
positionals,
|
|
51
57
|
unknown,
|
|
52
|
-
incomplete:
|
|
58
|
+
incomplete: incomplete[0],
|
|
53
59
|
has: (name) => options.some((option) => option.name === name),
|
|
54
60
|
get: (name) => options.findLast((option) => option.name === name)?.values,
|
|
55
61
|
};
|
package/src/codegen.ts
CHANGED
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
getSubsetOperator,
|
|
11
11
|
getEvaluator,
|
|
12
12
|
getFieldError,
|
|
13
|
+
getNonFunctionError,
|
|
14
|
+
getNonRecordError,
|
|
13
15
|
isClosedConstant,
|
|
14
16
|
isTlcInteger,
|
|
15
17
|
isValueArgument,
|
|
@@ -250,12 +252,13 @@ const generateExpression = (generator: Generator, expression: Expression, frame:
|
|
|
250
252
|
case "FunctionApplication": {
|
|
251
253
|
keepLazy(expression.function);
|
|
252
254
|
const functionCode = generate(expression.function);
|
|
255
|
+
const describeNonFunction = addReference(generator, getNonFunctionError(expression));
|
|
253
256
|
if (expression.args.length === 1)
|
|
254
|
-
return `apply(${functionCode}, ${generate(expression.args[0])})`;
|
|
255
|
-
return `apply(${functionCode}, tuple([${expression.args.map((arg) => generate(arg)).join(", ")}]))`;
|
|
257
|
+
return `apply(${functionCode}, ${generate(expression.args[0])}, undefined, ${describeNonFunction})`;
|
|
258
|
+
return `apply(${functionCode}, tuple([${expression.args.map((arg) => generate(arg)).join(", ")}]), undefined, ${describeNonFunction})`;
|
|
256
259
|
}
|
|
257
260
|
case "FieldAccess":
|
|
258
|
-
return `apply(${generate(expression.record)}, ${JSON.stringify(expression.field)}, ${addReference(generator, getFieldError(expression))})`;
|
|
261
|
+
return `apply(${generate(expression.record)}, ${JSON.stringify(expression.field)}, ${addReference(generator, getFieldError(expression))}, ${addReference(generator, getNonRecordError(expression))})`;
|
|
259
262
|
case "Record": {
|
|
260
263
|
const fields = getSortedFields(expression.fields);
|
|
261
264
|
if (hasDuplicateFields(fields)) return generateDelegate(generator, expression, frame);
|
package/src/config.ts
CHANGED
|
@@ -74,27 +74,96 @@ const KEYWORDS = new Set([
|
|
|
74
74
|
|
|
75
75
|
const SYMBOLS = ["<-", "<<", ">>", "=", "{", "}", ",", "[", "]", "(", ")"];
|
|
76
76
|
|
|
77
|
+
const SINGLE_KEYWORDS = {
|
|
78
|
+
INIT: "init",
|
|
79
|
+
NEXT: "next",
|
|
80
|
+
SPECIFICATION: "specification",
|
|
81
|
+
VIEW: "view",
|
|
82
|
+
SYMMETRY: "symmetry",
|
|
83
|
+
ALIAS: "alias",
|
|
84
|
+
_PERIODIC: "periodic",
|
|
85
|
+
_RL_REWARD: "rlReward",
|
|
86
|
+
} as const;
|
|
87
|
+
|
|
88
|
+
const LIST_KEYWORDS = {
|
|
89
|
+
INVARIANT: "invariants",
|
|
90
|
+
INVARIANTS: "invariants",
|
|
91
|
+
PROPERTY: "properties",
|
|
92
|
+
PROPERTIES: "properties",
|
|
93
|
+
CONSTRAINT: "constraints",
|
|
94
|
+
CONSTRAINTS: "constraints",
|
|
95
|
+
ACTION_CONSTRAINT: "actionConstraints",
|
|
96
|
+
ACTION_CONSTRAINTS: "actionConstraints",
|
|
97
|
+
POSTCONDITION: "postconditions",
|
|
98
|
+
POSTCONDITIONS: "postconditions",
|
|
99
|
+
_POSSIBLE: "possible",
|
|
100
|
+
} as const;
|
|
101
|
+
|
|
102
|
+
const isSingleKeyword = (text: string): text is keyof typeof SINGLE_KEYWORDS =>
|
|
103
|
+
Object.hasOwn(SINGLE_KEYWORDS, text);
|
|
104
|
+
|
|
105
|
+
const isListKeyword = (text: string): text is keyof typeof LIST_KEYWORDS =>
|
|
106
|
+
Object.hasOwn(LIST_KEYWORDS, text);
|
|
107
|
+
|
|
108
|
+
// JavaCC's TokenMgrError.addEscapes, which TLC's lexical errors use.
|
|
109
|
+
const escapeLexeme = (text: string) =>
|
|
110
|
+
[...text]
|
|
111
|
+
.map((character) => {
|
|
112
|
+
const escaped = { "\b": "\\b", "\t": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r" }[
|
|
113
|
+
character
|
|
114
|
+
];
|
|
115
|
+
if (escaped) return escaped;
|
|
116
|
+
if (character === '"' || character === "'" || character === "\\") return `\\${character}`;
|
|
117
|
+
const code = character.codePointAt(0) ?? 0;
|
|
118
|
+
return code < 0x20 || code > 0x7e ? `\\u${code.toString(16).padStart(4, "0")}` : character;
|
|
119
|
+
})
|
|
120
|
+
.join("");
|
|
121
|
+
|
|
122
|
+
// TLC reads a configuration with SANY's lexer, which reports a character it cannot read as a
|
|
123
|
+
// JavaCC lexical error.
|
|
124
|
+
const createLexicalError = (line: number, column: number, found: string | undefined, after = "") =>
|
|
125
|
+
new TlaConfigError(
|
|
126
|
+
`TLC found an error in the configuration file:\nLexical error at line ${line}, column ${column}. Encountered: ${found === undefined ? "<EOF> " : `"${escapeLexeme(found)}" (${found.codePointAt(0)}), `}after : "${escapeLexeme(after)}"`,
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const createConfigFileError = (line: number, detail: string) =>
|
|
130
|
+
new TlaConfigError(`TLC found an error in the configuration file at line ${line}\n${detail}`);
|
|
131
|
+
|
|
77
132
|
const tokenizeConfig = (source: string) => {
|
|
133
|
+
// TLC appends a newline so that a trailing \* comment ends.
|
|
134
|
+
const text = `${source}\n`;
|
|
78
135
|
const tokens: ConfigToken[] = [];
|
|
79
|
-
const cursor = { index: 0, line: 1 };
|
|
80
|
-
|
|
81
|
-
|
|
136
|
+
const cursor = { index: 0, line: 1, lineStart: 0 };
|
|
137
|
+
// Moves past text, keeping the line and where it starts.
|
|
138
|
+
const skip = (length: number) => {
|
|
139
|
+
const skipped = text.slice(cursor.index, cursor.index + length);
|
|
140
|
+
const lastBreak = skipped.lastIndexOf("\n");
|
|
141
|
+
if (lastBreak !== -1) {
|
|
142
|
+
cursor.line += skipped.split("\n").length - 1;
|
|
143
|
+
cursor.lineStart = cursor.index + lastBreak + 1;
|
|
144
|
+
}
|
|
145
|
+
cursor.index += length;
|
|
146
|
+
};
|
|
147
|
+
const getEndOfInputError = (after: string) =>
|
|
148
|
+
createLexicalError(cursor.line + 1, 0, undefined, after);
|
|
149
|
+
while (cursor.index < text.length) {
|
|
150
|
+
const rest = text.slice(cursor.index);
|
|
82
151
|
const whitespace = /^\s+/.exec(rest)?.[0];
|
|
83
152
|
if (whitespace) {
|
|
84
|
-
|
|
85
|
-
cursor.index += whitespace.length;
|
|
153
|
+
skip(whitespace.length);
|
|
86
154
|
continue;
|
|
87
155
|
}
|
|
88
156
|
if (rest.startsWith("\\*")) {
|
|
89
|
-
|
|
90
|
-
cursor.index += lineEnd === -1 ? rest.length : lineEnd;
|
|
157
|
+
cursor.index += rest.indexOf("\n");
|
|
91
158
|
continue;
|
|
92
159
|
}
|
|
93
160
|
if (rest.startsWith("(*")) {
|
|
94
161
|
const end = rest.indexOf("*)");
|
|
95
|
-
if (end === -1)
|
|
96
|
-
|
|
97
|
-
|
|
162
|
+
if (end === -1) {
|
|
163
|
+
cursor.line += rest.split("\n").length - 2;
|
|
164
|
+
throw getEndOfInputError("");
|
|
165
|
+
}
|
|
166
|
+
skip(end + 2);
|
|
98
167
|
continue;
|
|
99
168
|
}
|
|
100
169
|
const number = /^\d+(?![A-Za-z_])/.exec(rest)?.[0];
|
|
@@ -109,8 +178,18 @@ const tokenizeConfig = (source: string) => {
|
|
|
109
178
|
cursor.index += word.length;
|
|
110
179
|
continue;
|
|
111
180
|
}
|
|
112
|
-
|
|
113
|
-
|
|
181
|
+
if (rest.startsWith('"')) {
|
|
182
|
+
const string = /^"((?:[^"\\\n]|\\.)*)"/.exec(rest);
|
|
183
|
+
if (!string) {
|
|
184
|
+
const lineEnd = rest.indexOf("\n");
|
|
185
|
+
if (lineEnd === rest.length - 1) throw getEndOfInputError(rest);
|
|
186
|
+
throw createLexicalError(
|
|
187
|
+
cursor.line,
|
|
188
|
+
cursor.index + lineEnd - cursor.lineStart + 1,
|
|
189
|
+
"\n",
|
|
190
|
+
rest.slice(0, lineEnd),
|
|
191
|
+
);
|
|
192
|
+
}
|
|
114
193
|
tokens.push({ kind: "String", text: string[1], line: cursor.line });
|
|
115
194
|
cursor.index += string[0].length;
|
|
116
195
|
continue;
|
|
@@ -121,18 +200,18 @@ const tokenizeConfig = (source: string) => {
|
|
|
121
200
|
cursor.index += symbol.length;
|
|
122
201
|
continue;
|
|
123
202
|
}
|
|
124
|
-
const operator = matchOperator(
|
|
125
|
-
if (!operator)
|
|
126
|
-
throw
|
|
127
|
-
|
|
128
|
-
);
|
|
203
|
+
const operator = matchOperator(text, cursor.index);
|
|
204
|
+
if (!operator) {
|
|
205
|
+
throw createLexicalError(cursor.line, cursor.index - cursor.lineStart + 1, rest[0]);
|
|
206
|
+
}
|
|
129
207
|
tokens.push({ kind: "Word", text: operator.text, line: cursor.line });
|
|
130
208
|
cursor.index += operator.length;
|
|
131
209
|
}
|
|
132
|
-
tokens.push({ kind: "End", text: "", line: cursor.line });
|
|
210
|
+
tokens.push({ kind: "End", text: "", line: cursor.line - 1 });
|
|
133
211
|
return tokens;
|
|
134
212
|
};
|
|
135
213
|
|
|
214
|
+
// TLC's ModelConfig.parse, which takes any token for a name and stops a list at the next keyword.
|
|
136
215
|
export const parseConfig = (source: string): ModelConfig => {
|
|
137
216
|
const tokens = tokenizeConfig(source);
|
|
138
217
|
const cursor = { index: 0 };
|
|
@@ -155,183 +234,158 @@ export const parseConfig = (source: string): ModelConfig => {
|
|
|
155
234
|
periodic: undefined,
|
|
156
235
|
rlReward: undefined,
|
|
157
236
|
};
|
|
158
|
-
|
|
159
237
|
const deadlock = { isSet: false };
|
|
160
|
-
const
|
|
161
|
-
const advance = () => tokens[cursor.index++];
|
|
238
|
+
const advance = () => tokens[Math.min(cursor.index++, tokens.length - 1)];
|
|
162
239
|
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
|
-
);
|
|
169
|
-
}
|
|
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();
|
|
200
|
-
};
|
|
201
240
|
|
|
202
|
-
const parseValue = (): ConfigValue => {
|
|
203
|
-
|
|
204
|
-
if (
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (
|
|
241
|
+
const parseValue = (first: ConfigToken): ConfigValue => {
|
|
242
|
+
if (first.kind === "Number") return { kind: "Number", value: Number(first.text) };
|
|
243
|
+
if (first.kind === "String") return { kind: "String", value: first.text };
|
|
244
|
+
if (first.text === "TRUE" || first.text === "FALSE") {
|
|
245
|
+
return { kind: "Boolean", value: first.text === "TRUE" };
|
|
246
|
+
}
|
|
247
|
+
if (first.text === "{") {
|
|
209
248
|
const elements: ConfigValue[] = [];
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
249
|
+
let token = advance();
|
|
250
|
+
if (token.text !== "}") {
|
|
251
|
+
for (;;) {
|
|
252
|
+
elements.push(parseValue(token));
|
|
253
|
+
token = advance();
|
|
254
|
+
if (token.text !== ",") break;
|
|
255
|
+
token = advance();
|
|
256
|
+
}
|
|
214
257
|
}
|
|
215
|
-
|
|
258
|
+
if (token.text !== "}")
|
|
259
|
+
throw createConfigFileError(token.line, "It was expecting }, but did not find it.");
|
|
216
260
|
return { kind: "Set", elements };
|
|
217
261
|
}
|
|
218
|
-
if (
|
|
219
|
-
throw
|
|
220
|
-
`Expected a value but found ${JSON.stringify(token.text)} at line ${token.line}`,
|
|
221
|
-
);
|
|
262
|
+
if (first.kind !== "End") return { kind: "ModelValue", name: first.text };
|
|
263
|
+
throw createConfigFileError(first.line, "It was expecting a value, but did not find it.");
|
|
222
264
|
};
|
|
223
265
|
|
|
224
|
-
const parseModuleScope = () => {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
266
|
+
const parseModuleScope = (operator: string) => {
|
|
267
|
+
const name = advance();
|
|
268
|
+
if (name.kind === "End") {
|
|
269
|
+
throw createConfigFileError(name.line, `Expected an identifier after ${operator}[.`);
|
|
270
|
+
}
|
|
271
|
+
const close = advance();
|
|
272
|
+
if (close.text !== "]") {
|
|
273
|
+
throw createConfigFileError(close.line, "It was expecting ], but did not find it.");
|
|
274
|
+
}
|
|
275
|
+
return name.text;
|
|
230
276
|
};
|
|
231
277
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
278
|
+
// Returns the token after the constants, which starts the next section.
|
|
279
|
+
const parseConstants = (line: number) => {
|
|
280
|
+
for (;;) {
|
|
281
|
+
const first = advance();
|
|
282
|
+
if (first.kind === "End" || isKeyword(first)) return first;
|
|
283
|
+
const name = { text: first.text };
|
|
284
|
+
let token = advance();
|
|
285
|
+
while (token.text === "!") {
|
|
286
|
+
name.text = `${name.text}!${advance().text}`;
|
|
287
|
+
token = advance();
|
|
288
|
+
}
|
|
289
|
+
if (token.text === "<-") {
|
|
290
|
+
token = advance();
|
|
291
|
+
if (token.text === "[") {
|
|
292
|
+
const module = parseModuleScope("<-");
|
|
293
|
+
const target = advance();
|
|
294
|
+
if (target.kind === "End") {
|
|
295
|
+
throw createConfigFileError(target.line, "Expected an identifier after <-[mod].");
|
|
296
|
+
}
|
|
297
|
+
config.substitutions.push({ name: name.text, target: target.text, module });
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (token.kind === "End") {
|
|
301
|
+
throw createConfigFileError(token.line, "Expected an identifier after <-.");
|
|
241
302
|
}
|
|
242
|
-
|
|
243
|
-
expect("=");
|
|
244
|
-
const module = parseModuleScope();
|
|
245
|
-
config.constants.push({ name, value: parseValue(), args, ...(module && { module }) });
|
|
303
|
+
config.substitutions.push({ name: name.text, target: token.text });
|
|
246
304
|
continue;
|
|
247
305
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
306
|
+
const args: ConfigValue[] = [];
|
|
307
|
+
if (token.text === "(") {
|
|
308
|
+
for (;;) {
|
|
309
|
+
args.push(parseValue(advance()));
|
|
310
|
+
token = advance();
|
|
311
|
+
if (token.text !== ",") break;
|
|
312
|
+
}
|
|
313
|
+
if (token.text !== ")") throw createConfigFileError(line, "");
|
|
314
|
+
token = advance();
|
|
253
315
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
316
|
+
if (token.text !== "=") {
|
|
317
|
+
throw createConfigFileError(token.line, "It was expecting = or <-, but did not find it.");
|
|
318
|
+
}
|
|
319
|
+
token = advance();
|
|
320
|
+
const module = token.text === "[" ? parseModuleScope("=") : undefined;
|
|
321
|
+
const value = parseValue(module === undefined ? token : advance());
|
|
322
|
+
config.constants.push({
|
|
323
|
+
name: name.text,
|
|
324
|
+
value,
|
|
325
|
+
...(args.length > 0 && { args }),
|
|
326
|
+
...(module && { module }),
|
|
327
|
+
});
|
|
257
328
|
}
|
|
258
329
|
};
|
|
259
330
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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;
|
|
331
|
+
let token = advance();
|
|
332
|
+
while (token.kind !== "End") {
|
|
333
|
+
const keyword = token.text;
|
|
334
|
+
const line = token.line;
|
|
335
|
+
if (isSingleKeyword(keyword)) {
|
|
336
|
+
const name = advance();
|
|
337
|
+
if (name.kind === "End") {
|
|
338
|
+
throw createConfigFileError(
|
|
339
|
+
line,
|
|
340
|
+
`The keyword ${keyword} was not followed by an identifier.`,
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
const key = SINGLE_KEYWORDS[keyword];
|
|
344
|
+
if (config[key] !== undefined) {
|
|
345
|
+
throw createConfigFileError(line, `The keyword ${keyword} appeared twice.`);
|
|
346
|
+
}
|
|
347
|
+
config[key] = name.text;
|
|
348
|
+
token = advance();
|
|
349
|
+
} else if (isListKeyword(keyword)) {
|
|
350
|
+
const names = config[LIST_KEYWORDS[keyword]];
|
|
351
|
+
token = advance();
|
|
352
|
+
while (token.kind !== "End" && !isKeyword(token)) {
|
|
353
|
+
names.push(token.text);
|
|
354
|
+
token = advance();
|
|
355
|
+
}
|
|
356
|
+
} else if (keyword === "CONSTANT" || keyword === "CONSTANTS") {
|
|
357
|
+
token = parseConstants(line);
|
|
358
|
+
} else if (keyword === "CHECK_DEADLOCK") {
|
|
359
|
+
const value = advance();
|
|
360
|
+
if (value.kind === "End") {
|
|
361
|
+
throw createConfigFileError(
|
|
362
|
+
line,
|
|
363
|
+
"The keyword CHECK_DEADLOCK was not followed by an identifier.",
|
|
364
|
+
);
|
|
325
365
|
}
|
|
326
|
-
|
|
327
|
-
throw
|
|
366
|
+
if (value.text !== "TRUE" && value.text !== "FALSE") {
|
|
367
|
+
throw createConfigFileError(
|
|
368
|
+
value.line,
|
|
369
|
+
"It was expecting TRUE or FALSE, but did not find it.",
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
if (deadlock.isSet) {
|
|
373
|
+
throw createConfigFileError(line, "The keyword CHECK_DEADLOCK appeared twice.");
|
|
374
|
+
}
|
|
375
|
+
deadlock.isSet = true;
|
|
376
|
+
config.checkDeadlock = value.text === "TRUE";
|
|
377
|
+
token = advance();
|
|
378
|
+
} else {
|
|
379
|
+
throw createConfigFileError(line, "It was expecting a keyword, but did not find it.");
|
|
328
380
|
}
|
|
329
381
|
}
|
|
330
382
|
if (
|
|
331
383
|
config.specification !== undefined &&
|
|
332
384
|
(config.init !== undefined || config.next !== undefined)
|
|
333
385
|
) {
|
|
334
|
-
throw new TlaConfigError(
|
|
386
|
+
throw new TlaConfigError(
|
|
387
|
+
"The configuration file cannot specify both INIT/NEXT and SPECIFICATION fields.",
|
|
388
|
+
);
|
|
335
389
|
}
|
|
336
390
|
return config;
|
|
337
391
|
};
|