Skip to content

Semantic action attached to a parser that has attribute type of unused_type shall not inhibit the outer rule's attribute composition #104

Description

@saki7

This kind of grammar definition does not alter the semantics of the internal attribute as it's unused_type in the first place. Therefore, there's no reason that we must inhibit the rule parser's attribute handling even when semantic action is attached.

constexpr auto some_rule_grammar_def = 
    lit("prefix").on_match([](auto&& ctx) {
        if (x4::get<some_local_variable>(ctx) == 42) {
            do_something();
            return true;
        }
        return false;
    }) >>
    body_parser
;

Fundamentally, the code above shall match the semantics below:

constexpr auto some_rule_grammar_def = 
    eps([](auto&& ctx) {
        if (x4::get<some_local_variable>(ctx) == 42) {
            do_something();
            return true;
        }
        return false;
    }) >>
    body_parser
;

Workaround

We can currently use x4::as<x4::unused_type>(...) to explicitly re-enable the inhibited attribute. However it's actually a hack (which I introduced for some good reason) when I implemented x4::as, so it's solely a workaround and should not be the desired way of expressing it in application code.

constexpr auto some_rule_grammar_def = 
    as<unused_type>(lit("prefix").on_match([](auto&& ctx) { // <----- as<unused_type>(...) added
        if (x4::get<some_local_variable>(ctx) == 42) {
            do_something();
            return true;
        }
        return false;
    })) >>
    body_parser
;

Additional info

Related: #100

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttests neededUnit tests are required for all public API

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions