Skip to content

Instantly share code, notes, and snippets.

@syyyr

syyyr/main.cpp Secret

Last active March 8, 2021 11:00
Show Gist options
  • Save syyyr/94f7f9a0b65e8d4a81eb7a55be8e62ff to your computer and use it in GitHub Desktop.
Save syyyr/94f7f9a0b65e8d4a81eb7a55be8e62ff to your computer and use it in GitHub Desktop.
Boost Spirit X3 bug
#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