REBOL 3.0

PARSE: Rethinking REMOVE

Carl Sassenrath, CTO
REBOL Technologies
29-Sep-2009 5:21 GMT

Article #0255
Main page || Index || Prior Article [0254] || Next Article [0256] || 1 Comments || Send feedback

A83 implements REMOVE as a standard post-rule action. That is, the rule matches, and if successful, the REMOVE action is performed:

parse "abcd" ["ab" remove 1 "d"]

This line matches "ab" then removes the next char, "c", then matches "d".

An alternative (suggested by Steeve in a prior blog) is for REMOVE to work like a pre-rule action. (NOT is an example of a pre-rule action. It inverts the result of the rule that follows it.)

The above example would be written:

parse "abcd" ["ab" remove skip "d"]

Is there an advantage in this change? At first, it may seem equivalent. However, there is a small advantage. If, for example, I wanted to match against "c" before removing it, in the earlier method it would be:

parse "abcd" ["abc" remove -1 "d"]

and in the suggested method:

parse "abcd" ["ab" remove "c" "d"]

If I want to remove "ccc":

parse "abcccd" ["abccc" remove -3 "d"]

or:

parse "abcccd" ["ab" 3 "c" remove -3 "d"]

vs:

parse "abcccd" ["ab" remove "ccc" "d"]

or:

parse "abcccd" ["ab" remove 3 "c" "d"]

In the earlier method, I am required to keep the REMOVE argument in-agreement with the match rule; whereas, in the suggested method, they are the same.

This is consistent with good programming methods: avoid duplicate specification when possible. That is, avoid specifying the same thing (or its related properties) twice. This prevents the common mistake that if you change one of them, but forget to change the other, you've created a bug.

So, with that in mind the A84 release will test this REMOVE method. Although somewhat different than the other parse actions, I think we may find it a worthwhile approach. Please give it a try and let me know.

1 Comments

REBOL 3.0
Updated 27-Mar-2024 - Edit - Copyright REBOL Technologies - REBOL.net