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

Newbie Parse Problem!

 [1/3] from: garymiller::starband::net at: 3-Jul-2002 14:17


I have the following code fragment. All I get at the end is false. After reading the manual examples it seems as if I should at get 1, 2 and 3 printed. I'm not even getting 1! I'm obviously missing something. ================== UserInput: "hello there!" punctuation: charset [#"," #"." #"/" #"\" #"!"] parse UserInput [ to "hello" | "hi" | "howdy" {print 1} to "there" | punctuation {print 2} to punctuation {print 3} ] _____________________________________ Think you can't get high-speed Internet? Now you can! StarBand offers high-speed Internet via satellite. No phone lines needed. New lower prices. For all 50 U.S. States. See for yourself at: http://www.StarBand.com

 [2/3] from: greggirwin:mindspring at: 3-Jul-2002 14:21


Hi Gary, Try this: UserInput: "hello there!" punctuation: charset ",./\!" parse UserInput [ ["hello" | "hi" | "howdy"] (print 1) ["there" | punctuation] (print 2) [punctuation (print 3) | to end] ] There are many subtleties to PARSE, many of which you only learn about by trying things. It's amazingly powerful though, and worth the effort. BTW, welcome to REBOL! --Gregg

 [3/3] from: lmecir:mbox:vol:cz at: 3-Jul-2002 23:09


Hi Gary, <<Gary>> ... I have the following code fragment. All I get at the end is false. After reading the manual examples it seems as if I should at get 1, 2 and 3 printed. I'm not even getting 1! I'm obviously missing something. ================== UserInput: "hello there!" punctuation: charset [#"," #"." #"/" #"\" #"!"] parse UserInput [ to "hello" | "hi" | "howdy" {print 1} to "there" | punctuation {print 2} to punctuation {print 3} ] <</Gary>> if you write something like: do http://www.rebolforces.com/~ladislav/parseen.r parse/all UserInput reduce [ to-rule ["hello" | "hi" | "howdy"] first [(print 1)] to-rule ["there" | punctuation] first [(print 2)] to-rule [punctuation] first [(print 3)] ] , you will get the result: 1 2 3 == false Is that what you wanted? -L