semantic-actions

Boost spirit parser fails with incomplete type error

落花浮王杯 提交于 2019-12-11 13:46:26
问题 I've been trying all sorts of things but still not quite understanding why the following fails with 'incomplete type' error #define BOOST_PHOENIX_LIMIT 30 #define SPIRIT_ARGUMENTS_LIMIT 30 #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <ctime> #include <chrono> #include <string> #include <iomanip> namespace qi = boost::spirit::qi; namespace phi = boost::phoenix; using namespace std::chrono_literals; using namespace qi::labels; using It = std:

Simple sematic action destroys the result in Spirit X3

为君一笑 提交于 2019-12-08 12:45:53
问题 I have this Spirit X3 parser auto xyz_def = x3::omit[x3::int_] >> x3::eol >> (x3::lexeme[+(x3::char_ - x3::eol)]) >> x3::eol >> (*(chemical::parser::atom >> x3::eol) ; Which parses, with no problem something like this 2 Comment H 1.2 3.2 4.5 C 1.1 9.1 8.5 Now I want to use (instead of completely ignoring) the first integer as a hint to help build the vector (from the Kleen*). To do that I do: auto xyz_def = x3::omit[x3::int_[([](auto& ctx){x3::_val(ctx).reserve(x3::_attr(ctx));})]] >> x3::eol

Discarding parsed result after semantic action

只谈情不闲聊 提交于 2019-12-08 08:06:05
问题 In Boost.Spirit one can read from a stream to a std::vector simply by doing: #include<vector> #include<boost/spirit/include/qi.hpp> namespace sqi = boost::spirit::qi; int main(){ std::string const v_str = "AA BB CC"; std::vector<std::string> v; auto it = begin(v_str); bool r = sqi::phrase_parse(it, end(v_str), (*sqi::lexeme[+sqi::char_("A-Z")]), sqi::space, v); assert( v.size() == 3 and v[2] == "CC" ); } However, it happens that I know the number of elements in advance because of the input

Discarding parsed result after semantic action

丶灬走出姿态 提交于 2019-12-06 14:53:40
In Boost.Spirit one can read from a stream to a std::vector simply by doing: #include<vector> #include<boost/spirit/include/qi.hpp> namespace sqi = boost::spirit::qi; int main(){ std::string const v_str = "AA BB CC"; std::vector<std::string> v; auto it = begin(v_str); bool r = sqi::phrase_parse(it, end(v_str), (*sqi::lexeme[+sqi::char_("A-Z")]), sqi::space, v); assert( v.size() == 3 and v[2] == "CC" ); } However, it happens that I know the number of elements in advance because of the input format and I should be able to prereserve the space in the vector. For example if the input string is "3