-
-
Save syyyr/94f7f9a0b65e8d4a81eb7a55be8e62ff to your computer and use it in GitHub Desktop.
Boost Spirit X3 bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <boost/spirit/home/x3.hpp> | |
#include <boost/spirit/home/x3.hpp> | |
#include <boost/fusion/adapted/struct/adapt_struct.hpp> | |
namespace x3 = boost::spirit::x3; | |
struct numbers { | |
int value; | |
int value2; | |
// number& operator=(const int data) { | |
// this->value = data; | |
// return *this; | |
// } | |
}; | |
BOOST_FUSION_ADAPT_STRUCT(numbers, value, value2) | |
auto doSideEffects = x3::eps[([] (auto& ctx) { | |
// do some stuff... | |
})]; | |
auto wrappedDoSideEffects = x3::rule<class Rule, x3::unused_type>{} = doSideEffects; | |
auto my_rule = x3::rule<class my_class, numbers>{} = doSideEffects > x3::int32 > " " > x3::int32; | |
int main(int argc, char* argv[]) | |
{ | |
std::string input = "235 12"; | |
numbers out; | |
auto it = input.begin(); | |
auto res = x3::parse(it, input.end(), my_rule, out); | |
// This doesn't print 235 and 12, because doSideEffects breaks the parser. | |
// If I swap doSideEffects with wrappedDoSideEffects, it works again. | |
std::cout << "out.arg = " << out.value << "\n"; | |
std::cout << "out.arg = " << out.value2 << "\n"; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment