Split grammar (#15)

* Move grammar parsers to entity classes

* Fix includes

* Fix Entity5 test

* Small detail

* Fix unknown keys entities

* Persistent grammar objects

* Fix grammar

* Grammar from variable
This commit is contained in:
barsdeveloper
2023-09-18 21:13:28 +02:00
committed by GitHub
parent 872bdb7128
commit 78c62ee59a
48 changed files with 1807 additions and 1845 deletions

View File

@@ -310,7 +310,7 @@ describe("Entity initialization", () => {
initializeSerializerFactory()
SerializerFactory.registerSerializer(
Entity5,
new ObjectSerializer()
new ObjectSerializer(Entity5)
)
SerializerFactory.registerSerializer(
EntityF,
@@ -319,7 +319,6 @@ describe("Entity initialization", () => {
})
it("can serialize/deserialize", () => {
expect(entity = SerializerFactory.getSerializer(Entity5).read(entity5Value1)).to.deep.equal({
Name: "",
key1: "Value 1",
key2: {
lookbehind: "Foo",
@@ -327,7 +326,7 @@ describe("Entity initialization", () => {
arg2: "Argument 2",
},
})
expect(entity.key2).to.be.instanceof(UnknownKeysEntity)
expect(entity.key2).to.be.instanceof(EntityF)
expect(SerializerFactory.getSerializer(Entity5).write(entity)).to.equal(entity5Value1)
})
})

View File

@@ -65,6 +65,29 @@ const tests = [
delegate: true,
development: false,
},
{
name: "Call AS!%sasd Adsad DD",
value: String.raw`
Begin Object Class=/Script/BlueprintGraph.K2Node_CallDelegate Name="K2Node_CallDelegate_0" ExportPath=/Script/BlueprintGraph.K2Node_CallDelegate'"/PCG/BP_Elements/PCGAsset.PCGAsset:EventGraph.K2Node_CallDelegate_0"'
"DelegateReference"=(MemberName="AS!%sasdAdsadDD",MemberGuid=FB6F7CD342716A4FA22AA6AD6E6B7ED9,bSelfContext=True)
"NodePosX"=-176
"NodePosY"=368
"NodeGuid"=DE76D7A748D78DF77131B0AE166442A6
CustomProperties Pin (PinId=C329158B42D4E4DA1CAEF7A04ED77100,PinName="execute",PinType.PinCategory="exec",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=8D92F70C46C94C389AAC3E87191AB46A,PinName="then",Direction="EGPD_Output",PinType.PinCategory="exec",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=88182FCB4DE7B6D80AD1B79906069691,PinName="self",PinFriendlyName=NSLOCTEXT("K2Node", "BaseMCDelegateSelfPinName", "Target"),PinType.PinCategory="object",PinType.PinSubCategory="",PinType.PinSubCategoryObject=/Script/Engine.BlueprintGeneratedClass'"/PCG/BP_Elements/PCGAsset.PCGAsset_C"',PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
End Object
`,
size: [13, 6],
color: Configuration.nodeColors.blue,
icon: SVGIcon.node,
pins: 3,
pinNames: [
"Target",
],
delegate: false,
development: false,
},
]
generateNodeTests(tests)

View File

@@ -52,7 +52,7 @@ describe("Serializer", () => {
"InRangeMin"
)`)
.toString()
).to.be.equal(`If InRangeMin = InRangeMax, then that density value is mapped to the average of OutRangeMin and OutRangeMax\nAttribute type is "float" and its exact name is "InRangeMin"`))
})

View File

@@ -1,7 +1,7 @@
import EntityF from "./EntityF.js"
import IEntity from "../../js/entity/IEntity.js"
import ObjectEntity from "../../js/entity/ObjectEntity.js"
export default class Entity5 extends IEntity {
export default class Entity5 extends ObjectEntity {
static attributes = {
key1: {
@@ -11,8 +11,8 @@ export default class Entity5 extends IEntity {
type: EntityF,
},
}
static {
this.cleanupAttributes(this.attributes)
}
static grammar = this.createGrammar()
}

View File

@@ -1,3 +1,4 @@
import Grammar from "../../js/serialization/Grammar.js"
import IEntity from "../../js/entity/IEntity.js"
import Union from "../../js/entity/Union.js"
@@ -5,6 +6,7 @@ export default class EntityF extends IEntity {
static lookbehind = new Union("Foo", "Bar")
static attributes = {
...super.attributes,
arg1: {
type: Number,
},
@@ -13,6 +15,12 @@ export default class EntityF extends IEntity {
},
}
static grammar = this.createGrammar()
static createGrammar() {
return Grammar.createEntityGrammar(this, false)
}
constructor(values = {}) {
super(values)
}