Parsing/Destructuring a QUOTED! or QUASIFORM!

Quoteds (and quasiforms) can be seen kind of as containers...

But there isn't a good way to destructure them at the moment.

One off-the-cuff idea would be that you could SUBPARSE into them:

>> parse ['a:] [subparse quoted! set-word!]
== a:

>> parse [''a:] [subparse quoted! subparse quoted! set-word!]
== a:

>> parse [~(a b c)~] [subparse quasiform! subparse group! [some word!]]
== c

A bit of a belabored method. And because combinators require a series, I can't think of any efficient way to do that (vs. fabricating an array to hold a single item, and parsing that as a series.) But it's better than no method at all.

UPDATE: Having come up with a strategy for doing constraints like quote:quote:block?, it seems that covers a lot of use cases:

>> parse ['a:] [&quote:set-word!]
== a:

>> parse [''a:] [&quote:quote:set-word!]
== a:

>> parse [~(a b c)~] [subparse &quasi:group! [some word!]]
== c

It would require SUBPARSE to be willing to go inside quoted lists, which is easy enough to permit (and no reason not to, since it has to pass the type check you know what you're doing).

Seems to be reasonably powerful...just have to make peace with this strange new world of dialecting the act of calling functions itself. (!)

1 Like

I’m going to bring up something I’ve mentioned before: pattern-matching!

Imagining a possible syntax:

>> match ''a: ['($value): [probe value]]
a

>> match '~(a b c)~ [~(_ _ $value)~ [probe value]]
c

Rebol’s syntax makes this particularly ergonomic, because you can re-use value syntax for patterns.

1 Like

Yup, that's good in the spirit of DESTRUCTURE.

DESTRUCTURE Dialect

Using blanks in these cases to mean "match anything" makes me wonder if that should be the meaning of blank in parse in general...and switch over to # for space in strings (it now is the space character literal) and use '_ to match blanks in lists.

It's been up in the air a long time. My ambition to make _ what's used for spaces in string dialects has driven the current leaning, but, now that # is space, I guess I can live with that.

>> refinement-rule: [subparse chain! ['_ word!]]  ; would require the quote

>> parse [:foo] [refinement-rule]
== foo

It seems that if unquoted blank is literal in some pattern matching places and not others, that just gets confusing.

1 Like