[Spirit] real_policies<> and 1.0#NAN
Hi, Boost.Spirit is not sure of itself when it comes to parsing representations of infs and nans such as “1.0#NAN”. The docs [1] for the default real_policies<T> for parsing numbers say: “[…] with the additional detection of NaN and Inf as mandated by the C99 Standard and proposed for inclusion into the C++0x Standard: nan, nan(...), inf and infinity (the matching is case-insensitive). This corresponds to the following grammar:” The first sentence suggests that 1.0#NAN etc will not be parsed. But the grammar itself then says: <quote> nan = -lit("1.0#") >> no_case["nan"]
-('(' >> *(char_ - ')') >> ')') ;
inf
= no_case[lit("inf") >> -lit("inity")]
;
</quote>
suggesting that "#1.0NAN" is intended to parsed, but "#1.0INF" is not!
Then the in-code docs [2] however suggest that both "1.0#NAN" and "1.0#INF" are intended to be parsed:
<quote>
// The second call allows to recognize representation formats starting
// with a 1.0 (such as 1.0#NAN or 1.0#INF etc.).
</quote>
However, the actual code fails to parse either of these these. This is because in [3] the presence of the "0" causes frac_digits to be non-zero and so the "traits::is_equal_to_one(..)" condition is never tested. In the case "1.#NAN" (without a zero) frac_digits is zero so the condition is tested and we enter the traits::parse_nan code, but now the text parsed to this sub-parser is "#NAN" and the parser does not cater for the initial "#".
Could the maintainers state which behaviour is intended...hopefully I may be able to supply a patch to docs/code/tests knowing that.
Regards,
Pete
[1] http://www.boost.org/doc/libs/1_61_0/libs/spirit/doc/html/spirit/qi/referenc...
[2]
Hi,
Boost.Spirit is not sure of itself when it comes to parsing representations of infs and nans such as “1.0#NAN”.
The docs [1] for the default real_policies<T> for parsing numbers say: “[…] with the additional detection of NaN and Inf as mandated by the C99 Standard and proposed for inclusion into the C++0x Standard: nan, nan(...), inf and infinity (the matching is case-insensitive). This corresponds to the following grammar:”
The first sentence suggests that 1.0#NAN etc will not be parsed. But the grammar itself
<quote> nan = -lit("1.0#") >> no_case["nan"]
-('(' >> *(char_ - ')') >> ')') ;
inf = no_case[lit("inf") >> -lit("inity")] ; </quote>
suggesting that "#1.0NAN" is intended to parsed, but "#1.0INF" is not!
Then the in-code docs [2] however suggest that both "1.0#NAN" and "1.0#INF" are intended to be parsed:
<quote> // The second call allows to recognize representation formats starting // with a 1.0 (such as 1.0#NAN or 1.0#INF etc.). </quote>
However, the actual code fails to parse either of these these. This is because in [3]
On 08/06/2016 5:00 AM, Pete Bartlett wrote: then says: the presence of the "0" causes frac_digits to be non-zero and so the "traits::is_equal_to_one(..)" condition is never tested. In the case "1.#NAN" (without a zero) frac_digits is zero so the condition is tested and we enter the traits::parse_nan code, but now the text parsed to this sub-parser is "#NAN" and the parser does not cater for the initial "#".
Could the maintainers state which behaviour is intended...hopefully I may be able to
supply a patch to docs/code/tests knowing that.
Regards, Pete
[1] http://www.boost.org/doc/libs/1_61_0/libs/spirit/doc/html/spirit/qi/referenc... [2]
[3]
Hrmm... Following the standard is the intent. I'm very welcome to suggestions and of course patches :-) Regards, -- Joel de Guzman http://www.ciere.com http://boost-spirit.com http://www.cycfi.com/
participants (2)
-
Joel de Guzman
-
Pete Bartlett