mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-03 23:55:04 +08:00
Fix empty array grammar
This commit is contained in:
@@ -69,6 +69,7 @@ export default class Grammar {
|
||||
/**
|
||||
* @template T
|
||||
* @param {AttributeInfo<T>} attribute
|
||||
* @returns {Parsernostrum<T>}
|
||||
*/
|
||||
static grammarFor(attribute, type = attribute?.type, defaultGrammar = this.unknownValue) {
|
||||
let result = defaultGrammar
|
||||
@@ -78,9 +79,9 @@ export default class Grammar {
|
||||
}
|
||||
result = Parsernostrum.seq(
|
||||
Parsernostrum.reg(/\(\s*/),
|
||||
this.grammarFor(undefined, type[0]).sepBy(this.commaSeparation),
|
||||
this.grammarFor(undefined, type[0]).sepBy(this.commaSeparation).opt(),
|
||||
Parsernostrum.reg(/\s*(?:,\s*)?\)/),
|
||||
).map(([_0, values, _3]) => values)
|
||||
).map(([_0, values, _3]) => values instanceof Array ? values : [])
|
||||
} else if (type instanceof Union) {
|
||||
result = type.values
|
||||
.map(v => this.grammarFor(undefined, v))
|
||||
@@ -89,6 +90,7 @@ export default class Grammar {
|
||||
: Parsernostrum.alt(acc, cur)
|
||||
)
|
||||
} else if (type instanceof MirroredEntity) {
|
||||
// @ts-expect-error
|
||||
return this.grammarFor(undefined, type.getTargetType())
|
||||
.map(v => new MirroredEntity(type.type, () => v))
|
||||
} else if (attribute?.constructor === Object) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import ObjectReferenceEntity from "../entity/ObjectReferenceEntity.js"
|
||||
import PathSymbolEntity from "../entity/PathSymbolEntity.js"
|
||||
import PinEntity from "../entity/PinEntity.js"
|
||||
import PinReferenceEntity from "../entity/PinReferenceEntity.js"
|
||||
import PinTypeEntity from "../entity/PinTypeEntity.js"
|
||||
import RBSerializationVector2DEntity from "../entity/RBSerializationVector2DEntity.js"
|
||||
import RotatorEntity from "../entity/RotatorEntity.js"
|
||||
import SimpleSerializationRotatorEntity from "../entity/SimpleSerializationRotatorEntity.js"
|
||||
@@ -39,7 +40,6 @@ import ObjectSerializer from "./ObjectSerializer.js"
|
||||
import Serializer from "./Serializer.js"
|
||||
import SerializerFactory from "./SerializerFactory.js"
|
||||
import ToStringSerializer from "./ToStringSerializer.js"
|
||||
import PinTypeEntity from "../entity/PinTypeEntity.js"
|
||||
|
||||
Grammar.unknownValue =
|
||||
Parsernostrum.alt(
|
||||
|
||||
Reference in New Issue
Block a user