Questions tagged [boost-spirit-qi]

a practical, scalable parsing library for C++

Spirit.Qi is designed to be a practical parsing tool. The ability to generate a fully-working parser from a formal EBNF specification inlined in C++ significantly reduces development time.

Programmers typically approach parsing using ad hoc hacks with primitive tools such as scanf. Even regular-expression libraries (such as boost regex) or scanners (such as boost tokenizer) do not scale well when we need to write more elaborate parsers. Attempting to write even a moderately-complex parser using these tools leads to code that is hard to understand and maintain.

One prime objective is to make the tool easy to use. When one thinks of a parser generator, the usual reaction is “it must be big and complex with a steep learning curve.” Not so. Spirit is designed to be fully scalable. The library is structured in layers. This permits learning on an as-needed basis, after only learning the minimal core and basic concepts.

For development simplicity and ease in deployment, the entire library consists of only header files, with no libraries to link against or build. Just put the Spirit distribution in your include path, compile and run. Code size is very tight, essentially comparable to hand-written recursive descent code.

Have fun!

Further Reading

687 questions
8
votes
1 answer

Change attribute type when parsing binary with boost::spirit

I have been successfully using boost::spirit::qi to to parse a stream consisting of the built-in parsers (e.g. byte_, little_word, etc). However, I now need to parse data that doesn't neatly fall into one of these categories. For example, I would…
Michael Koval
  • 8,207
  • 5
  • 42
  • 53
8
votes
1 answer

Boost Spirit Qi Re-Establish Skipping with custom skip grammar

I have a grammar that has, up until now, been using the standard boost::spirit::ascii::space/boost::spirit::ascii::space_type skipper. I have some rules that use the skipper and some that don't, like qi::rule(),…
jtolds
  • 3,341
  • 3
  • 17
  • 14
8
votes
1 answer

Is Boost Spirit X3 production ready?

I'm migrating a hand-written parser to Boost.Spirit (2.5.4). First impressions are positive, but since I'm using C++17, X3 seems like a very attractive option. Fortunately, there are many resources available about X3: many questions about X3 on…
akim
  • 8,255
  • 3
  • 44
  • 60
8
votes
1 answer

Boost.Spirit.Qi: Take a rule's attribute and set it as a field of an enclosing rule's struct attribute?

Like, many of these other questions, I'm trying to parse a simple grammar into a tree of structs using Boost.Spirit.Qi. I'll try to distill what I'm trying to do to the simplest possible case. I have: struct Integer { int…
jtolds
  • 3,341
  • 3
  • 17
  • 14
8
votes
1 answer

deprecated warnings while using boost.spirit

I am trying to write some parsers with boost.spirit.qi but when i am compiling i am getting the following deprecated warnings: In file included from /usr/include/boost/iostreams/detail/is_dereferenceable.hpp:12:0 ... #pragma message: NOTE: Use of…
Exagon
  • 4,798
  • 6
  • 25
  • 53
8
votes
1 answer

How can I use polymorphic attributes with boost::spirit::qi parsers?

I would like my boost::spirit-based parser to be able to parse a file, convert the parsed rules into different types, and emit a vector containing all of the matches it found. All of the types that are emitted as attributes should be inherited from…
stix
  • 1,140
  • 13
  • 36
8
votes
2 answers

Assigning parsers to auto variables

Are spirit parsers not meant to be used with auto? A simple parser works fine when passed to qi::parse() inline, but crashes with segfault if passed via an auto variable: #include #include #include…
mstone
  • 414
  • 4
  • 11
8
votes
1 answer

Boost spirit skipper issues

I have trouble with boost spirit skippers. I need to parse a file like that : ROW int int [int, int] int [int, int] ... I am able to parse it without problem (thanks to stackoverflow ;) only if I add an '_' after the first int. In fact, I think…
sexyslippers69
  • 334
  • 2
  • 9
8
votes
3 answers

Boost Spirit QI slow

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…
Rseilbeck
  • 131
  • 1
  • 6
8
votes
1 answer

Building a Custom Expression Tree in Spirit:Qi (Without Utree or Boost::Variant)

First of all, if it is much easier using either Boost Variant or Utree, then I will settle with them, and i will try to solve my issues with them in another topic. However, i would very much like to be able to build a tree like i have…
RobVoisey
  • 1,083
  • 15
  • 24
7
votes
2 answers

C++/Boost: Writing a more powerful sscanf replacement

I want to write a function in C++ to replace C's sscanf that assigns the matches to iterator. Basically, I want something like: string s = "0.5 6 hello"; std::vector any_vector; sscanv(s, "%f %i %s", any_vector); cout << "float: " <<…
deuberger
  • 3,578
  • 6
  • 31
  • 33
7
votes
1 answer

How do I convert boost::spirit::qi::lexeme's attribute to std::string?

Consider: struct s { AttrType f(const std::string &); }; ...and a rule r with an attribute AttrType: template using rule_t = boost::spirit::qi::rule
Braden
  • 1,448
  • 10
  • 11
7
votes
1 answer

Boost::Spirit - on_error not printing

I'm trying to use the on_error mechanism of Boost::Spirit::qi to find out why the parsing failed. I've set a breakpoint at the on_error function and the function is being called, but no output (nada, nothing, void, ...). The simple on_error: …
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
7
votes
1 answer

What is the proper way to deal with deep recursion in boost::spirit::qi grammar?

I have a working grammar similar to the following: stock_price = symbol_ >> date_ >> price_; stock_prices_ = stock_price_ >> stock_prices_ | eps; grammar_ = lit( "PRICES" ) >> stock_prices_ >> lit( "END" ); The problem is, when the list of stock…
statguy
  • 1,627
  • 3
  • 13
  • 22
7
votes
1 answer

boost::optional to bool, inside boost::spirit::qi grammar

In my boost::spirit grammar I have the following snippet; implicit_method_declaration = (-(qi::token(ABSTRACT)) >> ...) The type of -(qi::token(ABSTRACT) is boost::optional> however I'm only using this…
Skeen
  • 4,614
  • 5
  • 41
  • 67
1
2
3
45 46