Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: A little parse help

From: jelinem1:nationwide at: 20-Aug-2001 16:25

Allow me to make an educated guess as to what's happening in the absence of data to test my theory. I've done this sort of thing a long time ago. I doubt that the multiple usage of URL within a 'rejoin is the culprit. When 'parse hangs and grabs the CPU, it is usually an indication that you have an infinite parse loop. The crux here is where the 'parse cursor is in the content string.
>> to "http://"
Places the cursor at the first element of the first match of this string.
>> copy URL to "<br>"
Moves the cursor through the url text to the first element of "<br>". Now we loop:
>> to "http://"
Places the cursor at the first element of the next match of this string. But wait! Where exactly did we find the "next occurance" of this string? When you changed the 'content string you did NOT affect the 'parse cursor. In other words, the 'parse cursor has the same index? relative to the beginning of the string as it did before you made the 'replace. SO...the cursor is now positioned WITHIN the 'link text and effectively points shortly before the second URL that you replaced in 'content! Clear as mud? As a solution, after you finish the replacement you will want to move the 'parse cursor: (length? link) - (length? URL). I think the 'parse word 'skip will do this. - Michael Jelinek Stefan Falk <[syke--amigaextreme--com]> Sent by: [rebol-bounce--rebol--com] 08/20/01 03:27 PM Please respond to rebol-list T To: <[rebol-list--rebol--com]> cc: bcc: Subject: [REBOL] Re: A little parse help Hi again, I get a really strange behaviour from parse when I try to do this (it's also an explanation to what I'm trying to do). if find content "http://" [ parse/all content [ any [ to "http://" copy URL to "<br>" ( link: rejoin [{<a href="} URL {">} URL {</a>}] replace content URL link ) ] ] ] When I try to do this, Rebol crashes, the processor on the web server hits 100% and the only solution is to stop the webserver and then start it again. However, if I do like this: string: "Test" if find content "http://" [ parse/all content [ any [ to "http://" copy URL to "<br>" ( link: rejoin [{<a href="} URL {">} string {</a>}] replace content URL link ) ] ] ] It works. It seems as if using URL two times within Rejoin will cause Rebol to hang. Any idea as to what is causing this? /Regards Stefan Falk - www.amigaextreme.com ----- Original Message ----- From: "Petr Krenzelok" <[Petr--Krenzelok--trz--cz]> To: <[rebol-list--rebol--com]> Sent: Monday, August 20, 2001 9:42 AM Subject: [REBOL] Re: A little parse help
> > Stefan Falk wrote: > > > Hi, > > I'm kinda tired today ;-) > > > > If I for example have this text: > > > > Quick brown fox jumps !image-brown.gif over the fence > > > > and I want to parse out the image file, I'll just do > > parse text [ any [ thru "!" copy wanted-text to " " ]] > > 1) I think that even your parse rule above is not ever met. 'parse, by
default,
> ommits spaces, so you would be probably better with parse/all here. > 2) I don't know your application, but wouldn't you would be better with
'find?
> e.g. > > ->> start: find/any str "!*.???" > == "!image-brown.gif over the fence" > ->> end: find start " " > == " over the fence" > ->> res: copy/part start end > == "!image-brown.gif" > ->> remove res > == "image-brown.gif" > ->> > > If your string is long, you can reassing its position in a loop, e.g.
str:
> end
and continue in searching another image ... Maybe not so elegant, but ...