mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:17:41 +08:00
* 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
52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
import Grammar from "../serialization/Grammar.js"
|
|
import IEntity from "./IEntity.js"
|
|
import Parsimmon from "parsimmon"
|
|
|
|
export default class UnknownKeysEntity extends IEntity {
|
|
|
|
static attributes = {
|
|
...super.attributes,
|
|
lookbehind: {
|
|
default: "",
|
|
ignored: true,
|
|
},
|
|
}
|
|
static {
|
|
this.cleanupAttributes(this.attributes)
|
|
}
|
|
static grammar = this.createGrammar()
|
|
|
|
static createGrammar() {
|
|
return Parsimmon.seq(
|
|
// Lookbehind
|
|
Grammar.regexMap(
|
|
new RegExp(`(${Grammar.Regex.Path.source}|${Grammar.Regex.Symbol.source}\\s*)?\\(\\s*`),
|
|
result => result[1] ?? ""
|
|
),
|
|
Grammar.attributeName
|
|
.skip(Grammar.equalSeparation)
|
|
.chain(attributeName =>
|
|
Grammar.unknownValue
|
|
.map(attributeValue =>
|
|
values => values[attributeName] = attributeValue
|
|
)
|
|
)
|
|
.sepBy1(Grammar.commaSeparation),
|
|
Parsimmon.regex(/\s*(?:,\s*)?\)/),
|
|
)
|
|
.map(([lookbehind, attributes, _2]) => {
|
|
let values = {}
|
|
if (lookbehind.length) {
|
|
values.lookbehind = lookbehind
|
|
}
|
|
attributes.forEach(attributeSetter => attributeSetter(values))
|
|
return new this(values)
|
|
})
|
|
}
|
|
|
|
constructor(values) {
|
|
super(values, true)
|
|
/** @type {String} */ this.lookbehind
|
|
}
|
|
}
|