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

Boost Karma object method call

as an extension to my question and the answer from sehe i want to call a function while generating my output. I added the method bool isRoby() and modified the emp rule. #include #include…
Roby
  • 2,011
  • 4
  • 28
  • 55
1
vote
1 answer

Parse MemoryMapped files using Spirit quoted and normal

in according to the answer from sehe i want to parse quoted and normal content from a memory mapped file, as fast as possible. The actual Parser looks like: namespace qi = boost::spirit::qi; using MatrixType = …
Roby
  • 2,011
  • 4
  • 28
  • 55
1
vote
1 answer

Template compilation errors with boost::spirit::qi and qi::alnum for C-style string

I use spirit in boost_1.59 to parse a c-like language(named stone originally written by java). But I have trouble in using boost::spirit::qi to parse the c-style string in stone. The whole code is at coliru. The parser rule I wrote is listed…
mhowto
  • 11
  • 1
1
vote
1 answer

Parsing a nested hierarchy in spirit qi - can't get the grammar right

I'm in way over my head with spirit::qi and need some help. I'm trying to parse a phrase that is of the form: ( wheels=4 & chassis=metal & engine=( cylinders=8 & volume=6209 ) ) ... into a nested structure: class dict : public std::map
1
vote
1 answer

Can`t compile boost spirit word_count_lexer example

I am continuing to learn the Boost Spirit library and have comile issue with example that I couldn`t compile. The source of example you can find here: source place. Also you can look at this code and compile result on Coliru #include…
AeroSun
  • 2,401
  • 2
  • 23
  • 46
1
vote
1 answer

boost qi attribute is coming up as qi::unused_type

Cannot figure out why this rule unary_msg doesnt work, it says the attribute type is qi::unused_type but this makes no sense to me. Why does boost torment me like this? template struct g3:…
1
vote
1 answer

Simple boost::spirit grammar SIGSEGV on Android

The parser namespace qi = boost::spirit::qi; template class action { public: action(std::vector>& parts) : m_parts{ parts } {} void operator()(const…
Hans Malherbe
  • 2,988
  • 24
  • 19
1
vote
2 answers

How to use the parse/phrase_parse function

Concretely, using the grammar g, how do I parse the string s ? What arguments should I give ? I've tried many calls and always got errors. Also, since I'm not sure yet which one I will use later, would there be any difference using phrase_parse…
LogicalKip
  • 514
  • 4
  • 13
1
vote
2 answers

Spirit Qi Parsing multilines from Console

I am using the Console as an input source. I looked for a way qi would parse a line and then it'd wait for the next line and continue parsing from that point. for example take the following grammar start = MultiLine | Line; Multiline = "{" *(Line)…
1
vote
1 answer

Why does qi::skip fail with tokens from the lexer?

I'm using boost::spirit lex and qi to parse some source code. I already skip white spaces from the input string using the lexer. What I would like to do is to switch skipping the comments depending on the context in the parser. Here is a basic demo.…
1
vote
3 answers

How to implement #ifdef in a boost::spirit::qi grammar?

Is there a good way to make a grammar nonterminal which is parsed differently, depending on results of some boost phoenix function? In my use-case, I have a grammar which among other things includes CPP-style #define directives, and #ifdef #else…
Chris Beck
  • 15,614
  • 4
  • 51
  • 87
1
vote
1 answer

Learning Boost.Spirit: parsing INI

I started to learn Boost.Spirit and finish reading Qi - Writing Parsers section. When reading, everything is easy and understandable. But when I try to do something, there are a lot of errors, because there are too many includes and namespaces and I…
grisha
  • 1,247
  • 1
  • 14
  • 20
1
vote
3 answers

What is the problem with this simple boost::spirit::qi parser?

I've got this simple parser intended to parse VB style double quoted strings. Thus, the parser should turn something like "This is a quoted string containing quotes ("" "")" into an output of This is a quoted string containing quotes (" ") Here is…
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
1
vote
1 answer

Order of semantic actions using Spirit (with Phoenix reference)

I'm building a parser to execute commands that a user may enter on the command line. The first part of the command is the module it belongs to, the second part is the module's function to call. Attached to the first parser is a semantic action (with…
ChristophK
  • 733
  • 7
  • 20
1
vote
1 answer

spirit qi no_case directive applied to grammar

I have a grammar that works properly, now I want to use it to parse a string without case sensitivity. I am running Boost 1.46 on Ubuntu 12.04 Linux. I tried the following code: bool parseSuccess = qi::phrase_parse(begin, end, …
giulatona
  • 137
  • 2
  • 9