// @ts-ignore
import parser from './parser';
const cache = {};
const getParser = () => {
    return parser;
};
export 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;
}
