christianp / asciimath2tex

JavaScript library to convert AsciiMath to TeX
Apache License 2.0
70 stars 16 forks source link

Unable to parse an expression containing 2 commas one by one or an empty string with a comma when using ECMAScript module #15

Closed KonBal closed 2 years ago

KonBal commented 2 years ago

Hello! I use your parser as an ECMAScript module and I see that I cannot pass an expression that contains ',,' (or simply ',' as the whole expression). The exception occurs:

asciimath2tex.js:455 Uncaught Error: Didn't EOF: 
    at AsciiMathParser.consume (asciimath2tex.js:455)
    at AsciiMathParser.parse (asciimath2tex.js:420)
else if(!this.eof(pos)) {
    throw(new Error("Didn't EOF: ",this.source(pos)));
}

However, if I include the parser as a CommonJS module taking the source code directly from the repository, the expressions are parsed fine, as in asciimath2tex.js the exception is not thrown for the same case. Instead, there are:

else if (!this.eof(t)) {
    var h = this.source(t, t + 1);
    a.push({tex: h, pos: t, ttype: "character"}), (e += h), (t += 1);
}

Could you explain, please, why there is a difference between the scripts and what behavior of the parser is correct?

christianp commented 2 years ago

There shouldn't be any difference between them. I must have forgotten to update the files in dist.

christianp commented 2 years ago

Looking back at #7, it seems that I was supposed to do some things after merging it, and then didn't! I've removed the dist directory from the repository, and updated the instructions. I've checked that the version of the package installed through npm deals with an input of ,,.