boost-spirit

decode http header value fully with boost spirit

倖福魔咒の 提交于 2019-12-22 09:55:31
问题 Once again, I find myself reaching for boost spirit. Once again I find myself defeated by it. A HTTP header value takes the general form: text/html; q=1.0, text/*; q=0.8, image/gif; q=0.6, image/jpeg; q=0.6, image/*; q=0.5, */*; q=0.1 i.e. value *OWS [; *OWS name *OWS [= *OWS possibly_quoted_value] *OWS [...]] *OWS [ , <another value> ...] so in my mind, this header decodes to: value[0]: text/html params: name : q value : 1.0 value[1]: text/* params: name : q value : 0.8 ... and so on. I am

Segmentation fault with trivial Spirit Parser grammar

丶灬走出姿态 提交于 2019-12-22 09:48:50
问题 I'm running into frequent segfaults with my Spirit Qi parser. After spending days to debug the issue (I found the stacktraces impossible to grok) I decided to trim it down to a minimal example. Can anyone tell what I'm doing wrong, if anything? Save code as bug.cpp, compile with g++ -Wall -o bug bug.cpp and you should be good to go. //#define BOOST_SPIRIT_DEBUG_PRINT_SOME 80 //#define BOOST_SPIRIT_DEBUG #include <boost/spirit/version.hpp> #include <boost/spirit/include/qi.hpp> #include

Boost spirit parse integer to custom list template

為{幸葍}努か 提交于 2019-12-22 09:19:38
问题 I have trouble with boost spirit to parse a file like that : int [int, int, int] [ int, int] ... Nothing really hard, the following grammar works for that: template<typename Iterator> struct parser_expression : qi::grammar<Iterator,ascii::space_type> { parser_expression() : parser_expression::base_type(start) { using qi::double_; using qi::int_; using boost::spirit::qi::char_; using qi::alpha; using qi::alnum; using qi::digit; using qi::eps; using qi::_val; using boost::phoenix::bind; start =

using boost::karma to format latitude/longitude strings

倾然丶 夕夏残阳落幕 提交于 2019-12-22 07:08:10
问题 I need to format double values into coordinate strings that have a very specific format, "DDMMSS.SSX" where: "DD" is the full degrees "MM" is the full minutes "SS.SS" is the seconds with fraction "X" is either "N" or "S" depending on hemisphere The fields need to be padded with zeroes. Spaces cannot be accepted. Examples for the formatting is as follows: 47.2535 ==> "471512.45N" -0.123345 ==> "000724.04S" I have managed to create the following program that does the job. However I have some

using boost::karma to format latitude/longitude strings

♀尐吖头ヾ 提交于 2019-12-22 07:07:13
问题 I need to format double values into coordinate strings that have a very specific format, "DDMMSS.SSX" where: "DD" is the full degrees "MM" is the full minutes "SS.SS" is the seconds with fraction "X" is either "N" or "S" depending on hemisphere The fields need to be padded with zeroes. Spaces cannot be accepted. Examples for the formatting is as follows: 47.2535 ==> "471512.45N" -0.123345 ==> "000724.04S" I have managed to create the following program that does the job. However I have some

how to parse and verify an ordered list of integers using qi

一曲冷凌霜 提交于 2019-12-22 06:47:52
问题 I'm parsing a text file, possibly several GB in size, consisting of lines as follows: 11 0.1 14 0.78 532 -3.5 Basically, one int and one float per line. The ints should be ordered and non-negative. I'd like to verify the data are as described, and have returned to me the min and max int in the range. This is what I've come up with: #include <iostream> #include <string> #include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/fusion/include/std_pair

How to parse DSL input to high performance expression template

廉价感情. 提交于 2019-12-22 00:07:02
问题 ( EDITED both title and main text and created a spin-off question that arose) For our application it would be ideal to parse a simple DSL of logical expressions. However the way I'd like to do this is to parse (at runtime) the input text which gives the expressions into some lazily evaluated structure (an expression template) which can then be later used within more performance sensitive code. Ideally the evaluation is as fast as possible using this technique as it will be used a large number

Boost-Spirit (X3) parsing without default constructors

怎甘沉沦 提交于 2019-12-21 23:57:13
问题 I'm trying to use Spirit X3 from Boost 1.65.1 to make a parser. I have reduced my problem to the following smaller example with simpler structures: #include <boost/config/warning_disable.hpp> #include <boost/spirit/home/x3.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <iostream> #include <vector> struct MyPair { MyPair(int x, int y) : mx(x), my(y) {}; //MyPair() {} // No default constructor - neither needed nor wanted. int mx; int my; }; /* BOOST_FUSION_ADAPT_STRUCT( MyPair,

Spirit Qi : rule for char [5]

不问归期 提交于 2019-12-21 23:24:01
问题 I have the following structure struct MyStruct { char CODE; char NAME[5]; }; I make it a fusion struct BOOST_FUSION_ADAPT_STRUCT ( MyStruct, (char, MARKET_CODE) (char, NAME[5]) ) My grammar is implemented as follow: MyStruct_parser() : ticker_parser::base_type(start) { using qi::lexeme; using ascii::char_; a_word %= lexeme[+(char_)]; start %= a_word >> a_word; } qi::rule<Iterator, std::string(), ascii::space_type> quoted_string; qi::rule<Iterator, Ticker(), ascii::space_type> start;

Parentheses in template parameters in Boost Spirit rules and grammars

假装没事ソ 提交于 2019-12-21 17:39:09
问题 Looking at this example for implementing a Spirit parser, something caught me out when I was trying to write something similar. The attribute template parameter of the grammar ( std::map<std::string, std::string>() ) and the signature template parameter of the rules (e.g. qi::rule<Iterator, std::string()> key, value ) contain parentheses. namespace qi = boost::spirit::qi; template <typename Iterator> struct keys_and_values : qi::grammar<Iterator, std::map<std::string, std::string>()> // <-