Re: Is the example for '-' difference parser wrong?

Phil Endecott via Spirit-general <[email protected]> Mon, 22 Nov 2021 18:09:30 +0000
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
Hi Mikael,

Mikael Asplund wrote:
> You consider where in the parsed input you are, check if it 
> matches p1 (char_ will check the next character), and IF p1 
> matches, check so that p2 doesn't also match from the same 
> position ("*/" will check the next two characters), and if 
> p2 matches, fail the whole expression (p1 - p2) and backtrack.

Hmm....

So the parser takes an iterator-pair, but it returns true if
it matches at the beginning of the range, not only if it
matches the entire range.

I think this differs from what '-' can mean in EBNF style
grammar descriptions, though some googling shows that
actually most such grammars don't have a '-' operator at all.
Unlike most extensions it's not obvious how '-' can be
transformed to more primitive operations.

If anyone is curious, the grammar that I need to recognise
looks something like this:

A ::= "begin" B* "end"

B ::= C ("begin" B "end" C)*

C ::= char* - (char* ("begin" | "end") char*)

Rule C is supposed to mean any sequence of characters,
possibly empty, not including the subsequence "begin" or
"end".

The result is supposed to match any input with matched begin...end
pairs.

With a direct translation to Spirit, this fails because the
rule for C always finds the "end" at the end of the input and
so fails to match, rather than successfully matching up to the
next "begin" or "end".


Thanks, Phil.