[REBOL] Re: Parse limitation ?
From: petr:krenzelok:trz:cz at: 8-Oct-2003 14:06
patrick à la poste wrote:
>Hi List,
>
>I'd like to parse a string searching for two things at the same time.
>it seems to me that this is impossible.
>
>For example, a text from which I want to extract the HREF and the SRC target.
>
>myText: {<A HREF="#section1"><IMG SRC="foobar.gif"><A HREF="#section1">}
>
>parse myText [
> any [ thru "HREF=" copy target to ">" (print target) |
> thru "SRC=" copy target to ">" (print target)
> ] ; any
>] ; parse
>
>"#section1"
>"#section1"
>
>parse myText [
> any [ thru "SRC=" copy target to ">" (print target) |
> thru "HREF=" copy target to ">" (print target)
> ] ; any
>] ; parse
>
>"foobar.gif"
>"#section1"
>
>The result is different depending which rule comes first. The only way I see as a workaround
is to parse the text twice. Is there a better (smarter) way?
>
I would just like to point out, that 'first directive or tu/thru [a | b
| c] was proposed for parse enahncement some time ago, but then some
parse gurus (e.g. Gabriele) admitted, that parse would have to work
other way internally and that it is not easy achievable (am I right,
Gabriele?)
OTOH - your example is just one of those which we often enough meet in
real life, but have no easy/elegant solution for, at least not for
novice being able to solve it ....
-pekr-