"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findPathTo = void 0;
exports.parse = parse;
exports.getAST = getAST;
exports.evaluate = evaluate;
exports.getAbstractSyntaxTree = getAbstractSyntaxTree;
const tslib_1 = require("tslib");
const evaluator_1 = require("./evaluator");
// @ts-ignore
const parser_1 = tslib_1.__importDefault(require("./parser"));
var utils_1 = require("./utils");
Object.defineProperty(exports, "findPathTo", { enumerable: true, get: function () { return utils_1.findPathTo; } });
const getParser = () => {
    return parser_1.default;
};
function parse(input) {
    const ast = getParser().parse(input.trim());
    const evaluate = (context) => {
        const result = (0, evaluator_1.evaluateNode)(ast, context);
        const lastResult = result[result.length - 1];
        return lastResult;
    };
    return { ast, evaluate };
}
function getAST(input) {
    const { ast } = parse(input);
    return ast;
}
const cache = {};
function evaluate(input, context) {
    cache[input] = cache[input] || parse(input);
    return cache[input].evaluate(context);
}
function getAbstractSyntaxTree(expression) {
    const { ast } = parse(expression);
    return ast;
}
