parser/lex.js
function lex(source) {
    var tokens = [];
    var chunk = clean(source);
    var total = chunk.length;
    var iterations = 0;

    while (chunk.length > 0) {
        for (var regexpName in REGEXPS) {
            var regexp = REGEXPS[regexpName];
            var match = regexp.exec(chunk);

            if (match) {
                var original = match[0];
                var str = original;
                if (regexpName === 'string') str = str.replace(/\\"/g, '"');
                tokens.push({ type: regexpName, string: str, original: original });
                // Need to slice the chunk at the original 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) {
            var parts = [
                'Runiq: Lexer ran too many iterations!',
                '--- Failed at chunk: `' + chunk + '`'
            ];
            throw new Error(parts.join('\n'));
        }
    }

    return tokens;
}
function lex(source) {
    var tokens = [];
    var chunk = clean(source);
    var total = chunk.length;
    var iterations = 0;

    while (chunk.length > 0) {
        for (var regexpName in REGEXPS) {
            var regexp = REGEXPS[regexpName];
            var match = regexp.exec(chunk);

            if (match) {
                var original = match[0];
                var str = original;
                if (regexpName === 'string') str = str.replace(/\\"/g, '"');
                tokens.push({ type: regexpName, string: str, original: original });
                // Need to slice the chunk at the original 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) {
            var parts = [
                'Runiq: Lexer ran too many iterations!',
                '--- Failed at chunk: `' + chunk + '`'
            ];
            throw new Error(parts.join('\n'));
        }
    }

    return tokens;
}
function lex ( source ) { var tokens = [ ] ; var chunk = clean ( source ) ; var total = chunk . length ; var iterations = 0 ; while ( chunk . length > 0 ) { for ( var regexpName in REGEXPS ) { var regexp = REGEXPS [ regexpName ] ; var match = regexp . exec ( chunk ) ; if ( match ) { var original = match [ 0 ] ; var str = original ; if ( regexpName === 'string' ) str = str . replace ( / \\" / g , '"' ) ; tokens . push ( { type : regexpName , string : str , original : original } ) ; // Need to slice the chunk at the original 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 ) { var parts = [ 'Runiq: Lexer ran too many iterations!' , '--- Failed at chunk: `' + chunk + '`' ] ; throw new Error ( parts . join ( '\n' ) ) ; } } return tokens ; }
Return an array of token objects for the clean source code string
Return an array of token objects for the clean source code string