Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file table.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146moduleRow=structletmodule_errore=Error(`table_rowe)typeitem_type=[`type_int|`type_float|`type_string][@@derivingsexp]typet_type=item_typearray[@@derivingsexp]typeitem=[`intofint|`floatoffloat|`stringofstring][@@derivingsexp]typet=itemarray[@@derivingsexp]moduleTags=structtypet=[|`separatorofchar|`strict_aboutof[`row_length|`cell_type]|`formatofitem_typearray]list[@@derivingsexp]letseparatorstags=List.filter_maptags~f:(function|`separatorc->Somec|_->None)letstrict_row_lengthtags=List.existstags~f:(function`strict_about`row_length->true|_->false)letstrict_cell_typetags=List.existstags~f:(function`strict_about`cell_type->true|_->false)letformattags=List.find_maptags~f:(function`formatf->Somef|_->None)letdefault=[`separator'\t']letdefault_extensiontags=matchseparatorstagswith|'\t'::_->"tsv"|','::_->"csv"|_->"table"letto_stringt=sexp_of_tt|>Sexplib.Sexp.to_stringletof_strings=tryOk(Sexplib.Sexp.of_strings|>t_of_sexp)withe->module_error(`tags_of_stringe)endmoduleError=structtypeline_parsing=[`wrong_formatof[`column_number|`float_of_stringofstring|`int_of_stringofstring]*t_type*string][@@derivingsexp]typet=line_parsing[@@derivingsexp]endletof_line?(separators=[' ';'\t'])?(strict_row_length=false)?(strict_cell_type=false)?formatline=letl=(line:Line.t:>string)inletmoduleWith_exns=structexceptionInt_of_stringofstringexceptionFloat_of_stringofstringletints=tryInt.of_stringswith_->raise(Int_of_strings)letfloats=tryFloat.of_stringswith_->raise(Float_of_strings)letof_line~formatl=lettokens=String.split_on_chars~on:separatorsl|>List.filter~f:((<>)"")|>Array.of_listinbeginmatchformatwith|None->Ok(Array.maptokens~f:(funs->`strings))|Someformat->begintryifstrict_row_length&&Array.lengthformat>Array.lengthtokensthenError(`wrong_format(`column_number,format,l))elsebeginletrow=Array.mapitokens~f:(funitok->lettyp=ifstrict_cell_typethenformat.(i)else(tryformat.(i)with_->`type_string)inmatchtypwith|`type_int->`int(inttok)|`type_float->`float(floattok)|`type_string->`stringtok)inOkrowendwith|Invalid_argument_(* should be the array access *)->Error(`wrong_format(`column_number,format,l))|Int_of_strings->Error(`wrong_format(`int_of_strings,format,l))|Float_of_strings->Error(`wrong_format(`float_of_strings,format,l))endendendin(With_exns.of_line~formatl:(t,_)Result.t)letto_line~sept=letitem_to_string=function|`inti->Int.to_stringi|`floatf->sprintf"%g"f|`strings->sinLine.of_string_unsafe(String.concat_array~sep(Array.mapt~f:item_to_string))moduleTransform=structletline_to_item?(tags:Tags.t=Tags.default)()=letseparators=Tags.separatorstagsinletstrict_row_length=Tags.strict_row_lengthtagsinletstrict_cell_type=Tags.strict_cell_typetagsinletformat=Tags.formattagsinTfxm.on_output~f:beginfuns->of_line~separators~strict_row_length~strict_cell_type?format(s:Lines.item)|>beginfunction|Oko->Oko|Errore->Error(`table_row(e:Error.line_parsing))endend(Tfxm.identity())letitem_to_line?(tags:Tags.t=Tags.default)()=letsep=Tags.separatorstags|>List.hd|>Option.value~default:'\t'|>Char.to_stringinTfxm.on_output~f:(to_line~sep)(Tfxm.identity())endend