fred-wang / TeXZilla

LALR Javascript LaTeX-to-MathML converter compatible with Unicode
http://fred-wang.github.io/TeXZilla/
130 stars 21 forks source link

Improve error message #16

Closed rgaiacs closed 10 years ago

rgaiacs commented 10 years ago

The default error message don't help very much.

Step to reproduce

  1. Try to parse \frac{1}.

It show

Parse error on line 1:
\frac{1}
--------^
Expecting '{', 'LEFT', 'OPFS', '.', 'BIG', 'BBIG', 'BIGG', 'BBIGG', 'BIGL', 'BBIGL', 'BIGGL', 'BBIGGL', 'NUM', 'TEXT', 'A', 'F', 'MI', 'MN', 'MO', 'OP', 'OPS', 'OPAS', 'MS', 'MTEXT', 'HIGH_SURROGATE', 'BMP_CHARACTER', 'OPERATORNAME', 'MATHOP', 'MATHBIN', 'MATHREL', 'FRAC', 'ROOT', 'SQRT', 'UNDERSET', 'OVERSET', 'UNDEROVERSET', 'XARROW', 'MATHRLAP', 'MATHLLAP', 'MATHCLAP', 'PHANTOM', 'TFRAC', 'BINOM', 'TBINOM', 'PMOD', 'UNDERBRACE', 'UNDERLINE', 'OVERBRACE', 'ACCENT', 'ACCENTNS', 'BOXED', 'SLASH', 'QUAD', 'QQUAD', 'NEGSPACE', 'NEGMEDSPACE', 'NEGTHICKSPACE', 'THINSPACE', 'MEDSPACE', 'THICKSPACE', 'SPACE', 'MATHRAISEBOX', 'MATHBB', 'MATHBF', 'MATHBIT', 'MATHSCR', 'MATHBSCR', 'MATHSF', 'MATHFRAK', 'MATHIT', 'MATHTT', 'MATHRM', 'HREF', 'STATUSLINE', 'TOOLTIP', 'TOGGLE', 'BTOGGLE', 'TENSOR', 'MULTI', 'BMATRIX', 'BGATHERED', 'BPMATRIX', 'BBMATRIX', 'BVMATRIX', 'BBBVMATRIX', 'BVVVMATRIX', 'BSMALLMATRIX', 'BCASES', 'BALIGNED', 'BARRAY', 'SUBSTACK', 'ARRAY', got 'EOF'\frac{1}

Comparison with LaTeX

$ cat e.tex
\documentclass{article}
\begin{document}
$\frac{1}$
\end{document}
$ pdflatex -interaction=nonstopmode e
...
! Missing } inserted.
<inserted text> 
                }
l.3 $\frac{1}$

! Too many }'s.
\frac #1#2->{\begingroup #1\endgroup \over #2}

l.3 $\frac{1}$
...

Solution

Replace JISON parser.parserError as suggest by @zaach here and here.

fred-wang commented 10 years ago

I removed the "Expecting..." line. Now we only have

Parse error on line 1: \frac{1} --------^