Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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 viboes, 8 years ago

Component: Nonespirit
Owner: set to Joel de Guzman

comment:2 by Joel de Guzman, 8 years ago

Resolution: invalid
Status: newclosed

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.

in reply to:  2 comment:3 by olegmax@…, 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 olegmax@…, 8 years ago

Resolution: invalid
Status: closedreopened

comment:5 by Joel de Guzman, 8 years ago

Sorry, you are right. OK, let me try again...

Last edited 8 years ago by Joel de Guzman (previous) (diff)

comment:6 by Joel de Guzman, 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.

in reply to:  6 comment:7 by olegmax@…, 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 Joel de Guzman, 8 years ago

Resolution: fixed
Status: reopenedclosed

comment:9 by Joel de Guzman, 8 years ago

It's fixed now in devel branch. Thanks for your diligence and sorry for my confusion.

Note: See TracTickets for help on using tickets.