hsp/compiler/jsgenerator/jsvalidator/validator.js
function formatError (error, input) {
    var message = error.toString().replace(/\s*\(\d*\:\d*\)\s*$/i, ''); // remove line number / col number

    var beforeMatch = ('' + input.slice(0, error.pos)).match(/.*$/i);
    var afterMatch = ('' + input.slice(error.pos)).match(/.*/i);
    var before = beforeMatch ? beforeMatch[0] : '';
    var after = afterMatch ? afterMatch[0] : '';

    // Prepare line info for txt display
    var cursorPos = before.length;
    var errChar = (after.length) ? after.slice(0, 1) : 'X';
    var lineStr = before + after;
    var lncursor = [];
    for (var i = 0; i < lineStr.length; i++) {
        lncursor[i] = (i === cursorPos) ? '^' : '-';
    }
    var lineInfoTxt = lineStr + '\r\n' + lncursor.join('');

    // Prepare line info for HTML display
    var lineInfoHTML = ['<span class="code">', before, '<span class="error" title="', message, '">', errChar, '</span>',
            after.slice(1), '</span>'].join('');

    return {
        description : message,
        lineInfoTxt : lineInfoTxt,
        lineInfoHTML : lineInfoHTML,
        code : lineStr,
        line : error.loc ? error.loc.line : -1,
        column : error.loc ? error.loc.column : -1
    };

}
function formatError (error, input) {
    var message = error.toString().replace(/\s*\(\d*\:\d*\)\s*$/i, ''); // remove line number / col number

    var beforeMatch = ('' + input.slice(0, error.pos)).match(/.*$/i);
    var afterMatch = ('' + input.slice(error.pos)).match(/.*/i);
    var before = beforeMatch ? beforeMatch[0] : '';
    var after = afterMatch ? afterMatch[0] : '';

    // Prepare line info for txt display
    var cursorPos = before.length;
    var errChar = (after.length) ? after.slice(0, 1) : 'X';
    var lineStr = before + after;
    var lncursor = [];
    for (var i = 0; i < lineStr.length; i++) {
        lncursor[i] = (i === cursorPos) ? '^' : '-';
    }
    var lineInfoTxt = lineStr + '\r\n' + lncursor.join('');

    // Prepare line info for HTML display
    var lineInfoHTML = ['<span class="code">', before, '<span class="error" title="', message, '">', errChar, '</span>',
            after.slice(1), '</span>'].join('');

    return {
        description : message,
        lineInfoTxt : lineInfoTxt,
        lineInfoHTML : lineInfoHTML,
        code : lineStr,
        line : error.loc ? error.loc.line : -1,
        column : error.loc ? error.loc.column : -1
    };

}
function formatError ( error , input ) { var message = error . toString ( ) . replace ( / \s*\(\d*\:\d*\)\s*$ / i , '' ) ; // remove line number / col number var beforeMatch = ( '' + input . slice ( 0 , error . pos ) ) . match ( / .*$ / i ) ; var afterMatch = ( '' + input . slice ( error . pos ) ) . match ( / .* / i ) ; var before = beforeMatch ? beforeMatch [ 0 ] : '' ; var after = afterMatch ? afterMatch [ 0 ] : '' ; // Prepare line info for txt display var cursorPos = before . length ; var errChar = ( after . length ) ? after . slice ( 0 , 1 ) : 'X' ; var lineStr = before + after ; var lncursor = [ ] ; for ( var i = 0 ; i < lineStr . length ; i ++ ) { lncursor [ i ] = ( i === cursorPos ) ? '^' : '-' ; } var lineInfoTxt = lineStr + '\r\n' + lncursor . join ( '' ) ; // Prepare line info for HTML display var lineInfoHTML = [ '<span class="code">' , before , '<span class="error" title="' , message , '">' , errChar , '</span>' , after . slice ( 1 ) , '</span>' ] . join ( '' ) ; return { description : message , lineInfoTxt : lineInfoTxt , lineInfoHTML : lineInfoHTML , code : lineStr , line : error . loc ? error . loc . line : - 1 , column : error . loc ? error . loc . column : - 1 } ; }
Formats the error as an error structure with line extract information.
@param {Object} error the exception.
@param {String} input the Javascript string.
@return {Object} the structured error.
Formats the error as an error structure with line extract information .