ACROSS vs. COPY and UPARSE Synthetic Ambiguity

A successfully matching UPARSE combinator produces two return values. One is the "synthesized product" of the rule. The other is an indication of how far the rule advanced.

I was a bit unsettled by things like this:

>> did uparse "abcde" ["a" test: copy (first ["Fhqwhgads"]) thru "e"]
== #[true]

>> test
== ""

Because COPY does not copy the synthesized result. It takes the span of the matched rule and copies across that span. GROUP!s don't move the parse position at all. So if you COPY a GROUP! you'll always get "".

Compare that with putting the copy inside the GROUP! so it runs as DO code:

>> did uparse "abcde" ["a" test: (copy first ["Fhqwhgads"]) thru "e"]
== #[true]

>> test
== "Fhqwhgads"

This made me skeptical of the word COPY and wanting to find a word that jumped off the page a bit distinctly from PARSE. I thought of ACROSS.

But... Aren't All The PARSE Words Different?

You might ask if there's any point to fretting over this, when you know that basically every combinator other than SET-WORD! and KEEP doesn't care about synthesized products. They operate on the rules.

Consider what this does:

>> uparse "aaa" [not (false), some "a"]
; null

You didn't get NOT and FALSE interacting there to make a truthy result that kept the parse going. Instead, GROUP! rules always succeed...and NOT was testing to see if the rule didn't succeed. Since it did, the parse failed.

This makes it seem like some combinators should indicate they can't be used in rule-span-checked slots. Maybe x: copy ("a") should be illegal due to some property GROUP! combinators have that make them not want to mix with COPY.

But what about this?

 >> uparse "ababccc" [x: copy y: collect [some [keep "a" keep "b"]] some "c"]
 == "c"

 >> x
 == "abab"

 >> y
 == ["a" "b" "a" b"]

Would it be better if COLLECT (or the Y SET-WORD! combinator) prevented you from capturing across the span of it, just because it synthesized a product? Is it messing with generality to disable the GROUP!s being spanned going to come back and bite us later?

Maybe this shows why I was uneasy about COPY. I dunno. But I'm not feeling thrilled with ACROSS.

Food for thought.