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

boost spirit semantic action parameters

in this article about boost spirit semantic actions it is mentioned that There are actually 2 more arguments being passed: the parser context and a reference to a boolean ‘hit’ parameter. The parser context is meaningful only if the…
lurscher
  • 25,930
  • 29
  • 122
  • 185
23
votes
1 answer

Boost Spirit: "Semantic actions are evil"?

Reading and watching this presentation: http://boost-spirit.com/home/2011/06/12/ast-construction-with-the-universal-tree/ I've discovered this statement -- basically we are suggested not to use semantic actions. I must admit, that I've already felt…
Kostya
  • 1,072
  • 11
  • 24
22
votes
1 answer

Is it possible to re-use boost::spirit::qi grammar in another grammar definition?

Is it possible to reuse boost::spirit:qi grammar in another grammar (as a rule for example)? For example if I define a grammar to parse line of text into a structure holding street address. template< typename iter > struct address_grammar…
stefanB
  • 77,323
  • 27
  • 116
  • 141
15
votes
1 answer

Dynamically combine Boost.Spirit.Qi rules at runtime (arbitrary number of alternatives)

I was wondering whether there is a way in Boost.Spirit.Qi to dynamically combine an arbitrary number of rules at runtime. The inner workings of Boost.Spirit are still a bit of a mystery to me, but since rules are implemented as objects it seems…
kloffy
  • 2,928
  • 2
  • 25
  • 34
15
votes
1 answer

How to benchmark Boost Spirit Parser?

I'm working on a compiler and I would like to improve its performances. I found that about 50% of the time is spent parsing the source files. As the source file are quite small and I do quite a lot of transformations after that, it seems to me that…
12
votes
1 answer

Boost.Spirit.Qi: How to return attributes with Nabialek trick

Following several tutorials (e.g. http://boost-spirit.com/home/articles/qi-example/nabialek-trick/) I want to use the Nabialek trick to have a dynamic parser. Parsing already works fine, but I don't get the attributes transported. Explanations like…
Mike M
  • 2,263
  • 3
  • 17
  • 31
11
votes
1 answer

boost::spirit access position iterator from semantic actions

Lets say I have code like this (line numbers for reference): 1: 2:function FuncName_1 { 3: var Var_1 = 3; 4: var Var_2 = 4; 5: ... I want to write a grammar that parses such text, puts all indentifiers (function and variable names) infos…
10
votes
1 answer

BOOST_FUSION_ADAPT_STRUCT doesn't take the right number of arguments

I am using Boost::Spirit to parse some text into structs. This requires using BOOST_FUSION_ADAPT_STRUCT for parsing text and directly storing into the structure. I know that the macro takes 2 arguments: the structure name as the 1st arg and all the…
Nik
  • 293
  • 5
  • 14
9
votes
1 answer

Retrieving AST from boost::spirit parser

After I've read the tutorials on boost::spirit, I quite liked it because of the parser combinator syntax. Making a parser is so easy. Unfortunately, the tutorials were not as exact on the matter of getting a complex data structure out of the parser.…
Lanbo
  • 15,118
  • 16
  • 70
  • 147
9
votes
3 answers

Boost::Spirit::Qi. How to turn inlined parser expressions into standalone grammars, and how to unpack the tuples generated by them?

I'm using QI and Phoenix, and I want to write a small grammar that returns 4 bools which are to be used as arguments for a function call inside a semantic action. I have several functions that need those things, and so far I have used this…
Erius
  • 1,021
  • 8
  • 21
9
votes
1 answer

Parsing a grammar with Boost Spirit

I am trying to parse a C-function like tree expressions like the following (using the Spirit Parser Framework): F( A() , B( GREAT( SOME , NOT ) ) , C( YES ) ) For this I am trying to use the three rules on the following grammar: template< typename…
lurscher
  • 25,930
  • 29
  • 122
  • 185
9
votes
1 answer

How do I parse end-of-line with boost::spirit::qi?

Shouldn't a simple eol do the trick? #include #include #include #include using boost::spirit::ascii::space; using boost::spirit::lit; using boost::spirit::qi::eol; using…
Greg Bacon
  • 134,834
  • 32
  • 188
  • 245
9
votes
1 answer

Spirit Qi attribute propagation issue with single-member struct

I have an compilation issue with Spirit Qi where it complains that value_type is not a member of identifier. For some reason, Qi's attribute system considers identifier to be a container type, and tries to enumerate it's value type. This is a…
namezero
  • 2,203
  • 3
  • 24
  • 37
9
votes
1 answer

Parse int or double using boost spirit (longest_d)

I'm looking for a way to parse a string as an int or a double, the parser should try both alternatives and choose the one matching the longest portion of the input stream. There is a deprecated directive (longest_d) that does exactly what I'm…
Hugo Corrá
  • 14,546
  • 3
  • 27
  • 39
9
votes
1 answer

How can I use the skipper ascii::space WITHOUT skipping eol?

I have to use boost::spirit for parsing, and I want use phrase_parse function : qi::phrase_parse(str.begin(), str.end(), grammar, ascii::space - qi::eol); But the fourth term (ascii::space - qi::eol), isnt allowed by my compiler. How can I use the…
Henri Sylvain
  • 93
  • 1
  • 4
1
2 3
45 46