kach / nearley

📜🔜🌲 Simple, fast, powerful parser toolkit for JavaScript.
https://nearley.js.org
MIT License
3.59k stars 232 forks source link

Calculator example: fixing some weird behavior about whitespaces #580

Open crguezl opened 3 years ago

crguezl commented 3 years ago

Hi,

Thanks for giving us Nearley.js. It is a great tool and I have used successfully in the classroom this course.

This pull request is about the arithmetic.ne grammar example in examples/calculator. When you run it, it has a peculiar behavior for some inputs like:

 ➜  calculator git:(master) . ./build-and-test.sh 
> sinpi
1.2246467991473532e-16
> sqrtsinpi
1.1066376096750703e-8

that is due to the set of rules for N and P and _

With the proposed change, this is the new behavior:

➜  calculator git:(master) ✗ . ./build-and-test.sh
> sinpi
-----^  Error.
> sin(pi)
1.2246467991473532e-16
> sqrtsinpi
------^  Error.
> sqrt(sin(pi))
1.1066376096750703e-8
> 

Nothing else changes