diff --git a/js/entity/ArrayEntity.js b/js/entity/ArrayEntity.js index da5791b..f3ba6da 100644 --- a/js/entity/ArrayEntity.js +++ b/js/entity/ArrayEntity.js @@ -7,7 +7,9 @@ export default class ArrayEntity extends IEntity { /** @type {typeof IEntity} */ static type - static grammar = this.createGrammar() + static grammar = /** @type {P>} */( + this.createGrammar() + ) get length() { return this.values.length @@ -43,8 +45,8 @@ export default class ArrayEntity extends IEntity { const result = /** @type {typeof ArrayEntity> & {type: T, grammar: P>> }} */( this.asUniqueClass() ) - result.type = /** @type {ExtractType} */(type) - result.grammar = result.createGrammar() + result.type = type + result.grammar = /** @type {P} */(result.createGrammar()) return result } diff --git a/js/entity/BooleanEntity.js b/js/entity/BooleanEntity.js index 70449a0..43d8569 100755 --- a/js/entity/BooleanEntity.js +++ b/js/entity/BooleanEntity.js @@ -3,13 +3,15 @@ import IEntity from "./IEntity.js" export default class BooleanEntity extends IEntity { - static grammar = P.regArray(/(true)|(True)|(false)|(False)/) - .map(v => { - const result = (v[1] ?? v[2]) ? new this(true) : new this(false) - result.uppercase = (v[2] ?? v[4]) !== undefined - return result - }) - .label("BooleanEntity") + static grammar = /** @type {P} */( + P.regArray(/(true)|(True)|(false)|(False)/) + .map(v => { + const result = (v[1] ?? v[2]) ? new this(true) : new this(false) + result.uppercase = (v[2] ?? v[4]) !== undefined + return result + }) + .label("BooleanEntity") + ) #uppercase = true get uppercase() { diff --git a/js/entity/ByteEntity.js b/js/entity/ByteEntity.js index 2614943..b1eedb5 100755 --- a/js/entity/ByteEntity.js +++ b/js/entity/ByteEntity.js @@ -3,7 +3,9 @@ import IntegerEntity from "./IntegerEntity.js" export default class ByteEntity extends IntegerEntity { - static grammar = P.numberByte.map(v => new this(v)) + static grammar = /** @type {P} */( + P.numberByte.map(v => new this(v)) + ) get value() { return super.value diff --git a/js/entity/ColorChannelEntity.js b/js/entity/ColorChannelEntity.js index 7bbfe7e..02352ae 100644 --- a/js/entity/ColorChannelEntity.js +++ b/js/entity/ColorChannelEntity.js @@ -3,7 +3,9 @@ import IEntity from "./IEntity.js" export default class ColorChannelEntity extends IEntity { - static grammar = P.number.map(v => new this(v)) + static grammar = /** @type {P} */( + P.number.map(v => new this(v)) + ) constructor(value = 0) { super() diff --git a/js/entity/EnumDisplayValueEntity.js b/js/entity/EnumDisplayValueEntity.js index 8d2084f..f6eaaee 100755 --- a/js/entity/EnumDisplayValueEntity.js +++ b/js/entity/EnumDisplayValueEntity.js @@ -4,5 +4,7 @@ import EnumEntity from "./EnumEntity.js" export default class EnumDisplayValueEntity extends EnumEntity { - static grammar = P.reg(Grammar.Regex.InsideString).map(v => new this(v)) + static grammar = /** @type {P} */( + P.reg(Grammar.Regex.InsideString).map(v => new this(v)) + ) } diff --git a/js/entity/EnumEntity.js b/js/entity/EnumEntity.js index d5d0824..cef42fa 100755 --- a/js/entity/EnumEntity.js +++ b/js/entity/EnumEntity.js @@ -1,7 +1,10 @@ +import P from "parsernostrum" import Grammar from "../serialization/Grammar.js" import SymbolEntity from "./SymbolEntity.js" export default class EnumEntity extends SymbolEntity { - static grammar = Grammar.symbol.map(v => new this(v)) + static grammar = /** @type {P} */( + Grammar.symbol.map(v => new this(v)) + ) } diff --git a/js/entity/FormatTextEntity.js b/js/entity/FormatTextEntity.js index 12bc1ce..d609e70 100644 --- a/js/entity/FormatTextEntity.js +++ b/js/entity/FormatTextEntity.js @@ -8,21 +8,22 @@ export default class FormatTextEntity extends IPrintableEntity { static attributeSeparator = ", " static lookbehind = ["LOCGEN_FORMAT_NAMED", "LOCGEN_FORMAT_ORDERED"] - /** @type {P} */ - 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} */( + 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) { diff --git a/js/entity/FunctionReferenceEntity.js b/js/entity/FunctionReferenceEntity.js index 7ab6c21..fd99ebd 100755 --- a/js/entity/FunctionReferenceEntity.js +++ b/js/entity/FunctionReferenceEntity.js @@ -13,8 +13,9 @@ export default class FunctionReferenceEntity extends IEntity { MemberName: StringEntity, MemberGuid: GuidEntity, } - /** @type {P} */ - static grammar = Grammar.createEntityGrammar(this, Grammar.commaSeparation, false, 0) + static grammar = /** @type {P} */( + Grammar.createEntityGrammar(this, Grammar.commaSeparation, false, 0) + ) constructor(values) { super(values) diff --git a/js/entity/GuidEntity.js b/js/entity/GuidEntity.js index a4be325..aed7d13 100755 --- a/js/entity/GuidEntity.js +++ b/js/entity/GuidEntity.js @@ -10,7 +10,9 @@ if (typeof window === "undefined") { export default class GuidEntity extends IEntity { - static grammar = P.reg(/[0-9A-F]{32}/i).map(v => new this(v)).label("GuidEntity") + static grammar = /** @type {P} */( + P.reg(/[0-9A-F]{32}/i).map(v => new this(v)).label("GuidEntity") + ) static generateGuid() { let values = new Uint32Array(4) diff --git a/js/entity/Integer64Entity.js b/js/entity/Integer64Entity.js index 1b7c454..c4e2387 100755 --- a/js/entity/Integer64Entity.js +++ b/js/entity/Integer64Entity.js @@ -3,7 +3,9 @@ import IEntity from "./IEntity.js" export default class Integer64Entity extends IEntity { - static grammar = P.numberBigInteger.map(v => new this(v)) + static grammar = /** @type {P} */( + P.numberBigInteger.map(v => new this(v)) + ) /** @type {bigint} */ #value diff --git a/js/entity/IntegerEntity.js b/js/entity/IntegerEntity.js index 9fd1805..33e518a 100755 --- a/js/entity/IntegerEntity.js +++ b/js/entity/IntegerEntity.js @@ -3,7 +3,9 @@ import NumberEntity from "./NumberEntity.js" export default class IntegerEntity extends NumberEntity { - static grammar = P.numberInteger.map(v => new this(v)) + static grammar = /** @type {P} */( + P.numberInteger.map(v => new this(v)) + ) get value() { return super.value diff --git a/js/entity/InvariantTextEntity.js b/js/entity/InvariantTextEntity.js index e72dc33..9be33c1 100644 --- a/js/entity/InvariantTextEntity.js +++ b/js/entity/InvariantTextEntity.js @@ -1,20 +1,22 @@ -import Parsernostrum from "parsernostrum" +import P from "parsernostrum" import IPrintableEntity from "./IPrintableEntity.js" export default class InvariantTextEntity extends IPrintableEntity { static lookbehind = "INVTEXT" - static grammar = Parsernostrum.alt( - Parsernostrum.seq( - Parsernostrum.reg(new RegExp(`${this.lookbehind}\\s*\\(`)), - Parsernostrum.doubleQuotedString, - Parsernostrum.reg(/\s*\)/) - ).map(([_0, value, _2]) => Number(value)), - Parsernostrum.reg(new RegExp(this.lookbehind)).map(() => 0) // InvariantTextEntity can not have arguments + static grammar = /** @type {P} */( + P.alt( + P.seq( + P.reg(new RegExp(`${this.lookbehind}\\s*\\(`)), + P.doubleQuotedString, + P.reg(/\s*\)/) + ).map(([_0, value, _2]) => Number(value)), + P.reg(new RegExp(this.lookbehind)).map(() => 0) // InvariantTextEntity can not have arguments + ) + .map(value => new this(value)) + .label("InvariantTextEntity") ) - .map(value => new this(value)) - .label("InvariantTextEntity") constructor(value = "") { super() @@ -22,13 +24,13 @@ export default class InvariantTextEntity extends IPrintableEntity { } print() { - let xxxx = Parsernostrum.alt( - Parsernostrum.seq( - Parsernostrum.reg(new RegExp(`${this.lookbehind}\\s*\\(`)), - Parsernostrum.doubleQuotedString, - Parsernostrum.reg(/\s*\)/) + let xxxx = P.alt( + P.seq( + P.reg(new RegExp(`${this.lookbehind}\\s*\\(`)), + P.doubleQuotedString, + P.reg(/\s*\)/) ).map(([_0, value, _2]) => Number(value)), - Parsernostrum.reg(new RegExp(this.lookbehind)).map(() => 0) // InvariantTextEntity can not have arguments + P.reg(new RegExp(this.lookbehind)).map(() => 0) // InvariantTextEntity can not have arguments ) return this.value } diff --git a/js/entity/KeyBindingEntity.js b/js/entity/KeyBindingEntity.js index a27419b..178c734 100644 --- a/js/entity/KeyBindingEntity.js +++ b/js/entity/KeyBindingEntity.js @@ -16,10 +16,11 @@ export default class KeyBindingEntity extends IEntity { bCmd: BooleanEntity, Key: SymbolEntity, } - /** @type {P} */ - static grammar = P.alt( - SymbolEntity.grammar.map(identifier => new this({ Key: identifier })), - Grammar.createEntityGrammar(this) + static grammar = /** @type {P} */( + P.alt( + SymbolEntity.grammar.map(identifier => new this({ Key: identifier })), + Grammar.createEntityGrammar(this) + ) ) constructor(values) { diff --git a/js/entity/LinearColorEntity.js b/js/entity/LinearColorEntity.js index b15d402..f1fcfa2 100644 --- a/js/entity/LinearColorEntity.js +++ b/js/entity/LinearColorEntity.js @@ -14,7 +14,9 @@ export default class LinearColorEntity extends IEntity { B: ColorChannelEntity.withDefault(), A: ColorChannelEntity.withDefault(type => new type(1)), } - static grammar = Grammar.createEntityGrammar(this).label("LinearColorEntity") + static grammar = /** @type {P} */( + Grammar.createEntityGrammar(this).label("LinearColorEntity") + ) #H = new ColorChannelEntity() get H() { diff --git a/js/entity/LocalizedTextEntity.js b/js/entity/LocalizedTextEntity.js index 13dd0db..e5fcf48 100755 --- a/js/entity/LocalizedTextEntity.js +++ b/js/entity/LocalizedTextEntity.js @@ -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*"(?${Grammar.Regex.InsideString.source})"\s*,` - + String.raw`\s*"(?${Grammar.Regex.InsideString.source})"\s*,` - + String.raw`\s*"(?${Grammar.Regex.InsideString.source})"\s*` - + String.raw`(?,\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} */( + P.regArray(new RegExp( + String.raw`${LocalizedTextEntity.lookbehind}\s*\(` + + String.raw`\s*"(?${Grammar.Regex.InsideString.source})"\s*,` + + String.raw`\s*"(?${Grammar.Regex.InsideString.source})"\s*,` + + String.raw`\s*"(?${Grammar.Regex.InsideString.source})"\s*` + + String.raw`(?,\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) diff --git a/js/entity/MacroGraphReferenceEntity.js b/js/entity/MacroGraphReferenceEntity.js index dbfdacf..ba07527 100755 --- a/js/entity/MacroGraphReferenceEntity.js +++ b/js/entity/MacroGraphReferenceEntity.js @@ -1,3 +1,4 @@ +import P from "parsernostrum" import Grammar from "../serialization/Grammar.js" import GuidEntity from "./GuidEntity.js" import IEntity from "./IEntity.js" @@ -11,7 +12,9 @@ export default class MacroGraphReferenceEntity extends IEntity { GraphBlueprint: ObjectReferenceEntity, GraphGuid: GuidEntity, } - static grammar = Grammar.createEntityGrammar(this) + static grammar = /** @type {P} */( + Grammar.createEntityGrammar(this) + ) constructor(values) { super(values) diff --git a/js/entity/NaturalNumberEntity.js b/js/entity/NaturalNumberEntity.js index 43df9fb..1ad3243 100755 --- a/js/entity/NaturalNumberEntity.js +++ b/js/entity/NaturalNumberEntity.js @@ -4,7 +4,9 @@ import IntegerEntity from "./IntegerEntity.js" export default class NaturalNumberEntity extends IntegerEntity { - static grammar = P.numberNatural.map(v => new this(v)) + static grammar = /** @type {P} */( + P.numberNatural.map(v => new this(v)) + ) get value() { return super.value diff --git a/js/entity/NullEntity.js b/js/entity/NullEntity.js index 60bffc1..2612a88 100644 --- a/js/entity/NullEntity.js +++ b/js/entity/NullEntity.js @@ -3,9 +3,11 @@ import IEntity from "./IEntity.js" export default class NullEntity extends IEntity { - // @ts-expect-error - static grammar = P.reg(new RegExp(String.raw`\(${P.whitespaceInlineOpt.getParser().regexp.source}\)`)) - .map(v => new this()) + static grammar = /** @type {P} */( + // @ts-expect-error + P.reg(new RegExp(String.raw`\(${P.whitespaceInlineOpt.getParser().regexp.source}\)`)) + .map(v => new this()) + ) toString( insideString = false, diff --git a/js/entity/NumberEntity.js b/js/entity/NumberEntity.js index 59161cb..f6a9cc7 100755 --- a/js/entity/NumberEntity.js +++ b/js/entity/NumberEntity.js @@ -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(`(?${this.numberRegexSource})|(?\\+?inf)|(?-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} */( + P.regArray( + new RegExp(`(?${this.numberRegexSource})|(?\\+?inf)|(?-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() { diff --git a/js/entity/ObjectEntity.js b/js/entity/ObjectEntity.js index fd3ae5f..ed34ef5 100755 --- a/js/entity/ObjectEntity.js +++ b/js/entity/ObjectEntity.js @@ -169,31 +169,32 @@ export default class ObjectEntity extends IEntity { } ) ) - /** @type {P} */ - static grammar = P.seq( - P.reg(/Begin +Object/), + static grammar = /** @type {P} */( P.seq( - P.whitespace, - P.alt( - this.createSubObjectGrammar(), - this.customPropertyGrammar, - Grammar.createAttributeGrammar(this, P.reg(Grammar.Regex.MultipleWordsSymbols)), - Grammar.createAttributeGrammar(this, Grammar.attributeNameQuoted, undefined, (obj, k, v) => - Utility.objectSet(obj, ["attributes", ...k, "quoted"], true) - ), - this.inlinedArrayEntryGrammar, + P.reg(/Begin +Object/), + P.seq( + P.whitespace, + P.alt( + this.createSubObjectGrammar(), + this.customPropertyGrammar, + Grammar.createAttributeGrammar(this, P.reg(Grammar.Regex.MultipleWordsSymbols)), + Grammar.createAttributeGrammar(this, Grammar.attributeNameQuoted, undefined, (obj, k, v) => + Utility.objectSet(obj, ["attributes", ...k, "quoted"], true) + ), + this.inlinedArrayEntryGrammar, + ) ) + .map(([_0, entry]) => entry) + .many(), + P.reg(/\s+End +Object/), ) - .map(([_0, entry]) => entry) - .many(), - P.reg(/\s+End +Object/), + .map(([_0, attributes, _2]) => { + const values = {} + attributes.forEach(attributeSetter => attributeSetter(values)) + return new this(values) + }) + .label("ObjectEntity") ) - .map(([_0, attributes, _2]) => { - const values = {} - attributes.forEach(attributeSetter => attributeSetter(values)) - return new this(values) - }) - .label("ObjectEntity") static grammarMultipleObjects = P.seq( P.whitespaceOpt, this.grammar, @@ -302,7 +303,7 @@ export default class ObjectEntity extends IEntity { const pinObject = this[Configuration.subObjectAttributeNameFromReference(objectReference, true)] if (pinObject) { const pinEntity = PinEntity.fromLegacyObject(pinObject) - pinEntity.LinkedTo = [] + pinEntity.LinkedTo = new (PinEntity.attributes.LinkedTo)() this.getCustomproperties(true).push(pinEntity) Utility.objectSet(this, ["attributes", "CustomProperties", "ignored"], true) } @@ -321,21 +322,14 @@ export default class ObjectEntity extends IEntity { if (this.getType() === Configuration.paths.materialExpressionComponentMask) { // The following attributes are too generic therefore not assigned a MirroredEntity const rgbaPins = Configuration.rgba.map(pinName => - this.getPinEntities().find(pin => pin.PinName === pinName && (pin.recomputesNodeTitleOnChange = true)) + this.getPinEntities().find(pin => pin.PinName.toString() === pinName && (pin.recomputesNodeTitleOnChange = true)) ) const attribute = {} - obj.R = new ( - MirroredEntity.of(BooleanEntity).withDefault().flagSilent() - )(() => rgbaPins[0].DefaultValue) - obj.G = new ( - MirroredEntity.of(BooleanEntity).withDefault().flagSilent() - )(() => rgbaPins[1].DefaultValue) - obj.B = new ( - MirroredEntity.of(BooleanEntity).withDefault().flagSilent() - )(() => rgbaPins[2].DefaultValue) - obj.A = new ( - MirroredEntity.of(BooleanEntity).withDefault().flagSilent() - )(() => rgbaPins[3].DefaultValue) + const silentBool = MirroredEntity.of(BooleanEntity).withDefault().flagSilent() + obj["R"] = new silentBool(() => rgbaPins[0].DefaultValue) + obj["G"] = new silentBool(() => rgbaPins[1].DefaultValue) + obj["B"] = new silentBool(() => rgbaPins[2].DefaultValue) + obj["A"] = new silentBool(() => rgbaPins[3].DefaultValue) obj.keys = [...Configuration.rgba, ...super.keys.filter(k => !Configuration.rgba.includes(k))] } } @@ -591,7 +585,7 @@ export default class ObjectEntity extends IEntity { } getDelegatePin() { - return this.getCustomproperties().find(pin => pin.PinType.PinCategory === "delegate") + return this.getCustomproperties().find(pin => pin.PinType.PinCategory.toString() === "delegate") } nodeColor() { diff --git a/js/entity/ObjectReferenceEntity.js b/js/entity/ObjectReferenceEntity.js index 8537cbe..2c84e32 100755 --- a/js/entity/ObjectReferenceEntity.js +++ b/js/entity/ObjectReferenceEntity.js @@ -29,12 +29,13 @@ export default class ObjectReferenceEntity extends IEntity { ) ).map(([full, type, path]) => new this(type, path, full)) static typeReferenceGrammar = this.typeReference.map(v => new this(v, "", v)) - /** @type {P} */ - static grammar = P.alt( - this.fullReferenceSerializedGrammar, - this.fullReferenceGrammar, - this.typeReferenceGrammar, - ).label("ObjectReferenceEntity") + static grammar = /** @type {P} */( + P.alt( + this.fullReferenceSerializedGrammar, + this.fullReferenceGrammar, + this.typeReferenceGrammar, + ).label("ObjectReferenceEntity") + ) #type get type() { diff --git a/js/entity/PinEntity.js b/js/entity/PinEntity.js index d2c84b4..a467582 100755 --- a/js/entity/PinEntity.js +++ b/js/entity/PinEntity.js @@ -92,8 +92,9 @@ export default class PinEntity extends IEntity { bAdvancedView: BooleanEntity.withDefault(), bOrphanedPin: BooleanEntity.withDefault(), } - /** @type {P} */ - static grammar = Grammar.createEntityGrammar(this) + static grammar = /** @type {P} */( + Grammar.createEntityGrammar(this) + ) #recomputesNodeTitleOnChange = false set recomputesNodeTitleOnChange(value) { diff --git a/js/entity/PinReferenceEntity.js b/js/entity/PinReferenceEntity.js index 48ab076..6083c71 100755 --- a/js/entity/PinReferenceEntity.js +++ b/js/entity/PinReferenceEntity.js @@ -5,13 +5,15 @@ import SymbolEntity from "./SymbolEntity.js" export default class PinReferenceEntity extends IEntity { - static grammar = P.seq( - SymbolEntity.grammar, - P.whitespace, - GuidEntity.grammar + static grammar = /** @type {P} */( + P.seq( + SymbolEntity.grammar, + P.whitespace, + GuidEntity.grammar + ) + .map(([objectName, _1, pinGuid]) => new this(objectName, pinGuid)) + .label("PinReferenceEntity") ) - .map(([objectName, _1, pinGuid]) => new this(objectName, pinGuid)) - .label("PinReferenceEntity") /** * @param {SymbolEntity} objectName diff --git a/js/entity/PinTypeEntity.js b/js/entity/PinTypeEntity.js index bb62736..b3bbe0c 100755 --- a/js/entity/PinTypeEntity.js +++ b/js/entity/PinTypeEntity.js @@ -1,3 +1,4 @@ +import P from "parsernostrum" import Grammar from "../serialization/Grammar.js" import BooleanEntity from "./BooleanEntity.js" import FunctionReferenceEntity from "./FunctionReferenceEntity.js" @@ -21,7 +22,9 @@ export default class PinTypeEntity extends IEntity { bIsUObjectWrapper: BooleanEntity.withDefault(), bSerializeAsSinglePrecisionFloat: BooleanEntity.withDefault(), } - static grammar = Grammar.createEntityGrammar(this).label("PinTypeEntity") + static grammar = /** @type {P} */( + Grammar.createEntityGrammar(this).label("PinTypeEntity") + ) constructor(values = {}) { super(values) diff --git a/js/entity/RBSerializationVector2DEntity.js b/js/entity/RBSerializationVector2DEntity.js index ee3f7fb..fd5f1b6 100644 --- a/js/entity/RBSerializationVector2DEntity.js +++ b/js/entity/RBSerializationVector2DEntity.js @@ -4,7 +4,7 @@ import Vector2DEntity from "./Vector2DEntity.js" export default class RBSerializationVector2DEntity extends Vector2DEntity { - static grammar = P.alt( + static grammar = /** @type {P} */(P.alt( P.regArray(new RegExp( /X\s*=\s*/.source + "(?" + Grammar.numberRegexSource + ")" + "\\s+" @@ -14,5 +14,5 @@ export default class RBSerializationVector2DEntity extends Vector2DEntity { Y: Number(y), })), Vector2DEntity.grammar - ).label("RBSerializationVector2DEntity") + ).label("RBSerializationVector2DEntity")) } diff --git a/js/entity/RotatorEntity.js b/js/entity/RotatorEntity.js index 573a30a..82a778a 100644 --- a/js/entity/RotatorEntity.js +++ b/js/entity/RotatorEntity.js @@ -1,3 +1,4 @@ +import P from "parsernostrum" import Grammar from "../serialization/Grammar.js" import IEntity from "./IEntity.js" import NumberEntity from "./NumberEntity.js" @@ -10,7 +11,9 @@ export default class RotatorEntity extends IEntity { P: NumberEntity.withDefault(), Y: NumberEntity.withDefault(), } - static grammar = Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("RotatorEntity") + static grammar = /** @type {P} */( + Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("RotatorEntity") + ) constructor(values) { super(values) diff --git a/js/entity/ScriptVariableEntity.js b/js/entity/ScriptVariableEntity.js index 4c839f9..627d2d1 100644 --- a/js/entity/ScriptVariableEntity.js +++ b/js/entity/ScriptVariableEntity.js @@ -1,3 +1,4 @@ +import P from "parsernostrum" import Grammar from "../serialization/Grammar.js" import GuidEntity from "./GuidEntity.js" import IEntity from "./IEntity.js" @@ -10,7 +11,9 @@ export default class ScriptVariableEntity extends IEntity { ScriptVariable: ObjectReferenceEntity, OriginalChangeId: GuidEntity, } - static grammar = Grammar.createEntityGrammar(this).label("ScriptVariableEntity") + static grammar = /** @type {P} */( + Grammar.createEntityGrammar(this).label("ScriptVariableEntity") + ) constructor(values = {}) { super(values) diff --git a/js/entity/SimpleSerializationRotatorEntity.js b/js/entity/SimpleSerializationRotatorEntity.js index d19ef74..06289bb 100644 --- a/js/entity/SimpleSerializationRotatorEntity.js +++ b/js/entity/SimpleSerializationRotatorEntity.js @@ -6,25 +6,26 @@ import NumberEntity from "./NumberEntity.js" export default class SimpleSerializationRotatorEntity extends RotatorEntity { static attributeSeparator = ", " - /** @type {P} */ - static grammar = P.alt( - P.regArray(new RegExp( - `(${NumberEntity.numberRegexSource})` - + String.raw`\s*,\s*` - + `(${NumberEntity.numberRegexSource})` - + String.raw`\s*,\s*` - + `(${NumberEntity.numberRegexSource})` - )).map(([_, p, pPrecision, y, yPrecision, r, rPrecision]) => new this({ - R: new NumberEntity(r, rPrecision?.length), - P: new NumberEntity(p, pPrecision?.length), - Y: new NumberEntity(y, yPrecision?.length), - })), - RotatorEntity.grammar.map(v => new this({ - R: v.R, - P: v.P, - Y: v.Y, - })) - ).label("SimpleSerializationRotatorEntity") + static grammar = /** @type {P} */( + P.alt( + P.regArray(new RegExp( + `(${NumberEntity.numberRegexSource})` + + String.raw`\s*,\s*` + + `(${NumberEntity.numberRegexSource})` + + String.raw`\s*,\s*` + + `(${NumberEntity.numberRegexSource})` + )).map(([_, p, pPrecision, y, yPrecision, r, rPrecision]) => new this({ + R: new NumberEntity(r, rPrecision?.length), + P: new NumberEntity(p, pPrecision?.length), + Y: new NumberEntity(y, yPrecision?.length), + })), + RotatorEntity.grammar.map(v => new this({ + R: v.R, + P: v.P, + Y: v.Y, + })) + ).label("SimpleSerializationRotatorEntity") + ) toString( insideString = false, diff --git a/js/entity/SimpleSerializationVector2DEntity.js b/js/entity/SimpleSerializationVector2DEntity.js index 950e328..2d498cd 100644 --- a/js/entity/SimpleSerializationVector2DEntity.js +++ b/js/entity/SimpleSerializationVector2DEntity.js @@ -6,21 +6,22 @@ import NumberEntity from "./NumberEntity.js" export default class SimpleSerializationVector2DEntity extends Vector2DEntity { static attributeSeparator = ", " - /** @type {P} */ - static grammar = P.alt( - P.regArray(new RegExp( - `(${NumberEntity.numberRegexSource})` - + String.raw`\s*,\s*` - + `(${NumberEntity.numberRegexSource})` - )).map(([_, x, xPrecision, y, yPrecision]) => new this({ - X: new NumberEntity(x, xPrecision?.length), - Y: new NumberEntity(y, yPrecision?.length), - })), - Vector2DEntity.grammar.map(v => new this({ - X: v.X, - Y: v.Y, - })) - ).label("SimpleSerializationVector2DEntity") + static grammar = /** @type {P} */( + P.alt( + P.regArray(new RegExp( + `(${NumberEntity.numberRegexSource})` + + String.raw`\s*,\s*` + + `(${NumberEntity.numberRegexSource})` + )).map(([_, x, xPrecision, y, yPrecision]) => new this({ + X: new NumberEntity(x, xPrecision?.length), + Y: new NumberEntity(y, yPrecision?.length), + })), + Vector2DEntity.grammar.map(v => new this({ + X: v.X, + Y: v.Y, + })) + ).label("SimpleSerializationVector2DEntity") + ) toString( insideString = false, diff --git a/js/entity/SimpleSerializationVector4DEntity.js b/js/entity/SimpleSerializationVector4DEntity.js index 9921ba6..ac12fd5 100644 --- a/js/entity/SimpleSerializationVector4DEntity.js +++ b/js/entity/SimpleSerializationVector4DEntity.js @@ -4,7 +4,7 @@ import Vector4DEntity from "./Vector4DEntity.js" export default class SimpleSerializationVector4DEntity extends Vector4DEntity { - static grammar = this.createGrammar() + static grammar = /** @type {P } */(this.createGrammar()) static createGrammar() { const number = Grammar.numberRegexSource diff --git a/js/entity/SimpleSerializationVectorEntity.js b/js/entity/SimpleSerializationVectorEntity.js index 1419736..3c79d59 100644 --- a/js/entity/SimpleSerializationVectorEntity.js +++ b/js/entity/SimpleSerializationVectorEntity.js @@ -6,25 +6,26 @@ import NumberEntity from "./NumberEntity.js" export default class SimpleSerializationVectorEntity extends VectorEntity { static attributeSeparator = ", " - /** @type {P} */ - 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} */( + 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( diff --git a/js/entity/StringEntity.js b/js/entity/StringEntity.js index 51dd42c..391be59 100755 --- a/js/entity/StringEntity.js +++ b/js/entity/StringEntity.js @@ -4,9 +4,11 @@ import IPrintableEntity from "./IPrintableEntity.js" export default class StringEntity extends IPrintableEntity { - static grammar = P.doubleQuotedString - .map(insideString => new this(Utility.unescapeString(insideString))) - .label("StringEntity") + static grammar = /** @type {P} */( + P.doubleQuotedString + .map(insideString => new this(Utility.unescapeString(insideString))) + .label("StringEntity") + ) /** @param {String} value */ constructor(value = "") { diff --git a/js/entity/SymbolEntity.js b/js/entity/SymbolEntity.js index 13a2c42..52c0133 100644 --- a/js/entity/SymbolEntity.js +++ b/js/entity/SymbolEntity.js @@ -1,3 +1,4 @@ +import P from "parsernostrum" import Grammar from "../serialization/Grammar.js" import IEntity from "./IEntity.js" @@ -7,7 +8,9 @@ export default class SymbolEntity extends IEntity { fromAttribute: (value, type) => new this(value), toAttribute: (value, type) => value.toString() } - static grammar = Grammar.symbol.map(v => new this(v)).label("SymbolEntity") + static grammar = /** @type {P} */( + Grammar.symbol.map(v => new this(v)).label("SymbolEntity") + ) constructor(value = "") { super() diff --git a/js/entity/TerminalTypeEntity.js b/js/entity/TerminalTypeEntity.js index da2b819..26334b0 100644 --- a/js/entity/TerminalTypeEntity.js +++ b/js/entity/TerminalTypeEntity.js @@ -1,3 +1,5 @@ +import P from "parsernostrum" +import Grammar from "../serialization/Grammar.js" import BooleanEntity from "./BooleanEntity.js" import IEntity from "./IEntity.js" import StringEntity from "./StringEntity.js" @@ -12,6 +14,9 @@ export default class TerminalTypeEntity extends IEntity { bTerminalIsWeakPointer: BooleanEntity, bTerminalIsUObjectWrapper: BooleanEntity, } + static grammar = /** @type {P} */( + Grammar.createEntityGrammar(this) + ) constructor(values) { super(values) diff --git a/js/entity/UnknownKeysEntity.js b/js/entity/UnknownKeysEntity.js index 0f47809..50136a1 100644 --- a/js/entity/UnknownKeysEntity.js +++ b/js/entity/UnknownKeysEntity.js @@ -4,27 +4,28 @@ import IEntity from "./IEntity.js" export default class UnknownKeysEntity extends IEntity { - /** @type {P} */ - static grammar = P.seq( - // Lookbehind - P.reg(new RegExp(`(${Grammar.Regex.Path.source}|${Grammar.Regex.Symbol.source}\\s*)?\\(\\s*`), 1), - P.seq(Grammar.attributeName, Grammar.equalSeparation).map(([attribute, equal]) => attribute) - .chain(attributeName => - this.unknownEntityGrammar.map(attributeValue => - values => values[attributeName] = attributeValue + static grammar = /** @type {P} */( + P.seq( + // Lookbehind + P.reg(new RegExp(`(${Grammar.Regex.Path.source}|${Grammar.Regex.Symbol.source}\\s*)?\\(\\s*`), 1), + P.seq(Grammar.attributeName, Grammar.equalSeparation).map(([attribute, equal]) => attribute) + .chain(attributeName => + this.unknownEntityGrammar.map(attributeValue => + values => values[attributeName] = attributeValue + ) ) - ) - .sepBy(Grammar.commaSeparation), - P.reg(/\s*(?:,\s*)?\)/), - ).map(([lookbehind, attributes, _2]) => { - lookbehind ??= "" - let values = {} - if (lookbehind.length) { - values.lookbehind = lookbehind - } - attributes.forEach(attributeSetter => attributeSetter(values)) - return new this(values) - }).label("UnknownKeysEntity") + .sepBy(Grammar.commaSeparation), + P.reg(/\s*(?:,\s*)?\)/), + ).map(([lookbehind, attributes, _2]) => { + lookbehind ??= "" + let values = {} + if (lookbehind.length) { + values.lookbehind = lookbehind + } + attributes.forEach(attributeSetter => attributeSetter(values)) + return new this(values) + }).label("UnknownKeysEntity") + ) static { IEntity.unknownEntity = this diff --git a/js/entity/UnknownPinEntity.js b/js/entity/UnknownPinEntity.js index 68b9738..b8aeb28 100755 --- a/js/entity/UnknownPinEntity.js +++ b/js/entity/UnknownPinEntity.js @@ -4,17 +4,19 @@ import PinEntity from "./PinEntity.js" export default class UnknownPinEntity extends PinEntity { - static grammar = P.seq( - P.reg(new RegExp(`(${Grammar.Regex.Symbol.source})\\s*\\(\\s*`), 1), - Grammar.createAttributeGrammar(this).sepBy(Grammar.commaSeparation), - P.reg(/\s*(?:,\s*)?\)/) - ).map(([lookbehind, attributes, _2]) => { - lookbehind ??= "" - let values = {} - if (lookbehind.length) { - values.lookbehind = lookbehind - } - attributes.forEach(attributeSetter => attributeSetter(values)) - return new this(values) - }).label("UnknownPinEntity") + static grammar = /** @type {P} */( + P.seq( + P.reg(new RegExp(`(${Grammar.Regex.Symbol.source})\\s*\\(\\s*`), 1), + Grammar.createAttributeGrammar(this).sepBy(Grammar.commaSeparation), + P.reg(/\s*(?:,\s*)?\)/) + ).map(([lookbehind, attributes, _2]) => { + lookbehind ??= "" + let values = {} + if (lookbehind.length) { + values.lookbehind = lookbehind + } + attributes.forEach(attributeSetter => attributeSetter(values)) + return new this(values) + }).label("UnknownPinEntity") + ) } diff --git a/js/entity/VariableReferenceEntity.js b/js/entity/VariableReferenceEntity.js index 7614079..eeaf61f 100755 --- a/js/entity/VariableReferenceEntity.js +++ b/js/entity/VariableReferenceEntity.js @@ -1,3 +1,4 @@ +import P from "parsernostrum" import Grammar from "../serialization/Grammar.js" import BooleanEntity from "./BooleanEntity.js" import GuidEntity from "./GuidEntity.js" @@ -13,7 +14,9 @@ export default class VariableReferenceEntity extends IEntity { MemberGuid: GuidEntity, bSelfContext: BooleanEntity, } - static grammar = Grammar.createEntityGrammar(this).label("VariableReferenceEntity") + static grammar = /** @type {P} */( + Grammar.createEntityGrammar(this).label("VariableReferenceEntity") + ) constructor(values) { super(values) diff --git a/js/entity/Vector2DEntity.js b/js/entity/Vector2DEntity.js index 4b72858..56acfb8 100644 --- a/js/entity/Vector2DEntity.js +++ b/js/entity/Vector2DEntity.js @@ -10,8 +10,9 @@ export default class Vector2DEntity extends IEntity { X: NumberEntity.withDefault(), Y: NumberEntity.withDefault(), } - /** @type {P} */ - static grammar = Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("Vector2DEntity") + static grammar = /** @type {P} */( + Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("Vector2DEntity") + ) constructor(values) { super(values) diff --git a/js/entity/Vector4DEntity.js b/js/entity/Vector4DEntity.js index 81bcca7..a0a95ef 100644 --- a/js/entity/Vector4DEntity.js +++ b/js/entity/Vector4DEntity.js @@ -1,3 +1,4 @@ +import P from "parsernostrum" import Grammar from "../serialization/Grammar.js" import IEntity from "./IEntity.js" import NumberEntity from "./NumberEntity.js" @@ -11,7 +12,9 @@ export default class Vector4DEntity extends IEntity { Z: NumberEntity.withDefault(), W: NumberEntity.withDefault(), } - static grammar = Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("Vector4DEntity") + static grammar = /** @type {P} */( + Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("Vector4DEntity") + ) constructor(values) { super(values) diff --git a/js/entity/VectorEntity.js b/js/entity/VectorEntity.js index 2b96157..e6d416a 100644 --- a/js/entity/VectorEntity.js +++ b/js/entity/VectorEntity.js @@ -11,8 +11,9 @@ export default class VectorEntity extends IEntity { Y: NumberEntity.withDefault(), Z: NumberEntity.withDefault(), } - /** @type {P} */ - static grammar = Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("VectorEntity") + static grammar = /** @type {P} */( + Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("VectorEntity") + ) constructor(values) { super(values)