Public
Edited
May 19, 2024
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
GodotParsing = new (class GodotParsing {
parseFile(text) {
return this.#parse(text, "File");
}

parseValue(text) {
return this.#parse(text, "Value");
}

#parse(text, startRule) {
const match = godotGrammar.match(text, startRule);
if (match.succeeded()) {
return godotSemantics(match).interpret();
} else {
throw new Error(match.message);
}
}
})()
Insert cell
class GodotFile {
fileType;
attributes;
entries;
constructor(fileType, attributes, entries) {
this.fileType = fileType;
this.attributes = attributes;
this.entries = entries;
}

serialize() {
const serializedHeadingParts = [this.fileType];
for (const [key, value] of this.attributes) {
serializedHeadingParts.push(`${key}=${value.serialize()}`);
}
const serializedHeading = `[${serializedHeadingParts.join(" ")}]`;

// TODO this.ensureValidEntryOrder();
const serializedEntries = this.entries.map((it) => it.serialize());

return [serializedHeading].concat(serializedEntries).join("\n\n") + "\n";
}
}
Insert cell
class GodotFileEntry {
entryType;
attributes;
properties;
constructor(entryType, attributes, properties) {
this.entryType = entryType;
this.attributes = attributes;
this.properties = properties;
}

get id() {
return this.attributes.get("id").value;
}

serialize() {
const serializedHeadingParts = [this.entryType];
for (const [key, value] of this.attributes) {
serializedHeadingParts.push(`${key}=${value.serialize()}`);
}
const serializedHeading = `[${serializedHeadingParts.join(" ")}]`;

const serializedProperties = [];
for (const [key, value] of this.properties) {
serializedProperties.push(`${key} = ${value.serialize()}`);
}

return [serializedHeading].concat(serializedProperties).join("\n");
}
}
Insert cell
class GodotExtResourceRef {
extResourceId;
constructor(extResourceId) {
this.extResourceId = extResourceId;
}

serialize() {
return `ExtResource("${this.extResourceId}")`;
}
}
Insert cell
class GodotSubResourceRef {
subResourceId;
constructor(subResourceId) {
this.subResourceId = subResourceId;
}

serialize() {
return `SubResource("${this.subResourceId}")`;
}
}
Insert cell
class GodotObjectValue {
typeName;
parameters;
constructor(typeName, parameters) {
this.typeName = typeName;
this.parameters = parameters;
}

serialize() {
const serializedParameters = this.parameters.map(it => it.serialize());
return `${this.typeName}(${serializedParameters.join(', ')})`
}
}
Insert cell
class GodotListValue {
values;
constructor(values) {
this.values = values;
}

serialize() {
const serializedValues = this.values.map((it) => it.serialize());
return `[${serializedValues.join(", ")}]`;
}
}
Insert cell
class GodotDictValue {
properties;
constructor(properties) {
this.properties = properties;
}

serialize() {
const serializedProperties = [];
for (const [key, value] of this.properties) {
serializedProperties.push(`${key}: ${value.serialize()}`);
}
return `{${serializedProperties.join(", ")}}`;
}
}
Insert cell
class GodotPrimitiveValue {
value;
sourceString;
constructor(value, sourceString) {
this.value = value;
this.sourceString = sourceString;
}

serialize() {
if (this.sourceString) {
return this.sourceString;
} else if (typeof this.value === "string") {
return `"${this.value}"`;
} else {
return String(this.value);
}
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more