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
7
votes
2 answers

How to parse csv using boost::spirit

I have this csv line std::string s = R"(1997,Ford,E350,"ac, abs, moon","some "rusty" parts",3000.00)"; I can parse it using boost::tokenizer: typedef boost::tokenizer< boost::escaped_list_separator , std::string::const_iterator, std::string>…
user841550
  • 1,067
  • 3
  • 16
  • 25
7
votes
3 answers

How to use boost::spirit to parse a sequence of words into a vector?

I'm trying to learn boost::spirit. As an example, I'm trying to parse a sequence of words into a vector. I tried this: #include #include namespace qi = boost::spirit::qi; int main() { …
Frank
  • 64,140
  • 93
  • 237
  • 324
6
votes
1 answer

Boost::Spirit simple grammar example

I'm going through the Boost Spirit (and Boost Fusion) tutorials (version 1.48.0). I've been playing with the toy employee example. The link to the source is here: http://www.boost.org/doc/libs/1_48_0/libs/spirit/example/qi/employee.cpp Here is the…
Paul Rigor
  • 986
  • 1
  • 12
  • 23
6
votes
1 answer

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

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…
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
6
votes
1 answer

boost::spirit::qi and out-of-sequence variables

I'm writing a lexigraphical analyser. It takes an English string, and converts it into a set of latitude/longitude co-ordinates. It's a bit like Google Earth. Anyway, I've written my symbol tables and grammar, and it's happily parsing formatted…
LogicalUnit
  • 111
  • 1
  • 1
  • 7
6
votes
1 answer

Boost.Spirit bug when mixing "alternates" with "optionals"?

I've only been working with Boost.Spirit (from Boost 1.44) for three days, trying to parse raw e-mail messages by way of the exact grammar in RFC2822. I thought I was starting to understand it and get somewhere, but then I ran into a…
Head Geek
  • 38,128
  • 22
  • 77
  • 87
6
votes
2 answers

Understanding the List Operator (%) in Boost.Spirit

Can you help me understand the difference between the a % b parser and its expanded a >> *(b >> a) form in Boost.Spirit? Even though the reference manual states that they are equivalent, The list operator, a % b, is a binary operator that matches a…
6
votes
2 answers

Boost Spirit and Lex parser problem

I've been struggling to try and (incrementally) modify example code from the documentation but with not much different I am not getting the behavior I expect. Specifically, the "if" statement fails when (my intent is that) it should be passing…
bpw1621
  • 2,962
  • 2
  • 32
  • 35
6
votes
1 answer

boost::spirit::qi keywords and identifiers

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
pt3dNyc
  • 369
  • 1
  • 16
6
votes
1 answer

Using boost::spirit, how do I require part of a record to be on its own line?

I have a record parser that throws one of several exceptions to indicate which rule failed. Front matter: #include #include #include #include #include #include…
Greg Bacon
  • 134,834
  • 32
  • 188
  • 245
6
votes
1 answer

Boost spirit poor performance with Alternative parser

I already asked question about this issue. But since there were no answers i'm asking again now with full compilable source code snippet. This code snippet should be compiled with no std=c++11 option, because of some issues with boost::variant move…
Alexander
  • 779
  • 8
  • 17
6
votes
1 answer

Understanding Boost.spirit's string parser

#include #include namespace qi = boost::spirit::qi; int main () { using qi::string; std::string input("a"); std::string::iterator strbegin = input.begin(); std::string p; bool ok =…
Ashot
  • 10,807
  • 14
  • 66
  • 117
6
votes
2 answers

Define parsers parameterized with sub-parsers in Boost Spirit

I would like to convert some old hand-written parsing code to Boost Spirit and learn (more of) spirit in the process. The old code uses streams and templates to parse definitions for some data-types and some containers. Some typical…
hmuelner
  • 8,093
  • 1
  • 28
  • 39
6
votes
2 answers

How to parse reserved words correctly in boost spirit

I'm trying to parse a sequence of the syntax: < direction > < type > < name >. For example: in float foo where the direction can be either in, out, or in_out. I've succeeded in parsing correct text by using a qi::symbols class to convert the…
Cthutu
  • 8,713
  • 7
  • 33
  • 49
6
votes
1 answer

Boost Spirit Qi Custom Syntesized Attribute (Set a specific member of a struct attribute via a semantic action)

Suppose I have a structure that I want to parse into with Spirit Qi, that is defined as such: struct data_ { bool export; std::wstring name; data_() : export(false) {} }; Also, suppose the struct has been adapted to fusion like…
namezero
  • 2,203
  • 3
  • 24
  • 37
1 2
3
45 46