mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-21 06:05:45 +08:00
Better typing for grammars
This commit is contained in:
@@ -15,22 +15,24 @@ export default class LocalizedTextEntity extends IPrintableEntity {
|
||||
key: StringEntity.withDefault(),
|
||||
value: StringEntity.withDefault(),
|
||||
}
|
||||
static grammar = P.regArray(new RegExp(
|
||||
String.raw`${LocalizedTextEntity.lookbehind}\s*\(`
|
||||
+ String.raw`\s*"(?<namespace>${Grammar.Regex.InsideString.source})"\s*,`
|
||||
+ String.raw`\s*"(?<key>${Grammar.Regex.InsideString.source})"\s*,`
|
||||
+ String.raw`\s*"(?<value>${Grammar.Regex.InsideString.source})"\s*`
|
||||
+ String.raw`(?<trailing>,\s+)?`
|
||||
+ String.raw`\)`,
|
||||
"m"
|
||||
)).map(({ groups: { namespace, key, value, trailing } }) => {
|
||||
return new this({
|
||||
namespace: new (this.attributes.namespace)(Utility.unescapeString(namespace)),
|
||||
key: new (this.attributes.namespace)(Utility.unescapeString(key)),
|
||||
value: new (this.attributes.namespace)(Utility.unescapeString(value)),
|
||||
trailing: trailing !== undefined,
|
||||
})
|
||||
}).label("LocalizedTextEntity")
|
||||
static grammar = /** @type {P<LocalizedTextEntity>} */(
|
||||
P.regArray(new RegExp(
|
||||
String.raw`${LocalizedTextEntity.lookbehind}\s*\(`
|
||||
+ String.raw`\s*"(?<namespace>${Grammar.Regex.InsideString.source})"\s*,`
|
||||
+ String.raw`\s*"(?<key>${Grammar.Regex.InsideString.source})"\s*,`
|
||||
+ String.raw`\s*"(?<value>${Grammar.Regex.InsideString.source})"\s*`
|
||||
+ String.raw`(?<trailing>,\s+)?`
|
||||
+ String.raw`\)`,
|
||||
"m"
|
||||
)).map(({ groups: { namespace, key, value, trailing } }) => {
|
||||
return new this({
|
||||
namespace: new (this.attributes.namespace)(Utility.unescapeString(namespace)),
|
||||
key: new (this.attributes.namespace)(Utility.unescapeString(key)),
|
||||
value: new (this.attributes.namespace)(Utility.unescapeString(value)),
|
||||
trailing: trailing !== undefined,
|
||||
})
|
||||
}).label("LocalizedTextEntity")
|
||||
)
|
||||
|
||||
constructor(values = {}) {
|
||||
super(values)
|
||||
|
||||
Reference in New Issue
Block a user