Parse and Break: why break cannot be used for getting out of "any" or "some" rule ?
- by Rebol Tutorial
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)