mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-28 03:24:43 +08:00
More tests and fixed
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import P from "parsernostrum"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import IEntity from "./IEntity.js"
|
||||
|
||||
export default class AlternativesEntity extends IEntity {
|
||||
@@ -17,8 +16,8 @@ export default class AlternativesEntity extends IEntity {
|
||||
|
||||
static createGrammar() {
|
||||
const grammars = this.alternatives.map(entity => entity.grammar)
|
||||
if (grammars.includes(Grammar.unknownValue)) {
|
||||
return Grammar.unknownValue
|
||||
if (grammars.includes(this.unknownEntityGrammar)) {
|
||||
return this.unknownEntityGrammar
|
||||
}
|
||||
return P.alt(...grammars)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export default class ArrayEntity extends IEntity {
|
||||
}
|
||||
|
||||
/** @returns {P<ArrayEntity<IEntity>>} */
|
||||
static createGrammar(elementGrammar = this.type?.grammar ?? P.lazy(() => Grammar.unknownValue)) {
|
||||
static createGrammar(elementGrammar = this.type?.grammar ?? P.lazy(() => this.unknownEntityGrammar)) {
|
||||
return this.inlined
|
||||
? elementGrammar
|
||||
: P.seq(
|
||||
@@ -24,13 +24,9 @@ export default class ArrayEntity extends IEntity {
|
||||
elementGrammar.sepBy(Grammar.commaSeparation).opt(),
|
||||
P.reg(/\s*(,\s*)?\)/, 1),
|
||||
).map(([_0, values, trailing]) => {
|
||||
let self = this
|
||||
const hasTrailing = trailing !== undefined
|
||||
if (hasTrailing !== self.trailing) {
|
||||
self = self.flagTrailing(hasTrailing)
|
||||
}
|
||||
values = values instanceof Array ? values : []
|
||||
return new self(values)
|
||||
const result = new this(values)
|
||||
result.trailing = trailing !== undefined
|
||||
}).label(`ArrayEntity of ${this.type?.className() ?? "unknown values"}`)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,22 @@ import IEntity from "./IEntity.js"
|
||||
|
||||
export default class BooleanEntity extends IEntity {
|
||||
|
||||
static grammar = P.regArray(/(true)|false/i)
|
||||
.map(v => v[1] ? new this(true) : new this(false))
|
||||
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")
|
||||
|
||||
#uppercase = true
|
||||
get uppercase() {
|
||||
return this.#uppercase
|
||||
}
|
||||
set uppercase(value) {
|
||||
this.#uppercase = value
|
||||
}
|
||||
|
||||
constructor(value = false) {
|
||||
super()
|
||||
this.value = value
|
||||
@@ -16,13 +28,17 @@ export default class BooleanEntity extends IEntity {
|
||||
return this.value
|
||||
}
|
||||
|
||||
toString(insideString = false) {
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
printKey = this.Self().printKey,
|
||||
) {
|
||||
return this.value
|
||||
? insideString
|
||||
? "true"
|
||||
: "True"
|
||||
: insideString
|
||||
? "false"
|
||||
: "False"
|
||||
? this.#uppercase
|
||||
? "True"
|
||||
: "true"
|
||||
: this.#uppercase
|
||||
? "False"
|
||||
: "false"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ export default class IEntity {
|
||||
/** @type {P<IEntity>} */
|
||||
static grammar = /** @type {any} */(P.failure())
|
||||
|
||||
/** @type {P<IEntity>} */
|
||||
static unknownEntityGrammar
|
||||
|
||||
/** @type {{ [key: String]: typeof IEntity }} */
|
||||
static attributes = {}
|
||||
|
||||
@@ -38,6 +41,14 @@ export default class IEntity {
|
||||
static silent = false // Do not serialize if default
|
||||
static trailing = false // Add attribute separator after the last attribute when serializing
|
||||
|
||||
#trailing = this.Self().trailing
|
||||
get trailing() {
|
||||
return this.#trailing
|
||||
}
|
||||
set trailing(value) {
|
||||
this.#trailing = value
|
||||
}
|
||||
|
||||
/** @type {String | String[]} */
|
||||
static lookbehind = ""
|
||||
|
||||
@@ -180,16 +191,6 @@ export default class IEntity {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {typeof IEntity} T
|
||||
* @this {T}
|
||||
*/
|
||||
static flagTrailing(value = true) {
|
||||
const result = this.asUniqueClass()
|
||||
result.trailing = value
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {typeof IEntity} T
|
||||
* @this {InstanceType<T>}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import IEntity from "./IEntity.js"
|
||||
|
||||
export default class IdentifierEntity extends IEntity {
|
||||
|
||||
static attributeConverter = {
|
||||
fromAttribute: (value, type) => new IdentifierEntity(value),
|
||||
toAttribute: (value, type) => value.toString()
|
||||
}
|
||||
static grammar = Grammar.symbol.map(v => new this(v))
|
||||
|
||||
/** @param {String} value */
|
||||
constructor(value) {
|
||||
super()
|
||||
this.value = value
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return this.value
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.value.toString()
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@ import P from "parsernostrum"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import BooleanEntity from "./BooleanEntity.js"
|
||||
import IEntity from "./IEntity.js"
|
||||
import IdentifierEntity from "./IdentifierEntity.js"
|
||||
import StringEntity from "./StringEntity.js"
|
||||
import SymbolEntity from "./SymbolEntity.js"
|
||||
|
||||
export default class KeyBindingEntity extends IEntity {
|
||||
|
||||
@@ -14,19 +14,15 @@ export default class KeyBindingEntity extends IEntity {
|
||||
bCtrl: BooleanEntity,
|
||||
bAlt: BooleanEntity,
|
||||
bCmd: BooleanEntity,
|
||||
Key: IdentifierEntity,
|
||||
Key: SymbolEntity,
|
||||
}
|
||||
static grammar = P.alt(
|
||||
IdentifierEntity.grammar.map(identifier => {
|
||||
const result = new this()
|
||||
result.Key = identifier
|
||||
return result
|
||||
}),
|
||||
SymbolEntity.grammar.map(identifier => new this({ Key: identifier })),
|
||||
Grammar.createEntityGrammar(this)
|
||||
)
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
constructor(values) {
|
||||
super(values)
|
||||
/** @type {InstanceType<typeof KeyBindingEntity.attributes.ActionName>} */ this.ActionName
|
||||
/** @type {InstanceType<typeof KeyBindingEntity.attributes.bShift>} */ this.bShift
|
||||
/** @type {InstanceType<typeof KeyBindingEntity.attributes.bCtrl>} */ this.bCtrl
|
||||
|
||||
@@ -85,9 +85,9 @@ export default class LinearColorEntity extends IEntity {
|
||||
|
||||
static getWhite() {
|
||||
return new LinearColorEntity({
|
||||
R: 1,
|
||||
G: 1,
|
||||
B: 1,
|
||||
R: new ColorChannelEntity(1),
|
||||
G: new ColorChannelEntity(1),
|
||||
B: new ColorChannelEntity(1),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -24,11 +24,11 @@ export default class LocalizedTextEntity extends IPrintableEntity {
|
||||
+ String.raw`\)`,
|
||||
"m"
|
||||
)).map(({ groups: { namespace, key, value, trailing } }) => {
|
||||
const self = trailing ? this.flagTrailing() : this
|
||||
return new self({
|
||||
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")
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import BooleanEntity from "./BooleanEntity.js"
|
||||
import FunctionReferenceEntity from "./FunctionReferenceEntity.js"
|
||||
import GuidEntity from "./GuidEntity.js"
|
||||
import IEntity from "./IEntity.js"
|
||||
import IdentifierEntity from "./IdentifierEntity.js"
|
||||
import IntegerEntity from "./IntegerEntity.js"
|
||||
import LinearColorEntity from "./LinearColorEntity.js"
|
||||
import MacroGraphReferenceEntity from "./MacroGraphReferenceEntity.js"
|
||||
@@ -123,9 +122,9 @@ export default class ObjectEntity extends IEntity {
|
||||
bCommentBubblePinned: BooleanEntity,
|
||||
bCommentBubbleVisible: BooleanEntity,
|
||||
NodeComment: StringEntity,
|
||||
AdvancedPinDisplay: IdentifierEntity,
|
||||
AdvancedPinDisplay: SymbolEntity,
|
||||
DelegateReference: VariableReferenceEntity,
|
||||
EnabledState: IdentifierEntity,
|
||||
EnabledState: SymbolEntity,
|
||||
NodeGuid: GuidEntity,
|
||||
ErrorType: IntegerEntity,
|
||||
ErrorMsg: StringEntity,
|
||||
|
||||
@@ -3,9 +3,12 @@ import IEntity from "./IEntity.js"
|
||||
|
||||
export default class SymbolEntity extends IEntity {
|
||||
|
||||
static attributeConverter = {
|
||||
fromAttribute: (value, type) => new this(value),
|
||||
toAttribute: (value, type) => value.toString()
|
||||
}
|
||||
static grammar = Grammar.symbol.map(v => new this(v)).label("SymbolEntity")
|
||||
|
||||
/** @param {String} value */
|
||||
constructor(value = "") {
|
||||
super()
|
||||
this.value = value
|
||||
|
||||
@@ -9,7 +9,7 @@ export default class UnknownKeysEntity extends IEntity {
|
||||
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 =>
|
||||
Grammar.unknownValue.map(attributeValue =>
|
||||
this.unknownEntityGrammar.map(attributeValue =>
|
||||
values => values[attributeName] = attributeValue
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user