Has anyone ever actually used THEN? Does anyone actually understand what it's for?
Red describes it as:
then : regardless of failure or success of what follows, skip the next alternate rule
But the easiest way to think of it is that these two things are equivalent:
rule1 THEN rule2 | rule3 [rule1 (cont: rule2) | (cont: rule3)] cont
It doesn't fit into the combinator model at all. Something like this would have to be part of the BLOCK! rules and recognized literally. It skips just one
|, which doesn't feel like it makes any sense.
Topaz says it removes
then (and that it "should be removed from Red's
parse too"). Yup.
The longer-winded PARSE project documentation tries to justify it by saying that dynamic rules (e.g. those using GROUP!s) are irregular or bad somehow. But this construct is much more irregular and bad. Axing it.
Purpose: Syntactic conditional pattern matching without dynamic rules.
Increases the expressiveness of the PARSE dialect to match that of the Generalized TDPL.
Together with FAIL it allows direct usage of the GTDPL in PARSE.
Dynamic rules tend to be a tricky process to write and debug, not to mention the potential binding issues if they aren't done just right. The more language patterns we can recognize without dynamic rules, the better.
Replaces the idiom:
[rule1 (cont: rule2) | (cont: rule3)] cont
THEN rule2 | rule3
If THEN is reached (any implied rule1 succeeded), then rule2 is matched and the next alternate (containing rule3) is skipped. If rule1 failed, the next alternate is backtracked to using the normal backtracking rules. If rule2 fails, then it backtracks to whatever rule4 alternate that there may be after the rule3 alternate, if any.
Parse to the #"a" delimiter, to the #"b" delimiter, or to the end of the input, whichever comes first:
any [[#"a" | #"b"] then [end skip] | skip]
Note: The word => has been suggested instead of THEN for this operation, but would require a REBOL syntax exception. THEN was accepted with that name, not as =>.
Here is the sole test of THEN that I'm deleting:
b: "abc" c: ["a" | "b"] a2: [any [b, e: here, (d: [seek e]) then fail | [c | (d: [fail]) fail]] d] a4: [any [b then e: here (d: [seek e]) fail | [c | (d: [fail]) fail]] d] equal? parse "aaaaabc" a2 parse "aaaaabc" a4