mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-27 02:34:45 +08:00
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:
@@ -1,8 +1,31 @@
|
||||
import Parsimmon from "parsimmon"
|
||||
import PinEntity from "./PinEntity.js"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
|
||||
export default class UnknownPinEntity extends PinEntity {
|
||||
|
||||
static lookbehind = ""
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
static createGrammar() {
|
||||
return Parsimmon.lazy(() => Parsimmon.seq(
|
||||
Grammar.regexMap(
|
||||
new RegExp(`${Grammar.Regex.Symbol.source}\\s*\\(\\s*`),
|
||||
result => result[1] ?? ""
|
||||
),
|
||||
Grammar.createAttributeGrammar(this).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)
|
||||
|
||||
Reference in New Issue
Block a user