You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.3 KiB
JavaScript
103 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
const util = require("util");
|
|
|
|
const reorderOperatorExpressions = require("./index");
|
|
|
|
let operators = [{
|
|
associativity: "right",
|
|
operators: ["++"]
|
|
}, {
|
|
associativity: "left",
|
|
operators: ["*", "/"]
|
|
}, {
|
|
associativity: "left",
|
|
operators: ["+", "-"]
|
|
}, {
|
|
associativity: "right",
|
|
operators: ["//"]
|
|
}, {
|
|
associativity: "left",
|
|
operators: ["<", "<=", ">", ">="]
|
|
}, {
|
|
// NOTE: Special case, can only occur once in sequence!
|
|
associativity: "none",
|
|
operators: ["==", "!="]
|
|
}, {
|
|
associativity: "left",
|
|
operators: ["&&"]
|
|
}, {
|
|
associativity: "left",
|
|
operators: ["||"]
|
|
}, {
|
|
// NOTE: Special case, can only occur once in sequence!
|
|
associativity: "none",
|
|
operators: ["->"]
|
|
}];
|
|
|
|
// let testData = {
|
|
// type: "operatorExpression",
|
|
// operator: "+",
|
|
// left: { type: "variable", name: "a" },
|
|
// right: {
|
|
// type: "operatorExpression",
|
|
// operator: "+",
|
|
// left: { type: "variable", name: "b" },
|
|
// right: {
|
|
// type: "operatorExpression",
|
|
// operator: "-",
|
|
// left: { type: "variable", name: "c" },
|
|
// right: {
|
|
// type: "operatorExpression",
|
|
// operator: "+",
|
|
// left: { type: "variable", name: "d" },
|
|
// right: {
|
|
// type: "operatorExpression",
|
|
// operator: "-",
|
|
// left: { type: "variable", name: "e" },
|
|
// right: {
|
|
// type: "operatorExpression",
|
|
// operator: "+",
|
|
// left: { type: "variable", name: "f" },
|
|
// right: { type: "variable", name: "g" }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
let testData = {
|
|
type: "operatorExpression",
|
|
operator: "+",
|
|
left: { type: "variable", name: "a" },
|
|
right: {
|
|
type: "operatorExpression",
|
|
operator: "*",
|
|
left: { type: "variable", name: "b" },
|
|
right: {
|
|
type: "operatorExpression",
|
|
operator: "&&",
|
|
left: { type: "variable", name: "c" },
|
|
right: {
|
|
type: "operatorExpression",
|
|
operator: "*",
|
|
left: { type: "variable", name: "d" },
|
|
right: {
|
|
type: "operatorExpression",
|
|
operator: "-",
|
|
left: { type: "variable", name: "e" },
|
|
right: {
|
|
type: "operatorExpression",
|
|
operator: "+",
|
|
left: { type: "variable", name: "f" },
|
|
right: { type: "variable", name: "g" }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log(util.inspect(reorderOperatorExpressions(testData, operators), {colors: true, depth: null}));
|