squiffy-compiler 6.0.1 → 7.0.0-beta.2
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 +79 -0
- package/dist/analyse.js +590 -0
- package/dist/compiler.d.ts +15 -40
- package/dist/compiler.js +19 -691
- package/dist/emit.d.ts +43 -0
- package/dist/emit.js +114 -0
- package/dist/language-service.d.ts +89 -0
- package/dist/language-service.js +748 -0
- package/dist/node.d.ts +13 -0
- package/dist/node.js +105 -0
- package/dist/parse.d.ts +17 -0
- package/dist/parse.js +263 -0
- package/dist/project.d.ts +40 -0
- package/dist/project.js +222 -0
- package/dist/story-graph.d.ts +64 -0
- package/dist/story-graph.js +359 -0
- package/dist/syntax.d.ts +150 -0
- package/dist/syntax.js +8 -0
- package/dist/text.d.ts +37 -0
- package/dist/text.js +288 -0
- package/package.json +24 -6
- package/syntaxes/squiffy.tmLanguage.json +972 -0
package/dist/emit.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Analysis } from "./analyse.js";
|
|
2
|
+
import type { Diagnostic } from "./syntax.js";
|
|
3
|
+
export interface Output {
|
|
4
|
+
story: OutputStory;
|
|
5
|
+
js: string[][];
|
|
6
|
+
}
|
|
7
|
+
interface OutputStory {
|
|
8
|
+
start: string;
|
|
9
|
+
id: string | null;
|
|
10
|
+
uiJsIndex?: number;
|
|
11
|
+
sections: Record<string, OutputSection>;
|
|
12
|
+
}
|
|
13
|
+
interface OutputSection {
|
|
14
|
+
text?: string;
|
|
15
|
+
clear?: boolean;
|
|
16
|
+
attributes?: string[];
|
|
17
|
+
jsIndex?: number;
|
|
18
|
+
passages?: Record<string, OutputPassage>;
|
|
19
|
+
passageCount?: number;
|
|
20
|
+
}
|
|
21
|
+
interface OutputPassage {
|
|
22
|
+
text?: string;
|
|
23
|
+
clear?: boolean;
|
|
24
|
+
attributes?: string[];
|
|
25
|
+
jsIndex?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface UiInfo {
|
|
28
|
+
title: string;
|
|
29
|
+
externalScripts: string[];
|
|
30
|
+
externalStylesheets: string[];
|
|
31
|
+
}
|
|
32
|
+
export interface EmitSettings {
|
|
33
|
+
globalJs?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface CompileSuccess {
|
|
36
|
+
success: true;
|
|
37
|
+
output: Output;
|
|
38
|
+
getJs: (excludeHeader?: boolean) => Promise<string>;
|
|
39
|
+
getUiInfo: () => UiInfo;
|
|
40
|
+
diagnostics: Diagnostic[];
|
|
41
|
+
}
|
|
42
|
+
export declare function emit(analysis: Analysis, settings?: EmitSettings): CompileSuccess;
|
|
43
|
+
export {};
|
package/dist/emit.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import pkg from "../package.json" with { type: "json" };
|
|
2
|
+
import { analysisInternals } from "./analyse.js";
|
|
3
|
+
const version = pkg.version;
|
|
4
|
+
// Produces the story data and JavaScript for an analysis that succeeded.
|
|
5
|
+
export function emit(analysis, settings = {}) {
|
|
6
|
+
const internals = analysisInternals.get(analysis);
|
|
7
|
+
if (!internals) {
|
|
8
|
+
throw new Error("emit() needs the result of analyse()");
|
|
9
|
+
}
|
|
10
|
+
if (!analysis.success) {
|
|
11
|
+
throw new Error("Can't emit a story whose analysis has errors");
|
|
12
|
+
}
|
|
13
|
+
const story = internals.story;
|
|
14
|
+
const output = {
|
|
15
|
+
story: {
|
|
16
|
+
start: story.start,
|
|
17
|
+
id: story.id,
|
|
18
|
+
sections: {},
|
|
19
|
+
},
|
|
20
|
+
js: [],
|
|
21
|
+
};
|
|
22
|
+
if (story.uiJs.length > 0) {
|
|
23
|
+
output.js.push(story.uiJs);
|
|
24
|
+
output.story.uiJsIndex = output.js.length - 1;
|
|
25
|
+
}
|
|
26
|
+
for (const sectionName of Object.keys(story.sections)) {
|
|
27
|
+
const section = story.sections[sectionName];
|
|
28
|
+
const outputSection = {};
|
|
29
|
+
output.story.sections[sectionName] = outputSection;
|
|
30
|
+
if (section.clear) {
|
|
31
|
+
outputSection.clear = true;
|
|
32
|
+
}
|
|
33
|
+
outputSection.text = section.output;
|
|
34
|
+
if (section.attributes.length > 0) {
|
|
35
|
+
outputSection.attributes = section.attributes;
|
|
36
|
+
}
|
|
37
|
+
if (section.js.length > 0) {
|
|
38
|
+
output.js.push(section.js);
|
|
39
|
+
outputSection.jsIndex = output.js.length - 1;
|
|
40
|
+
}
|
|
41
|
+
if ("@last" in section.passages) {
|
|
42
|
+
let passageCount = 0;
|
|
43
|
+
for (const passageName of Object.keys(section.passages)) {
|
|
44
|
+
if (passageName.length > 0 && passageName?.substring(0, 1) !== "@") {
|
|
45
|
+
passageCount++;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
outputSection.passageCount = passageCount;
|
|
49
|
+
}
|
|
50
|
+
if (Object.keys(section.passages).length == 0)
|
|
51
|
+
continue;
|
|
52
|
+
outputSection.passages = {};
|
|
53
|
+
for (const passageName of Object.keys(section.passages)) {
|
|
54
|
+
const passage = section.passages[passageName];
|
|
55
|
+
const outputPassage = {};
|
|
56
|
+
outputSection.passages[passageName] = outputPassage;
|
|
57
|
+
if (passage.clear) {
|
|
58
|
+
outputPassage.clear = true;
|
|
59
|
+
}
|
|
60
|
+
outputPassage.text = passage.output;
|
|
61
|
+
if (passage.attributes.length > 0) {
|
|
62
|
+
outputPassage.attributes = passage.attributes;
|
|
63
|
+
}
|
|
64
|
+
if (passage.js.length > 0) {
|
|
65
|
+
output.js.push(passage.js);
|
|
66
|
+
outputPassage.jsIndex = output.js.length - 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const getJs = async (excludeHeader) => {
|
|
71
|
+
const outputJs = [];
|
|
72
|
+
if (!excludeHeader) {
|
|
73
|
+
outputJs.push(`// Created with Squiffy ${version}`);
|
|
74
|
+
outputJs.push("// https://github.com/textadventures/squiffy");
|
|
75
|
+
}
|
|
76
|
+
if (settings.globalJs) {
|
|
77
|
+
outputJs.push("var story = {};");
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
outputJs.push("export const story = {};");
|
|
81
|
+
}
|
|
82
|
+
outputJs.push(`story.id = ${JSON.stringify(output.story.id, null, 4)};`);
|
|
83
|
+
if (output.story.uiJsIndex !== undefined) {
|
|
84
|
+
outputJs.push(`story.uiJsIndex = ${output.story.uiJsIndex};`);
|
|
85
|
+
}
|
|
86
|
+
outputJs.push(`story.start = ${JSON.stringify(output.story.start, null, 4)};`);
|
|
87
|
+
outputJs.push(`story.sections = ${JSON.stringify(output.story.sections, null, 4)};`);
|
|
88
|
+
outputJs.push("story.js = [");
|
|
89
|
+
for (const js of output.js) {
|
|
90
|
+
writeJs(outputJs, 1, js);
|
|
91
|
+
}
|
|
92
|
+
outputJs.push("];");
|
|
93
|
+
return outputJs.join("\n");
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
success: true,
|
|
97
|
+
output,
|
|
98
|
+
getJs: (excludeHeader) => getJs(excludeHeader || false),
|
|
99
|
+
getUiInfo: () => ({
|
|
100
|
+
title: story.title,
|
|
101
|
+
externalScripts: story.scripts,
|
|
102
|
+
externalStylesheets: story.stylesheets,
|
|
103
|
+
}),
|
|
104
|
+
diagnostics: analysis.diagnostics,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function writeJs(outputJsFile, tabCount, js) {
|
|
108
|
+
const tabs = new Array(tabCount + 1).join("\t");
|
|
109
|
+
outputJsFile.push(`${tabs}(squiffy, get, set) => {`);
|
|
110
|
+
for (const jsLine of js) {
|
|
111
|
+
outputJsFile.push(`${tabs}\t${jsLine}`);
|
|
112
|
+
}
|
|
113
|
+
outputJsFile.push(`${tabs}},`);
|
|
114
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Analysis } from "./analyse.js";
|
|
2
|
+
import type { Diagnostic, Position, Range } from "./syntax.js";
|
|
3
|
+
import { ProjectFile } from "./project.js";
|
|
4
|
+
import { StoryGraph } from "./story-graph.js";
|
|
5
|
+
export type { Diagnostic, Position, Range } from "./syntax.js";
|
|
6
|
+
export type { GraphEdge, GraphEdgeKind, GraphNode, StoryGraph } from "./story-graph.js";
|
|
7
|
+
export interface ProjectFiles {
|
|
8
|
+
list(): Promise<{
|
|
9
|
+
path: string;
|
|
10
|
+
}[]>;
|
|
11
|
+
readText(path: string): Promise<string>;
|
|
12
|
+
}
|
|
13
|
+
export interface LanguageServiceOptions {
|
|
14
|
+
files: ProjectFiles;
|
|
15
|
+
mainFile: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ProjectInfo {
|
|
18
|
+
projectFile?: ProjectFile;
|
|
19
|
+
error?: string;
|
|
20
|
+
mainFile: string;
|
|
21
|
+
storyFiles: string[];
|
|
22
|
+
excludedFiles: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface TextEdit {
|
|
25
|
+
range: Range;
|
|
26
|
+
newText: string;
|
|
27
|
+
}
|
|
28
|
+
export type WorkspaceEdit = Record<string, TextEdit[]>;
|
|
29
|
+
export interface Location {
|
|
30
|
+
file: string;
|
|
31
|
+
range: Range;
|
|
32
|
+
}
|
|
33
|
+
export interface DocumentSymbol {
|
|
34
|
+
name: string;
|
|
35
|
+
kind: "title" | "section" | "passage" | "snippet";
|
|
36
|
+
detail?: string;
|
|
37
|
+
range: Range;
|
|
38
|
+
selectionRange: Range;
|
|
39
|
+
children: DocumentSymbol[];
|
|
40
|
+
}
|
|
41
|
+
export interface CompletionItem {
|
|
42
|
+
label: string;
|
|
43
|
+
kind: "section" | "passage" | "attribute" | "snippet" | "directive";
|
|
44
|
+
insertText?: string;
|
|
45
|
+
detail?: string;
|
|
46
|
+
range: Range;
|
|
47
|
+
}
|
|
48
|
+
export interface Hover {
|
|
49
|
+
contents: string;
|
|
50
|
+
range: Range;
|
|
51
|
+
}
|
|
52
|
+
export interface FoldingRange {
|
|
53
|
+
startLine: number;
|
|
54
|
+
endLine: number;
|
|
55
|
+
}
|
|
56
|
+
export interface CodeAction {
|
|
57
|
+
title: string;
|
|
58
|
+
kind: "quickfix";
|
|
59
|
+
diagnostic?: Diagnostic;
|
|
60
|
+
edit: WorkspaceEdit;
|
|
61
|
+
}
|
|
62
|
+
export interface SectionAt {
|
|
63
|
+
section: string;
|
|
64
|
+
passage?: string;
|
|
65
|
+
}
|
|
66
|
+
export type RenameResult = {
|
|
67
|
+
edit: WorkspaceEdit;
|
|
68
|
+
} | {
|
|
69
|
+
error: string;
|
|
70
|
+
};
|
|
71
|
+
export interface LanguageService {
|
|
72
|
+
updateFile(path: string, text: string | undefined): void;
|
|
73
|
+
fileChanged(path: string): void;
|
|
74
|
+
setMainFile(path: string): void;
|
|
75
|
+
getProjectInfo(): Promise<ProjectInfo>;
|
|
76
|
+
getAnalysis(): Promise<Analysis>;
|
|
77
|
+
getDiagnostics(path: string): Promise<Diagnostic[]>;
|
|
78
|
+
getDocumentSymbols(path: string): Promise<DocumentSymbol[]>;
|
|
79
|
+
getDefinition(path: string, position: Position): Promise<Location | undefined>;
|
|
80
|
+
getReferences(path: string, position: Position, includeDeclaration?: boolean): Promise<Location[]>;
|
|
81
|
+
getRenameEdits(path: string, position: Position, newName: string): Promise<RenameResult | undefined>;
|
|
82
|
+
getCompletions(path: string, position: Position): Promise<CompletionItem[]>;
|
|
83
|
+
getHover(path: string, position: Position): Promise<Hover | undefined>;
|
|
84
|
+
getFoldingRanges(path: string): Promise<FoldingRange[]>;
|
|
85
|
+
getCodeActions(path: string, range: Range): Promise<CodeAction[]>;
|
|
86
|
+
getSectionAt(path: string, position: Position): Promise<SectionAt | undefined>;
|
|
87
|
+
getStoryGraph(): Promise<StoryGraph>;
|
|
88
|
+
}
|
|
89
|
+
export declare function createLanguageService(options: LanguageServiceOptions): LanguageService;
|