Sml parsing a csv file? -



Sml parsing a csv file? -

this question has reply here:

output truncated #-signs in repl 1 reply

these functions have defined (the other functions used within tested , work fine):

qstring : accepts string not contain double quote character (").

val qstring : string parser = (many (sat (fn c => not (c = #"\"")))) >>= (fn cs => homecoming (string.implode cs))

sepby : parser takes parser takes 2 parsers inputs; first 1 matches separator, , sec 1 matches content.

val sepby1 = fn s => fn p => p >>= (fn v1 => many (s >>= (fn _ => p >>= (fn v2 => homecoming v2))) >>= (fn v2 => homecoming (v1::v2))) val sepby = fn s => fn p => (sepby1 s p) +++ (return []) val csvline : record parser = sepby1 (ch #",") field >>= (fn l => newline >>= (fn _ => homecoming l)) val csvfile : csvfile parser = many csvline

input example:

val csvex = "\"john smith\",72,1782,\"colon, cristobal\"\n198,2,3,4,5,64434,\"two\"\n"

i # in place of strings should parsed. hints?

- parse csvfile csvex; val = ([[string #,number #,number #,string #], [number #,number #,number #,number #,number #,number #, string #]],"") : (csvfile * string) alternative

i suppose using sml/nj here. limit of nj's pretty printer. setting

control.print.printdepth := 20 (* or whatever *)

should lift it.

parsing sml

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -