squiffy-compiler 7.0.0-beta.3 → 7.0.0-beta.5
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/analyse.d.ts +2 -0
- package/dist/analyse.js +43 -1
- package/dist/compiler.d.ts +7 -0
- package/dist/compiler.js +3 -0
- package/dist/emit.d.ts +1 -0
- package/dist/emit.js +6 -0
- package/dist/language-service.js +39 -3
- package/dist/node.d.ts +2 -0
- package/dist/node.js +6 -2
- package/dist/parse.js +13 -4
- package/dist/project.d.ts +2 -0
- package/dist/project.js +14 -2
- package/dist/setters.d.ts +40 -0
- package/dist/setters.js +411 -0
- package/dist/story-graph.d.ts +2 -1
- package/dist/story-graph.js +10 -3
- package/dist/syntax.d.ts +9 -1
- package/dist/text.d.ts +4 -1
- package/dist/text.js +56 -32
- package/dist/twine/convert.d.ts +75 -0
- package/dist/twine/convert.js +626 -0
- package/dist/twine/expression.d.ts +62 -0
- package/dist/twine/expression.js +201 -0
- package/dist/twine/harlowe.d.ts +17 -0
- package/dist/twine/harlowe.js +1856 -0
- package/dist/twine/story.d.ts +24 -0
- package/dist/twine/story.js +231 -0
- package/dist/twine/sugarcube.d.ts +33 -0
- package/dist/twine/sugarcube.js +1584 -0
- package/package.json +2 -2
- package/syntaxes/squiffy.tmLanguage.json +33 -7
package/dist/analyse.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export interface AnalyseSettings {
|
|
|
12
12
|
parseCache?: ParseCache;
|
|
13
13
|
recover?: boolean;
|
|
14
14
|
storyFiles?: string[];
|
|
15
|
+
expressions?: boolean;
|
|
15
16
|
}
|
|
16
17
|
export declare class ParseCache {
|
|
17
18
|
private files;
|
|
@@ -33,6 +34,7 @@ export interface Analysis {
|
|
|
33
34
|
diagnostics: Diagnostic[];
|
|
34
35
|
sections: SectionSymbol[];
|
|
35
36
|
start: string;
|
|
37
|
+
expressions: boolean;
|
|
36
38
|
}
|
|
37
39
|
export declare class Story {
|
|
38
40
|
sections: Record<string, Section>;
|
package/dist/analyse.js
CHANGED
|
@@ -2,6 +2,7 @@ import { parse } from "./parse.js";
|
|
|
2
2
|
import { positionMapper, transformText } from "./text.js";
|
|
3
3
|
import { PROJECT_FILENAME } from "./project.js";
|
|
4
4
|
import { findV5Syntax } from "./v5.js";
|
|
5
|
+
import { attributesSetIn, BUILT_IN_ATTRIBUTES, findAtAttributes, findBuiltInAttributeSets, findUnquotedText } from "./setters.js";
|
|
5
6
|
// Caches the syntax tree of each file by filename, reparsing a file only when its text changes.
|
|
6
7
|
export class ParseCache {
|
|
7
8
|
constructor() {
|
|
@@ -191,6 +192,8 @@ export async function analyse(settings) {
|
|
|
191
192
|
const story = new Story();
|
|
192
193
|
const cache = settings.parseCache ?? new ParseCache();
|
|
193
194
|
const files = [];
|
|
195
|
+
// Each file's text, in the same order as files
|
|
196
|
+
const texts = [];
|
|
194
197
|
const diagnostics = [];
|
|
195
198
|
const legacyErrors = [];
|
|
196
199
|
const legacyWarnings = [];
|
|
@@ -212,9 +215,16 @@ export async function analyse(settings) {
|
|
|
212
215
|
async function processFile(text, filename, isFirst) {
|
|
213
216
|
const file = cache.parse(text, filename);
|
|
214
217
|
files.push(file);
|
|
218
|
+
texts.push(text);
|
|
215
219
|
processed.add(filename);
|
|
216
220
|
const lines = text.replace(/\r/g, "").split("\n");
|
|
217
221
|
warnAboutV5Syntax(text, lines, filename);
|
|
222
|
+
if (settings.expressions) {
|
|
223
|
+
for (const found of findAtAttributes(file)) {
|
|
224
|
+
const name = found.text.substring(1);
|
|
225
|
+
report("warning", "squiffy/at-attribute", filename, found.range, `Use ${name} rather than ${found.text}: in a story with a ${PROJECT_FILENAME}, setters name attributes without "@".`, found.range.start.line + 1);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
218
228
|
let section = null;
|
|
219
229
|
let passage = null;
|
|
220
230
|
let inUiBlock = false;
|
|
@@ -460,6 +470,21 @@ export async function analyse(settings) {
|
|
|
460
470
|
function warnExternalFilesUnavailable(line, node, filename) {
|
|
461
471
|
report("warning", "squiffy/external-files-unavailable", filename, lineRange(node), `"${line}" was ignored, as other files can't be loaded here`, node.range.start.line + 1);
|
|
462
472
|
}
|
|
473
|
+
// Text in a setter without quotes, as in Squiffy 6 (#373). A single word is only reported if no
|
|
474
|
+
// attribute of that name is set anywhere in the story, so this needs every file first.
|
|
475
|
+
function warnAboutUnquotedText() {
|
|
476
|
+
const set = new Set();
|
|
477
|
+
files.forEach((file, i) => attributesSetIn(file, texts[i]).forEach(name => set.add(name)));
|
|
478
|
+
for (const file of files) {
|
|
479
|
+
for (const found of findUnquotedText(file, name => set.has(name))) {
|
|
480
|
+
const quoted = found.quoted ?? `"${found.text}"`;
|
|
481
|
+
const message = found.kind == "word"
|
|
482
|
+
? `${found.text} isn't set anywhere in the story, so this sets ${found.attribute} to nothing. For the text ${quoted}, use quotes.`
|
|
483
|
+
: `Text in a setter goes in quotes in a story with a ${PROJECT_FILENAME}: ${quoted}.`;
|
|
484
|
+
report("warning", "squiffy/unquoted-text", file.filename, found.range, message, found.range.start.line + 1);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
463
488
|
function warnAboutV5Syntax(text, lines, filename) {
|
|
464
489
|
const truncate = (s) => s.length > 60 ? s.substring(0, 57) + "..." : s;
|
|
465
490
|
for (const match of findV5Syntax(text)) {
|
|
@@ -487,7 +512,7 @@ export async function analyse(settings) {
|
|
|
487
512
|
const getNextSectionName = () => {
|
|
488
513
|
return sectionNames[(sectionIndexes.get(section.name) ?? -1) + 1] || null;
|
|
489
514
|
};
|
|
490
|
-
const result = transformText(container.text.join("\n"), getNextSectionName);
|
|
515
|
+
const result = transformText(container.text.join("\n"), getNextSectionName, settings.expressions);
|
|
491
516
|
container.output = result.output;
|
|
492
517
|
const toPosition = positionMapper(container.textSources, container.text.map(t => t.length));
|
|
493
518
|
const toRange = (start, end) => ({ start: toPosition(start), end: toPosition(end) });
|
|
@@ -520,6 +545,13 @@ export async function analyse(settings) {
|
|
|
520
545
|
warn("squiffy/unknown-embed", embed.start, embed.end, `${where} there is an embed of {{embed "${embed.name}"}}, but no section or passage with that name exists`);
|
|
521
546
|
}
|
|
522
547
|
}
|
|
548
|
+
// {{goto}} only goes to sections
|
|
549
|
+
for (const goto of result.gotos) {
|
|
550
|
+
if (!goto.name || !(goto.name in story.sections)) {
|
|
551
|
+
const passage = goto.name in section.passages ? ` ({{goto}} can't go to a passage: use {{embed "${goto.name}"}} to show it here)` : "";
|
|
552
|
+
warn("squiffy/unknown-goto", goto.start, goto.end, `${where} there is a {{goto "${goto.name}"}}, but no section with that name exists${passage}`);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
523
555
|
}
|
|
524
556
|
// With recover, processFile carries on after errors, so check for them too
|
|
525
557
|
let success = await processFile(settings.script, settings.scriptBaseFilename, true);
|
|
@@ -553,6 +585,15 @@ export async function analyse(settings) {
|
|
|
553
585
|
}
|
|
554
586
|
}
|
|
555
587
|
}
|
|
588
|
+
if (settings.expressions) {
|
|
589
|
+
warnAboutUnquotedText();
|
|
590
|
+
}
|
|
591
|
+
// A story setting an attribute that Squiffy sets itself, such as turns (#377)
|
|
592
|
+
files.forEach((file, i) => {
|
|
593
|
+
for (const found of findBuiltInAttributeSets(file, texts[i])) {
|
|
594
|
+
report("warning", "squiffy/built-in-attribute", file.filename, found.range, `Squiffy sets ${found.name} itself: it's ${BUILT_IN_ATTRIBUTES.get(found.name)}. Use a different name for your own attribute.`, found.range.start.line + 1);
|
|
595
|
+
}
|
|
596
|
+
});
|
|
556
597
|
const analysis = {
|
|
557
598
|
success,
|
|
558
599
|
files,
|
|
@@ -564,6 +605,7 @@ export async function analyse(settings) {
|
|
|
564
605
|
passages: Object.values(section.passages).map(passage => ({ name: passage.name, node: passage.node })),
|
|
565
606
|
})),
|
|
566
607
|
start: story.start,
|
|
608
|
+
expressions: settings.expressions ?? false,
|
|
567
609
|
};
|
|
568
610
|
analysisInternals.set(analysis, { story, legacyErrors, legacyWarnings });
|
|
569
611
|
return analysis;
|
package/dist/compiler.d.ts
CHANGED
|
@@ -3,6 +3,12 @@ import { CompileSuccess } from "./emit.js";
|
|
|
3
3
|
import type { Diagnostic } from "./syntax.js";
|
|
4
4
|
export { findV5Syntax, convertV5Syntax } from "./v5.js";
|
|
5
5
|
export type { V5SyntaxMatch, V5ConversionProblem, V5ConversionResult } from "./v5.js";
|
|
6
|
+
export { convertSetters, convertSetter } from "./setters.js";
|
|
7
|
+
export { convertTwine, convertTwineStory, formatTwineProblems } from "./twine/convert.js";
|
|
8
|
+
export type { TwineConversionResult, TwineConversionProblem, TwineConversionOptions } from "./twine/convert.js";
|
|
9
|
+
export { parseTwine, isTwineSource, TwineParseError } from "./twine/story.js";
|
|
10
|
+
export type { TwineStory, TwinePassage } from "./twine/story.js";
|
|
11
|
+
export type { SetterConversion, SetterConversionProblem, SetterConversionResult } from "./setters.js";
|
|
6
12
|
export { parse } from "./parse.js";
|
|
7
13
|
export { analyse, ParseCache } from "./analyse.js";
|
|
8
14
|
export type { AnalyseSettings, Analysis, ExternalFiles, SectionSymbol, PassageSymbol } from "./analyse.js";
|
|
@@ -20,6 +26,7 @@ interface CompilerSettings {
|
|
|
20
26
|
globalJs?: boolean;
|
|
21
27
|
parseCache?: ParseCache;
|
|
22
28
|
storyFiles?: string[];
|
|
29
|
+
expressions?: boolean;
|
|
23
30
|
}
|
|
24
31
|
export interface CompileError {
|
|
25
32
|
success: false;
|
package/dist/compiler.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { analyse, analysisInternals } from "./analyse.js";
|
|
2
2
|
import { emit } from "./emit.js";
|
|
3
3
|
export { findV5Syntax, convertV5Syntax } from "./v5.js";
|
|
4
|
+
export { convertSetters, convertSetter } from "./setters.js";
|
|
5
|
+
export { convertTwine, convertTwineStory, formatTwineProblems } from "./twine/convert.js";
|
|
6
|
+
export { parseTwine, isTwineSource, TwineParseError } from "./twine/story.js";
|
|
4
7
|
// The compiler works in three stages, which can also be used separately:
|
|
5
8
|
// - parse() turns one file into a syntax tree, with a source range on every node
|
|
6
9
|
// - analyse() resolves @imports, builds the story's sections and passages, and reports diagnostics
|
package/dist/emit.d.ts
CHANGED
package/dist/emit.js
CHANGED
|
@@ -19,6 +19,9 @@ export function emit(analysis, settings = {}) {
|
|
|
19
19
|
},
|
|
20
20
|
js: [],
|
|
21
21
|
};
|
|
22
|
+
if (analysis.expressions) {
|
|
23
|
+
output.story.expressions = true;
|
|
24
|
+
}
|
|
22
25
|
if (story.uiJs.length > 0) {
|
|
23
26
|
output.js.push(story.uiJs);
|
|
24
27
|
output.story.uiJsIndex = output.js.length - 1;
|
|
@@ -83,6 +86,9 @@ export function emit(analysis, settings = {}) {
|
|
|
83
86
|
if (output.story.uiJsIndex !== undefined) {
|
|
84
87
|
outputJs.push(`story.uiJsIndex = ${output.story.uiJsIndex};`);
|
|
85
88
|
}
|
|
89
|
+
if (output.story.expressions) {
|
|
90
|
+
outputJs.push("story.expressions = true;");
|
|
91
|
+
}
|
|
86
92
|
outputJs.push(`story.start = ${JSON.stringify(output.story.start, null, 4)};`);
|
|
87
93
|
outputJs.push(`story.sections = ${JSON.stringify(output.story.sections, null, 4)};`);
|
|
88
94
|
outputJs.push("story.js = [");
|
package/dist/language-service.js
CHANGED
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
import { analyse, ParseCache } from "./analyse.js";
|
|
9
9
|
import { getStoryFiles, globToRegExp, parseProjectFile, PROJECT_FILENAME } from "./project.js";
|
|
10
10
|
import { convertV5Syntax, findV5Syntax } from "./v5.js";
|
|
11
|
+
import { findUnquotedText } from "./setters.js";
|
|
11
12
|
import { buildStoryGraph, storyGraphDiagnostics } from "./story-graph.js";
|
|
12
13
|
const sameSymbol = (a, b) => a.kind == b.kind && a.name == b.name && (a.kind == "section" || a.section == b.section);
|
|
14
|
+
const usageRange = (usage) => (usage.link ?? usage.embed ?? usage.goto).range;
|
|
13
15
|
// Directives, for completion, with what they do
|
|
14
16
|
const DIRECTIVES = [
|
|
15
17
|
["title", "Sets the story's title"],
|
|
@@ -175,6 +177,7 @@ export function createLanguageService(options) {
|
|
|
175
177
|
parseCache,
|
|
176
178
|
recover: true,
|
|
177
179
|
...(project.projectFile ? { storyFiles: project.storyFiles } : {}),
|
|
180
|
+
expressions: !!project.projectFile,
|
|
178
181
|
});
|
|
179
182
|
if (project.error) {
|
|
180
183
|
// A broken squiffy.json stops the story building, as it does in the CLI
|
|
@@ -232,6 +235,9 @@ export function createLanguageService(options) {
|
|
|
232
235
|
for (const embed of container.embeds) {
|
|
233
236
|
index.usages.push({ file: path, container, sectionNode: node, embed });
|
|
234
237
|
}
|
|
238
|
+
for (const goto of container.gotos) {
|
|
239
|
+
index.usages.push({ file: path, container, sectionNode: node, goto });
|
|
240
|
+
}
|
|
235
241
|
for (const statement of container.body) {
|
|
236
242
|
if (statement.type == "attribute") {
|
|
237
243
|
const name = attributeName(statement.value);
|
|
@@ -302,6 +308,10 @@ export function createLanguageService(options) {
|
|
|
302
308
|
return { kind: "section", name };
|
|
303
309
|
return undefined;
|
|
304
310
|
}
|
|
311
|
+
if (usage.goto) {
|
|
312
|
+
const name = usage.goto.name;
|
|
313
|
+
return name && index.sections.has(name) ? { kind: "section", name } : undefined;
|
|
314
|
+
}
|
|
305
315
|
const link = usage.link;
|
|
306
316
|
if (link.linkType == "section") {
|
|
307
317
|
if (link.form == "next") {
|
|
@@ -334,12 +344,12 @@ export function createLanguageService(options) {
|
|
|
334
344
|
return undefined;
|
|
335
345
|
return { file: section.file, range: passage.nameRange };
|
|
336
346
|
}
|
|
337
|
-
// What's at a position: a link, an embed, or the name in a section or passage header.
|
|
347
|
+
// What's at a position: a link, an embed, a goto, or the name in a section or passage header.
|
|
338
348
|
async function symbolAt(index, path, position) {
|
|
339
349
|
for (const usage of index.usages) {
|
|
340
350
|
if (usage.file != path)
|
|
341
351
|
continue;
|
|
342
|
-
const range = usage
|
|
352
|
+
const range = usageRange(usage);
|
|
343
353
|
if (!contains(range, position))
|
|
344
354
|
continue;
|
|
345
355
|
const symbol = resolveUsage(index, usage);
|
|
@@ -373,6 +383,8 @@ export function createLanguageService(options) {
|
|
|
373
383
|
function nameRangeInLink(index, usage, name) {
|
|
374
384
|
if (usage.embed)
|
|
375
385
|
return usage.embed.nameRange;
|
|
386
|
+
if (usage.goto)
|
|
387
|
+
return usage.goto.nameRange;
|
|
376
388
|
const link = usage.link;
|
|
377
389
|
if (link.form == "next")
|
|
378
390
|
return undefined;
|
|
@@ -396,7 +408,7 @@ export function createLanguageService(options) {
|
|
|
396
408
|
for (const usage of index.usages) {
|
|
397
409
|
const target = resolveUsage(index, usage);
|
|
398
410
|
if (target && sameSymbol(target, symbol)) {
|
|
399
|
-
result.push({ file: usage.file, range: usage
|
|
411
|
+
result.push({ file: usage.file, range: usageRange(usage) });
|
|
400
412
|
}
|
|
401
413
|
}
|
|
402
414
|
return result;
|
|
@@ -570,6 +582,13 @@ export function createLanguageService(options) {
|
|
|
570
582
|
if ((match = /\{\{~?\s*embed\s+["']([^"']*)$/.exec(prefix))) {
|
|
571
583
|
return [...passageItems(match[1]), ...sectionItems(match[1])];
|
|
572
584
|
}
|
|
585
|
+
// {{seen "name"}}, (visits "name") etc., which take a section or passage (#377)
|
|
586
|
+
if ((match = /(?:\{\{~?|\()\s*(?:seen|visits)\s+["']([^"']*)$/.exec(prefix))) {
|
|
587
|
+
return [...passageItems(match[1]), ...sectionItems(match[1])];
|
|
588
|
+
}
|
|
589
|
+
if ((match = /\{\{~?\s*goto\s+["']([^"']*)$/.exec(prefix))) {
|
|
590
|
+
return sectionItems(match[1]);
|
|
591
|
+
}
|
|
573
592
|
if ((match = /\[\[[^\]]*\]\]\(([^),]*)$/.exec(prefix))) {
|
|
574
593
|
return sectionItems(match[1]);
|
|
575
594
|
}
|
|
@@ -676,6 +695,23 @@ export function createLanguageService(options) {
|
|
|
676
695
|
actions.push({ title: `Create passage '${name}'`, kind: "quickfix", diagnostic, edit });
|
|
677
696
|
}
|
|
678
697
|
}
|
|
698
|
+
else if (diagnostic.code == "squiffy/at-attribute") {
|
|
699
|
+
const start = diagnostic.range.start;
|
|
700
|
+
const name = lines[start.line].substring(start.character + 1, diagnostic.range.end.character);
|
|
701
|
+
const edit = {};
|
|
702
|
+
addEdit(edit, path, { range: { start, end: { line: start.line, character: start.character + 1 } }, newText: "" });
|
|
703
|
+
actions.push({ title: `Change to ${name}`, kind: "quickfix", diagnostic, edit });
|
|
704
|
+
}
|
|
705
|
+
else if (diagnostic.code == "squiffy/unquoted-text") {
|
|
706
|
+
const start = diagnostic.range.start;
|
|
707
|
+
const found = findUnquotedText(tree.file, () => false)
|
|
708
|
+
.find(u => comparePositions(u.range.start, start) == 0);
|
|
709
|
+
if (!found?.quoted)
|
|
710
|
+
continue;
|
|
711
|
+
const edit = {};
|
|
712
|
+
addEdit(edit, path, { range: found.range, newText: found.quoted });
|
|
713
|
+
actions.push({ title: `Change to ${found.quoted}`, kind: "quickfix", diagnostic, edit });
|
|
714
|
+
}
|
|
679
715
|
else if (diagnostic.code == "squiffy/v5-syntax") {
|
|
680
716
|
const line = diagnostic.range.start.line;
|
|
681
717
|
const match = v5.find(m => m.line == line + 1
|
package/dist/node.d.ts
CHANGED
package/dist/node.js
CHANGED
|
@@ -70,7 +70,10 @@ async function folderStory(projectFile, options) {
|
|
|
70
70
|
throw new StoryNotFoundError(`The main file in ${projectFile}, ${project.main}, doesn't exist.`);
|
|
71
71
|
}
|
|
72
72
|
const story = getStoryFiles(project, await listSquiffyFiles(root), options.skip);
|
|
73
|
-
return {
|
|
73
|
+
return {
|
|
74
|
+
mainFile, storyFiles: story.included.map(file => path.resolve(root, file)), projectFile, expressions: true,
|
|
75
|
+
...(project.backButton !== undefined ? { backButton: project.backButton } : {}),
|
|
76
|
+
};
|
|
74
77
|
}
|
|
75
78
|
// Finds the story to build from what the author gave: a folder with a squiffy.json in it, or a
|
|
76
79
|
// .squiffy file.
|
|
@@ -93,7 +96,7 @@ export async function findStory(input, options = {}) {
|
|
|
93
96
|
}
|
|
94
97
|
const projectFile = await findProjectFile(path.dirname(resolved));
|
|
95
98
|
if (!projectFile)
|
|
96
|
-
return { mainFile: resolved };
|
|
99
|
+
return { mainFile: resolved, expressions: false };
|
|
97
100
|
const project = await readProject(projectFile);
|
|
98
101
|
if (path.resolve(path.dirname(projectFile), project.main) == resolved) {
|
|
99
102
|
return folderStory(projectFile, options);
|
|
@@ -101,5 +104,6 @@ export async function findStory(input, options = {}) {
|
|
|
101
104
|
return {
|
|
102
105
|
mainFile: resolved,
|
|
103
106
|
note: `Building just ${path.basename(resolved)}, as it isn't the main file in ${projectFile} (${project.main}).`,
|
|
107
|
+
expressions: true,
|
|
104
108
|
};
|
|
105
109
|
}
|
package/dist/parse.js
CHANGED
|
@@ -123,6 +123,7 @@ export function parse(text, filename) {
|
|
|
123
123
|
body: [],
|
|
124
124
|
links: [],
|
|
125
125
|
embeds: [],
|
|
126
|
+
gotos: [],
|
|
126
127
|
};
|
|
127
128
|
section.passages.push(passage);
|
|
128
129
|
textStarted = false;
|
|
@@ -232,9 +233,9 @@ export function parse(text, filename) {
|
|
|
232
233
|
return file;
|
|
233
234
|
}
|
|
234
235
|
function newSection(kind, range) {
|
|
235
|
-
return { type: "section", kind, range, body: [], passages: [], links: [], embeds: [] };
|
|
236
|
+
return { type: "section", kind, range, body: [], passages: [], links: [], embeds: [], gotos: [] };
|
|
236
237
|
}
|
|
237
|
-
// Fills in the links and
|
|
238
|
+
// Fills in the links, embeds and gotos in a section's or passage's text.
|
|
238
239
|
function findLinks(node, lines) {
|
|
239
240
|
const textNodes = node.body.filter((n) => n.type == "text");
|
|
240
241
|
if (!textNodes.length)
|
|
@@ -243,8 +244,10 @@ function findLinks(node, lines) {
|
|
|
243
244
|
const toPosition = positionMapper(sources, textNodes.map(n => n.text.length));
|
|
244
245
|
const toRange = (start, end) => ({ start: toPosition(start), end: toPosition(end) });
|
|
245
246
|
// Which section comes next isn't known until the story is analysed, but all that matters
|
|
246
|
-
// here is that there is one, so that [[text>]] is treated as a link.
|
|
247
|
-
|
|
247
|
+
// here is that there is one, so that [[text>]] is treated as a link. Link
|
|
248
|
+
// targets can have brackets in them, as in a story with a squiffy.json, whether or not this
|
|
249
|
+
// one has one: the two only differ when a target has a "(" in it.
|
|
250
|
+
const result = transformText(textNodes.map(n => n.text).join("\n"), () => "", true);
|
|
248
251
|
node.links = result.links.map((link) => ({
|
|
249
252
|
type: "link",
|
|
250
253
|
linkType: link.linkType,
|
|
@@ -260,4 +263,10 @@ function findLinks(node, lines) {
|
|
|
260
263
|
range: toRange(embed.start, embed.end),
|
|
261
264
|
nameRange: toRange(embed.nameStart, embed.nameEnd),
|
|
262
265
|
}));
|
|
266
|
+
node.gotos = result.gotos.map((goto) => ({
|
|
267
|
+
type: "goto",
|
|
268
|
+
name: goto.name,
|
|
269
|
+
range: toRange(goto.start, goto.end),
|
|
270
|
+
nameRange: toRange(goto.nameStart, goto.nameEnd),
|
|
271
|
+
}));
|
|
263
272
|
}
|
package/dist/project.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface ProjectFile {
|
|
|
6
6
|
main: string;
|
|
7
7
|
exclude: string[];
|
|
8
8
|
map?: MapPositions;
|
|
9
|
+
backButton?: boolean;
|
|
9
10
|
}
|
|
10
11
|
export interface MapPositions {
|
|
11
12
|
sections: Record<string, [number, number]>;
|
|
@@ -32,6 +33,7 @@ export declare function getStoryFiles(project: ProjectFile, paths: Iterable<stri
|
|
|
32
33
|
export declare function formatProjectFile(project: {
|
|
33
34
|
main: string;
|
|
34
35
|
exclude?: string[];
|
|
36
|
+
map?: MapPositions;
|
|
35
37
|
}): string;
|
|
36
38
|
export declare function updateProjectFile(text: string, changes: {
|
|
37
39
|
main?: string;
|
package/dist/project.js
CHANGED
|
@@ -54,8 +54,19 @@ export function parseProjectFile(text) {
|
|
|
54
54
|
if (!Array.isArray(exclude) || exclude.some(pattern => typeof pattern != "string")) {
|
|
55
55
|
return fail(`${PROJECT_FILENAME}'s "exclude" should be a list of file patterns, such as ["drafts/**"].`);
|
|
56
56
|
}
|
|
57
|
+
const backButton = data.backButton;
|
|
58
|
+
if (backButton !== undefined && typeof backButton != "boolean") {
|
|
59
|
+
return fail(`${PROJECT_FILENAME}'s "backButton" should be true or false.`);
|
|
60
|
+
}
|
|
57
61
|
const map = parseMapPositions(data.map);
|
|
58
|
-
return {
|
|
62
|
+
return {
|
|
63
|
+
success: true,
|
|
64
|
+
project: {
|
|
65
|
+
version, main: mainPath, exclude: exclude,
|
|
66
|
+
...(map ? { map } : {}),
|
|
67
|
+
...(backButton !== undefined ? { backButton } : {}),
|
|
68
|
+
},
|
|
69
|
+
};
|
|
59
70
|
}
|
|
60
71
|
const isPosition = (value) => Array.isArray(value) && value.length == 2 && value.every(n => typeof n == "number" && Number.isFinite(n));
|
|
61
72
|
const isObject = (value) => !!value && typeof value == "object" && !Array.isArray(value);
|
|
@@ -177,7 +188,8 @@ export function formatProjectFile(project) {
|
|
|
177
188
|
};
|
|
178
189
|
if (project.exclude?.length)
|
|
179
190
|
json.exclude = project.exclude;
|
|
180
|
-
|
|
191
|
+
const text = JSON.stringify(json, null, 2) + "\n";
|
|
192
|
+
return project.map ? updateProjectFile(text, { map: project.map }) : text;
|
|
181
193
|
}
|
|
182
194
|
// Changes a project file's text, keeping any other properties it has. Returns undefined if the
|
|
183
195
|
// text isn't a JSON object. A `map` with no positions removes it.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Range, SquiffyFile } from "./syntax.js";
|
|
2
|
+
export interface SetterConversionProblem {
|
|
3
|
+
line: number;
|
|
4
|
+
text: string;
|
|
5
|
+
reason: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SetterConversionResult {
|
|
8
|
+
script: string;
|
|
9
|
+
converted: number;
|
|
10
|
+
problems: SetterConversionProblem[];
|
|
11
|
+
}
|
|
12
|
+
export type SetterConversion = {
|
|
13
|
+
text: string;
|
|
14
|
+
} | {
|
|
15
|
+
problem: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function convertSetter(setter: string, options?: {
|
|
18
|
+
preferSingleQuotes?: boolean;
|
|
19
|
+
}): SetterConversion;
|
|
20
|
+
export declare function convertSetters(script: string): SetterConversionResult;
|
|
21
|
+
export interface AtAttribute {
|
|
22
|
+
text: string;
|
|
23
|
+
range: Range;
|
|
24
|
+
}
|
|
25
|
+
export declare function findAtAttributes(file: SquiffyFile): AtAttribute[];
|
|
26
|
+
export declare function attributesSetIn(file: SquiffyFile, text: string): Set<string>;
|
|
27
|
+
export interface UnquotedText {
|
|
28
|
+
text: string;
|
|
29
|
+
range: Range;
|
|
30
|
+
attribute: string;
|
|
31
|
+
kind: "word" | "words";
|
|
32
|
+
quoted: string | null;
|
|
33
|
+
}
|
|
34
|
+
export declare function findUnquotedText(file: SquiffyFile, isSet: (name: string) => boolean): UnquotedText[];
|
|
35
|
+
export declare const BUILT_IN_ATTRIBUTES: ReadonlyMap<string, string>;
|
|
36
|
+
export interface BuiltInAttributeSet {
|
|
37
|
+
name: string;
|
|
38
|
+
range: Range;
|
|
39
|
+
}
|
|
40
|
+
export declare function findBuiltInAttributeSets(file: SquiffyFile, text: string): BuiltInAttributeSet[];
|