Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Even more? parse

From: tomc:darkwing:uoregon at: 29-Jul-2003 17:02

parse has different modes depending on its arguments when both arguments are string! the effect is to return a block! with the first string split by the chars of the second string. the typical use ie to turn a string into a block of strings
>> parse string none
== ["this" "is" "a" "long" "string"]
>> parse string "s"
==["thi" "i" "a" "long" "" "tring"] broken up by whitespace and the char! s the /all refinement makes whitespace significant
>> block: parse/all s "s"
== ["thi" " i" " a long " "tring"]
>> mask: unique "thisisalongstring"
== "thisalongr" delimiters are not included in the output
>> parse string mask
== ["" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""] perhaps the main way parse is used is with a string and a block of rules in this mode parse returns true or false depending on whether the rules were sufficent to get you to the end of the string.
>> parse s [to "long" "long" to end]
== true
>> cs: charset mask
== make bitset! #{ 00000000000000000000000082D31C0000000000000000000000000000000000 }
>> parse string [some cs]
== true within the rules block you use parens to do stuff in rebol instead of in parse ... words heve differnt meanings within the .. dialect of parse
>> parse s [to "long" (print "hello") "long" to end]
hello == true result: copy "" parse string [ copy token to "long" (append result token) "long" copy token to end (append result token) ] == true
>> result
== "this is a string" out of time... hope that helps On Tue, 29 Jul 2003, Rebolinth wrote: