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
1
vote
1 answer

Parsing text file with binary envelope using boost Spririt

I'm currently trying to write a parser for an ASCII text file that is surrounded by a small envelope with checksum. The basic structure of the file is: <0x02><"File payload"><0x03><16bit CRC> and I want to extract the payload in another string to…
fhw72
  • 1,066
  • 1
  • 11
  • 19
1
vote
1 answer

In Boost Spirit Qi, how do I match every character up to the next whitespace (with pre-skip)

Within a boost::spirit::qi grammar rule, how do you match a string of characters up to and excluding the next whitespace character, as defined by the supplied skipper? For example, if the grammar is a set of attributes defined as: attributeList =…
Steger
  • 887
  • 7
  • 16
1
vote
1 answer

Error when compiling a grammar with debug activated

I'm trying to debug a boost::spirit grammar that I want to use in a Visual Studio project: This is my code snippet: #include #include #include…
Jepessen
  • 11,744
  • 14
  • 82
  • 149
1
vote
1 answer

Boost Spirit : something like permutation, but not exactly

I'm trying to get a grasp of Spirit, meaning I'm a noob at it (hence expect lack of proper terminology in the below). I have to parse this: value1 = 10 value2 = 20 value3 = 30 value4 = 40 Order doesn't matter but each "value1" ... "value4" line…
HornetMaX
  • 43
  • 5
1
vote
1 answer

Parsing heterogeneous data using Boost::Spirit

I'm trying to figure out how to approach the following problem. I have a structure of the following format: struct Data { time_t timestamp; string id; boost::optional data1; boost::optional data2; //…
Šimon Tóth
  • 35,456
  • 20
  • 106
  • 151
1
vote
1 answer

Using the auto_ expression in boost::spirit with std::vectors

I'm pretty new to boost::spirit. I would like to parse a string of comma separated objects into an std::vector (similarly as in the tutorials). The string could be of different types (known at compile time): integers, like "1,2,3", strings "Apple,…
srossi
  • 122
  • 1
  • 6
1
vote
1 answer

TBB parallelization of parsing with boots::spirit::qi

In my program, I use the Boost-Spirit-Qi to parse large data sets. Input data are sequential records . I am trying to use the TBB to increase the efficiency of parsing. The procedure for parallel processing is as follows: typedef map
stansy
  • 135
  • 1
  • 10
1
vote
2 answers

128 bit string to array using boost::spirit::*

I am currently starting with boost::spirit::*. I try to parse a 128 bit string into a simple c array with corresponding size. I created a short test which does the job: boost::spirit::qi::int_parser< boost::uint8_t, 16, 2, 2 > uint8_hex; …
Maik
  • 541
  • 4
  • 15
1
vote
1 answer

good/full Boot Spirit examples using version 2 syntax

Almost all of the examples I've gone and looked at so far from: http://boost-spirit.com/repository/applications/show_contents.php use the old syntax. I've read and re-read the actual documentation at…
bpw1621
  • 2,962
  • 2
  • 32
  • 35
1
vote
2 answers

rule to extract key+phrases from a text document

I want to extract the key phrases from the document: "something KEY phrase END something ... ect". My rule works well but the result does not contain of key name. What should be the rule in order to get a string: "KEY phrase". Thank you for the…
stansy
  • 135
  • 1
  • 10
1
vote
1 answer

Boost::Spirit placeholders and alternative parser

// 1 Mexpression = Mterm >> *( '+' >> Mterm [qi::_val = phoenix::new_(_1, '+', _2)] | '-' >> Mterm [qi::_val = phoenix::new_(_1, '-', _2)] ); Mterm = Mfactor >> *( '*' >> Mfactor [qi::_val =…
1
vote
1 answer

Boost spirit parser not compiling

I tried to write a simple expression parser with boost::spirit. I started with the calculator example (see: http://www.boost.org/doc/libs/1_41_0/libs/spirit/example/qi/calc2_ast.cpp) and tried to add a "ref" rule denoting a reference to a variable.…
gexicide
  • 38,535
  • 21
  • 92
  • 152
1
vote
1 answer

Boost Spirit kwd parser in Visual Studio 2013

I'm using Boost 1.57 with Visual Studio 2010. I would like to upgrade my project to Visual Studio 2013 but i'm having some problem with the boost Spirit parser. Seem to me that the kwd parser is broken somehow. The following code compiles correctly…
Gab
  • 756
  • 11
  • 23
1
vote
1 answer

boost::spirit stops at first match

I'm trying to parse the following: [SOFT] AQUA+ [FORWARD_SPEED] 0.00 [some other key] string value [PERIODS_NUMBER] 6 [HEADINGS_NUMBER] 13 [LOWEST_HEADINGS] 0.00 [HIGHEST_HEADINGS] 180.00 I don't know in advance what the keys…
Deimos
  • 1,835
  • 1
  • 16
  • 15
1
vote
1 answer

Trying to understand Boost Qi parsing into structs

I've got an embarrassingly simple problem that I can't seem to wrap my head around. I'm reading the boost documentation on how to parse into structs. The sample code provided for that chapter is straightforward - or so I thought. I would like to…
djf
  • 6,592
  • 6
  • 44
  • 62