Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X3: Incorrect attribute propagation for alternatives with equal attributes #771

Closed
Krzmbrzl opened this issue Sep 22, 2023 · 2 comments
Closed

Comments

@Krzmbrzl
Copy link

Krzmbrzl commented Sep 22, 2023

The docs state

a: A, b: A --> (a | b): A

meaning that an alternative between two rules/parsers that have the same attribute type will have an attribute that is the same as that common type (instead of a variant of the individual types).

However, this is not the case. Alternatives such as the above still result in an attribute of type variant< A, A >.

While (I think?) automatic propagation rules can correctly propagate this to an attribute of type A, this is a problem/inconvenience for e.g. semantic actions as they get the immediate attribute type and thus have to work with the variant.

MWE (Godbolt):

#include <boost/spirit/home/x3.hpp>

#include <type_traits>
#include <string>

namespace x3 = boost::spirit::x3;

int main() {
    auto validator = [](auto &ctx) {
        static_assert(std::is_same_v<std::remove_cvref_t<decltype(x3::_attr(ctx))>, int>);
    };
    auto parser = (x3::int_ | x3::int_)[validator];

    std::string input;
    x3::phrase_parse(input.begin(), input.end(), parser, x3::space);
}
@Krzmbrzl Krzmbrzl changed the title Incorrect attribute propagation for alternatives with equal attributes X3: Incorrect attribute propagation for alternatives with equal attributes Sep 22, 2023
@cppljevans
Copy link
Contributor

think this issue has already been raised in issue 722.

@Krzmbrzl
Copy link
Author

Yes indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants