Boost logo

Boost Users :

From: elviin (elviin_at_[hidden])
Date: 2006-01-17 02:11:38


Hi João!

I have adjusted the code according to your advise and the FAQ and it
is now working for me.
Here is the update:

//----------------
            cpp_code_block_text = anychar_p-(ch_p('{')|ch_p('}'));
            cpp_code_block_begin_p = ch_p('{');
            cpp_code_block_end_p = ch_p('}');

            cpp_code_block_p =
                    cpp_code_block_begin_p
>>
                        *(cpp_code_block_p|cpp_code_block_text)
>>
                    cpp_code_block_end_p;

At the first sight the boost::spirit seems to be difficult to use but
with more experience I recognize that it is realy nice/good tool.
Thank you João.

On 17/01/06, João Abecasis <jpabecasis_at_[hidden]> wrote:
> Hi!
>
> elviin wrote:
> > I created this parser and it is working for me
> > except the detail:
>
> [snip code]
>
> > And the problem is in repeat_p (0, 100). I'd like to use * instead but
> > it does not work for me because the parser runs forever. 100 means the
> > number of blocks cpp_code_block_p or cpp_code_block_text.
> >
> > Where is the problem?
>
> The code sample you provided can be summarized as
>
> continuation = *(anychar_p - (begin|end));
> all = begin >> *continuation >> end;
>
> Which, substituting continuation, is the same as:
>
> all = begin >> *(*(anychar_p - (begin|end))) >> end;
>
> The problem here is the double kleene star. The outer kleene will
> continue matching, in an infinite loop, as long as the inner one returns
> matches -- even if they're zero matches. Btw, this is a FAQ and is
> addressed here http://tinyurl.com/art36.
>
> When you substitute the outer * for repeat_p(0, 100) you only limit the
> loop. You still get 100 matches, even if they're all empty.
>
> The solution is pretty simple, and it is to remove one of the
> */repeat_p. For instance,
>
> continuation = *(anychar_p - (begin|end));
> all = begin >> continuation >> end;
>
> Best regards,
>
>
> João
>
> _______________________________________________
> 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