cortex-js / compute-engine

An engine for symbolic manipulation and numeric evaluation of math formulas expressed with MathJSON
https://cortexjs.io
MIT License
375 stars 47 forks source link

Parser doesn't insert `Missing` where expected #30

Open bengolds opened 2 years ago

bengolds commented 2 years ago

I've run into two more cases where I'd expect the parser to give an error by inserting Missing, akin to #28:

\\frac{x}{}=y parses as [ 'Multiply', [ 'Divide', 'x', '=' ], 'y' ]

\\sqrt{}=y parses as [ 'Multiply', [ 'Sqrt', '=' ], 'y' ]

Note that in both cases, if you have \placeholder inside of the empty brackets, it parses correctly:

\\frac{x}{\\placeholder}=y  parses as [ 'Equal', [ 'Divide', 'x', 'Missing' ], 'y' ]

\\sqrt{\\placeholder}=y parses as [ 'Equal', [ 'Sqrt', 'Missing' ], 'y' ]
strickinato commented 2 years ago

Confirmed still an issue in 0.4.3

> c.parse("\\frac{x}{}=y").json
[ 'Multiply', [ 'Divide', 'x', '=' ], 'y' ]

> c.parse("\\sqrt{}=y").json
[ 'Multiply', [ 'Sqrt', '=' ], 'y' ]

> c.parse("\\frac{x}{\\placeholder}=y").json
[ 'Equal', [ 'Divide', 'x', 'Missing' ], 'y' ]

> c.parse("\\sqrt{\\placeholder}=y").json
[ 'Equal', [ 'Sqrt', 'Missing' ], 'y' ]