boost-spirit

Read empty values with boost::spirit

跟風遠走 提交于 2019-12-20 04:00:11
问题 I want to read a CSV into a struct : struct data { std::string a; std::string b; std::string c; } However, I want to read even empty string to ensure all values are in their proper place. I adapted the struct to a boost::fusion, so the following works : // Our parser (using a custom skipper to skip comments and empty lines ) template <typename Iterator, typename skipper = comment_skipper<Iterator> > struct google_parser : qi::grammar<Iterator, addressbook(), skipper> { google_parser() :

Inconsistent Generator directive column behavior in boost karma

↘锁芯ラ 提交于 2019-12-20 03:48:21
问题 I am writing a karma generator to generate a HTML page and I am experiencing inconsistent behavior while using column directive. It could very well be my understanding of how it works. Basically I am generating a grid which requires me to insert some delimiters after every 2 occurrences of the data. The below is a basic program I adopted to do a test run. #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/karma.hpp> #include <boost/fusion/include/struct.hpp> #include

Assign default value to variable using boost spirit

拟墨画扇 提交于 2019-12-20 03:30:19
问题 Suppose I have the following string to parse: "1.2, 2.0, 3.9" and when I apply the following parser for it: struct DataStruct { double n1, n2, n3; }; BOOST_FUSION_ADAPT_STRUCT(DataStruct, (double, n1)(double, n2)(double, n3)) qi::rule<std::string::iterator, DataStruct()> data_ = qi::double_ >> ',' >> qi::double_ >> ',' >> qi::double_; auto str = "1.2, 2.0, 3.9"; auto it - str.begin(); if (qi::parse(it, str.end(), data_, res)) { std::cout << "parse completed" << std::endl; } everything is ok,

How to generalize a spirit parser to take lists in arbitrary order?

梦想的初衷 提交于 2019-12-19 04:01:36
问题 I have a simple parser which can parse lists of ints or quoted strings. If I do the SIMPLE_CASE where I take the input to be: std::string input1 = "{ INT: 42, 24 STR: \"Smith\", \"John\" }"; it parses correctly into my_record , which contains a list of ints and a list of std::string. I want to modify this code to be generic so that it can take zero or more INT lists and zero or more STR lists in arbitrary order and stuff them into my_record in the proper order. I would like my second, more

String parser with boost variant recursive wrapper

我们两清 提交于 2019-12-19 03:46:08
问题 The code below (adapted from spirit qi mini_xml example) does not compile. There is an error related to the rule brac that has an attribute of an recursive boost::variant . However, all commented out versions of brac do compile. I am very curious to know what makes the simple string parser so special in this case: #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator

Boost spirit compile issue

牧云@^-^@ 提交于 2019-12-18 09:12:04
问题 Hi I am very new to boost spirit library. Can you please let me know why below code is not compile? When I add "scientificNumber" rule to my grammar it dont compile. What can be the reason? I have added "scientificNumber" rule to make it possible to parse scientific notaion like "12E10". I dont know if this was the right way to do it. namespace qi = boost::spirit::qi; namespace phx = boost::phoenix; typedef boost::function<double()> Value; #define BINARY_FUNCTOR(name, op) \ struct name \ { \

Using boost::spirit::qi to parse numbers with separators

微笑、不失礼 提交于 2019-12-18 09:02:13
问题 I am attempting to use boost::spirit::qi to do some parsing. It's actually going quite well, and I successfully have managed to parse numbers in various bases based on a suffix. Examples: 123, c12h, 777o, 110101b. I then wanted to add the ability to allow a completely ignored separator character, to allow values like 123_456 or 1101_0011b to parse. I tried using the skip parser, but I highly suspect that I completely misunderstood how it was to be used. It compiles just fine, but my attempt

Boost Spirit Qi: Omit element in Kleene Star parser

限于喜欢 提交于 2019-12-18 08:58:33
问题 I want to parse special constructs and throw the rest away. But I don't want to use a skipper. I want to get a vector of these constructs, so I use a Kleene Star parser as main rule. But, everytime something gets thrown away, a default constructed element is inserted into the vector. Here is a made up example. It just looks for the string Test and throws the rest away, at least this is the plan. But every time the rule garbage succeeds it adds a default constructed item to the vector in the

Boost.Spirit.Qi crashes when assigning rule to a sequence including itself

橙三吉。 提交于 2019-12-18 08:55:31
问题 I have the following MWE: #include <string> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/support_istream_iterator.hpp> namespace spirit = boost::spirit; namespace qi = boost::spirit::qi; namespace phoenix = boost::phoenix; int main() { std::string input("1 2"); qi::rule<std::string::iterator, void(), qi::space_type> parser; qi::rule<std::string::iterator, void(), qi::space_type> parser2; qi::rule<std::string::iterator, void(

boost spirit parse with the source

青春壹個敷衍的年華 提交于 2019-12-18 08:46:11
问题 I would like to be able to parse a Number, to store its original source and to track its position in the source preserving it in the structure itself. This is what I have so far: #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_object.hpp> #include <boost/spirit/home/support/iterators/line_pos_iterator.hpp> #include