[REBOL] Re: parse consumption
From: gscottjones:mchsi at: 9-Sep-2002 9:54
From: "Anton"
> I have here a bit of confusion:
>
> parse "abc" [start: "abc" (remove/part start 3) :start end]
> ;== false
>
> parse "abc" [start: to "abc" (remove/part start 3) :start end]
> ;== true
>
> The first parse "consumes" the "abc" before removal,
> and the second one doesn't.
>
> Why does it matter whether "abc" is consumed or not?
>
> I am setting the input position to the start of the
> string afterwards with :start.
> I have verified that before the removal, start is at
> the beginning of the string.
>
> Also, this is the same both in latest beta
> and last full release.
Hi, Anton,
You may feel confused, but you actually are not!
:-)
Let me re-word what you have said, using slightly more information, and I
hope this reframes the issue in words that then make sense.
parse "abcd" [
start: "abc"
check: (
print [start/1 check/1 ] ;yields a and d
remove/part start 3
print start/1 ; yields d
) :start
to end
]
My analysis: *without* the 'to, then the parser matches through the pattern,
demonstrated by the check. So start still points to the initial start of
the string, but the parser has already moved through it. So it seems
consumed.
parse "abcd" [
start: to "abc"
check: (
print [start/1 check/1] ;yields a and a
remove/part start 3
print start/1 ;yields d
) :start
to end
]
My analysis: 'to only matches "to" the pattern, as demonstrated by check.
Parse still hasn't "moved through" the pattern, so it doesn't seem
consumed.
Did that help?
--Scott Jones