function parse$2(str, options) {
    if (options === void 0) { options = {}; }
    var tokens = lexer(str);
    var _a = options.prefixes, prefixes = _a === void 0 ? "./" : _a;
    var defaultPattern = "[^" + escapeString(options.delimiter || "/#?") + "]+?";
    var result = [];
    var key = 0;
    var i = 0;
    var path = "";
    var tryConsume = function (type) {
        if (i < tokens.length && tokens[i].type === type)
            return tokens[i++].value;
    };
    var mustConsume = function (type) {
        var value = tryConsume(type);
        if (value !== undefined)
            return value;
        var _a = tokens[i], nextType = _a.type, index = _a.index;
        throw new TypeError("Unexpected " + nextType + " at " + index + ", expected " + type);
    };
    var consumeText = function () {
        var result = "";
        var value;
        // tslint:disable-next-line
        while ((value = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR"))) {
            result += value;
        }
        return result;
    };
    while (i < tokens.length) {
        var char = tryConsume("CHAR");
        var name = tryConsume("NAME");
        var pattern = tryConsume("PATTERN");
        if (name || pattern) {
            var prefix = char || "";
            if (prefixes.indexOf(prefix) === -1) {
                path += prefix;
                prefix = "";
            }
            if (path) {
                result.push(path);
                path = "";
            }
            result.push({
                name: name || key++,
                prefix: prefix,
                suffix: "",
                pattern: pattern || defaultPattern,
                modifier: tryConsume("MODIFIER") || ""
            });
            continue;
        }
        var value = char || tryConsume("ESCAPED_CHAR");
        if (value) {
            path += value;
            continue;
        }
        if (path) {
            result.push(path);
            path = "";
        }
        var open = tryConsume("OPEN");
        if (open) {
            var prefix = consumeText();
            var name_1 = tryConsume("NAME") || "";
            var pattern_1 = tryConsume("PATTERN") || "";
            var suffix = consumeText();
            mustConsume("CLOSE");
            result.push({
                name: name_1 || (pattern_1 ? key++ : ""),
                pattern: name_1 && !pattern_1 ? defaultPattern : pattern_1,
                prefix: prefix,
                suffix: suffix,
                modifier: tryConsume("MODIFIER") || ""
            });
            continue;
        }
        mustConsume("END");
    }
    return result;
}
/**
 * Parse a string for the raw tokens.
 */
Parse a string for the raw tokens.
Parse a string for the raw tokens .
function parse$2(str, options) {
    if (options === void 0) { options = {}; }
    var tokens = lexer(str);
    var _a = options.prefixes, prefixes = _a === void 0 ? "./" : _a;
    var defaultPattern = "[^" + escapeString(options.delimiter || "/#?") + "]+?";
    var result = [];
    var key = 0;
    var i = 0;
    var path = "";
    var tryConsume = function (type) {
        if (i < tokens.length && tokens[i].type === type)
            return tokens[i++].value;
    };
    var mustConsume = function (type) {
        var value = tryConsume(type);
        if (value !== undefined)
            return value;
        var _a = tokens[i], nextType = _a.type, index = _a.index;
        throw new TypeError("Unexpected " + nextType + " at " + index + ", expected " + type);
    };
    var consumeText = function () {
        var result = "";
        var value;
        while ((value = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR"))) {
            result += value;
        }
        return result;
    };
    while (i < tokens.length) {
        var char = tryConsume("CHAR");
        var name = tryConsume("NAME");
        var pattern = tryConsume("PATTERN");
        if (name || pattern) {
            var prefix = char || "";
            if (prefixes.indexOf(prefix) === -1) {
                path += prefix;
                prefix = "";
            }
            if (path) {
                result.push(path);
                path = "";
            }
            result.push({
                name: name || key++,
                prefix: prefix,
                suffix: "",
                pattern: pattern || defaultPattern,
                modifier: tryConsume("MODIFIER") || ""
            });
            continue;
        }
        var value = char || tryConsume("ESCAPED_CHAR");
        if (value) {
            path += value;
            continue;
        }
        if (path) {
            result.push(path);
            path = "";
        }
        var open = tryConsume("OPEN");
        if (open) {
            var prefix = consumeText();
            var name_1 = tryConsume("NAME") || "";
            var pattern_1 = tryConsume("PATTERN") || "";
            var suffix = consumeText();
            mustConsume("CLOSE");
            result.push({
                name: name_1 || (pattern_1 ? key++ : ""),
                pattern: name_1 && !pattern_1 ? defaultPattern : pattern_1,
                prefix: prefix,
                suffix: suffix,
                modifier: tryConsume("MODIFIER") || ""
            });
            continue;
        }
        mustConsume("END");
    }
    return result;
}
function parse$2 ( str , options ) { if ( options === void 0 ) { options = { } ; } var tokens = lexer ( str ) ; var _a = options . prefixes , prefixes = _a === void 0 ? "./" : _a ; var defaultPattern = "[^" + escapeString ( options . delimiter || "/#?" ) + "]+?" ; var result = [ ] ; var key = 0 ; var i = 0 ; var path = "" ; var tryConsume = function ( type ) { if ( i < tokens . length && tokens [ i ] . type === type ) return tokens [ i ++ ] . value ; } ; var mustConsume = function ( type ) { var value = tryConsume ( type ) ; if ( value !== undefined ) return value ; var _a = tokens [ i ] , nextType = _a . type , index = _a . index ; throw new TypeError ( "Unexpected " + nextType + " at " + index + ", expected " + type ) ; } ; var consumeText = function ( ) { var result = "" ; var value ; while ( ( value = tryConsume ( "CHAR" ) || tryConsume ( "ESCAPED_CHAR" ) ) ) { result += value ; } return result ; } ; while ( i < tokens . length ) { var char = tryConsume ( "CHAR" ) ; var name = tryConsume ( "NAME" ) ; var pattern = tryConsume ( "PATTERN" ) ; if ( name || pattern ) { var prefix = char || "" ; if ( prefixes . indexOf ( prefix ) === - 1 ) { path += prefix ; prefix = "" ; } if ( path ) { result . push ( path ) ; path = "" ; } result . push ( { name : name || key ++ , prefix : prefix , suffix : "" , pattern : pattern || defaultPattern , modifier : tryConsume ( "MODIFIER" ) || "" } ) ; continue ; } var value = char || tryConsume ( "ESCAPED_CHAR" ) ; if ( value ) { path += value ; continue ; } if ( path ) { result . push ( path ) ; path = "" ; } var open = tryConsume ( "OPEN" ) ; if ( open ) { var prefix = consumeText ( ) ; var name_1 = tryConsume ( "NAME" ) || "" ; var pattern_1 = tryConsume ( "PATTERN" ) || "" ; var suffix = consumeText ( ) ; mustConsume ( "CLOSE" ) ; result . push ( { name : name_1 || ( pattern_1 ? key ++ : "" ) , pattern : name_1 && ! pattern_1 ? defaultPattern : pattern_1 , prefix : prefix , suffix : suffix , modifier : tryConsume ( "MODIFIER" ) || "" } ) ; continue ; } mustConsume ( "END" ) ; } return result ; }
Parse a string for the raw tokens.
Parse a string for the raw tokens .
// tslint:disable-next-line