[REBOL] Re: Parsing with 2 conditions
From: richard:coffre:francetelecom at: 10-Apr-2002 14:14
Thanks a lot for this complete explanation. It's clear now.
-----Message d'origine-----
De : Brett Handley [mailto:[brett--codeconscious--com]]
Envoy=E9 : mercredi 10 avril 2002 12:05
=C0 : [rebol-list--rebol--com]
Objet : [REBOL] Re: Parsing with 2 conditions
Bonsoir,
> The following instruction works :
> if parse/all ligne [thru "Symbol" to end]
> why the next one doesn't work :
> if parse/all ligne [ "Symbol" ]
First let's look END. END is like asking the question "Are we at the end?"
>> parse/all {} [end]
== true
>> parse/all {x} [end]
== false
In these cases, ["Symbol"] is the same as ["Symbol" END]:
>> parse/all {} []
== true
>> parse/all {} [end]
== true
>> parse/all {x} []
== false
>> parse/all {x} [end]
== false
>> parse/all {x} ["x"]
== true
>> parse/all {x} ["x" end]
== true
["Symbol"] is like "Is there a 'Symbol' here?"
>> parse/all {Symbol} ["Symbol"]
== true
>> parse/all {xSymbol} ["Symbol"]
== false
>> parse/all {xSymbol} ["x" "Symbol"]
== true
>> parse/all {xSymbol} [skip "Symbol"]
== true
>> parse/all {Symbolx} ["Symbol"]
== false
TO ... Is like saying "Keep going until you reach...":
>> parse/all {abcdef} [to "d" "def" end]
== true
>> parse/all {abcdef} [to "e" "ef" end]
== true
THRU ... Is like saying "Keep going until you reach the end of ..."
>> parse/all {abcdef} [thru "e" "f"]
== true
>> parse/all {abcdef} [thru "ef"]
== true
SKIP - "Advance by one position"
>> parse/all {abcdef} [to "e" skip "f" end]
== true
TO END is like "Keep going to the end"
>> parse/all {x} [to end]
== true
>> parse/all {xxxxxx} [to end]
== true
>> parse/all {x} [to end "x"]
== false
So after all that
[thru "Symbol" to end]
is like saying
"Keep going until you reach the end of 'Symbol'
(that is - after the 'l'), and then keep going to the end."
Whereas
[ "Symbol" ]
is simply like saying
"Is there 'Symbol' right here, and if is advance throught it.
Are we now at the end?"
> 2nd question :
> I have the instruction "if parse/all ligne [thru "Symbol" to end]" to look
> for the word Symbol in a string. How can I do to look for Symbol and Frame
> at the same time ?
>> parse/all {xxxSymbolxxx} [thru "Symbol" to end]
== true
>> parse/all {xxxFramexxx} [thru "Symbol" to end]
== false
>> parse/all {xxxFramexxx} [ [thru "Symbol" | thru "Frame"] to end]
== true
Also have a look at:
http://www.codeconscious.com/rebol/parse-tutorial.html
I hope this helps.
Brett Handley.