Compilation error when adding semantic action to the Boost Spirit parser

Thanks to the help of the user "sehe", I am now at the point where I can compile my ast.

(See here: https://stackoverflow.com/a/167688/ )

Now one of the data fields extracted from the JEDEC file that needs to be disassembled is as follows:

"12345 0000100101010111010110101011010"

I have already created a parser for using these fields:

std::string input("12345 010101010101010101010"); std::string::iterator st = input.begin(); qi::parse(st, input.end(), qi::ulong_ >> ' ' >> *qi::char_("01")); 

Obviously, this is not so difficult. Now my problem is that I want to assign ulong_ and a binary string to some local variables using a semantic action. This is what I did:

 using boost::phoenix::ref; std::string input("12345 010101010101010101010"); std::string::iterator st = input.begin(); uint32_t idx; std::string sequence; qi::parse(st, input.end(), qi::ulong_[ref(idx) = qi::_1] >> ' ' >> *qi::char_("01")[ref(sequence) += qi::_2]); 

But unfortunately, this does not even compile, and the error message that I get is not useful (at least for me)? I think this is something simple ... but I'm hopelessly stuck now .: - (

Does anyone have an idea what I'm doing wrong?

+1
source share
1 answer

Two ways:

  • fix SA

     qi::parse(st, input.end(), qi::ulong_[ref(idx) = qi::_1] >> ' ' >> qi::as_string[*qi::char_("01")] [phx::ref(sequence) += qi::_1]); 

    Notes:

    • it qi::_1 , because the expression to which SA joins does not expose two elements, only 1
    • explicitly phx::ref , because otherwise ADLยน will select std::ref (due to std::string )
    • use as_string to force the attribute type from std::vector<char>


  • However, of course, as always: Boost Spirit: "Semantic actions are evil"?

     qi::parse(st, input.end(), qi::ulong_ >> ' ' >> *qi::char_("01"), idx, sequence ); 

    Use the API parser to bind attribute references.

ยน What is an "Argument-dependent search" (for example, ADL or "Koenig Lookup")?

+1
source

Source: https://habr.com/ru/post/1216461/


All Articles