boost-spirit

What are the disadvantages of the Spirit parser-generator framework from boost.org?

此生再无相见时 提交于 2019-12-02 15:06:59
In several questions I've seen recommendations for the Spirit parser-generator framework from boost.org , but then in the comments there is grumbling from people using Spirit who are not happy. Will those people please stand forth and explain to the rest of us what are the drawbacks or downsides to using Spirit? It is a quite cool idea, and I liked it; it was especially useful to really learn how to use C++ templates. But their documentation recommends the usage of spirit for small to medium-size parsers. A parser for a full language would take ages to compile. I will list three reasons.

boost spirit on_error not triggered

笑着哭i 提交于 2019-12-02 10:51:33
问题 ^ No it is not. This was part of the problem, but if review the code as is right now, it already does what the pointed out question/answer shows ... and the errors are still not triggered. I have this boost spirit parser for string literal. It works. Now I would like to start handle errors when it fail. I copied the on_error handle 1-1 from the mini xml example and it compiles, but it is never triggered (no errors are outputted). This is the parser: #define BOOST_SPIRIT_USE_PHOENIX_V3 #define

parsing into std::vector<string> with Spirit Qi, getting segfaults or assert failures

拟墨画扇 提交于 2019-12-02 05:45:35
I am using Spirit Qi as my parser, to parse mathematical expressions into an expression tree. I keep track of such things as the types of the symbols which are encountered as I parse, and which must be declared in the text I am parsing. Namely, I am parsing Bertini input files , a simple-ish example of which is here , a complicated example is here , and for completeness purposes, as below: %input: our first input file variable_group x,y; function f,g; f = x^2 - 1; g = y^2 - 4; END; The grammar I have been working on will ideally find declaration statements, and then parse the following comma

Read empty values with boost::spirit

孤街醉人 提交于 2019-12-02 05:26:42
I want to read a CSV into a struct : struct data { std::string a; std::string b; std::string c; } However, I want to read even empty string to ensure all values are in their proper place. I adapted the struct to a boost::fusion, so the following works : // Our parser (using a custom skipper to skip comments and empty lines ) template <typename Iterator, typename skipper = comment_skipper<Iterator> > struct google_parser : qi::grammar<Iterator, addressbook(), skipper> { google_parser() : google_parser::base_type(contacts, "contacts") { using qi::eol; using qi::eps; using qi::_1; using qi::_val;

Boost spirit using local variables

无人久伴 提交于 2019-12-02 04:44:23
问题 I would like to define a rule based on a previously parsed value, i. e. the input string has the following structure: D <double number> or I <integer number> . I keep in a local boolean variable whether the first read character is D or I . The complete code is: #define BOOST_SPIRIT_USE_PHOENIX_V3 #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <string> namespace qi = boost::spirit::qi; namespace spirit = boost::spirit; namespace ascii = boost:

Boost Qi Composing rules using Functions

微笑、不失礼 提交于 2019-12-02 04:01:55
问题 I'm trying to define some Boost::spirit::qi parsers for multiple subsets of a language with minimal code duplication. To do this, I created a few basic rule building functions. The original parser works fine, but once I started to use the composing functions, my parsers no longer seem to work. The general language is of the form: A B: C There are subsets of the language where A , B , or C must be specific types, such as A is an int while B and C are floats. Here is the parser I used for that

Several matches in a one pass parser?

家住魔仙堡 提交于 2019-12-02 04:00:30
I am trying (yet) to populate several vectors with data parsed from a log. The key is do it as fast and efficient as possible, so I would like to collect all the data in only one pass (not "or" between rules). I have found the next problems: 1) Every time I use spirit and it does not work as expected I find myself totally loss and trying test and error for two hours. Is there any debug directive that gives some hint about what has gone wrong? 2) Is it valid the way I use phoenix construct? I mean, can it be used as I have done in code for avoiding using a symbol table? 3) Is there any way of

Boost spirit compile error for trivial grammar

情到浓时终转凉″ 提交于 2019-12-02 03:46:17
问题 I am trying to compile a parser with the following rules: else_statement = lit("else") > statement; if_statement = lit("if") >> '(' >> expression >> ')' >> statement >> -else_statement; The attribute of else_statement is statement , as is the statement rule that it consumes. The attribute of if_statement is a struct with members respectively types expression , statement and an optional statement ( boost::optional<statement> ). Using the following BOOST_FUSION_ADAPT_STRUCT 's: BOOST_FUSION

Combining rules at runtime and returning rules

一曲冷凌霜 提交于 2019-12-02 03:37:22
问题 I am trying to write some complex parser made on top of Spirit-X3, so I need to know some things: ♦ How to combine rules at runtime. (with Nabialek's trick) ♦ Is it ok to return rules like this: x3::rule<char> SomeFunction(std::string &str) { x3::rule<char> foo; auto bar = baz; BOOST_SPIRIT_DEFINE(foo, bar); return foo; } PS: SomeFunction won't have a fixed return, so I can't use just a x3::sequence 回答1: Yes, x3 makes it a lot easier to compose rules. Mainly because parser expressions don't

Boost.Spirit X3 parser “no type named type in(…)”

ぐ巨炮叔叔 提交于 2019-12-02 03:25:01
I was toying with Boost.Spirit X3 calculator example when I encountered an error I couldn't get my head around. I minimized the program to reduce complexity still throwing the same error. Say I want to parse an input as a list of statements (strings) followed by a delimiter (';'). This is my structure: namespace client { namespace ast { struct program { std::list<std::string> stmts; }; }} BOOST_FUSION_ADAPT_STRUCT(client::ast::program, (std::list<std::string>, stmts) ) The grammar is as follows: namespace client { namespace grammar { x3::rule<class program, ast::program> const program("program