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

Mikael Asplund <[email protected]> Mon, 22 Nov 2021 17:16:26 +0000
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <VI1PR06MB643042BB28F221725219F621AA9F9@VI1PR06MB6430.eurprd06.prod.outlook.com>
Hi, Phil!

I'm not really an expert, but I think I can solve the problem for you...

(char_ - "*/") is not "a parser that matches any character, except...". It's the combination of two parsers. The "minus" is not a modifier to the first parser... It's a combinatory rule, and the rule says "(p1 - p2)" means "p1 should match, but p2 should not". 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.

Any parser would work... like (char_ - int_) will match any character that is not a start of a valid integer.

Again, the operator "-" is a parser combiner, not a modifier for the first parser.

Regards,
   Mikael

-----Original Message-----
From: Phil Endecott via Spirit-general <[email protected]> 
Sent: Monday, November 22, 2021 16:55
To: [email protected]
Cc: Phil Endecott <[email protected]>
Subject: [Spirit-general] Is the example for '-' difference parser wrong?

Dear Experts,

The documentation for the difference parser at https://www.boost.org/doc/libs/1_77_0/libs/spirit/doc/html/spirit/qi/reference/operator/difference.html
gives this example:

   Parse a C/C++ style comment:
   test_parser("/*A Comment*/", "/*" >> *(char_ - "*/") >> "*/");

Is that correct?

My understanding is that char_ matches any single character.
So (char_ - "*/") will match any single character that does not also match "*/". Since "*/" is two characters, no single character can ever match "*/". So (char_ - "*/") is surely the same as just char_.

I was wondering if it were just a case of a misplaced paren, but I don't think it's that simple.

Have I misunderstood something?


Thanks, Phil.






_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general