lexer.js
function formatTokenDump(tokens, formatter, resultPrefix, resultSuffix) {
  var tokensSexpStr = "";
  var currentLine = -999;
  tokens.forEach(function(token, index) {
    // skip the wrapping () it's annoying in the dump
    if(!((index === 0 && token.text === "(") ||
        (index === tokens.length-1 && token.text === ")")))
    {
      // add a return if this starts a different line:
      if(currentLine !== -999 && token.line !== currentLine) {
        tokensSexpStr += '\n';
      }
      tokensSexpStr += formatter(token);
      currentLine = token.line;
    }
  });

  return (resultPrefix ? resultPrefix : "") +
          tokensSexpStr +
          (resultSuffix ? resultSuffix : "");
}
function formatTokenDump(tokens, formatter, resultPrefix, resultSuffix) {
  var tokensSexpStr = "";
  var currentLine = -999;
  tokens.forEach(function(token, index) {
    // skip the wrapping () it's annoying in the dump
    if(!((index === 0 && token.text === "(") ||
        (index === tokens.length-1 && token.text === ")")))
    {
      // add a return if this starts a different line:
      if(currentLine !== -999 && token.line !== currentLine) {
        tokensSexpStr += '\n';
      }
      tokensSexpStr += formatter(token);
      currentLine = token.line;
    }
  });

  return (resultPrefix ? resultPrefix : "") +
          tokensSexpStr +
          (resultSuffix ? resultSuffix : "");
}
function formatTokenDump ( tokens , formatter , resultPrefix , resultSuffix ) { var tokensSexpStr = "" ; var currentLine = - 999 ; tokens . forEach ( function ( token , index ) { // skip the wrapping () it's annoying in the dump if ( ! ( ( index === 0 && token . text === "(" ) || ( index === tokens . length - 1 && token . text === ")" ) ) ) { // add a return if this starts a different line: if ( currentLine !== - 999 && token . line !== currentLine ) { tokensSexpStr += '\n' ; } tokensSexpStr += formatter ( token ) ; currentLine = token . line ; } } ) ; return ( resultPrefix ? resultPrefix : "" ) + tokensSexpStr + ( resultSuffix ? resultSuffix : "" ) ; }
format the token dump into a string

note: we put all the tokens from a line on a line to make this easier
to match up with the original source when debugging problems.

@tokens = an array of tokens
@formatter = a function which takes a token and returns a string.
@resultPrefix = optional string to prepend to the result
@resultSuffix = optional string to append to the result
@returns the formatted string.
format the token dump into a string