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

Compile Boost Spirit Keyword Parser Example

I am having some trouble compiling the example code for boost keyword parser. I am using boost 1.63.0 and gcc 6.3.0 and specifying c++ 11. I ran: g++ -std=c++11 -I boost-1.63-0/include keywords-1.cpp and was hit by a massive wall of compiler…
joshu
  • 463
  • 8
  • 18
1
vote
1 answer

Boost spirit: Parse char_ with changing local variable value

I want to implement a grammar that requires parsing instance names and paths, where a path is a list of instance names separated by a divider. The divider can be either . (period) or / (slash) given in the input file before the paths are listed,…
tickferno
  • 81
  • 1
  • 10
1
vote
3 answers

Parse an integer with non-digits in between using boost spirit

I am trying to parse the numeric value from a string with non-digits in between. Is it possible to do it with boost spirit? For example, std::string s = "AB1234xyz5678C9"; int x = 0; boost::spirit::qi::parse(s.begin(), s.end(), /* Magic Input */,…
alex
  • 193
  • 2
  • 8
1
vote
1 answer

Boost ASIO ForwardIterator for streambuf

I am using boost::asio::async_read_until to read the \n-ended line from the TCP socket. Let me please recall that async_read_until signature is the…
0x2207
  • 878
  • 1
  • 6
  • 20
1
vote
1 answer

boost::spirit recursive imperative c++ grammar: BOOST_FUSION_ADAPT_STRUCT fails

I've been working on a grammar to parse imperative statements (if/else/do/while/for/switch etc.) in c++. All other statements are kept as strings. I'm currently only testing with if/else (though other statements should work analogous in a…
Untyr
  • 13
  • 4
1
vote
1 answer

Using semantic action together with attribute propagation in spirit

I played a little with code at link and I have another question. I added semantic action to: action = actions_ >> '(' >> parameters >> ')'[ /* semantic action placed here */]; so I can reuse the rule together with verification at multiple places.…
1
vote
1 answer

Boost Spirit Grammar To Detect Login Failure

I have written the following simple grammar to detect if a string returned by a server is a failed login. I was using it inlined in the phrase_parse function, but since the code gets called regularly, I wanted to make a static instance of the…
joshu
  • 463
  • 8
  • 18
1
vote
1 answer

When doing a compare, why must I cast an unsigned to avoid warnings

In the example below, if I don't cast 4 as unsigned I get a warning about '<=' signed/unsigned mismatch in default.hpp(144) followed by many more warning I don't follow. #include #include…
1
vote
1 answer

Can I test a parsed number as part of the rule. int_ <= 120

I'm very new to spirit::qi 2.5.2 and I'm not sure if I can test the parsed value as part of the rule. I've seen this; bool c = true; // a flag test_parser("1234", eps(phx::ref(c) == true) >> int_); test_phrase_parser("1 2 3 4", *(eps(phx::ref(c)…
1
vote
2 answers

Boost Spirit QI recursive

I must have missed something with the boost::recursive_wrapper thing, I always get an error: error: no matching function for call to 'boost::tuples::tuple, std::allocator >, client::compare_attr_op_t, std::basic_string, std::allocator >,…
Scapal
  • 31
  • 3
1
vote
1 answer

How do you create a generic parser using qi?

I am attempting to create generic parser-elements using qi as I unfortunately (MSVC must be supported) can not use X3. The idea is to have a templated struct: template struct parse_type; Which I could use like this: template T…
user3721426
  • 273
  • 2
  • 8
1
vote
1 answer

Boost Spirit Parser optional expression evaluation

I am trying to parse a line from a text file which of the form: [int_:] [int_/int_] [(int_, string)] string [string:int_]... Where [] are optional parameter but will contain tags such as (":", "(", ")", "/"). Also the last format is repeat format…
AmeyaVS
  • 814
  • 10
  • 26
1
vote
1 answer

Improve use of alternative parser

I extended the Mini XML example from the spirit manual. The grammar describes a xml tag that can be closed with '/>' and has no child nodes or which is closed like in the example with a closing tag '' and can optionally have children. #include…
MarcoH
  • 33
  • 4
1
vote
1 answer

How can I parse different structures with Boost.Spirit.Qi?

In this example, employee structs are parsed in the form "employee{int, string, string, double}". I would like to know whether it is possible to modify this example to also parse different types of structs, like "intern{int, string,…
xDD
  • 3,443
  • 1
  • 15
  • 12
1
vote
1 answer

attaching semantic actions to parser with boost spirit

I am trying to understand what "attaching" a semantic action to a parser exactly means, and more precisely I would like to understand when, and for what duration the semantic action is bound to the parser. For this, I modified slightly the…
Heyji
  • 1,113
  • 8
  • 26