peter-winter / ctpg

Compile Time Parser Generator is a C++ single header library which takes a language description as a C++ code and turns it into a LR1 table parser with a deterministic finite automaton lexical analyzer, all in compile time.
MIT License
456 stars 24 forks source link

Parsing exponent notation in json-parser #36

Closed nandanvasudevan closed 2 years ago

nandanvasudevan commented 2 years ago

I just saw that the to_js_number() does not work when the exponent does not have a sign (like 1.0e8). A quick look into the JSON schema tells me that it is allowed.

image

Was this missed or is support for these not required?

Here is a simple fix anyway. I am happy to provide a pull request if this is necessary. Just confused right now.

https://godbolt.org/z/7bo3d41K6

peter-winter commented 2 years ago

This is my mistake. First of all a fix to the regex is needed. The way you fixed it in to_js_number is way too complicated. I would do it like this:

exp_minus = *it == '-';
if (*it == '-' || *it == '+') ++it;
nandanvasudevan commented 2 years ago

I agree. Please go ahead!

Tested, just in case... Works as expected! https://godbolt.org/z/YnYhK7jMo

peter-winter commented 2 years ago

Fixed