Files
ueblueprint/js/serialization/GeneralSerializer.js
barsdeveloper 41b741e8b8 Small fixes
2022-01-08 18:57:37 +01:00

27 lines
960 B
JavaScript
Executable File

import Grammar from "./Grammar"
import Serializer from "./Serializer"
export default class GeneralSerializer extends Serializer {
constructor(wrap, entityType, prefix, separator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter) {
wrap = wrap ?? (v => `(${v})`)
super(entityType, prefix, separator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter)
this.wrap = wrap
}
read(value) {
let grammar = Grammar.getGrammarForType(Serializer.grammar, this.entityType)
const parseResult = grammar.parse(value)
if (!parseResult.status) {
console.error("Error when trying to parse the entity " + this.entityType.prototype.constructor.name)
return parseResult
}
return parseResult.value
}
write(object) {
let result = this.wrap(this.subWrite([], object))
return result
}
}