1

I would love to parse a string like this:

<stuff I don't care> <literal value> <more stuff I don't care>

with boost::spirit::qi. Let's assume that <literal value> is e.g. ABC, then I would like the parser to accept:

Some text ABC more text

but reject:

Some text ACB more text

Unfortunately,

*char_ >> lit("ABC") >> *char_

does not work due to qi's greediness. Is there an easy way to write this parser?

Markus Mayr
  • 4,038
  • 1
  • 20
  • 42
  • 3
    Doesn't `*(char_ - lit("ABC")) >> lit("ABC") >> *char_` work? – filmor Mar 08 '14 at 22:06
  • Thanks. I thought that the right-hand side parser of the minus operator must parse a subset of the parser at the left side. – Markus Mayr Mar 09 '14 at 05:44
  • I'll make this an answer then ;). I just wasn't sure, since it's been quite a while since I worked with Boost.Spirit (in particular before it was named Qi). – filmor Mar 09 '14 at 16:47

1 Answers1

3

Use

*(char_ - lit("ABC")) >> lit("ABC") >> *char_;

instead to prevent char_ from consuming "ABC".

filmor
  • 30,840
  • 6
  • 50
  • 48