boost-spirit

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 Signals Successful Parsing Despite Token Being Incomplete

谁说我不能喝 提交于 2019-11-29 14:50:11
I have a very simple path construct that I am trying to parse with boost spirit.lex. We have the following grammar: token := [a-z]+ path := (token : path) | (token) So we're just talking about colon separated lower-case ASCII strings here. I have three examples "xyz", "abc:xyz", "abc:xyz:". The first two should be deemed valid. The third one, which has a trailing colon, should not be deemed valid. Unfortunately the parser I have recognizes all three as being valid. The grammar should not allow an empty token, but apparently spirit is doing just that. What am I missing to get the third one

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

Parsing a pair of ints with boost spirit

孤人 提交于 2019-11-29 13:41:02
问题 I have the following code: std::string test("1.1"); std::pair<int, int> d; bool r = qi::phrase_parse( test.begin(), test.end(), qi::int_ >> '.' >> qi::int_, space, d ); So I'm trying to parse the string test and place the result in the std::pair d. However it is not working, I suspect it has to do with the Compound Attribute Rules. Any hints to how to get this working? The compiler error is the following: error: no matching function for call to 'std::pair::pair(const int&)' 回答1: It should

How to use Boost Spirit to parse Chinese(unicode utf-16)?

对着背影说爱祢 提交于 2019-11-29 11:30:56
My program does not recognize Chinese. How to use spirit to recognize Chinese? I use wstring and has convert it to utf-16. Here is my header file: #pragma once #define BOOST_SPIRIT_UNICODE #include <boost/spirit/include/qi.hpp> #include <string> #include <vector> #include <map> using namespace std; namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; typedef pair<wstring,wstring> WordMeaningType; typedef vector<WordMeaningType> WordMeaningsType; typedef pair<wstring,WordMeaningsType> WordType; typedef vector<WordType> WordListType; struct WordPaser :qi::grammar<wstring:

How to use boost::spirit to parse UTF-8?

社会主义新天地 提交于 2019-11-29 11:11:24
#include <algorithm> #include <iostream> #include <string> #include <vector> #define BOOST_SPIRIT_UNICODE // We'll use unicode (UTF8) all throughout #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/qi_parse.hpp> #include <boost/spirit/include/support_standard_wide.hpp> void parse_simple_string() { namespace qi = boost::spirit::qi; namespace encoding = boost::spirit::unicode; //namespace stw = boost::spirit::standard_wide; typedef std::wstring::const_iterator iterator_type; std::vector<std::wstring> result; std::wstring const input = LR"(12,3","ab,cd","G,G\"GG","kkk","10,\

How to use Boost::Spirit::Lex to lex a file without reading the whole file into memory first?

坚强是说给别人听的谎言 提交于 2019-11-29 10:44:59
I'm looking at writing a lexer using boost::spirit::lex, but all the examples I can find seem to assume that you've read the entire file into RAM first. I'd like to write a lexer that doesn't require the whole string to be in RAM, is that possible? Or do I need to use something else? I tried using istream_iterator, but boost gives me a compile error unless I use const char* as the iterator types. e.g. All the examples I can find basically do this: lex_functor_type< lex::lexertl::lexer<> > lex_functor; // assumes entire file is in memory char const* first = str.c_str(); char const* last =

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:

boost::spirit::x3 attribute compatibility rules, intuition or code?

谁说胖子不能爱 提交于 2019-11-29 08:44:20
Is there a document somewhere which describes how various spirit::x3 rule definition operations affect attribute compatibility? I was surprised when: x3::lexeme[ x3::alpha > *(x3::alnum | x3::char_('_')) ] could not be moved into a fusion-adapted struct: struct Name { std::string value; }; For the time being, I got rid of the first mandatory alphabetical character, but I would still like to express a rule which defines that the name string must begin with a letter. Is this one of those situations where I need to try adding eps around until it works, or is there a stated reason why the above

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;