|
Boost Users : |
From: João Abecasis (jpabecasis_at_[hidden])
Date: 2006-01-16 21:45:05
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 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