"use strict";
/**
 * Copyright (c) Haiku 2016-2018. All rights reserved.
 */
Object.defineProperty(exports, "__esModule", { value: true });
function tokenize(source, regexps) {
    var tokens = [];
    var chunk = source;
    var total = chunk.length;
    var iterations = 0;
    while (chunk.length > 0) {
        for (var i = 0; i < regexps.length; i++) {
            var regexp = regexps[i];
            var match = regexp.re.exec(chunk);
            if (match) {
                var value = match[0];
                tokens.push({ value: value, type: regexp.type });
                // Need to slice the chunk at the value match length
                chunk = chunk.slice(match[0].length, chunk.length);
                break;
            }
        }
        // We've probably failed to parse correctly if we get here
        if (iterations++ > total) {
            throw new Error('Unable to tokenize expression');
        }
    }
    return tokens;
}
exports.default = tokenize;
//# sourceMappingURL=tokenize.js.map