mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +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,4 +1,6 @@
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import IEntity from "./IEntity.js"
|
||||
import Parsimmon from "parsimmon"
|
||||
|
||||
export default class InvariantTextEntity extends IEntity {
|
||||
|
||||
@@ -9,10 +11,23 @@ export default class InvariantTextEntity extends IEntity {
|
||||
default: "",
|
||||
},
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
static createGrammar() {
|
||||
return Parsimmon.alt(
|
||||
Parsimmon.seq(
|
||||
Parsimmon.regex(new RegExp(`${this.lookbehind}\\s*\\(`)),
|
||||
Grammar.grammarFor(this.attributes.value),
|
||||
Parsimmon.regex(/\s*\)/)
|
||||
)
|
||||
.map(([_0, value, _2]) => value),
|
||||
Parsimmon.regex(new RegExp(this.lookbehind)) // InvariantTextEntity can not have arguments
|
||||
.map(() => "")
|
||||
).map(value => new this(value))
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
if (values.constructor !== Object) {
|
||||
|
||||
Reference in New Issue
Block a user