Thanks Tom,

This is more than I had expected. Your code is much more simple and it works
!

Regards
Patrick
----- Original Message ----- 
From: "Tom Conlin" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, November 17, 2003 6:08 AM
Subject: [REBOL] Re: parse problem


>
>
> Hi Patrick,
>
> Is this more or less what you are loking for?
>
>
> start-char: charset join {"} "{"
> not-start-char: complement start-char
> rule: [
> some[
> any not-start-char
> [
> ["{" copy string to "}" "}"]
> |
> [{"} copy string to {"} {"}]
> (print string)
> ]
> ]
> ]
> parse mold code rule
>
> Hello World!
> test
> test 2
> alone in the line
> Salut {you}
> problem?
>
>
>
> On Sun, 16 Nov 2003 [EMAIL PROTECTED] wrote:
>
> >
> > Hi List
> >
> > I have being struggling all day with a parse problem: extracting all
strings from a Rebol script.
> > It may seem trivial at the first look.
> > However as you know strings are delimited by a pair of (") or by ({) and
(}) and inclusions are allowed.
> > {Hello "vous"} and "Salut {you}" are valid strings.
> >
> > I have produced several solutions that were ok with my test data by
failed with a real script.
> > Here is my final draft which passed all my tests.
> > However it may not be perfect or simply wrong.
> >
> > Here is how it is supposed to work:
> >
> > rule1 is for "string" delimited by (")
> > rule2 is for {string} delimited by ({) and (})
> >
> > rule1 AND rule2 are applied.
> > If both passed, I keep the one with the nearest match and the parsing
position is adjusted.
> > otherwise rule1 is applied
> > otherwise rule2 is applied
> >
> > I will be glad if some parse gurus may have a critical look...
> >
> > 8<-----------------------------------------------------
> >
> > code: [
> >         Rebol []
> >         ; This is a program
> >         str: "Hello World!"
> >         print "test"
> >         str2: {Hello "vous"}
> >         print {test 2}
> >         print
> >         {alone in the line}
> >         print {"strange" thing}
> >         str3: "Salut {you}"
> >         print {problem?}
> > ]
> >
> > script: mold code
> > strings: copy []
> >
> > rule1: [thru #"^"" mark1: copy text1 to #"^"" skip end1:]
> > rule2: [thru #"{" mark2: copy text2 to #"}" skip end2:]
> >
> > store: [either (index? mark1) > (index? mark2)
> >                         [
> >                                 append strings text2
> >                                 restart: end2
> >                         ][
> >                                 append strings text1
> >                                 restart: end1
> >                         ]
> >                 ] ; store
> >
> >
> > parse script [ any [start: rule1 :start rule2 (do store) :restart |
> >                                         rule1 (append strings text1)|
> >                                         rule2 (append strings text2)] to
end]
> >
> > foreach s strings [print s]
> >
> > 8<-----------------------------------------------------
> >
> > Regards
> > Patrick
> >
> > --
> > To unsubscribe from this list, just send an email to
> > [EMAIL PROTECTED] with unsubscribe as the subject.
> >
> -- 
> To unsubscribe from this list, just send an email to
> [EMAIL PROTECTED] with unsubscribe as the subject.
>

-- 
To unsubscribe from this list, just send an email to
[EMAIL PROTECTED] with unsubscribe as the subject.

Reply via email to