he
This commit is contained in:
parent
df7c642077
commit
80df04d3f6
3 changed files with 37 additions and 12 deletions
|
|
@ -17,12 +17,13 @@ export function FormatProperties(properties: any) {
|
||||||
delete properties.anchor
|
delete properties.anchor
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(property_bags))
|
if (Object.keys(property_bags).length) {
|
||||||
if (properties.property_bags) {
|
if (properties.property_bags) {
|
||||||
properties.property_bags = { ...property_bags, ...properties.property_bags }
|
properties.property_bags = { ...property_bags, ...properties.property_bags }
|
||||||
} else {
|
} else {
|
||||||
properties.property_bags = property_bags
|
properties.property_bags = property_bags
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return properties
|
return properties
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
import { RandomBindingString } from "../../components/Utils.js"
|
import { RandomBindingString } from "../../components/Utils.js"
|
||||||
import { Expression, GenBinding } from "./types.js"
|
import { Expression, GenBinding } from "./types.js"
|
||||||
|
|
||||||
export const FuntionMap = new Map<
|
type Callback = (...args: Expression[]) => {
|
||||||
string,
|
genBindings?: GenBinding[]
|
||||||
(...args: Expression[]) => {
|
value: Expression
|
||||||
genBindings?: GenBinding[]
|
}
|
||||||
value: Expression
|
|
||||||
}
|
export const FuntionMap = new Map<string, Callback>()
|
||||||
>()
|
|
||||||
|
function callFn(name: string, ...args: Expression[]) {
|
||||||
|
return FuntionMap.get(name)!(...args)
|
||||||
|
}
|
||||||
|
|
||||||
// Default Functions
|
// Default Functions
|
||||||
FuntionMap.set("abs", number => {
|
FuntionMap.set("abs", number => {
|
||||||
|
|
@ -26,8 +29,29 @@ FuntionMap.set("new", expression => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
FuntionMap.set("max", (...args) => {
|
FuntionMap.set("sqrt", number => {
|
||||||
|
const rtn = RandomBindingString(16),
|
||||||
|
$1 = RandomBindingString(16),
|
||||||
|
$2 = RandomBindingString(16)
|
||||||
|
|
||||||
|
const { genBindings: absValue, value: absRtn } = callFn("abs")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
value: "#a",
|
genBindings: [
|
||||||
|
{
|
||||||
|
source: `${number} * 100 / 2`,
|
||||||
|
target: $1,
|
||||||
|
},
|
||||||
|
...absValue!,
|
||||||
|
{
|
||||||
|
source: `${absRtn} > 1`,
|
||||||
|
target: $2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: `(${number} < 0) * -1 + (${number} > -1) * (${$2} * ((${rtn} + ${number} / ${rtn}) / 2) + (not ${$2}) * ${rtn})`,
|
||||||
|
target: rtn,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
value: rtn,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Parser } from ".."
|
import { Parser, Panel } from ".."
|
||||||
|
|
||||||
const { gen, out } = new Parser("new(#a + #b) >= #b").out()
|
const { gen, out } = new Parser("abs(#a)").out()
|
||||||
|
|
||||||
console.log(gen, out)
|
console.log(gen, out)
|
||||||
|
|
|
||||||
Reference in a new issue