taocpp / PEGTL

Parsing Expression Grammar Template Library
Boost Software License 1.0
1.94k stars 228 forks source link

examples/double.hh: dot is not optional #52

Closed wojdyr closed 7 years ago

wojdyr commented 7 years ago

The example grammar in double.hh requires dot in the input, so it won't parse 2 or 2e0. (it's not an intentional limitation? numeral from lua53_parse.cc handles it correctly) Here is what the sum.cc program shows:

$ ./sum 
Give me a comma separated list of numbers.
The numbers are added using the PEGTL.
Type [q or Q] to quit

2.0
parsing OK; sum = 2
2.
parsing OK; sum = 2
2.e0
parsing OK; sum = 2
2e0
parsing failed
2
parsing failed
d-frey commented 7 years ago

This comes from the fact that it started reusing a programming language's definition of double, where a number without a dot is an integer and therefore a different type. But given that it is a stand-alone example, that doesn't make much sense so I'll fix it in a minute.