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

[REBOL] Re: Complex Series Parsing (Part 2)

From: petr:krenzelok:trz:cz at: 8-Mar-2001 23:29

----- Original Message ----- From: Terry Brownell <[depotcity--home--com]> To: Rebol List <[rebol-list--rebol--com]> Sent: Thursday, March 08, 2001 9:28 PM Subject: [REBOL] Complex Series Parsing (Part 2)
> Hello all. > > How do you parse this... > y: [ > <text> This is some text <tag> with a tag added </tag> and then some text
</text>
> ] > > So that you get this > > n: [ > <text> This is some text > <tag> > <text> with a tag added > </tag> > <text> and then some text > ] > > I tried this... > > n: [] > z: parse y none
have you really tested your code? I receive error for above line, as 'y has to be string, not block ...
> foreach val z [ > either find val "<" [append n val] [append n rejoin [{<text> } val]] > ]
hmm, but what about if your text contains some "<" too? I think more robust solution would be better: str: "<text> This is some text <tag> with a tag added </tag> and then some text </text>" result: copy "" alpha: charset [#"A" - #"Z" #"a" - #"z"] tag: [start: "<" [some alpha | "/" some alpha] ">" end: (tmp: copy/part start end append result either tmp ="<text>" ["<text>"][join newline [tmp newline]])] text: [some [tag | (append result "<text>") start: skip (append result copy/part start 1)]] parse/all str [text to end] print result