boost-spirit-qi

Using boost::spirit, how do I require part of a record to be on its own line?

I have a record parser that throws one of several exceptions to indicate which rule failed. Front matter: #include <iostream> #include <sstream> #include <stdexcept> #include <string> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/classic_position_iterator.hpp> using ...

How do I parse end-of-line with boost::spirit::qi?

Shouldn't a simple eol do the trick? #include <algorithm> #include <boost/spirit/include/qi.hpp> #include <iostream> #include <string> using boost::spirit::ascii::space; using boost::spirit::lit; using boost::spirit::qi::eol; using boost::spirit::qi::phrase_parse; struct fix : std::unary_function<char, void> { fix(std::string &result...

Parsing string, with Boost Spirit 2, to fill data in user defined struct

I'm using Boost.Spirit which was distributed with Boost-1.42.0 with VS2005. My problem is like this. I've this string which was delimted with commas. The first 3 fields of it are strings and rest are numbers. like this. String1,String2,String3,12.0,12.1,13.0,13.1,12.4 My rule is like this qi::rule<string::iterator, qi::skip_type> st...

Boost Spirit and Lex parser problem

I've been struggling to try and (incrementally) modify example code from the documentation but with not much different I am not getting the behavior I expect. Specifically, the "if" statement fails when (my intent is that) it should be passing (there was an "else" but that part of the parser was removed during debugging). The assignmen...

good/full Boot Spirit examples using version 2 syntax

Almost all of the examples I've gone and looked at so far from: http://boost-spirit.com/repository/applications/show_contents.php use the old syntax. I've read and re-read the actual documentation at http://www.boost.org/doc/libs/1_42_0/libs/spirit/doc/html/index.html and the examples therein. I know Joel is starting a compiler series ...

What header file is where the boost libray define its own primitive data type?

Recently, I try to use the boost::spirit::qi binary endian parser to parse some binary data depends on the endianness of the Platform. There is a simple example, like following: Using declarations and variables: using boost::spirit::qi::little_word; using boost::spirit::qi::little_dword; using boost::spirit::qi::little_qword; boost:...

Boost Binary Endian parser not working?

I am studying how to use boost spirit Qi binary endian parser. I write a small test parser program according to here and basics examples, but it doesn't work proper. It gave me the msg:"Error:no match". Here is my code. #include "boost/spirit/include/qi.hpp" #include "boost/spirit/include/phoenix_core.hpp" #include "boo...

boost spirit semantic action parameters

Hi, in this article about boost spirit semantic actions it is mentioned that There are actually 2 more arguments being passed: the parser context and a reference to a boolean ‘hit’ parameter. The parser context is meaningful only if the semantic action is attached somewhere to the right hand side of a rule. We will see ...

Parsing a grammar with Boost Spirit

I am trying to parse a C-function like tree expressions like the following (using the Spirit Parser Framework): F( A() , B( GREAT( SOME , NOT ) ) , C( YES ) ) For this I am trying to use the three rules on the following grammar: template< typename Iterator , typename ExpressionAST > struct InputGrammar : qi::grammar<Iterator, Express...

boost spirit qi numeric parsing of integer and floating points

Hi, i am trying to make sense of the following result. The test case code is #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_fusion.hpp> #include <boost/spirit/i...

Boost Spirit rule with custom attribute parsing

I am writing a Boost Spirit grammar to parse text into a vector of these structs: struct Pair { double a; double b; }; BOOST_FUSION_ADAPT_STRUCT( Pair, (double, a) (double, a) ) This grammar has a rule like this: qi::rule<Iterator, Pair()> pairSequence; However, the actual grammar of pairSequence is this: doub...

How can I track my input position with multiple inputs using Boost::Spirit::Qi?

Hello :) I'd like to support something like C++'s #include mechanism in a boost spirit parser. Essentially, I have a script command that asks my parser to load a sub script from a file. I'd like to be able to report error messages as described in the tracking input position while parsing post, but they don't cover parsing for multiple i...

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

Hello :) 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 the grammar I came up with for this: namespace qi = boost::spirit::qi; nam...

Parsing with Boost Spirit, getting extra items

This is long with a lot of code, so I hope Stack Overflow can cope with it. :P I'm trying to write an SVG parser with Boost Spirit. I have a grammar that populates a vector with "Contours," which are vectors of "BezierPoints," which may represent either regular points or points with bezier controls. So far I have this (not handling re...

[Boost-Spirit] Assigning or modifying inherited attributes in rule and propagating results to parent rule

Say I have a Boost Spirit grammar like this, where a parent rule passes an inherited attribute to its children. template <typename Iterator> struct MyGrammar : qi::grammar<Iterator, vector<Foo>()> { qi::rule<Iterator, vector<Foo>()> start; qi::rule<Iterator, vector<Foo>(Bar)> parent; qi::rule<Iterator, Foo(Bar)> child1; ...

Is there an alternative for boost::phoenix::at_c in combination with boost::spirit::qi::grammar

I have created a test application to illustrate my problem. It parses a list of integers preceded by "a=" or "b=" and is separated by "\r\n". The list contains multiple occurrences of those fields in any order. #include <string> #include <vector> #include <iostream> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/includ...

Is it possible to create custom Parsers in Boost.Spirit?

I was trying to create a custom Parser class in Boost.Spirit (2.3), but it didn't work out. The code is: template <class Iter> class crule : public boost::spirit::qi::parser<crule<Iter> > { rule<Iter> r_; public: crule(const rule<Iter>& r) : r_(r) {} template <class T> crule(const T& t) : r_(t) {} template<class Ctx, class Ski...

Boost Spirit auto-rule problem

I'm using attribute propagation to construct a syntax tree for a toy language. I've hit a problem at the definition of my if statement, it's hard to tell from the error message but I think the rhs attribute isn't collapsing into the expected attribute. It should collapse to a tuple <double,Statement,optional<Statement>> I think. The err...

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...