Object grammar fix

This commit is contained in:
barsdeveloper
2021-10-25 00:01:19 +02:00
parent f80c9f8dc1
commit bee57a1402
4 changed files with 48 additions and 15 deletions

View File

@@ -13,13 +13,13 @@ export default class ObjectEntity extends Entity {
Class: ObjectReferenceEntity,
Name: "",
bIsPureFunc: new TypeInitialization(false, false),
VariableReference: new TypeInitialization(new VariableReferenceEntity(), false),
FunctionReference: new TypeInitialization(new FunctionReferenceEntity(), false),
TargetType: new TypeInitialization(new ObjectReferenceEntity(), false),
NodePosX: Integer,
NodePosY: Integer,
VariableReference: new TypeInitialization(null, false, VariableReferenceEntity),
FunctionReference: new TypeInitialization(null, false, FunctionReferenceEntity),
TargetType: new TypeInitialization(null, false, ObjectReferenceEntity),
NodePosX: 0,
NodePosY: 0,
NodeGuid: GuidEntity,
CustomProperties: [PinEntity]
CustomProperties: [new TypeInitialization(null, false, PinEntity)]
}
getAttributes() {

View File

@@ -25,7 +25,7 @@ export default class Grammar {
Word = _ => P.regex(/[a-zA-Z]+/).desc("a word")
Guid = _ => P.regex(/[0-9a-zA-Z]{32}/).map(v => new GuidEntity({ value: v })).desc("32 digit hexadecimal (accepts all the letters for safety) value")
PathSymbol = _ => P.regex(/[0-9a-zA-Z_]+/)
ReferencePath = _ => P.seq(P.string("/"), r.PathSymbol.sepBy1(P.string(".")).tieWith("."))
ReferencePath = r => P.seq(P.string("/"), r.PathSymbol.sepBy1(P.string(".")).tieWith("."))
.tie()
.atLeast(2)
.tie()
@@ -155,10 +155,21 @@ export default class Grammar {
PinEntity,
attributeKey => Utility.objectGet(PinEntity.attributes, attributeKey)
)
CustomProperties = r =>
P.string("CustomProperties")
.then(P.whitespace)
.then(r.Pin)
.map(pin => entity => {
/** @type {Array} */
let properties = Utility.objectGet(entity, ["CustomProperties"], [])
properties.push(pin)
Utility.objectSet(entity, ["CustomProperties"], properties, true)
})
Object = r => P.seqMap(
P.seq(P.string("Begin"), P.whitespace, P.string("Object"), P.whitespace),
P.alt(
Grammar.CreateAttributeGrammar(r, P.string("CustomProperties"), _ => ObjectEntity.attributes.CustomProperties, P.whitespace),
r.CustomProperties,
Grammar.CreateAttributeGrammar(r, r.AttributeName, attributeKey => Utility.objectGet(ObjectEntity.attributes, attributeKey))
)
.sepBy1(P.whitespace),