boost-spirit

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:

more spirit madness - parser-types (rules vs int_parser<>) and meta-programming techniques

南楼画角 提交于 2019-12-31 10:57:18
问题 The question is in bold at the bottom, the problem is also summarized by the distillation code fragment towards the end. I am trying to unify my type system (the type system does to and from from type to string) into a single component(as defined by Lakos). I am using boost::array , boost::variant , and boost::mpl , in order to achieve this. I want to have the parser and generator rules for my types unified in a variant. there is a undefined type, a int4(see below) type and a int8 type. The

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:

in boost::spirit::lex, it takes longest time to do first parsing, following parsing will be much shorter

人盡茶涼 提交于 2019-12-31 03:05:58
问题 I feed a series of text into my sip parser.the first one takes the longest time, no matter which is the first one.I wonder if there is any initialization work when spirit::lex do the first parsing? template <typename Lexer> struct sip_token : lex::lexer<Lexer> { sip_token() { this->self.add_pattern ("KSIP", "sip:") ("KSIPS", "sips:") ("USERINFO", "[0-9a-zA-Z-_.!~*'()]+(:[0-9a-zA-Z-_.!~*'()&=+$,]*)?@") ("DOMAINLBL", "([0-9a-zA-Z]|([0-9a-zA-Z][0-9a-zA-Z-]*[0-9a-zA-Z]))") ("TOPLBL", "[a-zA-Z]|(

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,

cannot get boost::spirit parser&lexer working for token types other than std::string or int or double

倾然丶 夕夏残阳落幕 提交于 2019-12-30 11:03:10
问题 This does not compile (code below). There was another question here with the same error. But I don't understand the answer. I already tried inserting qi::eps in places -- but without success. I also tried already adding meta functions (boost::spirit::raits::is_container) for the types used -- but this also does not help. I also tried using the same variant containing all types I need to use everywhere. Same problem. Has anybody gotten this working for a lexer returning something else than

cannot get boost::spirit parser&lexer working for token types other than std::string or int or double

↘锁芯ラ 提交于 2019-12-30 11:02:36
问题 This does not compile (code below). There was another question here with the same error. But I don't understand the answer. I already tried inserting qi::eps in places -- but without success. I also tried already adding meta functions (boost::spirit::raits::is_container) for the types used -- but this also does not help. I also tried using the same variant containing all types I need to use everywhere. Same problem. Has anybody gotten this working for a lexer returning something else than

Function or functor calling using sprit boost parser library rule to save values in vector c++

徘徊边缘 提交于 2019-12-30 10:35:35
问题 I want to parse this line and storing all hex values in functor <005F> <0061> [<00660066> <00660069> <00660066006C>] this values in txt file and m reading this fill line by line like 005F 0061 00660066 00660069 00660066006C all values should be in vector but its not working the spirit rule is to parse this line is rule<> blanks = *blank_p; rule<> parse_int = blanks >> "<" >> int_p [AddEntry] >> ">"; rule<> parse_ints = *parse_int ; rule<> parse_range = *parse_int >>"[" >> blanks >> *parse_int