mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-24 07:44:42 +08:00
Better typing for grammars
This commit is contained in:
@@ -8,21 +8,22 @@ export default class FormatTextEntity extends IPrintableEntity {
|
||||
|
||||
static attributeSeparator = ", "
|
||||
static lookbehind = ["LOCGEN_FORMAT_NAMED", "LOCGEN_FORMAT_ORDERED"]
|
||||
/** @type {P<FormatTextEntity>} */
|
||||
static grammar = P.lazy(() => P.seq(
|
||||
// Resulting regex: /(LOCGEN_FORMAT_NAMED|LOCGEN_FORMAT_ORDERED)\s*/
|
||||
P.reg(new RegExp(String.raw`(${this.lookbehind.join("|")})\s*\(\s*`), 1),
|
||||
P.alt(
|
||||
...[StringEntity, LocalizedTextEntity, InvariantTextEntity, FormatTextEntity].map(type => type.grammar)
|
||||
).sepBy(P.reg(/\s*\,\s*/)),
|
||||
P.reg(/\s*\)/)
|
||||
static grammar = /** @type {P<FormatTextEntity>} */(
|
||||
P.lazy(() => P.seq(
|
||||
// Resulting regex: /(LOCGEN_FORMAT_NAMED|LOCGEN_FORMAT_ORDERED)\s*/
|
||||
P.reg(new RegExp(String.raw`(${this.lookbehind.join("|")})\s*\(\s*`), 1),
|
||||
P.alt(
|
||||
...[StringEntity, LocalizedTextEntity, InvariantTextEntity, FormatTextEntity].map(type => type.grammar)
|
||||
).sepBy(P.reg(/\s*\,\s*/)),
|
||||
P.reg(/\s*\)/)
|
||||
)
|
||||
.map(([lookbehind, values]) => {
|
||||
const result = new this(values)
|
||||
result.lookbehind = lookbehind
|
||||
return result
|
||||
}))
|
||||
.label("FormatTextEntity")
|
||||
)
|
||||
.map(([lookbehind, values]) => {
|
||||
const result = new this(values)
|
||||
result.lookbehind = lookbehind
|
||||
return result
|
||||
}))
|
||||
.label("FormatTextEntity")
|
||||
|
||||
/** @param {(StringEntity | LocalizedTextEntity | InvariantTextEntity | FormatTextEntity)[]} values */
|
||||
constructor(values) {
|
||||
|
||||
Reference in New Issue
Block a user