|
Boost Users : |
Subject: Re: [Boost-users] Xpressive, symantic actions and combination enumeration
From: Lee Simpson (L33Simpson+boostuser_at_[hidden])
Date: 2009-05-05 23:20:17
That is _exactly_ what I was after! Thanks so much.
On Wed, May 6, 2009 at 3:11 AM, Eric Niebler <eric_at_[hidden]> wrote:
> Eric Niebler wrote:
>
>> Lee Simpson wrote:
>>
>>> Hi,
>>>
>>> First let me say. Awesome library and thanks for releasing it to the
>>> world.
>>>
>>
>> Thanks!
>>
>> I'm looking for a way to apply all the currently queued semantic actions
>>> _without_ turning off backtracking.
>>> So, as the manual suggests, keep manages to apply the queued actions but
>>> it also turns off backtracking.
>>>
>>> <snip>
>>
>>>
>>> Any ideas?
>>>
>>
>> You don't have to turn off backtracking for the whole regex. You can use
>> keep() in a few strategic places within your regex as follows:
>>
>> sregex rx = ... >> keep(nil[ /*semantic action*/ ]) >> ...;
>>
>> "nil" always succeeds and consumes 0 characters. It's a way to cause the
>> semantic action to execute immediately. Would something like that help you?
>>
>
>
> In case I wasn't clear, here is a little program that demonstrates what I
> was getting at:
>
> #include <string>
> #include <iostream>
> #include <boost/xpressive/xpressive_static.hpp>
> #include <boost/xpressive/regex_actions.hpp>
> using namespace boost::xpressive;
>
> int main()
> {
> std::string text = "abcd";
> sregex rx =
> // Match some stuff and save some submatches
> (s1= +alpha) >> (s2= +alpha) >> eos >>
> // Display the submatches eagerly.
> keep(nil[ref(std::cout) << s1 << ", " << s2 << "\n"]) >>
> // Cause the fail and backtrack.
> ~before(nil);
>
> regex_match(text, rx);
>
> return 0;
> }
>
> For me, this dispays:
>
> abc, d
> ab, cd
> a, bcd
>
> HTH,
>
>
> --
> Eric Niebler
> BoostPro Computing
> http://www.boostpro.com
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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