[REBOL] parse and infinite loops (was: parse, again)
From: lmecir:mbox:vol:cz at: 6-Nov-2001 11:57
Hi Halvard & Rebols,
<<Just a sec... Why does parse "" [to end to end] yield 'true? What happens
when 'parse has done the first [to end]? Where is 'parse at then? And
wouldn't it be simple for rebol to know that once 'parse has reached 'end,
all further parse instructions must fail or be ignored? >>
You would be the first one who would see the trouble with such a simplistic
approach (how would you distinguish the cases):
parse "a" ["a" opt "b" opt "c"]
as opposed to
parse "a" ["a" opt "b" "c"]
The possibility of (infinite) loops is inevitable, if PARSE has to be
universal enough (bitter but true).
Simple infinite loops:
[some [any skip]]
[some [opt "a"]]
[some [to end]]
rule: [to end rule]
[some none]
[some []]
The rule of thumb for not being bugged by such kind of bugs is to use rules
that either consume at least something from input or, if they don't, then
they should finish their work.