metaeducation / ren-c

Library for embedding a Rebol interpreter into C codebases
GNU Lesser General Public License v3.0
126 stars 27 forks source link

Save parse position with POS: HERE, seek with SEEK POS #1115

Closed hostilefork closed 3 years ago

hostilefork commented 3 years ago

This is a small step toward broadening the applications of SET-WORD! and GET-WORD! in the parse dialect. The idea is that SET-WORD! will be used for capturing more than just parse positions, so the general purpose HERE rule can be used in the case that the parse position is what you want.

If you use a lone SET-WORD! without HERE after it, the near-term behavior for that will be to raise an error at the offending location. So long as you are updating, consider how commas might make the rules more readable, e.g.

 pos: any [integer! | text!]
 =>
 pos: here, any [integer! | text!]

That case is a good example showing the immediate readability benefits the change brings. What it ultimately is intended for--however--is to broaden the application of SET-WORD! in the dialect as a whole.

The analogous change for GET-WORD! behavior is now to use SEEK.

 :pos any [integer! | text!]
 =>
 seek pos, any [integer! | text!]

This offers an immediate benefit in clarity as well. But also, it means that GET-WORD! can find a more general use in PARSE as well.

Compatibility with the old PARSE rules is being pursued in the UPARSE implementation. This will be used with Redbol...although conceivably it could apply to anyone else who wanted to twist the meanings of SET-WORD! or GET-WORD!.