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::spirit::qi and access violation exception

in the next simple code I receive the "access violation" exception. Why it happens? I can`t get the reason. #define BOOST_SPIRIT_DEBUG #include #include namespace qi =…
AeroSun
  • 2,401
  • 2
  • 23
  • 46
1
vote
1 answer

Create and write to vector on the fly

I want to create vector and append values to it (if any) in one spirit rule. Is it possible? I tried something like below but with no success. Read code comments for details please. Thanks. typedef std::vector number_array; typedef…
Alexander
  • 779
  • 8
  • 17
1
vote
1 answer

Newbie Spirit not trying alternatives

I am having trouble getting Spirit to try alternatives. I am new to Spirit and probably doing something grossly wrong, so I apologize for dragging down the SNR but any help is appreciated: I am using a grammar like the following to match "character…
user2913094
  • 981
  • 9
  • 16
1
vote
1 answer

boost::spirit::qi matches[] trouble

I have the trouble with parsing on my project. At least I found the minimum code sample on which the problem appears. So at now tries to parse the string "bool func1; const bool func2;" Here the minimum sample code: namespace qi =…
AeroSun
  • 2,401
  • 2
  • 23
  • 46
1
vote
1 answer

boost spirit qi assign value from subrule

I am trying to parse 2 different type of strings and assign values into structures. For performance I am trying to use boost spirit subrules. strings can be of the following types Animal Type | Animal Attributes Ex DOG | Name=tim |…
Sanjit
  • 321
  • 2
  • 8
1
vote
1 answer

Boost.Spirit adding #include feature into calculator example

Following Boost.Spirit compiler examples I am migrating my Flex/Bison based calculator-like grammar to Spirit based. I want to add a feature #include. I have defined the include_statement grammar successfully. Should I follow the…
Forest Yang
  • 179
  • 5
1
vote
1 answer

Boost Spirit Phoenix function error

This code is from the examples for boost spirit libs, it's OK: on_error(expr,error_handler_function(eh)("expecting ", _4, _3)); However, this code failed to compile in Xcode: on_error(expr,error_handler_function(eh)("expecting ", _4,…
Matazure
  • 43
  • 4
1
vote
0 answers

Boost Spirit QI: Limit dynmically number of parsed values

I would like to parse data, which has the following format. ... Is it even possible to parse this format (without delimiters) using Boost Spirit? I am thinking and googling…
1
vote
1 answer

Boost Spirit Qi - Efficient Quote Grammar

I'm trying to implement a rule in my boost spirit qi grammar that will behave like QUOTE in a Lisp-like language. Something like: QUOTE(a b c) The idea is that anything between QUOTE's opening and closing parenthesis will be captured into a string…
pt3dNyc
  • 369
  • 1
  • 16
1
vote
0 answers

Problems with optional expression and parsing error position

I'm trying to write my first boost spirit parser for a specific messaging format and I encountered some problems. The boost library version used is 1.49.0! #include #include #include #include…
janr
  • 3,664
  • 3
  • 24
  • 36
1
vote
1 answer

Boost spirit revert parsing

I want to parse a file containing the following structure: some garbage *&% section1 { section_content } section2 { section_content } The rule parsing section_name1 { ... } section_name2 { ... } is already defined: section_name_rule =…
haykart
  • 957
  • 5
  • 14
  • 34
1
vote
1 answer

How can I stop my simple addition grammar terminating early in Boost Spirit?

I'm having difficulty making a toy grammar to parse addition work as desired in Boost Spirit. Here is my grammar and code: Syntax.h: #include #include namespace qi =…
Tim MB
  • 4,413
  • 4
  • 38
  • 48
1
vote
1 answer

boost spirit selects unmatched result

I have a file with the following format metal 1 1.2 2.2 wire 1.1 2.3 metal 2 3.2 12.2 ... This is a very simple format. "metal" and "wire" are keywords. And "metal" is followed by 1 uint and 2 double, while "wire" is followed by 2 double. I try…
1
vote
1 answer

Boost spirit parser attribute type not working.

int main() { std::string input("A90 (a-><>b)"); std::string::iterator strbegin = input.begin(); map p; qi::phrase_parse(strbegin, input.end(), (qi::char_ >> qi::int_) % ':', // parser grammar qi::space, //…
Yogi Joshi
  • 786
  • 1
  • 6
  • 19
1
vote
1 answer

Parsing Lat/Long failed: no character 'E'

I want to parse a lot of Lat/Long coordinates with the following format 1.123456W or 50.123456N, basically a double followed by a char ('N', 'S', 'W', 'E'). I just want to remove the character from the string, convert to double and change the sign…
Hhut
  • 1,128
  • 1
  • 12
  • 24