Better typing for grammars

This commit is contained in:
barsdeveloper
2024-06-06 23:16:21 +02:00
parent ad4ba2c46d
commit 98ebdd78b2
40 changed files with 301 additions and 233 deletions

View File

@@ -5,13 +5,15 @@ import IEntity from "./IEntity.js"
export default class NumberEntity extends IEntity {
static numberRegexSource = String.raw`${Grammar.numberRegexSource}(?<=(?:\.(\d*0+))?)`
static grammar = P.regArray(
new RegExp(`(?<n>${this.numberRegexSource})|(?<posInf>\\+?inf)|(?<negInf>-inf)`)
).map(({ 2: precision, groups: { n, posInf, negInf } }) => new this(
n ? Number(n) : posInf ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY,
precision?.length
static grammar = /** @type {P<NumberEntity>} */(
P.regArray(
new RegExp(`(?<n>${this.numberRegexSource})|(?<posInf>\\+?inf)|(?<negInf>-inf)`)
).map(({ 2: precision, groups: { n, posInf, negInf } }) => new this(
n ? Number(n) : posInf ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY,
precision?.length
)
).label("NumberEntity")
)
).label("NumberEntity")
#precision = 0
get precision() {