js数据结构的转换(pegJS转义的数据)

使用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: [],
}
  ],
}

各位小伙伴有没有好的思路或者方法帮一下,万分感谢

可以采用递归来解析,通过分析转义后的表达式,抽象出逻辑表达式,二元表达式,一元表达式,分别对应转义后的不同对象,然后通过递归的方式把转义后的对象转换成需要的数据结构
仅供参考,望采纳,谢谢。

写一个递归 遍历上面的json 生成下面的数据