Repository navigation
Replies: 4 comments 10 replies
|
Interesting, this quite a unique and new requirement. Can you explain briefly the rationale and the use case, just very high level? The interference with the parse tree might just be due to directly calling Is the correct way to call a sub-rule in your case, let me know if that is not enough to fix the parse tree issues. |
|
Btw, about the rule |
|
As for inclusion in the PEGTL, let me think about it some more. The PEGTL is now switching to C++20, but I can imagine a solution that works there based on extracting the type of the state from the member object/function pointer and then using the typed |
|
The rule |
Uh oh!
There was an error while loading. Please reload this page.
For one of my projects using PEGTL 4, I want a state object I pass to the parser to contain booleans that enable or disable certain rules. There might already be some method by which this can be done, which I have overlooked. I've done it by writing a custom rule called peg_cond. The template parameters of peg_cond include the member variable pointer (into the first state object), a rule to be invoked if that member variable is true, and rule to be invoked if the member variable is false. The latter defaults to failure.
The seems to work fine in my project, giving the expected parsing results. However, it interferes with the parse tree selector of the conditional rule. No node is generated for the rule, even if it has a true selector, though nodes are generated as appropriate for its child nodes.
I've put peg_cond.hh, along with a crude demo/test program, in a Codeberg repository:
https://codeberg.org/brouhaha/peg_cond_test
As written, my code requires C++26, and compiles and runs with either GCC g++ 16.2.1 or clang++22.1.8.
My rules have rule_t and subs_t declarations, but perhaps I'm missing something else that interferes wtih the selector of the direct child rule. Any help would be appreciated, as would any other constructive criticism
Should peg_cond be deemed useful and suitable as a contribution to PEGTL, you are welcome to it.
All reactions