Implicit Capture In PARSE - How To Get It?

ISO-8601 dates are very close to Rebol dates, but just different enough to make it a pain.

; ISO-8601
2021-09-15T12:20:53-04:00

; Rebol
15-Sep-2021/12:20:53-04:00

Are Rebol dates more readable? Yes. Are they so much better as to make it worthwhile to buck the standard? :man_shrugging: Are they in conflict with generalized PATH! representation? :man_shrugging:

Nevermind, This Post Is About Something Else

Let's say I just want to capture the YEAR, the MONTH, and the DAY out of an ISO-8601 date.

parse isodate [
    year: between <here> "-"
    month: between <here> "-"
    day: between <here> "T"
    ...
 ]

Despite having BETWEEN, it's laborious. (Historical Rebol needs copy to "-" followed by a SKIP, even more convoluted, and worse if you need to skip more than one series item).

It needs a shorthand. We have TAG! at our disposal, still:

parse isodate [year: <*> "-" month: <*> "-" day: <*> "T" ...]

And it could be plain *:

parse isodate [year: * "-" month: * "-" day: * "T" ...]

But I kind of find myself wishing for another lexical type that means "capture" that has the word "in it". I'd thought about this as being the meaning of @xxx before the current interpretation, and also $xxx:

parse isodate [$year "-" $month "-" $day "T" ...]

But almost certainly, $ is going to be binding-related in the default combinator set.

It Feels Weak To Not Have An Answer For This

Other parsing systems will always seem like they have an edge if there isn't a shorthand for this "capture until the next rule".

But it may be that the default combinators are just too saturated and general-purpose to sacrifice any WORD!-based syntax for such a capture. It might have to be another parameterized parse variation.

3 Likes

Given that there are more parts in the box, I thought of a possibility for this:

parse isodate [:year: "-" :month: "-" :day: "T" ...]

It still has a colon on the end, which can help hint that it's an assignment. But the colon on the front gives it a visual sense of balance, pulling it left to where you might imagine it doesn't take any arguments. And it suggests perhaps connecting the left and right in a way that would capture between it.

It's generalized to where you can put tuples inside it:

parse isodate [:date.year: "-" :date.month: "-" :date.day: "T" ...]

It's certainly weird, but it's the best idea I've had so far. Beyond just "$year and @year are taken", I actually think it's superior.

1 Like