Skip to content

Commit

Permalink
Fix empty array grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
barsdeveloper committed Mar 25, 2024
1 parent cc9e3d8 commit 77a583e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions dist/ueblueprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3083,6 +3083,7 @@ class Grammar {
/**
* @template T
* @param {AttributeInfo<T>} attribute
* @returns {Parsernostrum<DescribedType<T>>}
*/
static grammarFor(attribute, type = attribute?.type, defaultGrammar = this.unknownValue) {
let result = defaultGrammar;
Expand All @@ -3092,9 +3093,9 @@ 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))
Expand Down
2 changes: 1 addition & 1 deletion dist/ueblueprint.min.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions js/serialization/Grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion js/serialization/initializeSerializerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand Down

0 comments on commit 77a583e

Please sign in to comment.