This commit is contained in:
barsdeveloper
2024-05-31 15:09:48 +02:00
parent 1c2778fbf8
commit ecc71b76d1
45 changed files with 1191 additions and 1078 deletions

View File

@@ -1,13 +1,14 @@
import P from "parsernostrum"
import Grammar from "../serialization/Grammar.js"
import IEntity from "./IEntity.js"
export default class NumberEntity extends IEntity {
static grammar = P.regArray(
new RegExp(`(${P.number.getParser().parser.regexp.source})|(\\+?inf)|(-inf)`)
new RegExp(`(${Grammar.numberRegexSource})|(\\+?inf)|(-inf)`)
).map(([_0, n, plusInf, minusInf]) => new this(
n ? Number(n) : plusInf ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY
))
)).label("NumberEntity")
/** @type {Number} */
#value
@@ -31,6 +32,12 @@ export default class NumberEntity extends IEntity {
}
toString() {
if (this.value === Number.POSITIVE_INFINITY) {
return "+inf"
}
if (this.value === Number.NEGATIVE_INFINITY) {
return "-inf"
}
return this.value.toString()
}
}