boost-spirit-qi

parse typed csv file with boost::spirit::qi

点点圈 提交于 2019-12-22 10:59:05
问题 I want to parse a CSV-File with typed values. The type of every column is defined in the header, e.x.: int double double int unsigned 12 1.3 23445 1 42 45 46 47 48 49 The result data structure may be something like this 2-dimensional vector: using ColumnType = boost::variant< std::vector<int>, std::vector<unsigned>, std::vector<double> >; using ResultType = std::vector<ColumnType>; My working code: namespace phoenix = boost::phoenix; namespace qi = boost::spirit::qi; namespace ascii = boost:

Boost Semantic Actions causing parsing issues

强颜欢笑 提交于 2019-12-22 10:43:30
问题 I've been working with the Boost mini compiler example. Here is the root of the source code: http://www.boost.org/doc/libs/1_59_0/libs/spirit/example/qi/compiler_tutorial/mini_c/ The snippet that interests me is in statement_def.hpp The problem I am having is that if you attach semantic actions, for example like such, statement_ = variable_declaration[print_this_declaration] | assignment | compound_statement | if_statement | while_statement | return_statement ; And subsequent run the mini_c

Is there a way to match the content of a spirit::lex string token as a literal in a spirit::qi grammar

可紊 提交于 2019-12-22 10:10:40
问题 I'm writing a DSL and using a Boost Spirit lexer to tokenize my input. In my grammar, I want a rule similar to this (where tok is the lexer): header_block = tok.name >> ':' >> tok.stringval > ';' >> tok.description >> ':' >> tok.stringval > ';' ; Rather than specifying reserved words for the language (e.g. "name", "description") and deal with synchronizing these between the lexer and grammar, I want to just tokenize everything that matches [a-zA-Z_]\w* as a single token type (e.g. tok.symbol

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

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

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>()> // <-

Is there an alternative for boost::phoenix::at_c in combination with boost::spirit::qi::grammar

别等时光非礼了梦想. 提交于 2019-12-21 05:31:11
问题 I have created a test application to illustrate my problem. It parses a list of integers preceded by "a=" or "b=" and is separated by "\r\n". The list contains multiple occurrences of those fields in any order. #include <string> #include <vector> #include <iostream> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/fusion/include/adapt_struct.hpp> typedef std::vector<unsigned int> uint_vector_t; std::ostream& operator<<(std::ostream& out, const

Why does boost::spirit::qi::parse() not set this boost::variant's value?

↘锁芯ラ 提交于 2019-12-21 04:59:13
问题 When trying to parse text into a boost::variant, the variant's value does not get changed. The parsers by themselves appear to work fine, so my assumption is that I'm doing something wrong with the variant code. I'm using boost 1.46.1 and the following code compiles in Visual Studio 2008. 1st Update hkaiser noted that the rule and grammar template arguments must not be Variant but Variant() . This got a bit "further" as I now have a compilation error in boost_1_46_1\boost\variant\variant.hpp

boost::spirit::qi and out-of-sequence variables

一个人想着一个人 提交于 2019-12-21 04:42:12
问题 I'm writing a lexigraphical analyser. It takes an English string, and converts it into a set of latitude/longitude co-ordinates. It's a bit like Google Earth. Anyway, I've written my symbol tables and grammar, and it's happily parsing formatted data. struct LatLongDegrees { std::string dirLat_; double degLat_; std::string dirLong_; double degLong_; } For example: {"North", 23.59, "East", -30.82} Here is my grammar: basic =(latitude >> ' ' >> double_ >> ' ' >> longitude >> ' ' >> double_);