Grammar refactoring

* Grammar refactoring WIP

* ISerializer.grammar

* Fixing various bugs in the grammar

* Small touch that improoves performance

* Fix unknown values grammar

* Various fixes

* Serialization refactoring to drop suboject logic

* Details fixed

* Entity attributes initialization refactoring

* JSDoc error fixed

* Rename value key to default

* Remove useless default

* Revert string keys
This commit is contained in:
barsdeveloper
2023-04-01 19:55:16 +02:00
committed by GitHub
parent b235d63348
commit bb24486303
44 changed files with 6395 additions and 6248 deletions

View File

@@ -1,3 +1,4 @@
import Grammar from "./Grammar.js"
import ISerializer from "./ISerializer.js"
import ObjectEntity from "../entity/ObjectEntity.js"
import PinEntity from "../entity/PinEntity.js"
@@ -9,20 +10,20 @@ export default class ObjectSerializer extends ISerializer {
super(ObjectEntity, " ", "\n", false)
}
showProperty(entity, object, attributeKey, attributeValue) {
switch (attributeKey.toString()) {
showProperty(entity, key) {
switch (key) {
case "Class":
case "Name":
case "CustomProperties":
// Serielized separately
// Serielized separately, check write()
return false
}
return super.showProperty(entity, object, attributeKey, attributeValue)
return super.showProperty(entity, key)
}
/** @param {String} value */
read(value) {
const parseResult = ISerializer.grammar.Object.parse(value)
const parseResult = Grammar.objectEntity.parse(value)
if (!parseResult.status) {
throw new Error("Error when trying to parse the object.")
}
@@ -34,7 +35,7 @@ export default class ObjectSerializer extends ISerializer {
* @returns {ObjectEntity[]}
*/
readMultiple(value) {
const parseResult = ISerializer.grammar.MultipleObject.parse(value)
const parseResult = Grammar.multipleObject.parse(value)
if (!parseResult.status) {
throw new Error("Error when trying to parse the object.")
}
@@ -42,21 +43,20 @@ export default class ObjectSerializer extends ISerializer {
}
/**
* @param {ObjectEntity} object
* @param {ObjectEntity} entity
* @param {Boolean} insideString
*/
write(entity, object, insideString) {
let result = `Begin Object Class=${object.Class.path} Name=${this.writeValue(entity, object.Name, ["Name"], insideString)}
${this.subWrite(entity, [], object, insideString)
+ object
.CustomProperties.map(pin =>
this.attributeSeparator
+ this.attributePrefix
+ "CustomProperties "
+ SerializerFactory.getSerializer(PinEntity).serialize(pin)
)
.join("")}
End Object\n`
write(entity, insideString) {
let result = `Begin Object Class=${entity.Class.path} Name=${this.writeValue(entity, "Name", insideString)}\n`
+ super.write(entity, insideString)
+ entity.CustomProperties.map(pin =>
this.attributeSeparator
+ this.attributePrefix
+ "CustomProperties "
+ SerializerFactory.getSerializer(PinEntity).serialize(pin)
)
.join("")
+ "\nEnd Object\n"
return result
}
}