0

I'm trying to write a parser using boost::spirit that will match an alphanumeric sequence that may also contain the _ character, but will exclude the literals 'in' and 'out' (rule0).

For example, it should match "abc3x3_" , "_hello", "in_12", "out_in" etc. But should not match "in" or "out".

rule1 below is intended to achieve this.

typedef boost::spirit::qi::rule <const char*, string(), ascii::space_type> myRule;

myRule rule0 = qi::lit("in") | "out";  
myRule rule1 = ((qi::alpha | '_') >> *(qi::alnum | '_')) - rule0;  

The problem is that it doesn't match strings that contain the literals from rule0 as substrings:

For example, it doesn't match "_in", "in_12", "out1" etc.

Where am I wrong?

Daniel
  • 1,319
  • 14
  • 19
  • 1
    [This question](https://stackoverflow.com/questions/38039237/parsing-identifiers-except-keywords) uses Spirit.X3 but the ideas (and the operators) apply to your problem. – llonesmiz Jul 11 '17 at 08:14
  • There are more answers on this topic https://stackoverflow.com/search?tab=votes&q=user%3a85371%20keyword%20distinct e.g – sehe Jul 11 '17 at 14:09

0 Answers0