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
6
votes
1 answer

Getting boost::spirit::qi to use stl containers

I'm trying to parse something with boost.spirit's qi library, and I'm running into an issue. According to the spirit docs, a >> b should produce something with the type tuple. But this is a boost::tuple (aka fusion vector), and not a…
Neal P
  • 599
  • 1
  • 8
  • 16
6
votes
1 answer

Using simple Boost::Spirit grammars?

I couldn't get a grammar to work so I simplified it till it only parses an integer. Still can't get it to work. It is the following grammar: template struct rangeGrammar : qi::grammar { rangeGrammar() : …
jay1189947
  • 201
  • 1
  • 2
  • 9
6
votes
2 answers

boost::spirit::qi duplicate parsing on the output

I have this very simple parser using Boost::Spirit: rule zeroTo255 = (string("25") >> char_('0', '5')) | (char_('2') >> char_('0', '4') >> digit) | (char_('1') >> repeat[2](digit)) | (char_('1', '9')…
bruno nery
  • 2,022
  • 2
  • 20
  • 31
6
votes
1 answer

Why does this boost::spirit::qi rule not match the input?

I tried to continue to work on my previous example and expand the rules. My problem is, that rules that use ID_IDENTIFIER do not work - although I know that the lexer is working (using unit tests). Here's the example: #include…
Tobias Langner
  • 10,634
  • 6
  • 46
  • 76
6
votes
1 answer

Parsing a number of named sets of other named sets

So I want to write a... well... not-so-simple parser with boost::spirit::qi. I know the bare basics of boost spirit, having gotten acquainted with it for the first time in the past couple of hours. Basically I need to parse this: # comment # other…
Borislav Stanimirov
  • 1,609
  • 12
  • 23
6
votes
2 answers

How to throw an expectation_failure from a function in Boost Spirit?

In Boost::Spirit, how can I trigger an expectation_failure from a function bound with Boost::Bind? Background: I parse a large file that contains complex entries. When an entry is inconsistent with a previous entry I want to fail and throw an…
Frank
  • 64,140
  • 93
  • 237
  • 324
6
votes
1 answer

How to use boost::tuple as attribute in a boost::spirit rule?

I have the following rule in boost::spirit: typedef boost::tuple Entry; qi::rule entry; entry = qi::int_ >> qi::int_; But the second int is not written into the tuple. Is there a way to make it work without…
Frank
  • 64,140
  • 93
  • 237
  • 324
6
votes
1 answer

spirit::qi : passing inherited attribute reference to phoenix::function

The following code is a streamlined version of what i'm trying to do. Basically, I have struct (int_holder in the toy code), with a container data member. I want to insert an object (int in this case) and return to the parent qi::rule a pointer to…
Giuliano
  • 640
  • 3
  • 15
5
votes
1 answer

Why does boost::spirit::qi::parse() not set this boost::variant's value?

When trying to parse text into a boost::variant, the variant's value does not get changed. The parsers by themselves appear to work fine, so my assumption is that I'm doing something wrong with the variant code. I'm using boost 1.46.1 and the…
foraidt
  • 5,519
  • 5
  • 52
  • 80
5
votes
2 answers

how to parse and verify an ordered list of integers using qi

I'm parsing a text file, possibly several GB in size, consisting of lines as follows: 11 0.1 14 0.78 532 -3.5 Basically, one int and one float per line. The ints should be ordered and non-negative. I'd like to verify the data are as described, and…
dpj
  • 933
  • 1
  • 7
  • 14
5
votes
1 answer

Using a pointer to a parser in boost::spirit

Basically I'm doing an expression parser. As I'm in need of as good as possible performance, and according to the documentation construction of a grammar can be rather slow, I'd like to reuse the grammar and bind the symbol table just before…
Ylisar
  • 4,293
  • 21
  • 27
5
votes
1 answer

Qi Symbols slow performance?

I wanted to raise a subject that just sent me down a rabbit hole and brought up a question about qi::symbols. It all started while I was looking into the new beast library and read a tutorial example It starts with a function that guesses mime…
sehe
  • 374,641
  • 47
  • 450
  • 633
5
votes
1 answer

recursive BNF rule using boost spirit

I'm trying to write a parser for the following BNF rules using boost spirit (Boost v1.64) The rules are: ::= integer ::= "in" | "out" | "in_out" ::= "[" [] "]" …
Daniel
  • 1,319
  • 14
  • 19
5
votes
1 answer

Parsing preconditions and recursion with Boost::Spirit

I am trying to parse a PDDL file with Boost::Spirit and have some trouble with parsing preconditions into a struct. I am struggling to understand the Boost manual on how to get the condition into my struct and with recursion. I give a snippet of the…
Raptor
  • 736
  • 2
  • 8
  • 21
5
votes
1 answer

Parsing escaped strings with boost spirit

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…
Bruno
  • 53
  • 1
  • 4