#10193 closed Bugs (fixed)
[Spirit.qi] real_parser is too strict with the exponent part
Reported by: | anonymous | Owned by: | Joel de Guzman |
---|---|---|---|
Milestone: | To Be Determined | Component: | spirit |
Version: | Boost 1.55.0 | Severity: | Problem |
Keywords: | Cc: |
Description
E.g. parsing "4em" string fails with
double_ >> lit("em")
"e" is considered start of exponent part and integer is expected after it.
Exponent handling as described in documentation as follows:
exponent_part = (lit('e') | 'E') >> -sign >> +digit ;
But as it is implemented now, grammar should be:
exponent_part = (lit('e') | 'E') > -sign > +digit ;
It will be better if "e" is treated as exponent part only if it is followed by integer (with optional sign).
Change History (9)
comment:1 by , 8 years ago
Component: | None → spirit |
---|---|
Owner: | set to |
follow-up: 3 comment:2 by , 8 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:3 by , 8 years ago
Replying to djowel:
The grammar in the docs is correct. It parses '4e' just fine.
No, it is not. exponent_part grammar in docs requires at least one digit after 'e'. How can it match '4e'?
comment:4 by , 8 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
follow-up: 7 comment:6 by , 8 years ago
OK, second try. Pardon the confusion. 42e is indeed not valid. What was I thinking!
OK, here's what's happening. The parser parses 4e and attempts to find a number after that. So, 4em is not a double number and it fails. If I understand correctly, what you want is this:
exponent_part = -((lit('e') | 'E') >> -sign >> +digit);
Is that correct? In other words, the whole exponent part is optional. I think that makes sense. I reopened this as a bug.
comment:7 by , 8 years ago
Replying to djowel:
If I understand correctly, what you want is this:
exponent_part = -((lit('e') | 'E') >> -sign >> +digit);
Grammar in documentation is already treats exponent_part as optional. So, preferred solution for me as a library user is to sync code with existing grammar description. Not sure whether you may break backward compatibility in this case. May be additional option should be added...
Btw, grammar in documentation doesn't permit dot before exponent part (integer only mantissa), but I'm almost sure that actual code permits it.
comment:8 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
comment:9 by , 8 years ago
It's fixed now in devel branch. Thanks for your diligence and sorry for my confusion.
No, that is incorrect. '4e' is a valid real number even without an integer following it. The grammar in the docs is correct. No exceptions are thrown. It parses '4e' just fine. If that's not you want, then you can customize the real number parser.
See http://en.cppreference.com/w/cpp/language/floating_literal
If you do not agree with this, please start a discussion in the Spirit mailing list. I'm closing this one as invalid.