Comments on: PARSE: definition of termination and BREAK
Ok, from the prior posting, we've decided that iteration of rules will have no auto-termination based on the state of the input. This will be part of the A89 release.
NOTE: Users must be careful to avoid infinite loops.
For example, this is now an infinite loop:
parse "abc" [some ["a" | to end]]
because TO END is always TRUE and reaching the end of input is not a termination condition for the iteration.
We can call that an improper rule because it will always be true.
For an improper rule, to terminate the loop, you must use a BREAK:
parse "abc" [some ["a" | to end break]]
Note that BREAK simply stops the loop, it does not affect the result. For example:
parse "abc" [some ["a" break | to end]]
This is FALSE because only "a" was matched and TO END was never attempted.
Any bugs submissions posted for infinite loops on improper rules will be dismissed.
I should note that currently (in A89) BREAK exits immediately and does not process NOT, THEN, SET, COPY, RETURN, REMOVE, INSERT, CHANGE or other such post-match options. In other words, you cannot say NOT BREAK, but you can say NOT "abc" BREAK.
Of note... the term "improper rule" should be added as an official concept in the PARSE glossary.
it should be defined clearly, so people can refer to it in docs, discussions, and as a concept for new users to watch out for.
Agreed, Maxim. Definitely a documentation issue.
Sorry for retaining another gotcha, Fork, but to do otherwise would reduce the power of PARSE. Newbies can't win them all - sometimes we need to get work done.
Post a Comment:
You can post a comment here. Keep it on-topic.