mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-10 05:28:41 +00:00
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:
4
Lexer.js
4
Lexer.js
@@ -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
|
||||
|
Reference in New Issue
Block a user