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

Shutting off parse features

 [1/5] from: tbrownell:shaw:ca at: 8-Mar-2002 12:46


When parsing a string such as {Hello world, "this to" is an example;} parse will remove the comma, and the semi... and takes anything within quotes as a single value. Sometimes I just want to parse spaces so we get... ["Hello" "world," "this" "to" "is" "an" "example;"] Of course some rules could be created to do this, but it seems there should be an option to parse that "shuts off" the ,, ; and "" features... eg: parse/white TBrownell

 [2/5] from: gscottjones::mchsi::com at: 8-Mar-2002 15:43


From: "Terry Brownell"
> When parsing a string such as {Hello world, "this to" is an example;}
parse will remove the comma, and the semi... and takes anything within quotes as a single value.
> Sometimes I just want to parse spaces so we get... > ["Hello" "world," "this" "to" "is" "an" "example;"]
You make a good point, and as far as I can there is no easy way to do this without using a "rule". Here is a quick and dirty work-around, in case it proves useful for a specific problem: a: {Hello world, "this to" is an example;} parse/all trim/with a {"} " " ; yields ["Hello" "world," "this" "to" "is" "an" "example;"] --Scott Jones

 [3/5] from: greggirwin:mindspring at: 8-Mar-2002 15:46


Hi Terry, << When parsing a string such as {Hello world, "this to" is an example;} parse will remove the comma, and the semi... and takes anything within quotes as a single value. Sometimes I just want to parse spaces so we get... ["Hello" "world," "this" "to" "is" "an" "example;"] >> This gets you close:
>> parse/all {Hello world, "this to" is an example;} " "
== ["Hello" "world," "this to" "is" "an" "example;"] To ignore the quotes, I think you'll need a real rule-set. --Gregg

 [4/5] from: carl:cybercraft at: 9-Mar-2002 12:23


On 09-Mar-02, Terry Brownell wrote:
> When parsing a string such as {Hello world, "this to" is an > example;} parse will remove the comma, and the semi... and takes
<<quoted lines omitted: 4>>
> should be an option to parse that "shuts off" the ,, ; and "" > features... eg: parse/white
Well, the 'all refinement let's you parse everything except what you tell it not to parse. ie...
>> a: {Hello world, "this to" is an example;}
== {Hello world, "this to" is an example;}
>> parse/all a " "
== ["Hello" "world," "this to" "is" "an" "example;"] Though your "this to" becomes one string instead of two. Close to what you want though, and stripping out the speach-marks first would be one option. ie...
>> parse/all replace/all a "^"" "" " "
== ["Hello" "world," "this" "to" "is" "an" "example;"] gets your example right, at least. HTH. -- Carl Read

 [5/5] from: joel:neely:fedex at: 9-Mar-2002 10:11


Hi, Carl, Terry, and all A slightly more generic version... Carl Read wrote:
> On 09-Mar-02, Terry Brownell wrote: > > > When parsing a string such as {Hello world, "this to" is an > > example;} parse will remove the comma, and the semi... and takes > > anything within quotes as a single value. > > > Sometimes I just want to parse spaces so we get... > > ["Hello" "world," "this" "to" "is" "an" "example;"] >
...
> Well, the 'all refinement let's you parse everything except what you > tell it not to parse. ie... >
...
> Though your "this to" becomes one string instead of two. Close to > what you want though, and stripping out the speach-marks first would > be one option. ie... >
just-the-good-parts: func [ s [string!] /local result good-ones others fragment ][ good-ones: charset [#"A" - #"Z" #"a" - #"z" #"." #"," #";"] others: complement good-ones result: copy [] parse/all s [ any [ copy fragment some good-ones (append result fragment) | some others ] ] result ]
>> a: {Hello world, "this to" is an example;}
== {Hello world, "this to" is an example;}
>> just-the-good-parts a
== ["Hello" "world," "this" "to" "is" "an" "example;"] Suitable redefinitions of GOOD-ONES and OTHERS will let you keep or discard whatever characters you wish, of course. -jn- -- ; sub REBOL {}; sub head ($) {@_[0]} REBOL [] # despam: func [e] [replace replace/all e ":" "." "#" "@"] ; sub despam {my ($e) = @_; $e =~ tr/:#/.@/; return "\n$e"} print head reverse despam "moc:xedef#yleen:leoj" ;

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted