mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
Serialization compliant
This commit is contained in:
89
dist/ueblueprint.js
vendored
89
dist/ueblueprint.js
vendored
@@ -1108,6 +1108,7 @@ class PinEntity extends IEntity {
|
||||
LinkedTo: [PinReferenceEntity],
|
||||
DefaultValue: "",
|
||||
AutogeneratedDefaultValue: "",
|
||||
DefaultObject: new TypeInitialization(ObjectReferenceEntity, false, null),
|
||||
PersistentGuid: GuidEntity,
|
||||
bHidden: false,
|
||||
bNotConnectable: false,
|
||||
@@ -1229,31 +1230,60 @@ var Parsimmon = /*@__PURE__*/getDefaultExportFromCjs(parsimmon_umd_min.exports);
|
||||
let P$1 = Parsimmon;
|
||||
|
||||
class Grammar {
|
||||
// General
|
||||
InlineWhitespace = _ => P$1.regex(/[^\S\n]+/).desc("inline whitespace")
|
||||
InlineOptWhitespace = _ => P$1.regex(/[^\S\n]*/).desc("inline optional whitespace")
|
||||
WhitespaceNewline = _ => P$1.regex(/[^\S\n]*\n\s*/).desc("whitespace with at least a newline")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
InlineWhitespace = r => P$1.regex(/[^\S\n]+/).desc("inline whitespace")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
InlineOptWhitespace = r => P$1.regex(/[^\S\n]*/).desc("inline optional whitespace")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
WhitespaceNewline = r => P$1.regex(/[^\S\n]*\n\s*/).desc("whitespace with at least a newline")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Null = r => P$1.seq(P$1.string("("), r.InlineOptWhitespace, P$1.string(")")).map(_ => null).desc("null: ()")
|
||||
None = _ => P$1.string("None").map(_ => new ObjectReferenceEntity({ type: "None", path: "" })).desc("none")
|
||||
Boolean = _ => P$1.alt(P$1.string("True"), P$1.string("False")).map(v => v === "True" ? true : false).desc("either True or False")
|
||||
Number = _ => P$1.regex(/[\-\+]?[0-9]+(?:\.[0-9]+)?/).map(Number).desc("a number")
|
||||
Integer = _ => P$1.regex(/[\-\+]?[0-9]+/).map(v => new IntegerEntity(v)).desc("an integer")
|
||||
String = _ => P$1.regex(/(?:[^"\\]|\\.)*/).wrap(P$1.string('"'), P$1.string('"')).desc('string (with possibility to escape the quote using \")')
|
||||
Word = _ => P$1.regex(/[a-zA-Z]+/).desc("a word")
|
||||
Guid = _ => P$1.regex(/[0-9a-zA-Z]{32}/).map(v => new GuidEntity({ value: v })).desc("32 digit hexadecimal (accepts all the letters for safety) value")
|
||||
PathSymbolEntity = _ => P$1.regex(/[0-9a-zA-Z_]+/).map(v => new PathSymbolEntity({ value: v }))
|
||||
|
||||
/** @param {Grammar} r */
|
||||
None = r => P$1.string("None").map(_ => new ObjectReferenceEntity({ type: "None", path: "" })).desc("none")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Boolean = r => P$1.alt(P$1.string("True"), P$1.string("False")).map(v => v === "True" ? true : false).desc("either True or False")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Number = r => P$1.regex(/[\-\+]?[0-9]+(?:\.[0-9]+)?/).map(Number).desc("a number")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Integer = r => P$1.regex(/[\-\+]?[0-9]+/).map(v => new IntegerEntity(v)).desc("an integer")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
String = r => P$1.regex(/(?:[^"\\]|\\.)*/).wrap(P$1.string('"'), P$1.string('"')).desc('string (with possibility to escape the quote using \")')
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Word = r => P$1.regex(/[a-zA-Z]+/).desc("a word")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Guid = r => P$1.regex(/[0-9a-zA-Z]{32}/).map(v => new GuidEntity({ value: v })).desc("32 digit hexadecimal (accepts all the letters for safety) value")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
PathSymbolEntity = r => P$1.regex(/[0-9a-zA-Z_]+/).map(v => new PathSymbolEntity({ value: v }))
|
||||
|
||||
/** @param {Grammar} r */
|
||||
ReferencePath = r => P$1.seq(P$1.string("/"), r.PathSymbolEntity.map(v => v.toString()).sepBy1(P$1.string(".")).tieWith("."))
|
||||
.tie()
|
||||
.atLeast(2)
|
||||
.tie()
|
||||
.desc('a path (words with possibly underscore, separated by ".", separated by "/")')
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Reference = r => P$1.alt(
|
||||
r.None,
|
||||
r.ReferencePath.map(path => new ObjectReferenceEntity({ type: "", path: path })),
|
||||
...[r.ReferencePath.map(path => new ObjectReferenceEntity({ type: "", path: path }))].flatMap(
|
||||
v => [v, v.trim(P$1.string('"'))]
|
||||
),
|
||||
P$1.seqMap(
|
||||
r.Word,
|
||||
P$1.optWhitespace,
|
||||
P$1.alt(P$1.string(`"`), P$1.string(`'"`)).chain(
|
||||
P$1.alt(P$1.string('"'), P$1.string('\'"')).chain(
|
||||
result => r.ReferencePath.skip(
|
||||
P$1.string(result.split("").reverse().join(""))
|
||||
)
|
||||
@@ -1261,8 +1291,14 @@ class Grammar {
|
||||
(referenceType, _, referencePath) => new ObjectReferenceEntity({ type: referenceType, path: referencePath })
|
||||
)
|
||||
)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
AttributeName = r => r.Word.sepBy1(P$1.string(".")).tieWith(".").desc('words separated by ""')
|
||||
|
||||
/** @param {Grammar} r */
|
||||
AttributeAnyValue = r => P$1.alt(r.Null, r.None, r.Boolean, r.Number, r.Integer, r.String, r.Guid, r.Reference, r.LocalizedText)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
LocalizedText = r => P$1.seqMap(
|
||||
P$1.string(LocalizedTextEntity.lookbehind).skip(P$1.optWhitespace).skip(P$1.string("(")),
|
||||
r.String.trim(P$1.optWhitespace), // namespace
|
||||
@@ -1277,6 +1313,8 @@ class Grammar {
|
||||
value: value
|
||||
})
|
||||
)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
PinReference = r => P$1.seqMap(
|
||||
r.PathSymbolEntity,
|
||||
P$1.whitespace,
|
||||
@@ -1286,6 +1324,8 @@ class Grammar {
|
||||
pinGuid: pinGuid
|
||||
})
|
||||
)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
static getGrammarForType(r, attributeType, defaultGrammar) {
|
||||
switch (Utility.getType(attributeType)) {
|
||||
case Boolean:
|
||||
@@ -1328,7 +1368,8 @@ class Grammar {
|
||||
return defaultGrammar
|
||||
}
|
||||
}
|
||||
// Meta grammar
|
||||
|
||||
/** @param {Grammar} r */
|
||||
static CreateAttributeGrammar = (r, entityType, valueSeparator = P$1.string("=").trim(P$1.optWhitespace)) =>
|
||||
r.AttributeName.skip(valueSeparator)
|
||||
.chain(attributeName => {
|
||||
@@ -1340,7 +1381,8 @@ class Grammar {
|
||||
entity => Utility.objectSet(entity, attributeKey, attributeValue, true)
|
||||
)
|
||||
})
|
||||
// Meta grammar
|
||||
|
||||
/** @param {Grammar} r */
|
||||
static CreateMultiAttributeGrammar = (r, entityType) =>
|
||||
/**
|
||||
* Basically this creates a parser that looks for a string like 'Key (A=False,B="Something",)'
|
||||
@@ -1360,8 +1402,14 @@ class Grammar {
|
||||
attributes.forEach(attributeSetter => attributeSetter(result));
|
||||
return result
|
||||
})
|
||||
|
||||
/** @param {Grammar} r */
|
||||
FunctionReference = r => Grammar.CreateMultiAttributeGrammar(r, FunctionReferenceEntity)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Pin = r => Grammar.CreateMultiAttributeGrammar(r, PinEntity)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
CustomProperties = r =>
|
||||
P$1.string("CustomProperties")
|
||||
.then(P$1.whitespace)
|
||||
@@ -1373,6 +1421,7 @@ class Grammar {
|
||||
Utility.objectSet(entity, ["CustomProperties"], properties, true);
|
||||
})
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Object = r => P$1.seqMap(
|
||||
P$1.seq(P$1.string("Begin"), P$1.whitespace, P$1.string("Object"), P$1.whitespace),
|
||||
P$1
|
||||
@@ -1388,6 +1437,8 @@ class Grammar {
|
||||
return result
|
||||
}
|
||||
)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
MultipleObject = r => r.Object.sepBy1(P$1.whitespace).trim(P$1.optWhitespace)
|
||||
}
|
||||
|
||||
@@ -1465,7 +1516,7 @@ class ISerializer {
|
||||
+ this.writeValue(value);
|
||||
}
|
||||
}
|
||||
if (this.trailingSeparator && result.length && fullKey.length === 0) {
|
||||
if (this.trailingSeparator && result.length && fullKey.length === 1) {
|
||||
// append separator at the end if asked and there was printed content
|
||||
result += this.separator;
|
||||
}
|
||||
@@ -1525,7 +1576,7 @@ class ObjectSerializer extends ISerializer {
|
||||
* @param {ObjectEntity} object
|
||||
*/
|
||||
write(object) {
|
||||
let result = `Begin Object Class=${this.writeValue(object.Class)} Name=${this.writeValue(object.Name)}
|
||||
let result = `Begin Object Class=${object.Class.path} Name=${this.writeValue(object.Name)}
|
||||
${this.subWrite([], object)
|
||||
+ object
|
||||
.CustomProperties.map(pin => this.separator + this.prefix + "CustomProperties " + SerializerFactory.getSerializer(PinEntity).write(pin))
|
||||
@@ -3598,7 +3649,7 @@ function initializeSerializerFactory() {
|
||||
/** @param {ObjectReferenceEntity} objectReference */
|
||||
objectReference => (objectReference.type ?? "") + (
|
||||
objectReference.path
|
||||
? objectReference.type ? `'"${objectReference.path}"'` : objectReference.path
|
||||
? objectReference.type ? `'"${objectReference.path}"'` : `"${objectReference.path}"`
|
||||
: ""
|
||||
))
|
||||
);
|
||||
|
||||
@@ -43,6 +43,7 @@ export default class PinEntity extends IEntity {
|
||||
LinkedTo: [PinReferenceEntity],
|
||||
DefaultValue: "",
|
||||
AutogeneratedDefaultValue: "",
|
||||
DefaultObject: new TypeInitialization(ObjectReferenceEntity, false, null),
|
||||
PersistentGuid: GuidEntity,
|
||||
bHidden: false,
|
||||
bNotConnectable: false,
|
||||
|
||||
@@ -13,31 +13,60 @@ import Utility from "../Utility"
|
||||
let P = Parsimmon
|
||||
|
||||
export default class Grammar {
|
||||
// General
|
||||
InlineWhitespace = _ => P.regex(/[^\S\n]+/).desc("inline whitespace")
|
||||
InlineOptWhitespace = _ => P.regex(/[^\S\n]*/).desc("inline optional whitespace")
|
||||
WhitespaceNewline = _ => P.regex(/[^\S\n]*\n\s*/).desc("whitespace with at least a newline")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
InlineWhitespace = r => P.regex(/[^\S\n]+/).desc("inline whitespace")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
InlineOptWhitespace = r => P.regex(/[^\S\n]*/).desc("inline optional whitespace")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
WhitespaceNewline = r => P.regex(/[^\S\n]*\n\s*/).desc("whitespace with at least a newline")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Null = r => P.seq(P.string("("), r.InlineOptWhitespace, P.string(")")).map(_ => null).desc("null: ()")
|
||||
None = _ => P.string("None").map(_ => new ObjectReferenceEntity({ type: "None", path: "" })).desc("none")
|
||||
Boolean = _ => P.alt(P.string("True"), P.string("False")).map(v => v === "True" ? true : false).desc("either True or False")
|
||||
Number = _ => P.regex(/[\-\+]?[0-9]+(?:\.[0-9]+)?/).map(Number).desc("a number")
|
||||
Integer = _ => P.regex(/[\-\+]?[0-9]+/).map(v => new IntegerEntity(v)).desc("an integer")
|
||||
String = _ => P.regex(/(?:[^"\\]|\\.)*/).wrap(P.string('"'), P.string('"')).desc('string (with possibility to escape the quote using \")')
|
||||
Word = _ => P.regex(/[a-zA-Z]+/).desc("a word")
|
||||
Guid = _ => P.regex(/[0-9a-zA-Z]{32}/).map(v => new GuidEntity({ value: v })).desc("32 digit hexadecimal (accepts all the letters for safety) value")
|
||||
PathSymbolEntity = _ => P.regex(/[0-9a-zA-Z_]+/).map(v => new PathSymbolEntity({ value: v }))
|
||||
|
||||
/** @param {Grammar} r */
|
||||
None = r => P.string("None").map(_ => new ObjectReferenceEntity({ type: "None", path: "" })).desc("none")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Boolean = r => P.alt(P.string("True"), P.string("False")).map(v => v === "True" ? true : false).desc("either True or False")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Number = r => P.regex(/[\-\+]?[0-9]+(?:\.[0-9]+)?/).map(Number).desc("a number")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Integer = r => P.regex(/[\-\+]?[0-9]+/).map(v => new IntegerEntity(v)).desc("an integer")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
String = r => P.regex(/(?:[^"\\]|\\.)*/).wrap(P.string('"'), P.string('"')).desc('string (with possibility to escape the quote using \")')
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Word = r => P.regex(/[a-zA-Z]+/).desc("a word")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Guid = r => P.regex(/[0-9a-zA-Z]{32}/).map(v => new GuidEntity({ value: v })).desc("32 digit hexadecimal (accepts all the letters for safety) value")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
PathSymbolEntity = r => P.regex(/[0-9a-zA-Z_]+/).map(v => new PathSymbolEntity({ value: v }))
|
||||
|
||||
/** @param {Grammar} r */
|
||||
ReferencePath = r => P.seq(P.string("/"), r.PathSymbolEntity.map(v => v.toString()).sepBy1(P.string(".")).tieWith("."))
|
||||
.tie()
|
||||
.atLeast(2)
|
||||
.tie()
|
||||
.desc('a path (words with possibly underscore, separated by ".", separated by "/")')
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Reference = r => P.alt(
|
||||
r.None,
|
||||
r.ReferencePath.map(path => new ObjectReferenceEntity({ type: "", path: path })),
|
||||
...[r.ReferencePath.map(path => new ObjectReferenceEntity({ type: "", path: path }))].flatMap(
|
||||
v => [v, v.trim(P.string('"'))]
|
||||
),
|
||||
P.seqMap(
|
||||
r.Word,
|
||||
P.optWhitespace,
|
||||
P.alt(P.string(`"`), P.string(`'"`)).chain(
|
||||
P.alt(P.string('"'), P.string('\'"')).chain(
|
||||
result => r.ReferencePath.skip(
|
||||
P.string(result.split("").reverse().join(""))
|
||||
)
|
||||
@@ -45,8 +74,14 @@ export default class Grammar {
|
||||
(referenceType, _, referencePath) => new ObjectReferenceEntity({ type: referenceType, path: referencePath })
|
||||
)
|
||||
)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
AttributeName = r => r.Word.sepBy1(P.string(".")).tieWith(".").desc('words separated by ""')
|
||||
|
||||
/** @param {Grammar} r */
|
||||
AttributeAnyValue = r => P.alt(r.Null, r.None, r.Boolean, r.Number, r.Integer, r.String, r.Guid, r.Reference, r.LocalizedText)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
LocalizedText = r => P.seqMap(
|
||||
P.string(LocalizedTextEntity.lookbehind).skip(P.optWhitespace).skip(P.string("(")),
|
||||
r.String.trim(P.optWhitespace), // namespace
|
||||
@@ -61,6 +96,8 @@ export default class Grammar {
|
||||
value: value
|
||||
})
|
||||
)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
PinReference = r => P.seqMap(
|
||||
r.PathSymbolEntity,
|
||||
P.whitespace,
|
||||
@@ -70,6 +107,8 @@ export default class Grammar {
|
||||
pinGuid: pinGuid
|
||||
})
|
||||
)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
static getGrammarForType(r, attributeType, defaultGrammar) {
|
||||
switch (Utility.getType(attributeType)) {
|
||||
case Boolean:
|
||||
@@ -112,7 +151,8 @@ export default class Grammar {
|
||||
return defaultGrammar
|
||||
}
|
||||
}
|
||||
// Meta grammar
|
||||
|
||||
/** @param {Grammar} r */
|
||||
static CreateAttributeGrammar = (r, entityType, valueSeparator = P.string("=").trim(P.optWhitespace)) =>
|
||||
r.AttributeName.skip(valueSeparator)
|
||||
.chain(attributeName => {
|
||||
@@ -124,7 +164,8 @@ export default class Grammar {
|
||||
entity => Utility.objectSet(entity, attributeKey, attributeValue, true)
|
||||
)
|
||||
})
|
||||
// Meta grammar
|
||||
|
||||
/** @param {Grammar} r */
|
||||
static CreateMultiAttributeGrammar = (r, entityType) =>
|
||||
/**
|
||||
* Basically this creates a parser that looks for a string like 'Key (A=False,B="Something",)'
|
||||
@@ -144,8 +185,14 @@ export default class Grammar {
|
||||
attributes.forEach(attributeSetter => attributeSetter(result))
|
||||
return result
|
||||
})
|
||||
|
||||
/** @param {Grammar} r */
|
||||
FunctionReference = r => Grammar.CreateMultiAttributeGrammar(r, FunctionReferenceEntity)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Pin = r => Grammar.CreateMultiAttributeGrammar(r, PinEntity)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
CustomProperties = r =>
|
||||
P.string("CustomProperties")
|
||||
.then(P.whitespace)
|
||||
@@ -157,6 +204,7 @@ export default class Grammar {
|
||||
Utility.objectSet(entity, ["CustomProperties"], properties, true)
|
||||
})
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Object = r => P.seqMap(
|
||||
P.seq(P.string("Begin"), P.whitespace, P.string("Object"), P.whitespace),
|
||||
P
|
||||
@@ -172,5 +220,7 @@ export default class Grammar {
|
||||
return result
|
||||
}
|
||||
)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
MultipleObject = r => r.Object.sepBy1(P.whitespace).trim(P.optWhitespace)
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ export default class ISerializer {
|
||||
+ this.writeValue(value)
|
||||
}
|
||||
}
|
||||
if (this.trailingSeparator && result.length && fullKey.length === 0) {
|
||||
if (this.trailingSeparator && result.length && fullKey.length === 1) {
|
||||
// append separator at the end if asked and there was printed content
|
||||
result += this.separator
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ export default class ObjectSerializer extends ISerializer {
|
||||
* @param {ObjectEntity} object
|
||||
*/
|
||||
write(object) {
|
||||
let result = `Begin Object Class=${this.writeValue(object.Class)} Name=${this.writeValue(object.Name)}
|
||||
let result = `Begin Object Class=${object.Class.path} Name=${this.writeValue(object.Name)}
|
||||
${this.subWrite([], object)
|
||||
+ object
|
||||
.CustomProperties.map(pin => this.separator + this.prefix + "CustomProperties " + SerializerFactory.getSerializer(PinEntity).write(pin))
|
||||
|
||||
@@ -40,7 +40,7 @@ export default function initializeSerializerFactory() {
|
||||
/** @param {ObjectReferenceEntity} objectReference */
|
||||
objectReference => (objectReference.type ?? "") + (
|
||||
objectReference.path
|
||||
? objectReference.type ? `'"${objectReference.path}"'` : objectReference.path
|
||||
? objectReference.type ? `'"${objectReference.path}"'` : `"${objectReference.path}"`
|
||||
: ""
|
||||
))
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user