I've seen a few posts related to the nuances of keyword/identifier use in qi grammars, but I can't quite make sense of how the approach demonstrated in the boost examples is supposed to work...
Keywords declaration:
qi::symbols<char> keywords;
Example keyword set:
keywords.add
("foo")
("bar")
;
Identifier rule declaration:
qi::rule<std::string::const_iterator, std::string(), ascii::space_type> identifier;
Here's how the identifier rule is defined in the qi calc and compiler examples:
identifier = !keywords >> qi::raw[ qi::lexeme[ ( qi::alpha | '_' ) >> *( qi::alnum | '_' ) ] ];
Perhaps I'm reading the qi syntax wrong, but it seems to me that this would not accept any literal that matches or starts with a keyword. Rejecting a full keyword match is the desired behavior. But, I want to accept "food" as an identifier, even though it begins with the keyword "foo". This seems like a pretty standard use case, but having trouble finding documentation that really nails this down.
Can anyone offer an identifier rule that only rejects exact matches to keywords?
Thanks!