enkimute / ganja.js

:triangular_ruler: Javascript Geometric Algebra Generator for Javascript, c++, c#, rust, python. (with operator overloading and algebraic literals) -
MIT License
1.51k stars 106 forks source link

Amount of spaces causes inline operator overloading to fail #123

Open kungfooman opened 3 years ago

kungfooman commented 3 years ago

I just run into an issue with code like this:

      (l3 & l4) * (l1 & l2) * b * (l1 & l2) * (l3 & l4), 'b\'\'',
      (l3 & l4) * (l1 & l2) * b  * (l1 & l2) * (l3 & l4), 'b\'\'',

It looks nearly identical, but the amount of spaces (1 space vs 2 spaces) generates different behaviour:

image

broundtree commented 6 months ago

I think I have also run accross this problem... very confusing as to why code that works correctly crashes the app. My code sample is here on line 65. Just add one sauce where indicated and run, it fails. https://enkimute.github.io/ganja.js/examples/coffeeshop.html#7luxYQzPN

BTW: GREAT APP!!!!!

kungfooman commented 6 months ago

Right, the integrated Ganjascript parser isn't the most reliable piece of software :sweat_smile: I run into more issues and IMO the best way forward would be to resort to using a maintained and extendable JS parser library (I have most experience with @babel/parser, so I would probably go with that).

However Babel parser comes with around 0.5 MB extra download (unminified)...

Acorn is smaller at least:

https://www.npmjs.com/package/acorn/v/7.4.1?activeTab=code

image

And that's not minified yet aswell - adding minification and gzip - it's like the size of a small JPG.