Boost logo

Boost Users :

Subject: Re: [Boost-users] [spirit] alpha numeric characters
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-12-05 20:24:40

On Sat, Dec 5, 2009 at 5:33 PM, Ovanes Markarian <om_boost_at_[hidden]> wrote:
> Hello *,
> I currently use boost 1.36 to parse some input line like a->b->c-> ...
> I thought a, b, c can be strings containing letters or digits. Until now I
> thought that this defines alpha numeric characters. But when using the
> spirit rule:
> +((+alnum_p)[some_callback_func] >> str_p("->"))
> the some_callback_func gets as input the whole input sequence
> (a->b->c->...). Furthermore, it than gets called for b->c->... and than
> c->d->...
> Maybe my rule is wrong, but I can't get where.

That should be correct, might be a bug in Spirit.Classic. If you have
a complete example then please post it to the Spirit mailing list.

You should not be using Spirit.Classic though, instead use Spirit.Qi,
which is much better tested and much faster. The same code in
Spirit.Qi is:

+((+alnum)[some_callback_func] >> "->")

Or is you just want to stuff all the strings in a vector:

std::string input("a->b->c->");
std::vector result;

parse(input.begin(),input.end(),+(+alnum >> "->"),result);

result will be an array of: ["a","b","c"]

Also, if you only want the -> to be between strings and not following, use this:


That will parse out strings separated by "->", but no "->" at the
beginning or the end of the list. Spirit.Qi is a lot more powerful
and runs a lot faster then Spirit.Classic, and tends to be a lot
easier to use once you learn it.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at