boost-spirit

Implementing "NOT" in boost::spirit mini_c

I tried to modify the mini_c example of boost::spirit to match to my existing vocabulary. I therefore added a operator "NOT that should behave equal as "!": unary_expr = primary_expr | ("NOT" > primary_expr [op(op_not)]) // This does not work | ('!' > primary_expr [op(op_not)]) | ('-' > p...

How can I extract double pairs from an std::string with Boost Spirit?

I want to parse a string with a sequence of double pairs into an std::map with Boost Spirit. I adapted the example from http://svn.boost.org/svn/boost/trunk/libs/spirit/example/qi/key_value_sequence.cpp but I have a problem with difining a proper qi::rule for key and value: template <typename Iterator> struct keys_and_values : qi::gra...

encoding in boost.spirit

Hi! How i can set encoding for values in assign_a? I need to set cyrrilic, but i havent any idea how to do it #include "filter_data.h" #include <boost/bind.hpp> #include <boost/spirit.hpp> #include <boost/spirit/actor.hpp> #include <boost/spirit/attribute.hpp> #include <boost/config/warning_disable.hpp> #inc...

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, string}". Specifically, I would like to then pass the structure to a function overloaded on the structur...

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 <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost...

Understanding and using the Boost Phoenix Library with a focus on lazy evaluation

I just found out about the Boost Phoenix library (hidden in the Spirit project) and as a fan of the functional-programming style (but still an amateur; some small experience with haskell and scheme) i wanted to play around with this library to learn about reasonable applications of this library. Besides the increasement of expressivenes...

Parsing with Boost::Spirit (V2.4) into container.

I just started to dig into Boost::Spirit, latest version by now -- V2.4. The essense of my problem is following: I would like to parse strings like "1a2" or "3b4". So the rule I use is: (double_ >> lit('b') >> double_) | (double_ >> lit('a') >> double_); The attribute of the rule must be "vector <double>". And I'm reading it into ...

String to int using boost spirit

I hear that spirit is really fast at converting string to int. I am however unable to create a simple function that can do so. Something like int string_to_int(string& s) { /*?????*/ } Can anybody use boost spirit to fill in this function. By the way I am working on boost 1.34 and not the latest version. ...

How can I extract a std::string with boost.spirit?

Hi Using boost.spirit I try to parse simple command line of the form command:param1 param2... to do so I created this parser: (+(char_ - ':'))[ref(cmd) = _1] >> ':' >> (*char_)[ref(params) = _1] The attribute types of the two compounds parser is vector, so if cmd and params are of type vector this work. However if they are of type s...

Boost.Spirit bug when mixing "alternates" with "optionals"?

I've only been working with Boost.Spirit (from Boost 1.44) for three days, trying to parse raw e-mail messages by way of the exact grammar in RFC2822. I thought I was starting to understand it and get somewhere, but then I ran into a problem: #include <iostream> #include <boost/spirit/include/qi.hpp> namespace qi = boost::spirit::qi; u...

Parsing escaped strings with boost spirit

I´m working with Spirit 2.4 and I'd want to parse a structure like this: Text{text_field}; The point is that in text_field is a escaped string with the symbols '{', '}' and '\'. I would like to create a parser for this using qi. I've been trying this: using boost::spirit::standard::char_; using boost::spirit::standard::string; usi...