boost-spirit

Boost Spirit QI slow

混江龙づ霸主 提交于 2020-01-06 19:31:29
问题 I try to parse TPCH files with Boost Spirit QI. My implementation inspired by the employee example of Spirit QI ( http://www.boost.org/doc/libs/1_52_0/libs/spirit/example/qi/employee.cpp ). The data is in csv format and the tokens are delimited with a '|' character. It works but it is very slow (20 sec. for 1 GB). Here is my qi grammer for the lineitem file: struct lineitem { int l_orderkey; int l_partkey; int l_suppkey; int l_linenumber; std::string l_quantity; std::string l_extendedprice;

segmentation fault with trivial spirit parser

我的未来我决定 提交于 2020-01-06 02:57:24
问题 I've been using spirit::qi quite often for the past several months. However, this time I got a segfault that I really can't make any sense out of. I have reduced it to an extremely minimal test case, the grammar definition is 12 lines of code. This feels a lot like an earlier question but the solution there, of adding .alias() to some of the terminals so that qi doesn't make copies of them, doesn't seem to fix this. I'm concerned that there's something fundamental I'm missing here, since I've

How to make boost::spirit parser and lexer being able to deal with include files

╄→尐↘猪︶ㄣ 提交于 2020-01-05 09:09:12
问题 This is a do-nothing lexer&parser -- it returns the string read. I would like to have this extended to be able to deal with a C++-like include statement. I can imagine how to do this -- but I would like to know if there is some easier or already available way. If I would have to do this, I would implement my own iterator (to be passed to the lexer). This iterator would contain an index into a string (potentially using -1 to indicate end() iterator) a pointer to this string The lexer on

Boost Spirit optional parser and backtracking

南笙酒味 提交于 2020-01-04 14:11:50
问题 Why this parser leave 'b' in attributes, even if option wasn't matched? using namespace boost::spirit::qi; std::string str = "abc"; auto a = char_("a"); auto b = char_("b"); qi::rule<std::string::iterator, std::string()> expr; expr = +a >> -(b >> +a); std::string res; bool r = qi::parse( str.begin(), str.end(), expr >> lit("bc"), res ); It parses successfully, but res is "ab" . If parse "abac" with expr alone, option is matched and attribute is "aba" . Same with "aac" , option doesn't start

boost spirit qi match multiple elements

三世轮回 提交于 2020-01-04 05:52:49
问题 I would like to create a parser based on boost spirit qi that will be able to parse a list of integer values. That is obviously extremely easy and there are tons of examples. The list though is a bit smarter than a comma separated list and it could looks like: 17, 5, fibonacci(2, 4), 71, 99, range(5, 7) the result of the parser should be a std::vector with the following values: 17, 5, 1, 2, 3, 71, 99, 5, 6, 7 Where fibonacci(2, 4) results in 1, 2, 3 and range(5, 7) results in 5, 6, 7 Edit:

Ignore all characters up to a given word

我只是一个虾纸丫 提交于 2020-01-04 05:49:37
问题 I have this example code, which parses the string str correctly. How to I make it work if there any extra characters before and/or after the string? For example if I did str = std::string("AAA") + str + std::string("AAA") frame.h #define BOOST_SPIRIT_USE_PHOENIX_V3 //#define BOOST_SPIRIT_DEBUG #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/fusion/adapted/std_pair.hpp> namespace qi = boost::spirit::qi; namespace phx = boost::phoenix;

How to determine line/column numbers from boost::spirit::lex tokens?

浪尽此生 提交于 2020-01-04 05:30:31
问题 In its answer to this question, hkaiser said he would write an example of a token type which carries code position information. I really cannot find anything about this. Can anyone point me to such an example ? 回答1: He was probably referring to position_token , which did in fact get released, although there's little documentation. This SO question has good coverage of its usage. 来源: https://stackoverflow.com/questions/32073454/how-to-determine-line-column-numbers-from-boostspiritlex-tokens

Parsing a structure in an associative manner with Boost Spirit and Fusion

痴心易碎 提交于 2020-01-04 02:44:17
问题 I'm trying to parse a key-value string into a structure. Some key-values may be absent or may be in different order, so I wanted to use boost::fusion to adapt the structure and then parse into it with at_key<> directive. #include <iostream> #include <string> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/fusion/adapted.hpp> #include <boost/fusion/sequence.hpp> using namespace std; namespace qi = boost::spirit::qi; namespace ascii = boost:

Is it possible to attach an action to a boost::spirit::rule parser which assigns the parsed result to a member of a (yet) unknown instance?

一曲冷凌霜 提交于 2020-01-02 07:12:23
问题 I'm trying to reference a member of a (yet) unknown instance from within a boost::spirit rule definitions' action, so in pseudocode, instead of double_[ref(rN) = _1] I'm looking for something like X** ppx; double_[ref(&X::rN, ppx) = _1] A workaround for it could be a simple "semantic action" with a parameter which knows the instance and would be able to write to it, like qi::rule<Iterator, Skipper> start; my_grammar(DataContext*& dataContext) : my_grammar::base_type(start) , execContext

Is it possible to attach an action to a boost::spirit::rule parser which assigns the parsed result to a member of a (yet) unknown instance?

巧了我就是萌 提交于 2020-01-02 07:12:21
问题 I'm trying to reference a member of a (yet) unknown instance from within a boost::spirit rule definitions' action, so in pseudocode, instead of double_[ref(rN) = _1] I'm looking for something like X** ppx; double_[ref(&X::rN, ppx) = _1] A workaround for it could be a simple "semantic action" with a parameter which knows the instance and would be able to write to it, like qi::rule<Iterator, Skipper> start; my_grammar(DataContext*& dataContext) : my_grammar::base_type(start) , execContext