"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTokens = void 0;
const tslib_1 = require("tslib");
// @ts-ignore
const parser_1 = tslib_1.__importDefault(require("./parser"));
const cache = {};
const getParser = () => {
    return parser_1.default;
};
function getTokens(expression) {
    if (cache[expression]) {
        return cache[expression];
    }
    const tokens = [];
    const lexer = getParser().lexer;
    lexer.setInput(expression);
    while (!lexer.done) {
        const id = lexer.lex();
        const location = lexer.matched.length;
        tokens.push({
            type: getParser().terminals_[id],
            value: lexer.yytext,
            range: [location - lexer.yytext.length, location],
        });
    }
    // remove eof
    tokens.pop();
    cache[expression] = tokens;
    return tokens;
}
exports.getTokens = getTokens;
