boost-spirit-qi

Boost Spirit Qi: Omit element in Kleene Star parser

寵の児 提交于 2019-11-29 15:09:20
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 rule all , giving an output of 7 insteat of 1. How can I tell Spirit to just add to the vector if the

boost spirit parse with the source

混江龙づ霸主 提交于 2019-11-29 14:40:33
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 <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/io.hpp> #include <iostream> #include

Boost Spirit QI slow

醉酒当歌 提交于 2019-11-29 10:23:25
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; std::string l_discount; std::string l_tax; std::string l_returnflag; std::string l_linestatus; std:

Using lexer token attributes in grammar rules with Lex and Qi from Boost.Spirit

强颜欢笑 提交于 2019-11-29 07:57:17
Let's consider following code: #include <boost/phoenix.hpp> #include <boost/spirit/include/lex_lexertl.hpp> #include <boost/spirit/include/qi.hpp> #include <algorithm> #include <iostream> #include <string> #include <utility> #include <vector> namespace lex = boost::spirit::lex; namespace qi = boost::spirit::qi; namespace phoenix = boost::phoenix; struct operation { enum type { add, sub, mul, div }; }; template<typename Lexer> class expression_lexer : public lex::lexer<Lexer> { public: typedef lex::token_def<operation::type> operator_token_type; typedef lex::token_def<double> value_token_type;

Getting boost::spirit::qi to use stl containers

断了今生、忘了曾经 提交于 2019-11-28 20:56:14
I'm trying to parse something with boost.spirit's qi library, and I'm running into an issue. According to the spirit docs , a >> b should produce something with the type tuple<A, B> . But this is a boost::tuple (aka fusion vector), and not a std::tuple (which I want). Is there any easy way to make this conversion between boost::tuple => std::tuple ? The same documentation page says that *a should produce something with the type vector<A> . This seems to be producing a std::vector<A> (or some kind of boost::vector<A> that can implicitly convert to a std::vector<A> ). I just wanted to know if

How can I use the skipper ascii::space WITHOUT skipping eol?

冷暖自知 提交于 2019-11-28 18:58:17
I have to use boost::spirit for parsing, and I want use phrase_parse function : qi::phrase_parse(str.begin(), str.end(), grammar, ascii::space - qi::eol); But the fourth term (ascii::space - qi::eol), isnt allowed by my compiler. How can I use the skipper ascii::space WITHOUT skipping eol ? The simplest answer is qi::phrase_parse(str.begin(), str.end(), grammar, ascii::blank); Of course, it depends on your grammar too: if it expects a specific skipper class you might need to change that. See below for a generic way to handle that (although you could just specify qi::blank_type for a Grammar

Boost spirit revert parsing

陌路散爱 提交于 2019-11-28 14:27:32
I want to parse a file containing the following structure: some garbage *&% section1 { section_content } section2 { section_content } The rule parsing section_name1 { ... } section_name2 { ... } is already defined: section_name_rule = lexeme[+char_("A-Za-z0-9_")]; section = section_name_rule > lit("{") > /*some complicated things*/... > lit("}"); sections %= +section; So I need to skip any garbage until the sections rule is met. Is there any way to accomplish this? I have tried seek[sections] , but it seems not to work. EDIT : I localized the reason why seek is not working: if I use follows

boost::spirit::qi permutation parser and synthesized attributes

僤鯓⒐⒋嵵緔 提交于 2019-11-28 12:53:05
I'm trying to put together a simple command line parser with SPIRIT without semantic actions. I'm using BOOST 1.52 but I would like to avoid using C++11 features. The grammar has the following syntax: [-p num1] [-j] [--jobs num2] str1 str2 Optional parameters can be in any order. I successfully parsed only optional parameters. Once I add the additional mandatory two string parsers it breaks. It breaks even when I try to write down the "rstart" attributes explicitly and avoid type deduction using "auto". Any help or suggestion is very appreciated! #include <iostream> #include <string> #include

Syntax tree empty nodes issue with Spirit Qi MiniC example

耗尽温柔 提交于 2019-11-28 12:42:39
Dear Spirit Qi experts. I have played around with the MiniC example in Spirit Qi, and have noticed an issue with "empty" AST nodes in the expression grammar. It will generate "expression" nodes that hold nothing but a single operand of type "expression" again. I think the issue is due to the recursive rule definitions for the operator precedence: // expression.hpp qi::rule<Iterator, ast::expression(), skipper<Iterator> > expr, equality_expr, relational_expr, logical_or_expr, logical_and_expr, additive_expr, multiplicative_expr ; // expression_def.hpp expr = logical_or_expr.alias() ; logical_or

AST and operator precedence in rule definition

自作多情 提交于 2019-11-28 11:47:24
Hello [¹] I have a simple parser (see below). It intends to parse conditional expressions (relational arithmetic operations and logic combinations thereof). In the example given there, it parses successfully A>5 but then stops and ignores the rest of the input, and this is consistent with my impl. How do I change the expr_ rule to make it parse the entire input? #include <cstdint> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/variant/recursive_wrapper.hpp> namespace qi = boost::spirit::qi;