Rebol2 Prohibited Series Switching During a PARSE
>> series1: [a a a]
== [a a a]
>> series2: [b b b]
== [b b b]
>> parse series1 ['a :series2 some 'b]
** Script Error: Invalid argument: b b b
The error wasn't particularly informative. But it was trying to tell you that you couldn't do that.
Red Chose to Follow Suit, and Prohibits Series Switching During a PARSE
red>> series1: [a a a]
== [a a a]
red>> series2: [b b b]
== [b b b]
red>> parse series1 ['a :series2 some 'b]
*** Script Error: PARSE - get-word refers to a different series! :series2
R3-Alpha Decided To Make It Legal
r3-alpha>> series1: [a a a]
== [a a a]
r3-alpha>> series2: [b b b]
== [b b b]
r3-alpha>> parse series1 ['a :series2 some 'b]
== true
I wasn't aware the feature was used, but @rgchris used it in the Rebol3 version of altjson:
Scripts/r3-alpha/altjson.r3 at 6fa69eabe11fe78b9fd0a7bd6bb17a923cee0b2b · rgchris/Scripts · GitHub
The Feature Was Added to R3-Alpha Circa 2009
Carl's blog entry:
http://www.rebol.net/r3blogs/0265.html
He points out one fairly clear reason why this is sketchy:
The problem is this: if you change the series but the rule fails, forcing a recovery to a prior index, it's still the new series. That is, we do not recover to the old series.
If advanced users are willing to live with that restriction, then this change can be made.
Another comment says the opposite of what I would think:
Input switching would make parsing of big (or streaming) files more easy, as we wouldn't have to keep the whole data in memory, and could read it as needed, without losing the current parse state.
Doing streaming parsing correctly requires tighter control over the process... not less.
Can The Desire Be Met Other Ways?
Since you're basically destroying the ability to meaningfully backtrack, I don't know how this is that different from starting a new parse.
I'd like it to be easy to return results out of a parse (see the RETURN/ACCEPT post)
So why wouldn't you have some kind of driving loop on the outside of your parse that looks for a continuation signal, and then starts a new parse with what it's given?
I want to take a look at the cases and see if they could be done some other way. So maybe @rgchris can explain the rational behind the choice in altjson, and if there's some feature that would be a better fit.