boost-spirit-qi

Boost Spirit optional parser and backtracking

南笙酒味 提交于 2020-01-04 14:11:50
问题 Why this parser leave 'b' in attributes, even if option wasn't matched? using namespace boost::spirit::qi; std::string str = "abc"; auto a = char_("a"); auto b = char_("b"); qi::rule<std::string::iterator, std::string()> expr; expr = +a >> -(b >> +a); std::string res; bool r = qi::parse( str.begin(), str.end(), expr >> lit("bc"), res ); It parses successfully, but res is "ab" . If parse "abac" with expr alone, option is matched and attribute is "aba" . Same with "aac" , option doesn't start

boost spirit qi match multiple elements

三世轮回 提交于 2020-01-04 05:52:49
问题 I would like to create a parser based on boost spirit qi that will be able to parse a list of integer values. That is obviously extremely easy and there are tons of examples. The list though is a bit smarter than a comma separated list and it could looks like: 17, 5, fibonacci(2, 4), 71, 99, range(5, 7) the result of the parser should be a std::vector with the following values: 17, 5, 1, 2, 3, 71, 99, 5, 6, 7 Where fibonacci(2, 4) results in 1, 2, 3 and range(5, 7) results in 5, 6, 7 Edit:

Boost Spirit Qi crashes for memory violation

大城市里の小女人 提交于 2020-01-02 08:56:09
问题 But I cannot figure out why...? http://coliru.stacked-crooked.com/a/2912593bb421a35e #include <boost/fusion/adapted/struct.hpp> #include <boost/spirit/include/qi.hpp> namespace bsq = boost::spirit::qi; int main() { std::uint16_t major, minor, build, revision; auto versionParser = bsq::uint_ >> -('.' >> bsq::uint_) >> -('.' >> bsq::uint_) >> -('.' >> bsq::uint_); std::string version = "3.5.1"; auto start = version.begin(); if (!bsq::parse(start, version.end(), versionParser, major, minor,

Is it possible to attach an action to a boost::spirit::rule parser which assigns the parsed result to a member of a (yet) unknown instance?

一曲冷凌霜 提交于 2020-01-02 07:12:23
问题 I'm trying to reference a member of a (yet) unknown instance from within a boost::spirit rule definitions' action, so in pseudocode, instead of double_[ref(rN) = _1] I'm looking for something like X** ppx; double_[ref(&X::rN, ppx) = _1] A workaround for it could be a simple "semantic action" with a parameter which knows the instance and would be able to write to it, like qi::rule<Iterator, Skipper> start; my_grammar(DataContext*& dataContext) : my_grammar::base_type(start) , execContext

Is it possible to attach an action to a boost::spirit::rule parser which assigns the parsed result to a member of a (yet) unknown instance?

巧了我就是萌 提交于 2020-01-02 07:12:21
问题 I'm trying to reference a member of a (yet) unknown instance from within a boost::spirit rule definitions' action, so in pseudocode, instead of double_[ref(rN) = _1] I'm looking for something like X** ppx; double_[ref(&X::rN, ppx) = _1] A workaround for it could be a simple "semantic action" with a parameter which knows the instance and would be able to write to it, like qi::rule<Iterator, Skipper> start; my_grammar(DataContext*& dataContext) : my_grammar::base_type(start) , execContext

in boost::spirit::qi, is it possible to dynamically modify rule definition in runtime

谁说我不能喝 提交于 2020-01-02 05:14:05
问题 I wrote some grammar with boost::spirit::qi::rule to parse the internet packet. the grammar is something like: qi::rule<Iterator> start, request, response, status, query ; start = (request | response | status | query) >> lit("\r\n"); to improve the performance, user maybe want to skip some rules in the runtime, e.g. ignore "response","status","query" and only try to match request, so the rule will change to: start = (request ) >> lit("\r\n"); is it possible to do that? e.g, is there a

How to pass the iterator to a function in spirit qi

你。 提交于 2020-01-01 03:51:27
问题 template <typename Iterator> struct parse_grammar : qi::grammar<Iterator, std::string()> { parse_grammar() : parse_grammar::base_type(start_p, "start_p"){ a_p = ',' > qi::double_; b_p = *a_p; start_p = qi::double_ > b_p >> qi::eoi; } qi::rule<Iterator, std::string()> a_p; qi::rule<Iterator, std::string()> b_p; qi::rule<Iterator, std::string()> start_p; }; // implementation std::vector<double> parse(std::istream& input, const std::string& filename) { // iterate over stream input typedef std:

Parsing text file with binary envelope using boost Spririt

半世苍凉 提交于 2019-12-31 05:05:08
问题 I'm currently trying to write a parser for an ASCII text file that is surrounded by a small envelope with checksum. The basic structure of the file is: <0x02><"File payload"><0x03><16bit CRC> and I want to extract the payload in another string to feed it to the next parser. The parser expression I use to parse this envelope is: qi::phrase_parse( first, last, char_('\x02') >> *print >> char_('\x02') >> *xdigit, space ); The input is consumed... and I already tried to dump out the payload: qi:

Getting into boost spirit; Qi or X3?

烂漫一生 提交于 2019-12-31 02:41:19
问题 I was making an interpreter for a small personal project with a friend; we started implementing all the classes and general structure in which the code would be translated to then execute just to postpone the actual parsing code into these structures. Now we have to build the parser, and after some search I found posts and people all over the place speaking about spirit Qi and spirit X3 as if they were (i think they are) 2 different ways of making a parser, but no-one saying the difference,

Getting into boost spirit; Qi or X3?

ぃ、小莉子 提交于 2019-12-31 02:41:07
问题 I was making an interpreter for a small personal project with a friend; we started implementing all the classes and general structure in which the code would be translated to then execute just to postpone the actual parsing code into these structures. Now we have to build the parser, and after some search I found posts and people all over the place speaking about spirit Qi and spirit X3 as if they were (i think they are) 2 different ways of making a parser, but no-one saying the difference,