mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-16 10:54:42 +08:00
Better typing for grammars
This commit is contained in:
@@ -1,20 +1,22 @@
|
||||
import Parsernostrum from "parsernostrum"
|
||||
import P from "parsernostrum"
|
||||
import IPrintableEntity from "./IPrintableEntity.js"
|
||||
|
||||
export default class InvariantTextEntity extends IPrintableEntity {
|
||||
|
||||
static lookbehind = "INVTEXT"
|
||||
|
||||
static grammar = Parsernostrum.alt(
|
||||
Parsernostrum.seq(
|
||||
Parsernostrum.reg(new RegExp(`${this.lookbehind}\\s*\\(`)),
|
||||
Parsernostrum.doubleQuotedString,
|
||||
Parsernostrum.reg(/\s*\)/)
|
||||
).map(([_0, value, _2]) => Number(value)),
|
||||
Parsernostrum.reg(new RegExp(this.lookbehind)).map(() => 0) // InvariantTextEntity can not have arguments
|
||||
static grammar = /** @type {P<InvariantTextEntity>} */(
|
||||
P.alt(
|
||||
P.seq(
|
||||
P.reg(new RegExp(`${this.lookbehind}\\s*\\(`)),
|
||||
P.doubleQuotedString,
|
||||
P.reg(/\s*\)/)
|
||||
).map(([_0, value, _2]) => Number(value)),
|
||||
P.reg(new RegExp(this.lookbehind)).map(() => 0) // InvariantTextEntity can not have arguments
|
||||
)
|
||||
.map(value => new this(value))
|
||||
.label("InvariantTextEntity")
|
||||
)
|
||||
.map(value => new this(value))
|
||||
.label("InvariantTextEntity")
|
||||
|
||||
constructor(value = "") {
|
||||
super()
|
||||
@@ -22,13 +24,13 @@ export default class InvariantTextEntity extends IPrintableEntity {
|
||||
}
|
||||
|
||||
print() {
|
||||
let xxxx = Parsernostrum.alt(
|
||||
Parsernostrum.seq(
|
||||
Parsernostrum.reg(new RegExp(`${this.lookbehind}\\s*\\(`)),
|
||||
Parsernostrum.doubleQuotedString,
|
||||
Parsernostrum.reg(/\s*\)/)
|
||||
let xxxx = P.alt(
|
||||
P.seq(
|
||||
P.reg(new RegExp(`${this.lookbehind}\\s*\\(`)),
|
||||
P.doubleQuotedString,
|
||||
P.reg(/\s*\)/)
|
||||
).map(([_0, value, _2]) => Number(value)),
|
||||
Parsernostrum.reg(new RegExp(this.lookbehind)).map(() => 0) // InvariantTextEntity can not have arguments
|
||||
P.reg(new RegExp(this.lookbehind)).map(() => 0) // InvariantTextEntity can not have arguments
|
||||
)
|
||||
return this.value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user