Skip to content

excluding some characters from string #201

Answered by d-frey
MahaZaid asked this question in Q&A
Discussion options

You must be logged in to vote

Start by having rules for your keywords:

struct kw_and : TAO_PEGTL_KEYWORD("AND") {};
struct kw_or : TAO_PEGTL_KEYWORD("OR") {};

Then have a rule for any keyword:

struct keywords : sor< kw_and, kw_or > {};

Finally, use the minus<> rule to match an identifier and make sure it is not a keyword.

struct label : minus< identifier, keywords > {};

This should do the trick. You can, of course, use more complicated grammars if you want to exclude everything that contains a keyword or more complicated patterns.

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by d-frey
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #201 on December 09, 2020 08:18.