arithy / packcc

A parser generator for C
Other
348 stars 29 forks source link

How to write conditional rules? #84

Open tamlok opened 2 days ago

tamlok commented 2 days ago

Hi,

I am writing a markdown parser. As what we know, there are some feature extensions to the standard markdown grammar. So I want to provide some macros as switches and only compile a certain rules based on the switch.

One solution might be evaluating a C code expression as a precondition check.

I am trying to rewrite the PEG parser here in PackCC and it has the ability to use a C code expression as a precondition check: https://github.com/vnotex/peg-markdown-highlight/blob/20f17c03969a1655c39536bf78f3ee5c2a9dd9f7/pmh_grammar.leg#L97

What is the right way to do it in PackCC?

Thanks!