ArrayEntity parsing fixed

This commit is contained in:
barsdeveloper
2024-05-31 18:39:58 +02:00
parent ecc71b76d1
commit 8258572e56
6 changed files with 53 additions and 23 deletions

11
dist/ueblueprint.js vendored
View File

@@ -4525,7 +4525,14 @@ class ArrayEntity extends IEntity {
/** @type {typeof IEntity} */
static type
static grammar = this.createGrammar()
static #grammar
static get grammar() {
return this.#grammar ?? this.createGrammar()
}
static set grammar(value) {
this.#grammar = value;
}
//static grammar = this.createGrammar()
/** @param {ExtractType<T>[]} values */
constructor(values = []) {
@@ -4560,7 +4567,7 @@ class ArrayEntity extends IEntity {
this.asUniqueClass()
);
result.type = /** @type {ExtractType<T>} */(type);
this.grammar = result.createGrammar();
result.grammar = result.createGrammar();
return result
}

File diff suppressed because one or more lines are too long

View File

@@ -42,7 +42,7 @@ export default class ArrayEntity extends IEntity {
this.asUniqueClass()
)
result.type = /** @type {ExtractType<T>} */(type)
this.grammar = result.createGrammar()
result.grammar = result.createGrammar()
return result
}

View File

@@ -57,6 +57,7 @@ export default class IEntity {
this.#keys = [... new Set(value)]
}
/** @param {{ [key: String]: IEntity }} values */
constructor(values = {}) {
const keys = Utility.mergeArrays(Object.keys(values), Object.keys(this.Self().attributes))
for (const key of keys) {

View File

@@ -24,8 +24,4 @@ export default class UnknownKeysEntity extends IEntity {
attributes.forEach(attributeSetter => attributeSetter(values))
return new this(values)
}).label("UnknownKeysEntity")
constructor(values = {}) {
super(values)
}
}

View File

@@ -57,43 +57,69 @@ test("ArrayEntity", () => {
123,
3BEF2168446CAA32D5B54289FAB2F0BA,
Some(a=1, b="2")
)`)).toStrictEqual(new ArrayEntity([
)`)).toEqual(new ArrayEntity([
new StringEntity("alpha"),
new StringEntity("beta"),
new NumberEntity(123),
new GuidEntity("3BEF2168446CAA32D5B54289FAB2F0BA"),
new (UnknownKeysEntity.withLookbehind("Some"))({
a: 1,
b: "2",
a: new NumberEntity(1),
b: new StringEntity("2"),
})
]))
expect(grammar.parse(`(
A(first = (9,8,7,6,5), second = 00000000000000000000000000000000),
B(key="hello"),
)`)).toStrictEqual([
)`)).toEqual(new ArrayEntity([
new UnknownKeysEntity({
lookbehind: "A",
first: [9, 8, 7, 6, 5],
lookbehind: new StringEntity("A"),
first: new ArrayEntity([
new NumberEntity(9),
new NumberEntity(8),
new NumberEntity(7),
new NumberEntity(6),
new NumberEntity(5),
]),
second: new GuidEntity("00000000000000000000000000000000"),
}),
new UnknownKeysEntity({
lookbehind: "B",
key: "hello",
lookbehind: new StringEntity("B"),
key: new StringEntity("hello"),
})
])
]))
// Nested
expect(grammar.parse("((1, 2), (3, 4))")).toStrictEqual([[1, 2], [3, 4]])
expect(grammar.parse('(((1, 2), (3, 4)), 5)')).toStrictEqual([[[1, 2], [3, 4]], 5])
expect(grammar.parse("((1, 2), (3, 4))")).toEqual(new ArrayEntity([
new ArrayEntity([new NumberEntity(1), new NumberEntity(2)]),
new ArrayEntity([new NumberEntity(3), new NumberEntity(4)]),
]))
expect(grammar.parse('(((1, 2), (3, 4)), 5)')).toEqual(new ArrayEntity([
new ArrayEntity([
new ArrayEntity([new NumberEntity(1), new NumberEntity(2)]),
new ArrayEntity([new NumberEntity(3), new NumberEntity(4)])
]),
new NumberEntity(5)
]))
expect(grammar.parse(`(
One(a = (1,(2,(3,(4)))), b = ()),
)`)).toStrictEqual([
)`)).toEqual(new ArrayEntity([
new UnknownKeysEntity({
lookbehind: "One",
a: [1, [2, [3, [4]]]],
a: new ArrayEntity([
new NumberEntity(1),
new ArrayEntity([
new NumberEntity(2),
new ArrayEntity([
new NumberEntity(3),
new ArrayEntity([
new NumberEntity(4),
])
])
])
]),
b: null,
}),
])
]))
})
test("Boolean", () => {