boost-spirit-qi

In boost spirit, use of multi_pass with streaming file input, which iterator needed

孤街醉人 提交于 2019-12-12 13:30:52
问题 I want to input a significant size csv file to parse it with spirit qi (using boost 1.59.0). There are examples of this and it looks straight forward, but the obvious setup to this results in a compile error where the first parameter to qi::phrase_parse(...) is not accepted. What works here? (One example is at: How to pass the iterator to a function in spirit qi ) The code: #define BOOST_SPIRIT_DEBUG //#define BOOST_SPIRIT_DEBUG_PRINT_SOME 200 //#define BOOST_SPIRIT_DEBUG_OUT std::cerr

boost spirit skipper - compile-time error

我只是一个虾纸丫 提交于 2019-12-12 11:07:37
问题 I have the following code: #include <boost/fusion/include/define_struct.hpp> #include <boost/spirit/include/qi.hpp> #include <iostream> #include <string> BOOST_FUSION_DEFINE_STRUCT( (), foo, (int, bar) (int, baz) ) template <typename Iterator> struct parser : boost::spirit::qi::grammar<Iterator, foo(), boost::spirit::qi::ascii::space_type> { parser() : parser::base_type(start) { start %= boost::spirit::qi::int_ >> boost::spirit::qi::int_; } boost::spirit::qi::rule<Iterator, foo(), boost:

Searching for Holy Grail of search and replace in C++

元气小坏坏 提交于 2019-12-12 08:59:14
问题 Recently I was looking for a way to replace tokens in string which is essentially find and replace (but there is at least one additional approach to the problem) and looks like quite banal task. I've came with couple of possible implementations but none of them was satisfying from performance point of view. Best achievement was ~50us per iteration. The case was ideal, the string was never growing in size and initially I've omitted the requirement to be case insensitive Here is the code at

Class v/s struct in boost::spirit

♀尐吖头ヾ 提交于 2019-12-11 19:27:03
问题 In the boost::spirit documentation, grammars are defined by using struct. For example, template <typename Iterator> struct my_grammar : qi::grammar<Iterator, qi::locals<std::string>, ascii::space_type > { my_grammar() : my_grammar::base_type(start, "start") { // using this and that // rules and action etc. } }; I am wondering if I can write it using class (if not then why?). I am doing this. In header file template<typename Iterator> class my_grammar { public: my_grammar(); // rules

How to implement #ifdef in a boost::spirit::qi grammar?

不羁的心 提交于 2019-12-11 12:52:23
问题 Is there a good way to make a grammar nonterminal which is parsed differently, depending on results of some boost phoenix function? In my use-case, I have a grammar which among other things includes CPP-style #define directives, and #ifdef #else #endif directives. (It's not actually the C preprocessor though its just some crude imitation made by someone else.) When I parse it in qi, I pass my grammar (in its ctor) a reference to a "preprocessor database" object which is adapted to a fusion

Rolling back changes in alternative parsers in qi spirit

百般思念 提交于 2019-12-11 11:59:11
问题 I'm having some trouble using the alternative parser, I need the parser to rollback changes if the first option failed. I tried using hold[] but I get the error that it "could not deduce template argument" I'm trying to parse an AST, and I'm storing it in: struct node; BOOST_FUSION_DEFINE_STRUCT( , node, (std::string, element) (std::string, category) (std::vector<node>, children) ) 'element' is the element parsed, 'category' it's classification, and then I have a vector to store his children

rule to extract key+phrases from a text document

女生的网名这么多〃 提交于 2019-12-11 10:49:09
问题 I want to extract the key phrases from the document: "something KEY phrase END something ... ect". My rule works well but the result does not contain of key name. What should be the rule in order to get a string: "KEY phrase". Thank you for the advice. std::vector<std::string> doc; bool r = qi::phrase_parse(first,last, ( qi::omit[*(qi::char_-"KEY")] >> qi::lexeme[ "KEY" >> *(qi::char_-"KEY" -"END")] ) % "END" , qi::space, doc); 回答1: qi::lit(...) doesn't synthesize an attribute. qi::string(...

How do you output the original unparsed code (as a comment) from a spirit parser

懵懂的女人 提交于 2019-12-11 10:37:22
问题 Given the input string: A = 23; B = 5 , I currently get the (expected) output: Output: 0xa0000023 Output: 0xa0010005 ------------------------- I would like to see this instead: Output: 0xa0000023 // A = 23 Output: 0xa0010005 // B = 5 ------------------------- The core line of code is: statement = eps[_val = 0x50000000] >> identifier[_val += _1<<16] >> "=" >> hex[_val += (_1 & 0x0000FFFF)]; Where identifier is a qi::symbols table lookup. The rest of my code looks like this: #include <boost

Error when using boost::spirit::qi::phrase_parse() with a qi::grammar

最后都变了- 提交于 2019-12-11 09:36:09
问题 I'm doing an IRC message parser with Boost.Spirit but I'm getting a (very long) error when I try to parse an input. I've followed the "Roman Numerals" example. Also, I'm using g++4.7 with -std=c++11 . The error occurs only when I call phrase_parse() on test.cpp , not when I make an instance of message_grammar . The grammar class is: class message_grammar : qi::grammar<std::string::const_iterator, std::string()> { public: message_grammar() : base_type(m_message) { using qi::_val; using qi::_1;

Spirit Grammar parse issue

无人久伴 提交于 2019-12-11 09:15:11
问题 I have the following, class BATSTradeMsg : public BATSMessageBase { BATSTradeMsg(int timestamp, char msgtype, uint64_t orderId, char side, uint32_t shares, std::string const &symbol, uint64_t price, uint64_t execId) : BATSMessageBase(timestamp, msgtype), m_orderId(orderId), m_side(side), m_shares(shares), m_symbol(symbol), m_price(price), m_execId(execId) { } uint64_t m_orderId; // Base 36 Numeric values come over the wire in ascii char m_side; uint32_t m_shares; std::string m_symbol; uint64