boost-spirit

Cannot get Boost Spirit grammar to use known keys for std::map<>

梦想的初衷 提交于 2019-11-28 06:26:04
问题 I seem to be experiencing some mental block with Boost Spirit I just cannot get by. I have a fairly simple grammar I need to handle, where I would like to put the values into a struct, that contains a std::map<> as one of it's members. The key names for the pairs are known up front, so that only those are allowed. There could be one to many keys in the map, in any order with each key name validated via qi. The grammar looks something like this, as an example. test .|*|<hostname> add|modify

Spirit X3: parser with internal state

无人久伴 提交于 2019-11-28 05:54:18
问题 I want to efficiently parse large CSV-like files, whose order of columns I get at runtime. With Spirit Qi, I would parse each field with a lazy auxiliary parser that would select at runtime which column-specific parser to apply to each column. But X3 doesn't seem to have lazy (despite that it's listed in documentation). After reading recommendations here on SO, I've decided to write a custom parser. It ended up being pretty nice, but now I've noticed I don't really need the pos variable be

Parsing escaped strings with boost spirit

人走茶凉 提交于 2019-11-28 04:10:37
问题 I´m working with Spirit 2.4 and I'd want to parse a structure like this: Text{text_field}; The point is that in text_field is a escaped string with the symbols '{', '}' and '\'. I would like to create a parser for this using qi. I've been trying this: using boost::spirit::standard::char_; using boost::spirit::standard::string; using qi::lexeme; using qi::lit; qi::rule< IteratorT, std::string(), ascii::space_type > text; qi::rule< IteratorT, std::string(), ascii::space_type > content; qi::rule

Boost Spirit QI slow

半腔热情 提交于 2019-11-28 03:53:46
问题 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;

Spirit unable to assign attribute to single-element struct (or fusion sequence)

假装没事ソ 提交于 2019-11-28 01:57:27
My goal is to have my qi::grammar return an attribute. I'm having significant difficulty doing this with a spirit::lexer though. I'd expect that with the given grammar below, if I called it with spirit::qi::parse(begin, end, grammar, output); , that the struct ident output would have the contents of the parsed lexeme. The error seems to mostly flow out of this line: start %= lexer.identifier; System Notes Boost 1.47.0 Mac OS X 10.7.2 clang++ or g++ (errors shown below are from clang++) Compile Command g++ -g -c -O0 -Wall -DBOOST_SPIRIT_DEBUG -DBOOST_SPIRIT_LEXERTL_DEBUG -DBOOST_SPIRIT_USE

Parsing a command language using Boost Spirit

笑着哭i 提交于 2019-11-28 01:52:14
问题 I am building a parser for a command language that I've pieced together from various samples. I've read the Boost Spirit Qi and Lex docs, and I think I understand the basics, but from what I've read, I should avoid attributes and use utree. What docs I've found on utree basically suck. Given the code below, I have the following questions: How do I annotate the parser to create an AST using utree? How do I walk the utree after it is built, to discover what was parsed? e.g. for token-only

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

 ̄綄美尐妖づ 提交于 2019-11-28 01:25:59
问题 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

boost::spirit::qi keywords and identifiers

别等时光非礼了梦想. 提交于 2019-11-28 01:18:33
I've seen a few posts related to the nuances of keyword/identifier use in qi grammars, but I can't quite make sense of how the approach demonstrated in the boost examples is supposed to work... Keywords declaration: qi::symbols<char> keywords; Example keyword set: keywords.add ("foo") ("bar") ; Identifier rule declaration: qi::rule<std::string::const_iterator, std::string(), ascii::space_type> identifier; Here's how the identifier rule is defined in the qi calc and compiler examples: identifier = !keywords >> qi::raw[ qi::lexeme[ ( qi::alpha | '_' ) >> *( qi::alnum | '_' ) ] ]; Perhaps I'm

C++ Boost qi recursive rule construction

廉价感情. 提交于 2019-11-28 00:25:26
[It seems my explanations and expectations are not clear at all, so I added precision on how I'd like to use the feature at the end of the post] I'm currently working on grammars using boost qi. I had a loop construction for a rule cause I needed to build it from the elements of a vector. I have re-written it with simple types, and it looks like: #include <string> // using boost 1.43.0 #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/qi_eps.hpp> #include <boost/spirit/include/phoenix.hpp> namespace bqi = boost::spirit::qi; typedef const char* Iterator; // function that you

How to increase the gcc executable stack size?

扶醉桌前 提交于 2019-11-27 23:59:56
问题 I have large Boost/Spirit metaprogram that is blowing gcc's stack when I try to compile it. How can I increase gcc's stack size, so I can compile this program? Note: There's no infinite recursion going on, but there is enough incidental recursion to exhaust gcc's stack. 回答1: On Linux, you can expand the stack size in /etc/security/limits.conf. You can check your current stack size by using $ ulimit -s 8192 Then expand the stack to be double than that: youruser soft stack 16384 And then relog.