mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
41 lines
972 B
JavaScript
Executable File
41 lines
972 B
JavaScript
Executable File
import P from "parsernostrum"
|
|
import IEntity from "./IEntity.js"
|
|
|
|
export default class InvariantTextEntity extends IEntity {
|
|
|
|
static lookbehind = "INVTEXT"
|
|
|
|
static grammar = this.createGrammar()
|
|
|
|
constructor(value = "") {
|
|
super()
|
|
this.value = value
|
|
}
|
|
|
|
/** @returns {P<InvariantTextEntity>} */
|
|
static createGrammar() {
|
|
return P.alt(
|
|
P.seq(
|
|
P.reg(new RegExp(`${this.lookbehind}\\s*\\(`)),
|
|
P.doubleQuotedString,
|
|
P.reg(/\s*\)/)
|
|
).map(([_0, value, _2]) => value),
|
|
P.reg(new RegExp(this.lookbehind)).map(() => "") // InvariantTextEntity can have no arguments
|
|
)
|
|
.map(value => new this(value))
|
|
.label("InvariantTextEntity")
|
|
}
|
|
|
|
doSerialize() {
|
|
return this.lookbehind + '("' + this.value + '")'
|
|
}
|
|
|
|
valueOf() {
|
|
return this.value
|
|
}
|
|
|
|
toString() {
|
|
return this.value
|
|
}
|
|
}
|