mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-27 18:54:44 +08:00
Various fixes
This commit is contained in:
25
js/serialization/GeneralSerializer.js
Executable file
25
js/serialization/GeneralSerializer.js
Executable file
@@ -0,0 +1,25 @@
|
||||
import Grammar from "./Grammar"
|
||||
import Serializer from "./Serializer"
|
||||
|
||||
export default class GeneralSerializer extends Serializer {
|
||||
|
||||
constructor(keyword = "", entityType, prefix = "", separator = ",", trailingSeparator = false) {
|
||||
super(entityType, prefix, separator, trailingSeparator)
|
||||
this.keyword = keyword
|
||||
}
|
||||
|
||||
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.key ?? ""}(${this.subWrite([], object)})`
|
||||
return result
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user