squiffy-compiler 6.0.1 → 7.0.0-beta.11
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 +10 -2
- package/dist/analyse.d.ts +96 -0
- package/dist/analyse.js +951 -0
- package/dist/compiler.d.ts +32 -40
- package/dist/compiler.js +26 -691
- package/dist/css-urls.d.ts +4 -0
- package/dist/css-urls.js +59 -0
- package/dist/emit.d.ts +71 -0
- package/dist/emit.js +192 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +14 -0
- package/dist/ignore.d.ts +8 -0
- package/dist/ignore.js +71 -0
- package/dist/infix-expressions.d.ts +19 -0
- package/dist/infix-expressions.js +713 -0
- package/dist/language-service.d.ts +90 -0
- package/dist/language-service.js +883 -0
- package/dist/node.d.ts +23 -0
- package/dist/node.js +122 -0
- package/dist/parse.d.ts +22 -0
- package/dist/parse.js +316 -0
- package/dist/project.d.ts +129 -0
- package/dist/project.js +488 -0
- package/dist/quest/aslx.d.ts +51 -0
- package/dist/quest/aslx.js +184 -0
- package/dist/quest/convert.d.ts +20 -0
- package/dist/quest/convert.js +552 -0
- package/dist/quest/script.d.ts +92 -0
- package/dist/quest/script.js +453 -0
- package/dist/quest/scripts.d.ts +24 -0
- package/dist/quest/scripts.js +506 -0
- package/dist/quest/text.d.ts +18 -0
- package/dist/quest/text.js +323 -0
- package/dist/section-labels.d.ts +4 -0
- package/dist/section-labels.js +64 -0
- package/dist/setters.d.ts +49 -0
- package/dist/setters.js +477 -0
- package/dist/story-graph.d.ts +71 -0
- package/dist/story-graph.js +445 -0
- package/dist/syntax.d.ts +198 -0
- package/dist/syntax.js +8 -0
- package/dist/templates.d.ts +17 -0
- package/dist/templates.js +180 -0
- package/dist/text.d.ts +44 -0
- package/dist/text.js +348 -0
- package/dist/twine/audio.d.ts +21 -0
- package/dist/twine/audio.js +80 -0
- package/dist/twine/convert.d.ts +131 -0
- package/dist/twine/convert.js +1057 -0
- package/dist/twine/expression.d.ts +88 -0
- package/dist/twine/expression.js +318 -0
- package/dist/twine/harlowe.d.ts +27 -0
- package/dist/twine/harlowe.js +2341 -0
- package/dist/twine/settings.d.ts +9 -0
- package/dist/twine/settings.js +322 -0
- package/dist/twine/story.d.ts +24 -0
- package/dist/twine/story.js +231 -0
- package/dist/twine/sugarcube.d.ts +40 -0
- package/dist/twine/sugarcube.js +2172 -0
- package/dist/v5.js +2 -1
- package/package.json +35 -6
- package/syntaxes/squiffy.tmLanguage.json +1003 -0
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
// Reads Quest's script language (ASL), as it's written in a gamebook's page scripts: statements
|
|
2
|
+
// such as msg ("..."), if (...) { } else { }, firsttime { }, and calls to the gamebook's functions,
|
|
3
|
+
// such as SetFlagOn ("lamp") or MovePlayer (Page2). Anything it can't read is kept as a "raw"
|
|
4
|
+
// statement, with its source, so the converter can report it rather than lose it.
|
|
5
|
+
class ParseError extends Error {
|
|
6
|
+
}
|
|
7
|
+
function tokenize(source) {
|
|
8
|
+
const tokens = [];
|
|
9
|
+
let i = 0;
|
|
10
|
+
while (i < source.length) {
|
|
11
|
+
const c = source[i];
|
|
12
|
+
if (c == "\n") {
|
|
13
|
+
tokens.push({ type: "nl", text: "\n", start: i, end: i + 1 });
|
|
14
|
+
i++;
|
|
15
|
+
}
|
|
16
|
+
else if (/\s/.test(c)) {
|
|
17
|
+
i++;
|
|
18
|
+
}
|
|
19
|
+
else if (c == "/" && source[i + 1] == "/") {
|
|
20
|
+
while (i < source.length && source[i] != "\n")
|
|
21
|
+
i++;
|
|
22
|
+
}
|
|
23
|
+
else if (c == "\"") {
|
|
24
|
+
let value = "";
|
|
25
|
+
let j = i + 1;
|
|
26
|
+
for (; j < source.length && source[j] != "\""; j++) {
|
|
27
|
+
if (source[j] == "\\" && j + 1 < source.length) {
|
|
28
|
+
j++;
|
|
29
|
+
value += source[j] == "n" ? "\n" : source[j];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
value += source[j];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
tokens.push({ type: "str", text: source.substring(i, j + 1), value, start: i, end: j + 1 });
|
|
36
|
+
i = j + 1;
|
|
37
|
+
}
|
|
38
|
+
else if (/\d/.test(c)) {
|
|
39
|
+
// A number, or a name that starts with one, such as 1B in the page name Option 1B
|
|
40
|
+
const m = /^\d+\.\d+(?![\p{L}_])|^[\p{L}\p{N}_]+/u.exec(source.substring(i));
|
|
41
|
+
tokens.push({ type: /^[\d.]+$/.test(m[0]) ? "num" : "word", text: m[0], start: i, end: i + m[0].length });
|
|
42
|
+
i += m[0].length;
|
|
43
|
+
}
|
|
44
|
+
else if (/[\p{L}_]/u.test(c)) {
|
|
45
|
+
const m = /^[\p{L}\p{N}_]+/u.exec(source.substring(i));
|
|
46
|
+
tokens.push({ type: "word", text: m[0], start: i, end: i + m[0].length });
|
|
47
|
+
i += m[0].length;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const two = source.substring(i, i + 2);
|
|
51
|
+
const op = ["<=", ">=", "<>", "!=", "==", "&&", "||"].includes(two) ? two : c;
|
|
52
|
+
tokens.push({ type: "+-*/%=<>(){},.[]!".includes(op) || op.length == 2 ? "op" : "other", text: op, start: i, end: i + op.length });
|
|
53
|
+
i += op.length;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return tokens;
|
|
57
|
+
}
|
|
58
|
+
const keywords = new Set(["and", "or", "not", "true", "false", "null", "if", "else", "firsttime", "otherwise", "switch", "case", "default"]);
|
|
59
|
+
export class ScriptParser {
|
|
60
|
+
// names: the names of the game's objects, such as its pages, which can have spaces in them
|
|
61
|
+
constructor(source, names) {
|
|
62
|
+
Object.defineProperty(this, "source", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
value: source
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(this, "names", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
configurable: true,
|
|
71
|
+
writable: true,
|
|
72
|
+
value: names
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(this, "tokens", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
configurable: true,
|
|
77
|
+
writable: true,
|
|
78
|
+
value: void 0
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(this, "pos", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
configurable: true,
|
|
83
|
+
writable: true,
|
|
84
|
+
value: 0
|
|
85
|
+
});
|
|
86
|
+
this.tokens = tokenize(source);
|
|
87
|
+
}
|
|
88
|
+
static parse(source, names) {
|
|
89
|
+
const parser = new ScriptParser(source, names);
|
|
90
|
+
const body = parser.statements(false);
|
|
91
|
+
return body;
|
|
92
|
+
}
|
|
93
|
+
peek(offset = 0) {
|
|
94
|
+
return this.tokens[this.pos + offset];
|
|
95
|
+
}
|
|
96
|
+
is(text, offset = 0) {
|
|
97
|
+
const t = this.peek(offset);
|
|
98
|
+
return !!t && t.type != "str" && t.text == text;
|
|
99
|
+
}
|
|
100
|
+
expect(text) {
|
|
101
|
+
const t = this.peek();
|
|
102
|
+
if (!t || t.type == "str" || t.text != text)
|
|
103
|
+
throw new ParseError(`expected "${text}"`);
|
|
104
|
+
this.pos++;
|
|
105
|
+
return t;
|
|
106
|
+
}
|
|
107
|
+
skipNewlines() {
|
|
108
|
+
while (this.peek()?.type == "nl")
|
|
109
|
+
this.pos++;
|
|
110
|
+
}
|
|
111
|
+
// Statements, up to the end of the script, or the } that ends a block
|
|
112
|
+
statements(inBlock) {
|
|
113
|
+
const result = [];
|
|
114
|
+
for (;;) {
|
|
115
|
+
this.skipNewlines();
|
|
116
|
+
const t = this.peek();
|
|
117
|
+
if (!t) {
|
|
118
|
+
if (inBlock)
|
|
119
|
+
throw new ParseError("a block with no }");
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
if (inBlock && this.is("}"))
|
|
123
|
+
return result;
|
|
124
|
+
result.push(this.statement());
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
block() {
|
|
128
|
+
this.skipNewlines();
|
|
129
|
+
this.expect("{");
|
|
130
|
+
const body = this.statements(true);
|
|
131
|
+
this.expect("}");
|
|
132
|
+
return body;
|
|
133
|
+
}
|
|
134
|
+
// One statement. If it can't be read, it's kept as raw text, up to the end of its line (and
|
|
135
|
+
// any block that starts on it).
|
|
136
|
+
statement() {
|
|
137
|
+
const start = this.pos;
|
|
138
|
+
try {
|
|
139
|
+
const stmt = this.statementOrThrow();
|
|
140
|
+
this.endOfStatement();
|
|
141
|
+
return stmt;
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
if (!(e instanceof ParseError))
|
|
145
|
+
throw e;
|
|
146
|
+
this.pos = start;
|
|
147
|
+
this.skipRawStatement();
|
|
148
|
+
return { k: "raw", src: this.sourceFrom(start) };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
endOfStatement() {
|
|
152
|
+
const t = this.peek();
|
|
153
|
+
if (t && t.type != "nl" && !this.is("}"))
|
|
154
|
+
throw new ParseError("more after the end of a statement");
|
|
155
|
+
}
|
|
156
|
+
skipRawStatement() {
|
|
157
|
+
let depth = 0;
|
|
158
|
+
while (this.peek()) {
|
|
159
|
+
const t = this.peek();
|
|
160
|
+
if (t.type == "nl" && depth <= 0)
|
|
161
|
+
return;
|
|
162
|
+
if (t.type == "op" && (t.text == "{" || t.text == "("))
|
|
163
|
+
depth++;
|
|
164
|
+
if (t.type == "op" && (t.text == "}" || t.text == ")")) {
|
|
165
|
+
if (depth <= 0)
|
|
166
|
+
return;
|
|
167
|
+
depth--;
|
|
168
|
+
this.pos++;
|
|
169
|
+
// A block ends the statement, unless else or otherwise follows it
|
|
170
|
+
if (depth == 0 && t.text == "}") {
|
|
171
|
+
let j = 0;
|
|
172
|
+
while (this.peek(j)?.type == "nl")
|
|
173
|
+
j++;
|
|
174
|
+
if (!this.is("else", j) && !this.is("otherwise", j))
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
this.pos++;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
sourceFrom(startToken) {
|
|
183
|
+
const first = this.tokens[startToken];
|
|
184
|
+
const last = this.tokens[this.pos - 1];
|
|
185
|
+
if (!first || !last || this.pos <= startToken)
|
|
186
|
+
return "";
|
|
187
|
+
return this.source.substring(first.start, last.end).trim();
|
|
188
|
+
}
|
|
189
|
+
statementOrThrow() {
|
|
190
|
+
const start = this.pos;
|
|
191
|
+
const t = this.peek();
|
|
192
|
+
const src = () => this.sourceFrom(start);
|
|
193
|
+
if (t.type != "word")
|
|
194
|
+
throw new ParseError("a statement that doesn't start with a name");
|
|
195
|
+
if (t.text == "if") {
|
|
196
|
+
const branches = [];
|
|
197
|
+
let otherwise;
|
|
198
|
+
this.pos++;
|
|
199
|
+
branches.push({ cond: this.condition(), body: this.block() });
|
|
200
|
+
for (;;) {
|
|
201
|
+
let j = 0;
|
|
202
|
+
while (this.peek(j)?.type == "nl")
|
|
203
|
+
j++;
|
|
204
|
+
if (!this.is("else", j))
|
|
205
|
+
break;
|
|
206
|
+
this.pos += j + 1;
|
|
207
|
+
if (this.is("if")) {
|
|
208
|
+
this.pos++;
|
|
209
|
+
branches.push({ cond: this.condition(), body: this.block() });
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
otherwise = this.block();
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return { k: "if", branches, otherwise, src: src() };
|
|
217
|
+
}
|
|
218
|
+
if (t.text == "firsttime") {
|
|
219
|
+
this.pos++;
|
|
220
|
+
const body = this.block();
|
|
221
|
+
let j = 0;
|
|
222
|
+
while (this.peek(j)?.type == "nl")
|
|
223
|
+
j++;
|
|
224
|
+
let otherwise;
|
|
225
|
+
if (this.is("otherwise", j)) {
|
|
226
|
+
this.pos += j + 1;
|
|
227
|
+
otherwise = this.block();
|
|
228
|
+
}
|
|
229
|
+
return { k: "firsttime", body, otherwise, src: src() };
|
|
230
|
+
}
|
|
231
|
+
if (t.text == "switch") {
|
|
232
|
+
this.pos++;
|
|
233
|
+
const value = this.condition();
|
|
234
|
+
this.skipNewlines();
|
|
235
|
+
this.expect("{");
|
|
236
|
+
const cases = [];
|
|
237
|
+
let otherwise;
|
|
238
|
+
for (;;) {
|
|
239
|
+
this.skipNewlines();
|
|
240
|
+
if (this.is("}"))
|
|
241
|
+
break;
|
|
242
|
+
if (this.is("case")) {
|
|
243
|
+
this.pos++;
|
|
244
|
+
this.expect("(");
|
|
245
|
+
const values = this.expressionList(")");
|
|
246
|
+
this.expect(")");
|
|
247
|
+
cases.push({ values, body: this.block() });
|
|
248
|
+
}
|
|
249
|
+
else if (this.is("default")) {
|
|
250
|
+
this.pos++;
|
|
251
|
+
otherwise = this.block();
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
throw new ParseError("expected case or default");
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
this.expect("}");
|
|
258
|
+
return { k: "switch", value, cases, otherwise, src: src() };
|
|
259
|
+
}
|
|
260
|
+
// Two-word commands
|
|
261
|
+
const second = this.peek(1);
|
|
262
|
+
const twoWord = second?.type == "word" && { play: ["sound"], stop: ["sound"], list: ["add", "remove"], dictionary: ["add", "remove"], on: ["ready"] }[t.text]?.includes(second.text);
|
|
263
|
+
if (twoWord && t.text == "on") {
|
|
264
|
+
this.pos += 2;
|
|
265
|
+
return { k: "call", fn: "on ready", args: [], callback: this.block(), src: src() };
|
|
266
|
+
}
|
|
267
|
+
if (twoWord) {
|
|
268
|
+
this.pos += 2;
|
|
269
|
+
const args = this.is("(") ? this.arguments() : [];
|
|
270
|
+
return { k: "call", fn: `${t.text} ${second.text}`, args, src: src() };
|
|
271
|
+
}
|
|
272
|
+
// An assignment, such as game.lamp = true, or a local variable, such as x = 1
|
|
273
|
+
const save = this.pos;
|
|
274
|
+
if (!keywords.has(t.text)) {
|
|
275
|
+
try {
|
|
276
|
+
const target = this.path();
|
|
277
|
+
if (this.is("=")) {
|
|
278
|
+
this.pos++;
|
|
279
|
+
const value = this.expression();
|
|
280
|
+
return { k: "assign", target, value, src: src() };
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
catch (e) {
|
|
284
|
+
if (!(e instanceof ParseError))
|
|
285
|
+
throw e;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
this.pos = save;
|
|
289
|
+
// A call, with or without brackets, and a callback if it has one. Its name can have dots
|
|
290
|
+
// in it, such as JS.eval.
|
|
291
|
+
let fn = t.text;
|
|
292
|
+
this.pos++;
|
|
293
|
+
while (this.is(".") && this.peek(1)?.type == "word") {
|
|
294
|
+
fn += "." + this.peek(1).text;
|
|
295
|
+
this.pos += 2;
|
|
296
|
+
}
|
|
297
|
+
const args = this.is("(") ? this.arguments() : [];
|
|
298
|
+
let callback;
|
|
299
|
+
let j = 0;
|
|
300
|
+
while (this.peek(j)?.type == "nl")
|
|
301
|
+
j++;
|
|
302
|
+
if (this.is("{", j) && (j == 0 || t.text == "GetInput" || t.text == "ShowMenu")) {
|
|
303
|
+
callback = this.block();
|
|
304
|
+
}
|
|
305
|
+
return { k: "call", fn, args, callback, src: src() };
|
|
306
|
+
}
|
|
307
|
+
condition() {
|
|
308
|
+
this.expect("(");
|
|
309
|
+
const e = this.expression();
|
|
310
|
+
this.expect(")");
|
|
311
|
+
return e;
|
|
312
|
+
}
|
|
313
|
+
arguments() {
|
|
314
|
+
this.expect("(");
|
|
315
|
+
const args = this.expressionList(")");
|
|
316
|
+
this.expect(")");
|
|
317
|
+
return args;
|
|
318
|
+
}
|
|
319
|
+
expressionList(end) {
|
|
320
|
+
const items = [];
|
|
321
|
+
this.skipNewlines();
|
|
322
|
+
if (this.is(end))
|
|
323
|
+
return items;
|
|
324
|
+
for (;;) {
|
|
325
|
+
this.skipNewlines();
|
|
326
|
+
items.push(this.expression());
|
|
327
|
+
this.skipNewlines();
|
|
328
|
+
if (!this.is(","))
|
|
329
|
+
return items;
|
|
330
|
+
this.pos++;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
expression() {
|
|
334
|
+
return this.binary(0);
|
|
335
|
+
}
|
|
336
|
+
binary(level) {
|
|
337
|
+
if (level >= ScriptParser.levels.length)
|
|
338
|
+
return this.unary();
|
|
339
|
+
let left = this.binary(level + 1);
|
|
340
|
+
for (;;) {
|
|
341
|
+
const t = this.peek();
|
|
342
|
+
if (!t || t.type == "str" || !ScriptParser.levels[level].includes(t.text))
|
|
343
|
+
return left;
|
|
344
|
+
this.pos++;
|
|
345
|
+
this.skipNewlines();
|
|
346
|
+
const op = t.text == "||" ? "or" : t.text == "&&" ? "and" : t.text == "==" ? "=" : t.text == "!=" ? "<>" : t.text;
|
|
347
|
+
left = { k: "bin", op, l: left, r: this.binary(level + 1) };
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
unary() {
|
|
351
|
+
if (this.is("not") || this.is("!")) {
|
|
352
|
+
this.pos++;
|
|
353
|
+
return { k: "not", e: this.unary() };
|
|
354
|
+
}
|
|
355
|
+
if (this.is("-")) {
|
|
356
|
+
this.pos++;
|
|
357
|
+
return { k: "neg", e: this.unary() };
|
|
358
|
+
}
|
|
359
|
+
return this.primary();
|
|
360
|
+
}
|
|
361
|
+
primary() {
|
|
362
|
+
const t = this.peek();
|
|
363
|
+
if (!t)
|
|
364
|
+
throw new ParseError("an expression that ends too soon");
|
|
365
|
+
if (t.type == "str") {
|
|
366
|
+
this.pos++;
|
|
367
|
+
return { k: "str", v: t.value };
|
|
368
|
+
}
|
|
369
|
+
if (t.type == "num" && !this.objectName()) {
|
|
370
|
+
this.pos++;
|
|
371
|
+
return { k: "num", v: Number(t.text) };
|
|
372
|
+
}
|
|
373
|
+
if (this.is("(")) {
|
|
374
|
+
this.pos++;
|
|
375
|
+
const e = this.expression();
|
|
376
|
+
this.expect(")");
|
|
377
|
+
return e;
|
|
378
|
+
}
|
|
379
|
+
if (t.type == "word" && (t.text == "true" || t.text == "false")) {
|
|
380
|
+
this.pos++;
|
|
381
|
+
return { k: "bool", v: t.text == "true" };
|
|
382
|
+
}
|
|
383
|
+
if (t.type == "word" && t.text == "null") {
|
|
384
|
+
this.pos++;
|
|
385
|
+
return { k: "null" };
|
|
386
|
+
}
|
|
387
|
+
if ((t.type == "word" || t.type == "num") && !keywords.has(t.text)) {
|
|
388
|
+
// A function call, such as GetBoolean (game, "lamp")
|
|
389
|
+
if (t.type == "word" && this.is("(", 1) && !this.objectName()) {
|
|
390
|
+
this.pos++;
|
|
391
|
+
const args = this.arguments();
|
|
392
|
+
return { k: "call", fn: t.text, args };
|
|
393
|
+
}
|
|
394
|
+
return this.path();
|
|
395
|
+
}
|
|
396
|
+
throw new ParseError(`unexpected "${t.text}"`);
|
|
397
|
+
}
|
|
398
|
+
// The name of one of the game's objects at the current token, which can be several words,
|
|
399
|
+
// e.g. Room 551 Weather. Returns how many tokens it is, or 0.
|
|
400
|
+
objectName() {
|
|
401
|
+
let best = 0;
|
|
402
|
+
let name = "";
|
|
403
|
+
for (let n = 0; n < 12; n++) {
|
|
404
|
+
const t = this.peek(n);
|
|
405
|
+
if (!t || (t.type != "word" && t.type != "num"))
|
|
406
|
+
break;
|
|
407
|
+
if (n > 0) {
|
|
408
|
+
const gap = this.source.substring(this.peek(n - 1).end, t.start);
|
|
409
|
+
if (gap != " ")
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
name += (n > 0 ? " " : "") + t.text;
|
|
413
|
+
if (this.names.has(name))
|
|
414
|
+
best = n + 1;
|
|
415
|
+
}
|
|
416
|
+
return best;
|
|
417
|
+
}
|
|
418
|
+
// A name, or a dotted path such as player.parent or game.lamp
|
|
419
|
+
path() {
|
|
420
|
+
const parts = [];
|
|
421
|
+
for (;;) {
|
|
422
|
+
const t = this.peek();
|
|
423
|
+
if (!t || (t.type != "word" && t.type != "num") || keywords.has(t.text))
|
|
424
|
+
throw new ParseError("expected a name");
|
|
425
|
+
const words = this.objectName();
|
|
426
|
+
if (words > 1) {
|
|
427
|
+
parts.push(this.tokens.slice(this.pos, this.pos + words).map(w => w.text).join(" "));
|
|
428
|
+
this.pos += words;
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
if (t.type == "num" && parts.length == 0 && words == 0)
|
|
432
|
+
throw new ParseError("expected a name");
|
|
433
|
+
parts.push(t.text);
|
|
434
|
+
this.pos++;
|
|
435
|
+
}
|
|
436
|
+
if (!this.is("."))
|
|
437
|
+
return { k: "path", parts };
|
|
438
|
+
this.pos++;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
Object.defineProperty(ScriptParser, "levels", {
|
|
443
|
+
enumerable: true,
|
|
444
|
+
configurable: true,
|
|
445
|
+
writable: true,
|
|
446
|
+
value: [
|
|
447
|
+
["or", "||"],
|
|
448
|
+
["and", "&&"],
|
|
449
|
+
["=", "==", "<>", "!=", "<", ">", "<=", ">="],
|
|
450
|
+
["+", "-"],
|
|
451
|
+
["*", "/", "%"],
|
|
452
|
+
]
|
|
453
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Expr } from "../twine/expression.js";
|
|
2
|
+
import type { QStmt } from "./script.js";
|
|
3
|
+
import type { TextContext } from "./text.js";
|
|
4
|
+
export interface ScriptContext extends TextContext {
|
|
5
|
+
readonly page?: string;
|
|
6
|
+
readonly inCallback?: boolean;
|
|
7
|
+
isPage(name: string): boolean;
|
|
8
|
+
linkAttribute(source: string, destination: string): string;
|
|
9
|
+
linkValue(source: string, destination: string, text: string): Expr;
|
|
10
|
+
newFirstTime(): string;
|
|
11
|
+
noteStyle(): void;
|
|
12
|
+
continueSection?(content: string): string;
|
|
13
|
+
}
|
|
14
|
+
export interface ConvertedScript {
|
|
15
|
+
directives: string[];
|
|
16
|
+
lines: string[];
|
|
17
|
+
}
|
|
18
|
+
export declare const INPUT_ATTRIBUTE = "input";
|
|
19
|
+
export declare function convertScript(statements: QStmt[], ctx: ScriptContext): ConvertedScript;
|
|
20
|
+
export declare function linkChanges(statements: QStmt[], currentPage: string | undefined, isPage: (name: string) => boolean): Generator<{
|
|
21
|
+
source: string;
|
|
22
|
+
destination: string;
|
|
23
|
+
text?: string;
|
|
24
|
+
}>;
|