使用pegJs转义了一个字符串数据,但是不知道怎么把转义的数据再转换成我们需要的数据结构
转换出的数据
//转义前的数据
let o = '(LeftRightMove == "-20°" && ExceptResult == "65537") && is_support == "False" || (is_explorer == "False") || ExceptResult == "null" && (DownUpMove == "-20°" && Brightness == "1000lux")'
//转移后的数据
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "LogicalExpression",
"operator": "OR",
"conditionleft": {
"type": "LogicalExpression",
"operator": "OR",
"conditionleft": {
"type": "LogicalExpression",
"operator": "AND",
"conditionleft": {
"type": "LogicalExpression",
"operator": "AND",
"conditionleft": {
"type": "BinaryExpression",
"operator": "==",
"left": {
"type": "Identifier",
"name": "LeftRightMove"
},
"right": {
"type": "Literal",
"value": "-20°"
}
},
"conditionright": {
"type": "BinaryExpression",
"operator": "==",
"left": {
"type": "Identifier",
"name": "ExceptResult"
},
"right": {
"type": "Literal",
"value": "65537"
}
}
},
"conditionright": {
"type": "BinaryExpression",
"operator": "==",
"left": {
"type": "Identifier",
"name": "is_support"
},
"right": {
"type": "Literal",
"value": "False"
}
}
},
"conditionright": {
"type": "BinaryExpression",
"operator": "==",
"left": {
"type": "Identifier",
"name": "is_explorer"
},
"right": {
"type": "Literal",
"value": "False"
}
}
},
"conditionright": {
"type": "LogicalExpression",
"operator": "AND",
"conditionleft": {
"type": "BinaryExpression",
"operator": "==",
"left": {
"type": "Identifier",
"name": "ExceptResult"
},
"right": {
"type": "Literal",
"value": "null"
}
},
"conditionright": {
"type": "LogicalExpression",
"operator": "AND",
"conditionleft": {
"type": "BinaryExpression",
"operator": "==",
"left": {
"type": "Identifier",
"name": "DownUpMove"
},
"right": {
"type": "Literal",
"value": "-20°"
}
},
"conditionright": {
"type": "BinaryExpression",
"operator": "==",
"left": {
"type": "Identifier",
"name": "Brightness"
},
"right": {
"type": "Literal",
"value": "1000lux"
}
}
}
}
}
}
]
}
需要的数据结构
const rulesDataDefaultItem = {
relation: 'AND',
id: 1,
conditions: [
{
name: 'name',
operator: '=',
value: 'value',
selectvalues: 'AND',
},
{
name: 'name',
operator: '=',
value: 'value',
selectvalues: 'AND',
},
],
children: [
{
relation: 'AND',
id: 1,
conditions: [
{
name: 'name',
operator: '=',
value: 'value',
selectvalues: 'AND',
},
{
name: 'name',
operator: '=',
value: 'value',
selectvalues: 'AND',
},
],
children: [],
}
],
}
各位小伙伴有没有好的思路或者方法帮一下,万分感谢