If you want control over whitespace as you parse, try using the "all"
refinement and including a whitespace charset in your parse pattern.
>> s-char: charset [#"^(line)" #"^(tab)" #" "]
== make bitset! #{
0006000001000000000000000000000000000000000000000000000000000000
}
>> s: [s-char]
== [s-char]
>> s?: [any s-char]
== [any s-char]
>> s+: [some s-char]
== [some s-char]
>> parse/all " " s
== false
>> parse/all " " s
== true
>> parse/all "" s
== false
>> parse/all " " s?
== true
>> parse/all " " s?
== true
>> parse/all "" s?
== true
>> parse/all " " s+
== true
>> parse/all " " s+
== true
>> parse/all "" s+
== false
Then we can control where space is allowed, and how much:
>> parse/all "the radio" ["the" s "radio"]
== true
>> parse/all "the radio " ["the" s "radio"]
== false
>> parse/all "the radio " [s? "the" s+ "radio" s?]
== true
The "all" refinement makes the parse command whitespace-sensitive. There's
also a "case" refined to make comparisons case-sensitive. Note that I'm
using ? and + as part of the words s? and s+, they aren't reserved as
"operators" as they may be in other languages.
Steve
> -----Original Message-----
> From: [EMAIL PROTECTED]@ARTISOFT
> Sent: Friday, October 08, 1999 4:04 PM
> To: [EMAIL PROTECTED]
> Subject: [REBOL] Parse question Re:
>
>
>
> [EMAIL PROTECTED] wrote:
>
> > Hi
> > The question:
> >
> > Why if
> > parse "the radio" ["the" "radio"]
> > parse "the radio" ["the" "radio"]
> > parse " the radio" ["the" "radio"]
> >
> > are all true,
> >
> > parse " the radio " ["the" "radio"]
> >
> > is false?
>
> I think it's because of how rules are applied. The first rule says, -
> does "the" matches the input string? If so, it ignores spaces, and tries
> to do second part of your rule, so it tries to match "radio".
>
> Try this:
>
> space: #" "
> parse " the radio" [any space "the" "radio"]
>
> ;hmm, I thought even "some space" should work, but it doesn't. It also
> count for the space at the end of the string:
>
> space: #" "
> parse " the radio " [any space "the" "radio" any space] ;or
>
> space: #" "
> parse " the radio" [any space "the" "radio" to end] ; or
>
> space: #" "
> parse " the radio" [thru "the" "radio" to end]
>
> but i think parse should ignore spaces in the beginning and in the end
> of the string, as it ignores them between the words. Or just use trim on
> your string:
>
> ->> parse trim " the radio " ["the" "radio"]
> == true
>
> Hope this helps,
>
> Regards,
>
> -pekr-
>
> >
> >
> > Thank you
> >
> > --
> > Luis Marzulli
> > e-mail: [EMAIL PROTECTED]
> > Caracas, VENEZUELA
> > ----------------------------------------------------------
> > Earn money when you or your friends are on the Web
> > click --> http://www.alladvantage.com/go.asp?refid=BXX890
>