Boost logo

Boost Users :

Subject: [Boost-users] ignoring stuff
From: jono (jp_at_[hidden])
Date: 2008-11-27 22:17:11


hi all,

i'm trying to ignore unecognized lines of input (so following lines can be processed without the
parse failing).

eg: very simple scenario as follows:

///===================================================
{
        using namespace boost::spirit;
        typedef file_iterator<char> iterator_t;
        typedef scanner<iterator_t, scanner_policies_t> scanner_t;
        typedef rule<scanner_t> rule_t;

        int red=0, green=0, blue=0;

        rule_t option =
                (str_p("red") >> '=' >> int_p[assign(red)])
                |
                (str_p("green") >> '=' >> int_p[assign(green)])
                |
                (str_p("blue") >> '=' >> int_p[assign(blue)])
                |
                ;

        iterator_t first(filename.c_str());
        if (!first) return;
        iterator_t last = first.make_end();

        parse(first, last, *option, space_p);
}
///===================================================

wiw is a parser that will skip over the unrecognized line with input like this:
        ------------------
        red = 255
        kermit = green
        green = 128
        blue = 128
        ------------------
and correctly interpret the green and blue values..

i played around with eol_p as i want to skip whole lines of unrecognized content. i thought it
would be easy, but i can't seem to get it right.

can anybody do my job for me?

cheers
Jono


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net