Make errors more informative

Make error messages from the lexing and parsing stages be a bit more helpful. If
provided with the input and a position, the error will display the error
position, and the nearby input with the error position underlined (yay combining
marks). Also, standardize the errors a bit (remove doubled "Error:" strings)

Test plan:
 - Make sure the errors look totally sweet (before: {F15602}, after: {F15603})
 - Trigger every error (that can be triggered) in Parser, Lexer, and buildTree
   using the inputs:
  `a^`
  `a_`
  `a^x^x`
  `a_x_x`
  `\color f`
  `\blue `
  `\Huge`
  `\llap`
  `\text`
  `\dfrac`
  `\dfrac{x}`
  `\d`
  `\blue{`
  `\color{#f`
  `{\Huge{x}}`
 - See that the tests still work

Auditors: alpert
This commit is contained in:
Emily Eisenberg
2014-03-29 23:30:25 -04:00
parent c22d8644cc
commit e68cc472c6
4 changed files with 72 additions and 27 deletions

View File

@@ -80,7 +80,7 @@ Lexer.prototype._innerLex = function(pos, normals, ignoreWhitespace) {
// We didn't match any of the tokens, so throw an error.
throw new ParseError("Unexpected character: '" + input[0] +
"' at position " + pos);
"'", this, pos);
}
// A regex to match a CSS color (like #ffffff or BlueViolet)
@@ -101,7 +101,7 @@ Lexer.prototype._innerLexColor = function(pos) {
}
// We didn't match a color, so throw an error.
throw new ParseError("Invalid color at position " + pos);
throw new ParseError("Invalid color", this, pos);
};
// Lex a single token