mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-21 06:05:45 +08:00
Grammar fixed
This commit is contained in:
@@ -39,10 +39,7 @@ export default class Entity {
|
||||
fullKey,
|
||||
target[property],
|
||||
defaultValue,
|
||||
(t, _, v) => {
|
||||
console.log(v)
|
||||
t.push(v)
|
||||
})
|
||||
(t, _, v) => t.push(v))
|
||||
continue
|
||||
}
|
||||
if (defaultValue instanceof TypeInitialization) {
|
||||
|
||||
@@ -3,10 +3,7 @@ import ObjectReferenceEntity from "./ObjectReferenceEntity"
|
||||
|
||||
export default class FunctionReferenceEntity extends Entity {
|
||||
static attributes = {
|
||||
MemberParent: new ObjectReferenceEntity({
|
||||
type: "Class",
|
||||
path: "/Script/Engine.GameplayStatics"
|
||||
}),
|
||||
MemberParent: ObjectReferenceEntity,
|
||||
MemberName: ""
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,24 @@
|
||||
import Entity from "./Entity"
|
||||
|
||||
export default class Integer extends Entity {
|
||||
|
||||
static attributes = {
|
||||
value: 0
|
||||
}
|
||||
|
||||
constructor(value) {
|
||||
super()
|
||||
this.value = Math.round(new Number(value).valueOf())
|
||||
if (value?.constructor === String) {
|
||||
value = Number(value)
|
||||
}
|
||||
if (value?.constructor === Number) {
|
||||
value = {
|
||||
value: Math.round(value.valueOf())
|
||||
}
|
||||
}
|
||||
super(value)
|
||||
}
|
||||
|
||||
getAttributes() {
|
||||
return Integer.attributes
|
||||
}
|
||||
}
|
||||
15
js/entity/LocalizedTextEntity.js
Normal file
15
js/entity/LocalizedTextEntity.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import Entity from "./Entity"
|
||||
|
||||
export default class LocalizedTextEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
namespace: "",
|
||||
key: "",
|
||||
value: ""
|
||||
}
|
||||
|
||||
getAttributes() {
|
||||
return LocalizedTextEntity.attributes
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import VariableReferenceEntity from "./VariableReferenceEntity"
|
||||
export default class ObjectEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
Class: "",
|
||||
Class: ObjectReferenceEntity,
|
||||
Name: "",
|
||||
bIsPureFunc: new TypeInitialization(false, false),
|
||||
VariableReference: new TypeInitialization(new VariableReferenceEntity(), false),
|
||||
|
||||
@@ -3,7 +3,7 @@ import Entity from "./Entity"
|
||||
export default class ObjectReferenceEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
type: "None",
|
||||
type: "",
|
||||
path: ""
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@ export default class ObjectReferenceEntity extends Entity {
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.type + (this.path ? `'"${this.path}"'` : "")
|
||||
return (this.type ?? "") + (
|
||||
this.path
|
||||
? this.type ? `'"${this.path}"'` : this.path
|
||||
: ""
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,13 @@ import Entity from "./Entity";
|
||||
import Guid from "../Guid";
|
||||
import ObjectReferenceEntity from "./ObjectReferenceEntity";
|
||||
import TypeInitialization from "./TypeInitialization";
|
||||
import LocalizedTextEntity from "./LocalizedTextEntity";
|
||||
|
||||
export default class PinEntity extends Entity {
|
||||
static attributes = {
|
||||
PinId: Guid,
|
||||
PinName: [new TypeInitialization(5, true), "ciao"],
|
||||
PinName: "",
|
||||
PinFriendlyName: new TypeInitialization(new LocalizedTextEntity(), false),
|
||||
PinToolTip: "",
|
||||
Direction: new TypeInitialization("", false),
|
||||
PinType: {
|
||||
|
||||
@@ -6,23 +6,24 @@ import Parsimmon from "parsimmon"
|
||||
import PinEntity from "../entity/PinEntity"
|
||||
import Utility from "../Utility"
|
||||
import ObjectEntity from "../entity/ObjectEntity"
|
||||
import LocalizedTextEntity from "../entity/LocalizedTextEntity"
|
||||
|
||||
let P = Parsimmon
|
||||
|
||||
export default class Grammar {
|
||||
// General
|
||||
InlineWhitespace = _ => P.regex(/[^\S\n]+/)
|
||||
InlineOptWhitespace = _ => P.regex(/[^\S\n]*/)
|
||||
WhitespaceNewline = _ => P.regex(/[^\S\n]*\n\s*/)
|
||||
InlineWhitespace = _ => P.regex(/[^\S\n]+/).desc("inline whitespace")
|
||||
InlineOptWhitespace = _ => P.regex(/[^\S\n]*/).desc("inline optional whitespace")
|
||||
WhitespaceNewline = _ => P.regex(/[^\S\n]*\n\s*/).desc("whitespace with at least a newline")
|
||||
Null = r => P.seq(P.string("("), r.InlineOptWhitespace, P.string(")")).map(_ => null).desc("null: ()")
|
||||
None = _ => P.string("None").map(_ => new ObjectReferenceEntity({ type: "None" })).desc("none")
|
||||
Boolean = _ => P.alt(P.string("True"), P.string("False")).map(v => v === "True" ? true : false).desc("either True or False")
|
||||
Number = _ => P.regex(/[0-9]+(?:\.[0-9]+)?/).map(Number).desc("a number")
|
||||
Integer = _ => P.regex(/[0-9]+/).map(Integer).desc("an integer")
|
||||
Integer = _ => P.regex(/[0-9]+/).map(v => new Integer(v)).desc("an integer")
|
||||
String = _ => P.regex(/(?:[^"\\]|\\")*/).wrap(P.string('"'), P.string('"')).desc('string (with possibility to escape the quote using \")')
|
||||
Word = _ => P.regex(/[a-zA-Z]+/).desc("a word")
|
||||
Guid = _ => P.regex(/[0-9a-zA-Z]{32}/).desc("32 digit hexadecimal (accepts all the letters for safety) value")
|
||||
ReferencePath = _ => P.seq(P.string("/"), P.regex(/[a-zA-Z_]+/).sepBy1(P.string(".")).tieWith("."))
|
||||
ReferencePath = _ => P.seq(P.string("/"), P.regex(/[0-9a-zA-Z_]+/).sepBy1(P.string(".")).tieWith("."))
|
||||
.tie()
|
||||
.atLeast(2)
|
||||
.tie()
|
||||
@@ -45,7 +46,21 @@ export default class Grammar {
|
||||
)
|
||||
)
|
||||
AttributeName = r => r.Word.sepBy1(P.string(".")).tieWith(".").desc('words separated by ""')
|
||||
AttributeAnyValue = r => P.alt(r.Null, r.None, r.Boolean, r.Number, r.Integer, r.String, r.Guid, r.Reference)
|
||||
AttributeAnyValue = r => P.alt(r.Null, r.None, r.Boolean, r.Number, r.Integer, r.String, r.Guid, r.Reference, r.LocalizedText)
|
||||
LocalizedText = r => P.seqMap(
|
||||
P.string("NSLOCTEXT").skip(P.optWhitespace).skip(P.string("(")),
|
||||
r.String.trim(P.optWhitespace),
|
||||
P.string(","),
|
||||
r.String.trim(P.optWhitespace),
|
||||
P.string(","),
|
||||
r.String.trim(P.optWhitespace),
|
||||
P.string(")"),
|
||||
(_, namespace, __, key, ___, value, ____) => new LocalizedTextEntity({
|
||||
namespace: namespace,
|
||||
key: key,
|
||||
value: value
|
||||
})
|
||||
)
|
||||
static getGrammarForType(r, type, defaultGrammar) {
|
||||
switch (type) {
|
||||
case Boolean:
|
||||
@@ -60,13 +75,19 @@ export default class Grammar {
|
||||
return r.Guid
|
||||
case ObjectReferenceEntity:
|
||||
return r.Reference
|
||||
case LocalizedTextEntity:
|
||||
return r.LocalizedText
|
||||
case FunctionReferenceEntity:
|
||||
return r.FunctionReference
|
||||
case PinEntity:
|
||||
return r.Pin
|
||||
default:
|
||||
return defaultGrammar
|
||||
}
|
||||
}
|
||||
// Meta grammar
|
||||
static CreateAttributeGrammar = (r, attributeGrammar, attributeSupplier, valueSeparator = P.string("=")) =>
|
||||
attributeGrammar.skip(valueSeparator.trim(P.optWhitespace))
|
||||
static CreateAttributeGrammar = (r, attributeGrammar, attributeSupplier, valueSeparator = P.string("=").trim(P.optWhitespace)) =>
|
||||
attributeGrammar.skip(valueSeparator)
|
||||
.chain(attributeName => {
|
||||
const attributeKey = attributeName.split(".")
|
||||
const attribute = attributeSupplier(attributeKey)
|
||||
@@ -86,34 +107,29 @@ export default class Grammar {
|
||||
/** @type {Array} */
|
||||
let array = Utility.objectGet(entity, attributeKey, [])
|
||||
array.push(attributeValue)
|
||||
return Utility.objectSet(entity, attributeKey, array)
|
||||
return Utility.objectSet(entity, attributeKey, array, true)
|
||||
}
|
||||
: entity => Utility.objectSet(entity, attributeKey, attributeValue)
|
||||
: entity => Utility.objectSet(entity, attributeKey, attributeValue, true)
|
||||
) // returns attributeSetter
|
||||
})
|
||||
// Meta grammar
|
||||
static CreateMultiAttributeGrammar = (r, keyGrammar, entityType, attributeSupplier) =>
|
||||
/**
|
||||
* Basically this creates a parser that looks for a string like 'AttributeName (A=False,B="Something",)'
|
||||
* Basically this creates a parser that looks for a string like 'Key (A=False,B="Something",)'
|
||||
* Then it populates an object of type EntityType with the attribute values found inside the parentheses.
|
||||
*/
|
||||
P.seqObj(
|
||||
keyGrammar,
|
||||
P.optWhitespace,
|
||||
P.string("("),
|
||||
[
|
||||
"attributes", // this is the name of the attribute of object passed to map chained next
|
||||
Grammar.CreateAttributeGrammar(r, r.AttributeName, attributeSupplier)
|
||||
.trim(P.optWhitespace)
|
||||
.sepBy(P.string(","))
|
||||
.skip(P.regex(/,?/).then(P.optWhitespace)) // Optional trailing comma
|
||||
],
|
||||
P.string(')')
|
||||
).map(object => {
|
||||
let result = new entityType()
|
||||
object.attributes.forEach(attributeSetter => attributeSetter(result))
|
||||
return result
|
||||
})
|
||||
P.seqMap(
|
||||
P.seq(keyGrammar, P.optWhitespace, P.string("(")),
|
||||
Grammar.CreateAttributeGrammar(r, r.AttributeName, attributeSupplier)
|
||||
.trim(P.optWhitespace)
|
||||
.sepBy(P.string(","))
|
||||
.skip(P.regex(/,?/).then(P.optWhitespace)), // Optional trailing comma
|
||||
P.string(')'),
|
||||
(_, attributes, __) => {
|
||||
let result = new entityType()
|
||||
attributes.forEach(attributeSetter => attributeSetter(result))
|
||||
return result
|
||||
})
|
||||
FunctionReference = r => Grammar.CreateMultiAttributeGrammar(
|
||||
r,
|
||||
P.succeed(),
|
||||
@@ -129,13 +145,11 @@ export default class Grammar {
|
||||
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.string(" ")),
|
||||
Grammar.CreateAttributeGrammar(r, r.AttributeName, attributeKey => Utility.objectGet(ObjectEntity, attributeKey))
|
||||
Grammar.CreateAttributeGrammar(r, P.string("CustomProperties"), _ => ObjectEntity.attributes.CustomProperties, P.whitespace),
|
||||
Grammar.CreateAttributeGrammar(r, r.AttributeName, attributeKey => Utility.objectGet(ObjectEntity.attributes, attributeKey))
|
||||
)
|
||||
.trim(r.InlineOptWhitespace) // whitespace which is NOT newline
|
||||
.sepBy(P.string("\n"))
|
||||
.skip(r.WhitespaceNewline), // Optional trailing comma
|
||||
P.seq(P.string("End"), P.whitespace, P.string("Object")),
|
||||
.sepBy1(P.whitespace),
|
||||
P.seq(r.WhitespaceNewline, P.string("End"), P.whitespace, P.string("Object")),
|
||||
(_, attributes, __) => {
|
||||
let result = new ObjectEntity()
|
||||
attributes.forEach(attributeSetter => attributeSetter(result))
|
||||
|
||||
Reference in New Issue
Block a user