YAPAQ
[1/9] from: hallvard::ystad::oops-as::no at: 2-Mar-2004 14:53
Hi,
YAPAQ: Yet Another PArse Question
I know this has been asked before, but the list archives are so full of parse emails
that I couldn't find it. Here goes:
I want to parse a string like this: {word1 word2 "expression 1" "expression 2" word3
"expression 3"}
and I want the output to be: ["word1" "word2" "expression 1" "expression 2" "word3" "expression
3"]
So I need a parse rule that considers quotation marks and treats anything between quotation
marks as one single entry. I'm lazy, and don't want to write it myself if someone else
already has. I think someone has. Does anyone remember having seen such a parse rule?
And where?
Thanks,
HY
[2/9] from: nitsch-lists:netcologne at: 2-Mar-2004 16:31
Am Dienstag, 2. M=E4rz 2004 14:53 schrieben Sie:
> Hi,
>
> YAPAQ: Yet Another PArse Question
>
...
> I want to parse a string like this: {word1 word2 "expression 1" "expression
> 2" word3 "expression 3"} and I want the output to be: ["word1" "word2"
> "expression 1" "expression 2" "word3" "expression 3"]
>
...
Quotes are inbuild. so:
!>> parse
{word1 word2 "expression 1" "expression 2" word3 "expression 3"} ""
== ["word1" "word2" "expression 1" "expression 2" "word3" "expression 3"]
-Volker
[3/9] from: g:santilli:tiscalinet:it at: 2-Mar-2004 16:36
Hi Hallvard,
On Tuesday, March 2, 2004, 2:53:19 PM, you wrote:
HY> I want to parse a string like this: {word1 word2
HY> "expression 1" "expression 2" word3 "expression 3"}
HY> and I want the output to be: ["word1" "word2" "expression
HY> 1" "expression 2" "word3" "expression 3"]
>> parse {word1 word2 "expression 1" "expression 2" word3 "expression 3"} none
== ["word1" "word2" "expression 1" "expression 2" "word3" "expression 3"]
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[4/9] from: ptretter:charter at: 2-Mar-2004 10:17
load {word1 word2 "expression 1" "expression 2" word3 "expression 3"}
----- Original Message -----
From: "Hallvard Ystad" <[hallvard--ystad--oops-as--no]>
To: <[rebol-list--rebol--com]>
Sent: Tuesday, March 02, 2004 7:53 AM
Subject: [REBOL] YAPAQ
> Hi,
>
> YAPAQ: Yet Another PArse Question
>
> I know this has been asked before, but the list archives are so full of
parse emails that I couldn't find it. Here goes:
> I want to parse a string like this: {word1 word2 "expression 1"
expression 2
word3 "expression 3"}
> and I want the output to be: ["word1" "word2" "expression 1" "expression
2" "word3" "expression 3"]
> So I need a parse rule that considers quotation marks and treats anything
between quotation marks as one single entry. I'm lazy, and don't want to
write it myself if someone else already has. I think someone has. Does
anyone remember having seen such a parse rule? And where?
[5/9] from: carl:cybercraft at: 2-Mar-2004 22:29
On 03-Mar-04, Volker Nitsch wrote:
> Am Dienstag, 2. M=E4rz 2004 14:53 schrieben Sie:
>> Hi,
<<quoted lines omitted: 13>>
> == ["word1" "word2" "expression 1" "expression 2" "word3"
> "expression 3"]
Out of interest, is there any difference in behaviour between using an
empty string and none as the parse rule? ie...
>> parse {word1 word2 "str 1" "str 2"} none
== ["word1" "word2" "str 1" "str 2"]
>> parse {word1 word2 "str 1" "str 2"} ""
== ["word1" "word2" "str 1" "str 2"]
--
Carl Read
[6/9] from: hallvard:ystad:oops-as:no at: 3-Mar-2004 14:45
Dixit Volker Nitsch (16.31 02.03.2004):
>Quotes are inbuild. so:
>!>> parse
>{word1 word2 "expression 1" "expression 2" word3 "expression 3"} ""
>== ["word1" "word2" "expression 1" "expression 2" "word3" "expression 3"]
Yes, but:
>> a: parse {e1 e2 "e 3" e4 ee"e 5" e6 ^{e 7^}} none
== ["e1" "e2" "e 3" "e4" {ee"e} {5"} "e6" "{e" "7}"]
>> print third a
e 3
So 1) I need a parse rule that will see { } as string delimiters, and preferably also
divide {ee"e 5"} into ["ee" "e5"] or [{ee"e 5"}] And 2) I want to keep the quotes, so
that this could be the output:
>> print third a
e 3
Any help greatly appreciated. As I said, I think this problem has been solved here on
the list before, but I can't seem to find out when.
HY
[7/9] from: rotenca:telvia:it at: 3-Mar-2004 16:42
If they are all valid rebol value, you can load the string or try this:
str: {e1 e2 "e 3" e4 ee"e 5" e6 ^{e 7^}}
until [res: load/next str probe to string! res/1 tail? str: res/2]
Else you must write a parse rule.
---
Ciao
Romano
[8/9] from: rlist:techscribe at: 5-Mar-2004 13:21
Hi Hallvard.
you wrote:
(1)
>I want to parse a string like this:
>
>{word1 word2 "expression 1" "expression 2" word3 "expression 3"}
>and I want the output to be:
>
>["word1" "word2" "expression 1" "expression 2" "word3" "expression 3"]
>
and (2)
>Yes, but:
>>> a: parse {e1 e2 "e 3" e4 ee"e 5" e6 ^{e 7^}} none
<<quoted lines omitted: 6>>
>>> print third
>"e 3"
Comparing your two posts I'm confused as to what you want. In post one
the string "expression 3" was supposed to evaluate to "expression 3".
Well, print "expression 3" will look like your first "e 3" example,
namely minus quotation marks.
If, instead, print third a (note the missing a in your example code the
second time around) should evaluate to "e 3", then in your first post,
you should have asked that "expression 3" evaluate to {"expression 3"}.
Now, I don't know where your error is: Is the error in your first post,
and "expression 3" should have become {"expression 3"} in your example?
Or is the error in your second post, and you do not realize that
expression 3
will be displayed as expression 3, whereas what you are
looking for is
>> print mold third a
e 3
[9/9] from: hallvard:ystad:oops-as:no at: 5-Mar-2004 23:27
Dixit Elan (22.21 05.03.2004):
>Comparing your two posts I'm confused as to what you want. In post one
>the string "expression 3" was supposed to evaluate to "expression 3".
<<quoted lines omitted: 3>>
>second time around) should evaluate to "e 3", then in your first post,
>you should have asked that "expression 3" evaluate to {"expression 3"}.
You're right.
>Now, I don't know where your error is: Is the error in your first post,
>and "expression 3" should have become {"expression 3"} in your example?
<<quoted lines omitted: 3>>
> >> print mold third a
>"e 3"
I am looking for the quotes. I want the output to be
e 3
but I cannot use 'mold, because
>> print mold first a
e1
...and I don't want the quotes when there were none in the original string.
Does this make things clearer? I've begun thinking about the parse rule myself, but I
thought I remembered someone having solved this before on this list, so I hoped to spare
the thinking (and rethinking, and...).
HY
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted