Skip to content

Throw custom error per rule #203

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

You must be logged in to vote

You could unroll minus back to rematch and use the inner rule to raise an error directly:

struct andOperator : TAO_PEGTL_STRING("AND") {};
struct invalidKeyword {};
struct keyword: rematch<identifier, not_at< andOperator, eof, raise< invalidKeyword > > > {};
struct atomic: seq< keyword, plus<space>, andOperator, plus<space>, keyword >{};
struct expression: must<atomic> {};

Now it will use the error message specialization for invalidKeyword when an identifier matches a keyword.

Replies: 2 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #203 on December 09, 2020 08:16.