[spirit] alpha numeric characters
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. Thanks for advice, Ovanes
On Sat, Dec 5, 2009 at 5:33 PM, Ovanes Markarian
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: (+alnum)%"->" 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.
Thanks for that answer. But as far as I see it no, Spirit.Qi is not part of
boost 1.36?
At least docs do not state anything, but I can find includes for Qi. I will
give it a try.
On Sun, Dec 6, 2009 at 2:24 AM, OvermindDL1
On Sat, Dec 5, 2009 at 5:33 PM, Ovanes Markarian
wrote:
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:
(+alnum)%"->"
I tried it as well, but it nether worked. Unfortunately I have to define a grammar and cannot pass strings around.
What I wonder, even (+range_p('a','z'))[some_callback] parses a->b->c-> as the whole sequence Many thanks for the answer. Best Regards, Ovanes
Hi,
not being able to answer any of your other wuestions, I can tell you
that Spirit 2.1, which includes a fully updated an well tested
spirit.qi has just been release with boost 1.41.
Best,
Dee
On Sun, Dec 6, 2009 at 9:51 AM, Ovanes Markarian
Thanks for that answer. But as far as I see it no, Spirit.Qi is not part of boost 1.36? At least docs do not state anything, but I can find includes for Qi. I will give it a try.
On Sun, Dec 6, 2009 at 2:24 AM, OvermindDL1
wrote: On Sat, Dec 5, 2009 at 5:33 PM, Ovanes Markarian
wrote: 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:
(+alnum)%"->"
I tried it as well, but it nether worked. Unfortunately I have to define a grammar and cannot pass strings around.
What I wonder, even
(+range_p('a','z'))[some_callback] parses a->b->c-> as the whole sequence
Many thanks for the answer.
Best Regards, Ovanes
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Sat, Dec 5, 2009 at 7:08 PM, Diederick C. Niehorster
Hi,
not being able to answer any of your other wuestions, I can tell you that Spirit 2.1, which includes a fully updated an well tested spirit.qi has just been release with boost 1.41.
Best, Dee
On Sun, Dec 6, 2009 at 9:51 AM, Ovanes Markarian
wrote: Thanks for that answer. But as far as I see it no, Spirit.Qi is not part of boost 1.36? At least docs do not state anything, but I can find includes for Qi. I will give it a try.
Correct, Spirit 2.0 and higher has four parts, Classic (what you are using), QI (the newer much fixed classic), Karma (does the opposite of Qi), and Lex (a lexer). Boost 1.36 is old, and I know Spirit.Classic has bugs back in that old version that have been fixed later on (even in the latest Boost 1.41 Spirit.Classic still has some more bugs fixed, it is still being kept up even if Spirit.Qi has fully replaced it in every way). You *really* need to update. Spirit2.0 came out in Boost 1.39. Spirit2.1 came out in Boost 1.41. Spirit2.2 should come out in Boost 1.42 hopefully (it is backwards compatible still, just has even more functionality, like being able to define your own auto-type conversions).
participants (3)
-
Diederick C. Niehorster
-
Ovanes Markarian
-
OvermindDL1