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

Parse string containing literal with Boost Spirit Qi

I would love to parse a string like this: with boost::spirit::qi. Let's assume that is e.g. ABC, then I would like the parser to accept: Some text ABC more text but…
Markus Mayr
  • 4,038
  • 1
  • 20
  • 42
1
vote
1 answer

Spirit Qi: Inserting pre-defined output in a rule

How can I setup a rule that returns pre-defined output rather than something parsed from my input text? Like this example: GiveQuoteOrText will first try to parse the input as a quoted string using Quoted, and if that fails should always output…
user173342
  • 1,820
  • 1
  • 19
  • 45
1
vote
1 answer

boost spirit and related parts

I need to create a rule via boost spirit that should match situations like return foo; and return (foo); I tried smth like this: start %= "return" >> -boost::spirit::qi::char_('(') >> identifier >> -boost::spirit::qi::char_(')') >> ';'; but this…
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
1
vote
1 answer

First and last iterator position in sequence

I need to parse http-header fields: key:value\r\n key:value\r\n How parse value as two iterators, indicating the beginning and the end?
1
vote
1 answer

expected unqualified-id before 'namespace' error in working with boost spirit qi

I am writing a c++ application with several complex structs and I want to read a string and fill those structs by data provided in that text. But for easier understanding and debugging, i've wrote easy program with same problem. This is my…
1
vote
1 answer

boost spirit, boost any and quoted string - compile-time error

I have the following code: #include #include #include #include template struct parser : boost::spirit::qi::grammar
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
1
vote
1 answer

boost spirit and boost any - unexpected result

I have the following code: #include #include #include #include template struct parser : boost::spirit::qi::grammar
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
1
vote
1 answer

boost spirit - unable to get attributes

I have the following code: #define BOOST_SPIRIT_DEBUG #include #include #include #include #include #include struct…
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
1
vote
1 answer

How can I extract std::string object via boost spirit

I have the following code: #include #include #include #include #include struct function { std::string ret_type; std::string…
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
1
vote
1 answer

Error defining a grammar in spirit with the * y alnum

I have the following grammar and when I compile I have many errors. #include namespace qi = boost::spirit::qi; template struct parser : qi::grammar { parser() :…
1
vote
1 answer

Boost Spirit debug enum class (c++11) compile error

I am trying to debug a simple struct which contains an enum class with BOOST_SPIRIT_DEBUG_NODE, but I always get the compile error "C:\boost\boost\spirit\home\support\attributes.hpp:1226: error: cannot bind 'std::basic_ostream' lvalue to…
Xander
  • 687
  • 9
  • 15
1
vote
1 answer

No matching function for call error for Qi semantic action

I have part of a grammar as follows: typedef SemanticActions< IterType > SemanticActionsType; string_ %= lexeme[ +( spirit::qi::alnum | punct )]; component_ = lit( '-' ) >> string_[boost::bind( &SemanticActionsType::new_component_name, &actions_,…
statguy
  • 1,627
  • 3
  • 13
  • 22
1
vote
1 answer

Boost::spirit illegal_backtracking exception

I use Boost.Spirit.Lex and .Qi for a simple calculator project and (as usual) it gives me some pain to debug and use. The debug prints: boost::spirit::multi_pass::illegal_backtracking This exception is thrown and I can't…
Pierre T.
  • 380
  • 1
  • 13
1
vote
1 answer

boost spirit how to access child nodes (leaves) from parent nodes

I would like to evaluate boolean expression such as a=b & s<9 or simply a=b with only comparison operator (wihtout logical operator such as |, & and !). We can have the following AST: = / \ / \ a b…
user2891256
  • 29
  • 1
  • 4
1
vote
0 answers

boost spirit on_error not triggered

^ No it is not. This was part of the problem, but if review the code as is right now, it already does what the pointed out question/answer shows ... and the errors are still not triggered. I have this boost spirit parser for string literal. It…
gsf
  • 6,612
  • 7
  • 35
  • 64