Mailing List Archive: 49091 messages

## [REBOL] Re: parse, again... (or rather: still!)

### From: joel:neely:fedex at: 6-Nov-2001 0:33

```
Hi, Hallvard,

>
> Just a sec...  Why does parse "" [to end to end] yield 'true?
> What happens when 'parse has done the first [to end]? Where is
> 'parse at then? And wouldn't it be simple for rebol to know that
> once 'parse has reached 'end, all further parse instructions
> must fail or be ignored? (I just feel the infinite loop is
> unneccessary).
>

Please!  NO!  Let's not add one more special case that has to
be memorized because it doesn't follow the simple, consistent
pattern.

Consider this example..

>> parse "x" [to "x" to "x" to "x" to "x" to "x" to "x" skip]
== true

As I understand it (and I'm sure someone will tell me if I'm
off target ;-), the meaning of

to foo

is very simple:

Is it possible to move forward 0 or more characters and
arrive at foo?

(I'm thinking here only in terms of the result of the entire
PARSE expression, and ignoring the side-effects for the moment.)

Being able to move forward zero characters is highly useful in
parsing (generally speaking, not REBOL specific) and I'd certainly
not like to lose that ability.

Of course, the meaning of

skip

is

Is it possible to move forward exactly one character?

and the final result of PARSE means

Did the supplied rule reach the end of the string?

With only these pieces of model, we can accurately predict the
behavior both of the previous example and this one:

>> parse "x" [to "x" to end to end to end to end to end to end]
== true

Now, consider that

some foo

means

Can we match the sub-pattern FOO one or more times?

or, imperatively

Match the sub-pattern FOO as many times (>= 1) as possible.

Then it's not surprising that

>> parse "x" [some [to "x"] skip]

will wander off into the weeds and never come back (and we can
get the same with ANY = "... zero or more ...").

I suspect that any programming language sufficienly powerful for
practical use allows one to write an infinite loop.  Complicating
it with extra heuristics designed to protect me from myself seems