Enhancement Request: Rules affected by semantic actions #12
-
Hi, ContextI'm trying to build a parser for extracting URLs in context (eg. given free / structured text, extract all the URLs within it). Repository: https://github.com/divyekapoor/grepurls. The code in there is an enhancement of the contrib/uri.hh implementation. While specifying the grammar for this, one of the issues to be resolved is the handling of contextual delimiters: eg. print('mailto:[email protected]') should be parsed as: mailto:[email protected] instead of: mailto:[email protected]') because single quote and closing parens are allowed within the URI. To enable this, I have to change a rule called sub_delims in response to a context: struct sub_delims : one< '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=' > {}; When within a single quoted context, IssueIn a simple recursive descent parser, I would put the allowed delimiters in a vector and when switching to a single-quoted, double-quoted or parenthesized context, I would simply remove the appropriate delimiters from Thanks & I appreciate all the hard work that has gone into PEGTL. Cheers! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi Divye, thanks for writing in such a clear way that I don't have to guess what you are trying to achieve and what the issues are. Now regarding the issue, the short answer is: It's possible, but requires the implementation of custom parsing rules:
This is just the short run-through, let us know if you need some more information... You can also write us at pegtl(at)colin-hirsch.net . Best regards, Colin |
Beta Was this translation helpful? Give feedback.
-
Thank you for an excellent response. I got the hang of it. |
Beta Was this translation helpful? Give feedback.
Hi Divye,
thanks for writing in such a clear way that I don't have to guess what you are trying to achieve and what the issues are.
Now regarding the issue, the short answer is: It's possible, but requires the implementation of custom parsing rules:
static bool match
in the examples direc…