Skip to content

parsing fails with apparently valid grammar #68

Answered by d-frey
dcourtois asked this question in Q&A
Discussion options

You must be logged in to vote

There are two problems: You don't have a grammar that matches the whole input and you have the wrong order of choices in _real. The second problem leads to seq<A,B> to not even try to match B when is is able to match A. In your case, seq< plus< digit >, opt< _expo > > matches the 1 of the input 1.2. So it doesn't even look at the other choices. Since your grammar does not require eof at the end, this does match - but not the whole input. When you have [1.2] as an input, it matches [, then matches 1 for _real and then expects ], but gets . - hence it fails on this input.

To solve it, use

struct _expression : seq< sor<
    _real,
    seq< one< '[' >, _real, one< ']' > >
>, eof > {};

to mak…

Replies: 11 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by d-frey
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants
Converted from issue

This discussion was converted from issue #68 on December 09, 2020 10:33.