Skip to content

Commit

Permalink
More tests and string fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
barsdeveloper committed Apr 25, 2024
1 parent 279163c commit 08e2e8e
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 28 deletions.
41 changes: 29 additions & 12 deletions dist/ueblueprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class Configuration {
7: 2,
}
static smoothScrollTime = 1000 // ms
static stringEscapedCharacters = /['"\\]/g
static stringEscapedCharacters = /["\\]/g
static subObjectAttributeNamePrefix = "#SubObject"
/** @param {ObjectEntity} objectEntity */
static subObjectAttributeNameFromEntity = (objectEntity, nameOnly = false) =>
Expand Down Expand Up @@ -3291,6 +3291,11 @@ class GuidEntity extends IEntity {

class ObjectReferenceEntity extends IEntity {

static #quoteSymbols = [
[`'"`, Grammar.Regex.InsideString.source],
[`'`, Grammar.Regex.InsideSingleQuotedString.source],
[`"`, Grammar.Regex.InsideString.source]
]
static attributes = {
...super.attributes,
type: new AttributeInfo({
Expand All @@ -3301,11 +3306,13 @@ class ObjectReferenceEntity extends IEntity {
default: "",
serialized: true,
}),
delim: new AttributeInfo({
ignored: true,
}),
}
static quoted = Parsernostrum.regArray(new RegExp(
`'"(` + Grammar.Regex.InsideString.source + `)"'`
+ `|'(` + Grammar.Regex.InsideSingleQuotedString.source + `)'`
+ `|"(` + Grammar.Regex.InsideString.source + `)"`
this.#quoteSymbols.map(([delim, parser]) =>
delim + "(" + parser + ")" + delim.split("").reverse().join("")).join("|")
)).map(([_0, a, b, c]) => a ?? b ?? c)
static path = this.quoted.getParser().parser.regexp.source + "|" + Grammar.Regex.Path.source
static typeReference = Parsernostrum.reg(
Expand All @@ -3317,14 +3324,22 @@ class ObjectReferenceEntity extends IEntity {
+ /\s*/.source
+ "(?:" + this.quoted.getParser().parser.regexp.source + ")"
)
).map(([_0, type, ...path]) => new this({ type, path: path.find(v => v) }))
).map(([_0, type, ...path]) => new this({
type,
path: path.find(v => v),
delim: this.#quoteSymbols[path.findIndex(v => v)]?.[0] ?? "",
}))
static fullReferenceSerializedGrammar = Parsernostrum.regArray(
new RegExp(
"(" + this.typeReference.getParser().regexp.source + ")"
+ /\s*/.source
+ `'(` + Grammar.Regex.InsideSingleQuotedString.source + `)'`
)
).map(([_0, type, ...path]) => new this({ type, path: path.find(v => v) }))
).map(([_0, type, ...path]) => new this({
type,
path: path.find(v => v),
delim: "'",
}))
static typeReferenceGrammar = this.typeReference.map(v => new this({ type: v, path: "" }))
static grammar = this.createGrammar()

Expand Down Expand Up @@ -3352,6 +3367,7 @@ class ObjectReferenceEntity extends IEntity {
super(values);
/** @type {String} */ this.type;
/** @type {String} */ this.path;
/** @type {String} */ this.delim;
}

static createNoneInstance() {
Expand All @@ -3363,7 +3379,7 @@ class ObjectReferenceEntity extends IEntity {
}

toString() {
return this.type + (this.path ? `'${this.path}'` : "")
return this.type + (this.path ? (this.delim + this.path + this.delim.split("").reverse().join("")) : "")
}
}

Expand Down Expand Up @@ -12964,11 +12980,12 @@ function initializeSerializerFactory() {
new CustomSerializer(
objectReference => {
let type = objectReference.type ?? "";
let name = objectReference.path ?? "";
if (type && name && Utility.isSerialized(objectReference, "path")) {
name = `'${name}'`;
let path = objectReference.path ?? "";
let delim = objectReference.delim ?? "";
if (type && path && Utility.isSerialized(objectReference, "path")) {
path = delim + path + delim.split("").reverse().join("");
}
let result = type + name;
let result = type + path;
if (Utility.isSerialized(objectReference, "type")) {
result = `"${result}"`;
}
Expand All @@ -12985,7 +13002,7 @@ function initializeSerializerFactory() {

SerializerFactory.registerSerializer(
PinEntity,
new Serializer(PinEntity, (entity, v) => `${entity.getLookbehind()} (${v})`, ",", true)
new Serializer(PinEntity, (entity, v) => `${entity.getLookbehind()} (${v})`, ",", false)
);

SerializerFactory.registerSerializer(
Expand Down
8 changes: 4 additions & 4 deletions dist/ueblueprint.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export default class Configuration {
7: 2,
}
static smoothScrollTime = 1000 // ms
static stringEscapedCharacters = /['"\\]/g
static stringEscapedCharacters = /["\\]/g
static subObjectAttributeNamePrefix = "#SubObject"
/** @param {ObjectEntity} objectEntity */
static subObjectAttributeNameFromEntity = (objectEntity, nameOnly = false) =>
Expand Down
28 changes: 22 additions & 6 deletions js/entity/ObjectReferenceEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import IEntity from "./IEntity.js"

export default class ObjectReferenceEntity extends IEntity {

static #quoteSymbols = [
[`'"`, Grammar.Regex.InsideString.source],
[`'`, Grammar.Regex.InsideSingleQuotedString.source],
[`"`, Grammar.Regex.InsideString.source]
]
static attributes = {
...super.attributes,
type: new AttributeInfo({
Expand All @@ -17,11 +22,13 @@ export default class ObjectReferenceEntity extends IEntity {
default: "",
serialized: true,
}),
delim: new AttributeInfo({
ignored: true,
}),
}
static quoted = Parsernostrum.regArray(new RegExp(
`'"(` + Grammar.Regex.InsideString.source + `)"'`
+ `|'(` + Grammar.Regex.InsideSingleQuotedString.source + `)'`
+ `|"(` + Grammar.Regex.InsideString.source + `)"`
this.#quoteSymbols.map(([delim, parser]) =>
delim + "(" + parser + ")" + delim.split("").reverse().join("")).join("|")
)).map(([_0, a, b, c]) => a ?? b ?? c)
static path = this.quoted.getParser().parser.regexp.source + "|" + Grammar.Regex.Path.source
static typeReference = Parsernostrum.reg(
Expand All @@ -33,14 +40,22 @@ export default class ObjectReferenceEntity extends IEntity {
+ /\s*/.source
+ "(?:" + this.quoted.getParser().parser.regexp.source + ")"
)
).map(([_0, type, ...path]) => new this({ type, path: path.find(v => v) }))
).map(([_0, type, ...path]) => new this({
type,
path: path.find(v => v),
delim: this.#quoteSymbols[path.findIndex(v => v)]?.[0] ?? "",
}))
static fullReferenceSerializedGrammar = Parsernostrum.regArray(
new RegExp(
"(" + this.typeReference.getParser().regexp.source + ")"
+ /\s*/.source
+ `'(` + Grammar.Regex.InsideSingleQuotedString.source + `)'`
)
).map(([_0, type, ...path]) => new this({ type, path: path.find(v => v) }))
).map(([_0, type, ...path]) => new this({
type,
path: path.find(v => v),
delim: "'",
}))
static typeReferenceGrammar = this.typeReference.map(v => new this({ type: v, path: "" }))
static grammar = this.createGrammar()

Expand Down Expand Up @@ -68,6 +83,7 @@ export default class ObjectReferenceEntity extends IEntity {
super(values)
/** @type {String} */ this.type
/** @type {String} */ this.path
/** @type {String} */ this.delim
}

static createNoneInstance() {
Expand All @@ -79,6 +95,6 @@ export default class ObjectReferenceEntity extends IEntity {
}

toString() {
return this.type + (this.path ? `'${this.path}'` : "")
return this.type + (this.path ? (this.delim + this.path + this.delim.split("").reverse().join("")) : "")
}
}
11 changes: 6 additions & 5 deletions js/serialization/initializeSerializerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,12 @@ export default function initializeSerializerFactory() {
new CustomSerializer(
objectReference => {
let type = objectReference.type ?? ""
let name = objectReference.path ?? ""
if (type && name && Utility.isSerialized(objectReference, "path")) {
name = `'${name}'`
let path = objectReference.path ?? ""
let delim = objectReference.delim ?? ""
if (type && path && Utility.isSerialized(objectReference, "path")) {
path = delim + path + delim.split("").reverse().join("")
}
let result = type + name
let result = type + path
if (Utility.isSerialized(objectReference, "type")) {
result = `"${result}"`
}
Expand All @@ -237,7 +238,7 @@ export default function initializeSerializerFactory() {

SerializerFactory.registerSerializer(
PinEntity,
new Serializer(PinEntity, (entity, v) => `${entity.getLookbehind()} (${v})`, ",", true)
new Serializer(PinEntity, (entity, v) => `${entity.getLookbehind()} (${v})`, ",", false)
)

SerializerFactory.registerSerializer(
Expand Down
30 changes: 30 additions & 0 deletions tests/parsing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ test("ObjectReferenceEntity", () => {
reference = serializer.read(`EdGraphPin'"K2Node_DynamicCast_2126.EdGraphPin_3990988"'`)
expect(reference).toBeInstanceOf(ObjectReferenceEntity)
expect(reference).toMatchObject({ type: "EdGraphPin", path: "K2Node_DynamicCast_2126.EdGraphPin_3990988" })
expect(serializer.write(reference)).toBe(`EdGraphPin'"K2Node_DynamicCast_2126.EdGraphPin_3990988"'`)

reference = serializer.read(
`"/Script/Engine.MaterialExpressionMaterialFunctionCall'MaterialExpressionMaterialFunctionCall_0'"`
Expand All @@ -241,6 +242,9 @@ test("ObjectReferenceEntity", () => {
type: "/Script/Engine.EdGraph",
path: "/Engine/EditorBlueprintResources/StandardMacros.StandardMacros:Do N",
})
expect(serializer.write(reference)).toBe(
`/Script/Engine.EdGraph'"/Engine/EditorBlueprintResources/StandardMacros.StandardMacros:Do N"'`
)

reference = serializer.read(
`EdGraphPin'"K2Node_CommutativeAssociativeBinaryOperator_152.EdGraphPin_4045"'`
Expand All @@ -250,6 +254,9 @@ test("ObjectReferenceEntity", () => {
type: "EdGraphPin",
path: "K2Node_CommutativeAssociativeBinaryOperator_152.EdGraphPin_4045",
})
expect(serializer.write(reference)).toBe(
`EdGraphPin'"K2Node_CommutativeAssociativeBinaryOperator_152.EdGraphPin_4045"'`
)

reference = serializer.read(
`Function'"/Game/Mods/CrazyDinos/ElementalDragon/CDElementalDragon_Character_BP.SKEL_CDElementalDragon_Character_BP_C:ROS Change Element"'`
Expand All @@ -259,21 +266,27 @@ test("ObjectReferenceEntity", () => {
type: "Function",
path: "/Game/Mods/CrazyDinos/ElementalDragon/CDElementalDragon_Character_BP.SKEL_CDElementalDragon_Character_BP_C:ROS Change Element",
})
expect(serializer.write(reference)).toBe(
`Function'"/Game/Mods/CrazyDinos/ElementalDragon/CDElementalDragon_Character_BP.SKEL_CDElementalDragon_Character_BP_C:ROS Change Element"'`
)

reference = serializer.read(`EdGraph'/Game/Systems/BP_MacroGlobal.BP_MacroGlobal:Or+Branch'`)
expect(reference).toBeInstanceOf(ObjectReferenceEntity)
expect(reference).toMatchObject({
type: "EdGraph",
path: "/Game/Systems/BP_MacroGlobal.BP_MacroGlobal:Or+Branch",
})
expect(serializer.write(reference)).toBe(`EdGraph'/Game/Systems/BP_MacroGlobal.BP_MacroGlobal:Or+Branch'`)

reference = serializer.read(`/Script/Engine.EdGraph'"+-Weird/2,Macro"'`)
expect(reference).toBeInstanceOf(ObjectReferenceEntity)
expect(reference).toMatchObject({ type: "/Script/Engine.EdGraph", path: "+-Weird/2,Macro" })
expect(serializer.write(reference)).toBe(`/Script/Engine.EdGraph'"+-Weird/2,Macro"'`)

reference = serializer.read(`/Script/BlueprintGraph.K2Node_VariableGet`)
expect(reference).toBeInstanceOf(ObjectReferenceEntity)
expect(reference).toMatchObject({ type: "/Script/BlueprintGraph.K2Node_VariableGet", path: "" })
expect(serializer.write(reference)).toBe(`/Script/BlueprintGraph.K2Node_VariableGet`)

reference = serializer.read(
`/Script/Engine.MaterialExpressionMaterialFunctionCall'MaterialExpressionMaterialFunctionCall_0'`
Expand All @@ -283,6 +296,9 @@ test("ObjectReferenceEntity", () => {
type: "/Script/Engine.MaterialExpressionMaterialFunctionCall",
path: "MaterialExpressionMaterialFunctionCall_0",
})
expect(serializer.write(reference)).toBe(
`/Script/Engine.MaterialExpressionMaterialFunctionCall'MaterialExpressionMaterialFunctionCall_0'`
)

reference = serializer.read(
`/Script/Engine.MaterialExpressionMaterialFunctionCall'/Engine/Transient.Material_0:MaterialGraph_0.MaterialGraphNode_3.MaterialExpressionMaterialFunctionCall_0'`
Expand All @@ -292,6 +308,17 @@ test("ObjectReferenceEntity", () => {
type: "/Script/Engine.MaterialExpressionMaterialFunctionCall",
path: "/Engine/Transient.Material_0:MaterialGraph_0.MaterialGraphNode_3.MaterialExpressionMaterialFunctionCall_0",
})
expect(serializer.write(reference)).toBe(
`/Script/Engine.MaterialExpressionMaterialFunctionCall'/Engine/Transient.Material_0:MaterialGraph_0.MaterialGraphNode_3.MaterialExpressionMaterialFunctionCall_0'`
)

reference = serializer.read(`/Script/CoreUObject.Class'"/Script/Engine.GameModeBase"'`)
expect(reference).toBeInstanceOf(ObjectReferenceEntity)
expect(reference).toMatchObject({
type: "/Script/CoreUObject.Class",
path: "/Script/Engine.GameModeBase",
})
expect(serializer.write(reference)).toBe(`/Script/CoreUObject.Class'"/Script/Engine.GameModeBase"'`)
})

test("PinEntity", () => {
Expand Down Expand Up @@ -367,6 +394,9 @@ test("String", () => {
expect(serializer.read('"hello world 123 - éèàò@ç ^ ^^^"')).toStrictEqual("hello world 123 - éèàò@ç ^ ^^^")
expect(serializer.read('"\\""')).toStrictEqual('"')
expect(() => serializer.read("Hello")).toThrow()

expect(serializer.write(`"/Script/CoreUObject.Class'/Script/Interhaptics.HapticSource'"`))
.toBe(`"/Script/CoreUObject.Class'/Script/Interhaptics.HapticSource'"`)
})

test("UnknownKeysValue", () => {
Expand Down

0 comments on commit 08e2e8e

Please sign in to comment.