Parse and Break: why break cannot be used for getting out of "any" or "some" rule ?

Posted by Rebol Tutorial on Stack Overflow See other posts from Stack Overflow or by Rebol Tutorial
Published on 2010-03-16T19:53:29Z Indexed on 2010/03/16 21:11 UTC
Read the original article Hit count: 146

Filed under:

Let say I have to parse a hierarchical set of tags

<tag>
<subtag1 attr1=value1 attr2=value2>
<subtag1 attr1=value1 attr2=value2>
<subtag1 attr1=value1 attr2=value2>
</tag>

Why can't I use break inside some or any to get out of a level hierarchy ? This would allow to do that kind of parsing instead of having a headache to do so ?

I'm asking this because I read here http://www.codeconscious.com/rebol/parse-tutorial.html it would create an infinite loop

This case produces an infinite loop. Because the BREAK is within a sub-rule of the rule that SOME is processing. The BREAK does not affect success/failure status or the input pointer - it just exits a rule early:

rule-to-break: [(print "Break") break] == [(print "Break") break] parse "X" [some [rule-to-break] "X"] Break *Break* ... Break *Break*(escape)

© Stack Overflow or respective owner

Related posts about rebol