mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-14 00:54:48 +08:00
Better typing for grammars
This commit is contained in:
@@ -6,25 +6,26 @@ import NumberEntity from "./NumberEntity.js"
|
||||
export default class SimpleSerializationVectorEntity extends VectorEntity {
|
||||
|
||||
static attributeSeparator = ", "
|
||||
/** @type {P<SimpleSerializationVectorEntity>} */
|
||||
static grammar = P.alt(
|
||||
P.regArray(new RegExp(
|
||||
`(${NumberEntity.numberRegexSource})`
|
||||
+ String.raw`\s*,\s*`
|
||||
+ `(${NumberEntity.numberRegexSource})`
|
||||
+ String.raw`\s*,\s*`
|
||||
+ `(${NumberEntity.numberRegexSource})`
|
||||
))
|
||||
.map(([_, x, xPrecision, y, yPrecision, z, zPrecision]) => new this({
|
||||
X: new NumberEntity(x, xPrecision?.length),
|
||||
Y: new NumberEntity(y, yPrecision?.length),
|
||||
Z: new NumberEntity(z, zPrecision?.length),
|
||||
})),
|
||||
VectorEntity.grammar.map(v => new this({
|
||||
X: v.X,
|
||||
Y: v.Y,
|
||||
Z: v.Z,
|
||||
}))
|
||||
static grammar = /** @type {P<SimpleSerializationVectorEntity>} */(
|
||||
P.alt(
|
||||
P.regArray(new RegExp(
|
||||
`(${NumberEntity.numberRegexSource})`
|
||||
+ String.raw`\s*,\s*`
|
||||
+ `(${NumberEntity.numberRegexSource})`
|
||||
+ String.raw`\s*,\s*`
|
||||
+ `(${NumberEntity.numberRegexSource})`
|
||||
))
|
||||
.map(([_, x, xPrecision, y, yPrecision, z, zPrecision]) => new this({
|
||||
X: new NumberEntity(x, xPrecision?.length),
|
||||
Y: new NumberEntity(y, yPrecision?.length),
|
||||
Z: new NumberEntity(z, zPrecision?.length),
|
||||
})),
|
||||
VectorEntity.grammar.map(v => new this({
|
||||
X: v.X,
|
||||
Y: v.Y,
|
||||
Z: v.Z,
|
||||
}))
|
||||
)
|
||||
)
|
||||
|
||||
toString(
|
||||
|
||||
Reference in New Issue
Block a user