[REBOL] Re: Another question
From: carl:cybercraft at: 15-Feb-2002 11:48
On 15-Feb-02, Gregg Irwin wrote:
> Hi Alex,
> << I'm trying to figure out parse... how, for instance, would I use
> a parse expression to break some text into words, which are grouped
> with quotation marks (so you could make "foo bar" one word), but
> quotation marks preceded by a backslash are treated as normal text?
> "Hello world," I said -> ["Hello world", "I", "said"] >>
> Do you need to escape the quotes (i.e. is there source data that
> contains them)? If not, parse's behavior should be pretty darn
> close:
>>> parse {"Hello world," I said} none
> == ["Hello world," "I" "said"]
> Hmmm. If the escapes exist, you might also just replace them:
>>> parse replace/all {\"Hello world,\" I said} {\"} {"} none
> == ["Hello world," "I" "said"]
> Though that still removes them from the text. You'll probably have
> to write some rules if that doesn't work for you.
I took his question to mean that he wanted to transform the likes of
this...
{"Hello world", he said. \"Indeed you did" I replied.}
into this...
["Hello world" , "he" "said" . "Indeed" "you" did" "I" "replied" .]
I can't work out the parsing off the top of my head, (sorry - this
probably isn't a very useful post), but I'd like to point out that I
don't think you can include comers and some other punctuation in
blocks like he seemed to want. ie...
>> a: ["a" , "b"]
** Syntax Error: Invalid word -- ,
** Near: (line 1) a: ["a" , "b"]
doesn't work. Full stops are okay though...
>> a: ["a" . "b"]
== ["a" . "b"]
> << Also, how would I match on a left bracket, any member of a block,
> and then a right bracket? Here's a pseudocode example:
> "[" FOLLOWED BY ("red" OR "green" OR "blue") FOLLOWED BY "]" >>
> Can you use block parsing? REBOL can recognize things for you in
> mnay cases.
>>> parse [[blue]] [set b block!]
> == true
>>> b
> == [blue]
> --Gregg
--
Carl Read