tla-ts 0.0.3-dev.fd18eec → 0.0.3-dev.fe239f8
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/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +167 -36
- package/dist/index.d.ts +167 -36
- 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 -21
- package/dist/run-cli.js +1351 -21
- package/dist/transfer.cjs +83 -34
- package/dist/transfer.js +83 -34
- package/package.json +5 -1
- package/src/ast.ts +53 -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 +1344 -285
- package/src/cli.ts +8 -1
- package/src/codegen.ts +68 -21
- package/src/config.ts +225 -206
- package/src/environment.ts +417 -124
- package/src/errors.ts +168 -9
- package/src/evaluate.ts +722 -146
- package/src/exit-codes.ts +6 -24
- package/src/index.ts +1 -0
- package/src/instances.ts +4 -2
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +183 -37
- package/src/lexer.ts +32 -4
- package/src/live-check.ts +204 -148
- package/src/liveness.ts +190 -117
- package/src/obligation-expression.ts +2 -2
- package/src/obligation-source.ts +2 -0
- package/src/parallel-worker.ts +6 -1
- package/src/parallel.ts +57 -6
- package/src/parser.ts +437 -130
- 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 +1347 -414
- package/src/run-cli.ts +1167 -174
- package/src/runtime.ts +16 -0
- 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 +25 -5
- package/src/standard-modules.ts +203 -146
- package/src/standard-ranges.ts +116 -0
- package/src/state-graph.ts +29 -6
- package/src/subexpressions.ts +221 -161
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +158 -120
- package/src/symmetry.ts +168 -50
- package/src/tableau.ts +3 -1
- package/src/tlc-ext.ts +13 -17
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +49 -21
- package/src/tlc-modules.ts +0 -4
- package/src/tlc-order.ts +55 -9
- package/src/tlc-random.ts +28 -3
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-version.ts +18 -0
- package/src/transfer.ts +15 -3
- package/src/value-sources.ts +29 -0
- package/src/values.ts +683 -256
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,147 +78,149 @@ const KEYWORDS = new Set([
|
|
|
72
78
|
"_RL_REWARD",
|
|
73
79
|
]);
|
|
74
80
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
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);
|
|
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]);
|
|
104
85
|
|
|
105
|
-
const
|
|
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}`);
|
|
86
|
+
const SYMBOLS = ["<-", "<<", ">>", "=", "{", "}", ",", "[", "]", "(", ")", "!"];
|
|
131
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.
|
|
132
90
|
const tokenizeConfig = (source: string) => {
|
|
133
|
-
// TLC appends a newline so that a trailing \* comment ends.
|
|
134
|
-
const text = `${source}\n`;
|
|
135
91
|
const tokens: ConfigToken[] = [];
|
|
136
92
|
const cursor = { index: 0, line: 1, lineStart: 0 };
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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;
|
|
144
114
|
}
|
|
145
|
-
cursor.index += length;
|
|
115
|
+
cursor.index += text.length;
|
|
146
116
|
};
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
while (cursor.index < text.length) {
|
|
150
|
-
const rest = text.slice(cursor.index);
|
|
117
|
+
while (cursor.index < source.length) {
|
|
118
|
+
const rest = source.slice(cursor.index);
|
|
151
119
|
const whitespace = /^\s+/.exec(rest)?.[0];
|
|
152
120
|
if (whitespace) {
|
|
153
|
-
skip(whitespace
|
|
121
|
+
skip(whitespace);
|
|
154
122
|
continue;
|
|
155
123
|
}
|
|
156
124
|
if (rest.startsWith("\\*")) {
|
|
157
|
-
|
|
125
|
+
const lineEnd = rest.indexOf("\n");
|
|
126
|
+
skip(lineEnd === -1 ? rest : rest.slice(0, lineEnd));
|
|
158
127
|
continue;
|
|
159
128
|
}
|
|
160
129
|
if (rest.startsWith("(*")) {
|
|
161
130
|
const end = rest.indexOf("*)");
|
|
162
131
|
if (end === -1) {
|
|
163
|
-
|
|
164
|
-
|
|
132
|
+
skip(rest);
|
|
133
|
+
addEndOfInputError("");
|
|
134
|
+
return tokens;
|
|
165
135
|
}
|
|
166
|
-
skip(end + 2);
|
|
136
|
+
skip(rest.slice(0, end + 2));
|
|
167
137
|
continue;
|
|
168
138
|
}
|
|
139
|
+
const line = cursor.line;
|
|
169
140
|
const number = /^\d+(?![A-Za-z_])/.exec(rest)?.[0];
|
|
170
141
|
if (number) {
|
|
171
|
-
tokens.push({ kind: "Number", text: number, line
|
|
172
|
-
|
|
142
|
+
tokens.push({ kind: "Number", text: number, line });
|
|
143
|
+
skip(number);
|
|
173
144
|
continue;
|
|
174
145
|
}
|
|
175
|
-
const word = /^[A-Za-z0-9_
|
|
146
|
+
const word = /^[A-Za-z0-9_]+/.exec(rest)?.[0];
|
|
176
147
|
if (word) {
|
|
177
|
-
tokens.push({ kind: "Word", text: word, line
|
|
178
|
-
|
|
148
|
+
tokens.push({ kind: "Word", text: word, line });
|
|
149
|
+
skip(word);
|
|
179
150
|
continue;
|
|
180
151
|
}
|
|
181
152
|
if (rest.startsWith('"')) {
|
|
182
|
-
const string = /^"((?:[^"\\\n]
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
"\n",
|
|
190
|
-
rest.slice(0, lineEnd),
|
|
191
|
-
);
|
|
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;
|
|
192
160
|
}
|
|
193
|
-
tokens.push({ kind: "String", text: string[1], line
|
|
194
|
-
|
|
161
|
+
tokens.push({ kind: "String", text: string[1], line });
|
|
162
|
+
skip(text);
|
|
195
163
|
continue;
|
|
196
164
|
}
|
|
197
165
|
const symbol = SYMBOLS.find((candidate) => rest.startsWith(candidate));
|
|
198
166
|
if (symbol) {
|
|
199
|
-
tokens.push({ kind: "Symbol", text: symbol, line
|
|
200
|
-
|
|
167
|
+
tokens.push({ kind: "Symbol", text: symbol, line });
|
|
168
|
+
skip(symbol);
|
|
201
169
|
continue;
|
|
202
170
|
}
|
|
203
|
-
const operator = matchOperator(
|
|
171
|
+
const operator = matchOperator(source, cursor.index);
|
|
204
172
|
if (!operator) {
|
|
205
|
-
|
|
173
|
+
addLexicalError(cursor.index, "");
|
|
174
|
+
return tokens;
|
|
206
175
|
}
|
|
207
|
-
tokens.push({ kind: "Word", text: operator.text, line
|
|
208
|
-
cursor.index
|
|
176
|
+
tokens.push({ kind: "Word", text: operator.text, line });
|
|
177
|
+
skip(source.slice(cursor.index, cursor.index + operator.length));
|
|
209
178
|
}
|
|
210
|
-
tokens.push({ kind: "End", text: "", line: cursor.line
|
|
179
|
+
tokens.push({ kind: "End", text: "", line: cursor.line });
|
|
211
180
|
return tokens;
|
|
212
181
|
};
|
|
213
182
|
|
|
214
|
-
// TLC's
|
|
215
|
-
|
|
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;
|
|
216
224
|
const tokens = tokenizeConfig(source);
|
|
217
225
|
const cursor = { index: 0 };
|
|
218
226
|
const config: ModelConfig = {
|
|
@@ -235,157 +243,168 @@ export const parseConfig = (source: string): ModelConfig => {
|
|
|
235
243
|
rlReward: undefined,
|
|
236
244
|
};
|
|
237
245
|
const deadlock = { isSet: false };
|
|
238
|
-
const
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
+
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}`);
|
|
246
251
|
}
|
|
247
|
-
|
|
252
|
+
return token;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const parseValue = (token: ConfigToken): ConfigValue => {
|
|
256
|
+
if (token.kind === "Number") return { kind: "Number", value: Number(token.text) };
|
|
257
|
+
if (token.kind === "String") return { kind: "String", value: token.text };
|
|
258
|
+
if (token.text === "TRUE" || token.text === "FALSE")
|
|
259
|
+
return { kind: "Boolean", value: token.text === "TRUE" };
|
|
260
|
+
if (token.text === "{") {
|
|
248
261
|
const elements: ConfigValue[] = [];
|
|
249
|
-
|
|
250
|
-
if (token.text !== "}") {
|
|
251
|
-
|
|
252
|
-
elements.push(parseValue(token));
|
|
253
|
-
token = advance();
|
|
254
|
-
if (token.text !== ",") break;
|
|
255
|
-
token = advance();
|
|
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();
|
|
256
269
|
}
|
|
257
270
|
}
|
|
258
|
-
if (token.text !== "}")
|
|
259
|
-
throw
|
|
271
|
+
if (current.token.text !== "}") {
|
|
272
|
+
throw createSyntaxError(current.token.line, "It was expecting }, but did not find it.");
|
|
273
|
+
}
|
|
260
274
|
return { kind: "Set", elements };
|
|
261
275
|
}
|
|
262
|
-
if (
|
|
263
|
-
throw
|
|
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.");
|
|
264
278
|
};
|
|
265
279
|
|
|
280
|
+
// A module name in brackets after = or <-, which applies the assignment in that module.
|
|
266
281
|
const parseModuleScope = (operator: string) => {
|
|
267
282
|
const name = advance();
|
|
268
283
|
if (name.kind === "End") {
|
|
269
|
-
throw
|
|
284
|
+
throw createSyntaxError(name.line, `Expected an identifier after ${operator}[.`);
|
|
270
285
|
}
|
|
271
286
|
const close = advance();
|
|
272
287
|
if (close.text !== "]") {
|
|
273
|
-
throw
|
|
288
|
+
throw createSyntaxError(close.line, "It was expecting ], but did not find it.");
|
|
274
289
|
}
|
|
275
290
|
return name.text;
|
|
276
291
|
};
|
|
277
292
|
|
|
278
|
-
//
|
|
279
|
-
const parseConstants = (
|
|
280
|
-
|
|
293
|
+
// TLC reports a malformed argument list at the line of the CONSTANT keyword.
|
|
294
|
+
const parseConstants = (keywordLine: number) => {
|
|
295
|
+
while (true) {
|
|
281
296
|
const first = advance();
|
|
282
|
-
if (first.kind === "End" ||
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
token = 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();
|
|
288
302
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
303
|
+
const name = current.name;
|
|
304
|
+
if (current.token.text === "<-") {
|
|
305
|
+
current.token = advance();
|
|
306
|
+
if (current.token.text === "[") {
|
|
292
307
|
const module = parseModuleScope("<-");
|
|
293
308
|
const target = advance();
|
|
294
309
|
if (target.kind === "End") {
|
|
295
|
-
throw
|
|
310
|
+
throw createSyntaxError(target.line, "Expected an identifier after <-[mod].");
|
|
296
311
|
}
|
|
297
|
-
config.substitutions.push({ name
|
|
312
|
+
config.substitutions.push({ name, target: target.text, module });
|
|
298
313
|
continue;
|
|
299
314
|
}
|
|
300
|
-
if (token.kind === "End") {
|
|
301
|
-
throw
|
|
315
|
+
if (current.token.kind === "End") {
|
|
316
|
+
throw createSyntaxError(current.token.line, "Expected an identifier after <-.");
|
|
302
317
|
}
|
|
303
|
-
config.substitutions.push({ name
|
|
318
|
+
config.substitutions.push({ name, target: current.token.text });
|
|
304
319
|
continue;
|
|
305
320
|
}
|
|
306
321
|
const args: ConfigValue[] = [];
|
|
307
|
-
|
|
308
|
-
|
|
322
|
+
const hasArgs = current.token.text === "(";
|
|
323
|
+
if (hasArgs) {
|
|
324
|
+
while (true) {
|
|
309
325
|
args.push(parseValue(advance()));
|
|
310
|
-
token = advance();
|
|
311
|
-
if (token.text !== ",") break;
|
|
326
|
+
current.token = advance();
|
|
327
|
+
if (current.token.text !== ",") break;
|
|
328
|
+
}
|
|
329
|
+
if (current.token.text !== ")") {
|
|
330
|
+
throw createSyntaxError(keywordLine, "");
|
|
312
331
|
}
|
|
313
|
-
|
|
314
|
-
token = advance();
|
|
332
|
+
current.token = advance();
|
|
315
333
|
}
|
|
316
|
-
if (token.text !== "=") {
|
|
317
|
-
throw
|
|
334
|
+
if (current.token.text !== "=") {
|
|
335
|
+
throw createSyntaxError(
|
|
336
|
+
current.token.line,
|
|
337
|
+
"It was expecting = or <-, but did not find it.",
|
|
338
|
+
);
|
|
318
339
|
}
|
|
319
|
-
token = advance();
|
|
320
|
-
const module = token.text === "[" ? parseModuleScope("=") : undefined;
|
|
321
|
-
const value = parseValue(module === undefined ? token : advance());
|
|
340
|
+
current.token = advance();
|
|
341
|
+
const module = current.token.text === "[" ? parseModuleScope("=") : undefined;
|
|
342
|
+
const value = parseValue(module === undefined ? current.token : advance());
|
|
322
343
|
config.constants.push({
|
|
323
|
-
name
|
|
344
|
+
name,
|
|
324
345
|
value,
|
|
325
|
-
...(
|
|
326
|
-
...(module && { module }),
|
|
346
|
+
...(hasArgs && { args }),
|
|
347
|
+
...(module !== undefined && { module }),
|
|
327
348
|
});
|
|
328
349
|
}
|
|
329
350
|
};
|
|
330
351
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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();
|
|
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.`);
|
|
355
370
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const
|
|
360
|
-
if (
|
|
361
|
-
throw
|
|
362
|
-
line,
|
|
363
|
-
"The keyword CHECK_DEADLOCK was not followed by an identifier.",
|
|
364
|
-
);
|
|
371
|
+
return argument;
|
|
372
|
+
};
|
|
373
|
+
if (singleKey !== undefined) {
|
|
374
|
+
const name = advanceToArgument();
|
|
375
|
+
if (config[singleKey] !== undefined) {
|
|
376
|
+
throw createDuplicateKeywordError(line, keyword);
|
|
365
377
|
}
|
|
378
|
+
config[singleKey] = name.text;
|
|
379
|
+
current.token = advance();
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
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();
|
|
366
392
|
if (value.text !== "TRUE" && value.text !== "FALSE") {
|
|
367
|
-
throw
|
|
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.");
|
|
393
|
+
throw createSyntaxError(value.line, "It was expecting TRUE or FALSE, but did not find it.");
|
|
374
394
|
}
|
|
395
|
+
if (deadlock.isSet) throw createDuplicateKeywordError(line, keyword);
|
|
375
396
|
deadlock.isSet = true;
|
|
376
397
|
config.checkDeadlock = value.text === "TRUE";
|
|
377
|
-
token = advance();
|
|
378
|
-
|
|
379
|
-
throw createConfigFileError(line, "It was expecting a keyword, but did not find it.");
|
|
398
|
+
current.token = advance();
|
|
399
|
+
continue;
|
|
380
400
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
);
|
|
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();
|
|
389
408
|
}
|
|
390
409
|
return config;
|
|
391
410
|
};
|