Let's suppose we need to parse "a" or "ab" inputs.
The following naive parser fails: auto parser = 'a' | 'a' > 'b';
One of the solution is to rewrite the parser to match the end of the input this way: auto parser = 'a' >> eoi | 'a' > 'b'
And it works fine.
But now suppose we need to parse a more complex input, like "a ab". And I'd like to reuse the old parser.
So I write auto parser2 = lexeme[ parser ] > lexeme[ parser ]
But parser2
will fail to parse "a ab" since eoi
isn't matched.
I know that an obvious solution is to rewrite the grammar ( like 'a' >> 'b' | 'a'
or 'a' >> -'b'
or somehow ). But I wonder if there is a way to match not only end of line but also an end of a lexeme?
Thank you in advance.