I have written a csv decoder: //////////// // CSV reader
proc get_value(s:string, i:&int,res:&string) { var r = ""; proc add(j:int) { r += s.[j]; } n := len s; enum state_t = skip,collect,quote; fun eq(a:state_t, b:state_t)=> caseno a == caseno b; var state = skip; var j:int=n; forall j in *i upto n-1 do if s.[j] == char "," do break; elif s.[j] == char " " do if state == skip do continue; elif state == quote do add j; else state = skip; done; elif s.[j] == char '"' do if state == quote do state = skip; else state = quote; done; else add j; done; done; i <- j+1; res <- r; } inp := '1, 2.0 , "Hel lo" , joe'; var res = ""; var pos = 0; whilst pos < len inp do get_value (inp, &pos, &res); if len res >0 do println$ "res=" + res; done; done; println "done"; /////////////// Now, first issue to observe is that you cannot compare enums without writing a comparison routine. [Note the new syntax allowed for enums too, but enum s = { ... } still doesn't work, which is what I coded first, then had to look up the grammar :] The second issue is the horrible state/value comparisons. In the space test, I cannot write a match, because the continue will not work, since it would be inside a function. This suggests a procedural match would be useful: match c with | 1 => println "x"; println "y"; | 2 => {} endmatch; However to parse this compared with match c with | 1 => { p; } endmatch; is tricky: it requires examining one branch to see if the return type is void or some other value, and the parser cannot determine types. It can check for expressions vs statements however (felix has no expression-as-statement like C). Still, Dypgen should handle this easily. -- john skaller skal...@users.sourceforge.net ------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp as they present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language