So UPARSE design is really clicking along now, and here's a new idea that helps address the loss of the advancement behaviors traditionally built into old ANY/SOME when using the new WHILE/SOME
The idea is to break out a test for advancing as a rule of its own:
>> uparse "a" [further [opt "a" opt "b"] (<at least one!>)]
== <at least one!>
>> uparse "b" [further [opt "a" opt "b"] (<at least one!>)]
== <at least one!>
>> uparse "" [further [opt "a" opt "b"] (<at least one!>)]
; null
(Note: I had originally called this ADVANCING, but FURTHER is less likely to be used as a variable name to track an advancing state, e.g. advancing: true
. And ADVANCES sounds like it might actually be taking an action. FURTHER is a shorter word that is a strange part of speech that is unlikely to be a variable or misunderstood as taking action. Feedback welcome.)
You wouldn't have to use it with loops. But if you use it with a loop, it's quite clear, and stops you from infinite looping when everything "opts out" yet still succeeds a rule:
>> uparse "abba" [
while further [opt ["a" (print "A")] opt ["b" (print "B")]]
]
A
B
B
A
; null-2
OOO...So much beauty, I cannot take it.