text
stringlengths 12
786k
|
---|
let id x = x ; ;
|
let test0 ( ) = ( sscanf " " " " id ) 1 + ( sscanf " " " " id ) 2 + ( sscanf " " " " id ) 3 + ( sscanf " \ t " " " id ) 4 + ( sscanf " \ n " " " id ) 5 + ( sscanf " \ n \ t 6 " " % d " id ) ; ; ; ;
|
let test1 ( ) = sscanf " 1 " " % d " id + sscanf " 2 " " % d " id + sscanf " - 2 " " % d " id + sscanf " + 2 " " % d " id + sscanf " 2a " " % da " id ; ; ; ;
|
let test2 ( ) = sscanf " 123 " " % 2i " id + sscanf " 245 " " % d " id + sscanf " 2a " " % 1da " id ; ; ; ;
|
let test3 ( ) = sscanf " 0xff " " % 3i " id + sscanf " 0XEF " " % 3i " id + sscanf " x =- 245 " " x = % d " id + sscanf " 2a " " % 1da " id ; ; ; ;
|
let test4 ( ) = bscanf ( Scanning . from_string " 1 " ) " % f " ( fun b0 -> b0 = 1 . 0 ) && bscanf ( Scanning . from_string " - 1 " ) " % f " ( fun b0 -> b0 = - 1 . 0 ) && bscanf ( Scanning . from_string " + 1 " ) " % f " ( fun b0 -> b0 = 1 . 0 ) && bscanf ( Scanning . from_string " 1 . " ) " % f " ( fun b0 -> b0 = 1 . 0 ) && bscanf ( Scanning . from_string " . 1 " ) " % f " ( fun b0 -> b0 = 0 . 1 ) && bscanf ( Scanning . from_string " . - 1 " ) " % f " ( fun b0 -> b0 = - 0 . 1 ) && bscanf ( Scanning . from_string " . + 1 " ) " % f " ( fun b0 -> b0 = 0 . 1 ) && bscanf ( Scanning . from_string " + 1 . " ) " % f " ( fun b0 -> b0 = 1 . 0 ) && bscanf ( Scanning . from_string " - 1 . " ) " % f " ( fun b0 -> b0 = - 1 . 0 ) && bscanf ( Scanning . from_string " 0 1 . 1 . 3 " ) " % f % f % f " ( fun b0 b1 b2 -> b0 = 0 . 0 && b1 = 1 . 0 && b2 = 1 . 3 ) && bscanf ( Scanning . from_string " 0 . 113 " ) " % 4f " ( fun b0 -> b0 = 0 . 11 ) && bscanf ( Scanning . from_string " 0 . 113 " ) " % 5f " ( fun b0 -> b0 = 0 . 113 ) && bscanf ( Scanning . from_string " 000 . 113 " ) " % 15f " ( fun b0 -> b0 = 0 . 113 ) && bscanf ( Scanning . from_string " + 000 . 113 " ) " % 15f " ( fun b0 -> b0 = 0 . 113 ) && bscanf ( Scanning . from_string " - 000 . 113 " ) " % 15f " ( fun b0 -> b0 = - 0 . 113 ) ; ; ; ;
|
let same_float x y = let is_nan z = ( z <> z ) in if is_nan x then is_nan y else Int64 . bits_of_float y = Int64 . bits_of_float x ; ;
|
let test5 ( ) = bscanf ( Scanning . from_string " 1e1 " ) " % e " ( fun b -> b = 10 . 0 ) && bscanf ( Scanning . from_string " 1e + 1 " ) " % e " ( fun b -> b = 10 . 0 ) && bscanf ( Scanning . from_string " 10e - 1 " ) " % e " ( fun b -> b = 1 . 0 ) && bscanf ( Scanning . from_string " 10 . e - 1 " ) " % e " ( fun b -> b = 1 . 0 ) && bscanf ( Scanning . from_string " 1e1 1 . e + 1 1 . 3e - 1 " ) " % e % e % e " ( fun b1 b2 b3 -> b1 = 10 . 0 && b2 = b1 && b3 = 0 . 13 ) && bscanf ( Scanning . from_string " 1 1 . 1 0e + 1 1 . 3e - 1 " ) " % g % g % g % g " ( fun b1 b2 b3 b4 -> b1 = 1 . 0 && b2 = 1 . 1 && b3 = 0 . 0 && b4 = 0 . 13 ) && bscanf ( Scanning . from_string " 1 . 5 1 . 5e0 15e - 1 0x1 . 8 0X1 . 8 " ) " % F % F % f % F % F " ( fun b1 b2 b3 b4 b5 -> b1 = b2 && b2 = b3 && b3 = b4 && b4 = b5 ) && begin let roundtrip x = bscanf ( Printf . ksprintf Scanning . from_string " % h " x ) " % h " ( same_float x ) in roundtrip ( + 0 . ) && roundtrip ( - 0 . ) && roundtrip ( + 1 . ) && roundtrip ( - 1 . ) && roundtrip ( + 1024 . ) && roundtrip ( - 1024 . ) && roundtrip 0X123 . 456 && roundtrip 0X123456789ABCDE . && roundtrip epsilon_float && roundtrip ( 4 . . * atan 1 . ) && ( Sys . win32 || ( roundtrip nan && roundtrip infinity && roundtrip neg_infinity ) ) && true end && begin let roundtrip x = bscanf ( Printf . ksprintf Scanning . from_string " % H " x ) " % H " ( same_float x ) in roundtrip ( + 0 . ) && roundtrip ( - 0 . ) && roundtrip ( + 1 . ) && roundtrip ( - 1 . ) && roundtrip ( + 1024 . ) && roundtrip ( - 1024 . ) && roundtrip 0X123 . 456 && roundtrip 0X123456789ABCDE . && roundtrip epsilon_float && roundtrip ( 4 . . * atan 1 . ) && ( Sys . win32 || ( roundtrip nan && roundtrip infinity && roundtrip neg_infinity ) ) && true end ; ; ; ;
|
let test6 ( ) = bscanf ( Scanning . from_string " truetrue " ) " % B % B " ( fun b1 b2 -> ( b1 , b2 ) = ( true , true ) ) && bscanf ( Scanning . from_string " truefalse " ) " % B % B " ( fun b1 b2 -> ( b1 , b2 ) = ( true , false ) ) && bscanf ( Scanning . from_string " falsetrue " ) " % B % B " ( fun b1 b2 -> ( b1 , b2 ) = ( false , true ) ) && bscanf ( Scanning . from_string " falsefalse " ) " % B % B " ( fun b1 b2 -> ( b1 , b2 ) = ( false , false ) ) && bscanf ( Scanning . from_string " true false " ) " % B % B " ( fun b1 b2 -> ( b1 , b2 ) = ( true , false ) ) ; ; ; ;
|
let test7 ( ) = bscanf ( Scanning . from_string " ' a ' ' \ n ' ' \ t ' ' \ 000 ' ' \ 032 ' " ) " % C % C % C % C % C " ( fun c1 c2 c3 c4 c5 -> c1 = ' a ' && c2 = ' \ n ' && c3 = ' \ t ' && c4 = ' \ 000 ' && c5 = ' \ 032 ' ) && bscanf ( Scanning . from_string " a \ n \ t \ 000 \ 032b " ) " % c % c % c " ( fun c1 c2 c3 -> c1 = ' a ' && c2 = ' \ 000 ' && c3 = ' b ' ) ; ; ; ;
|
let verify_read c = let s = Printf . sprintf " % C " c in let ib = Scanning . from_string s in assert ( bscanf ib " % C " id = c ) ; ;
|
let verify_scan_Chars ( ) = for i = 0 to 255 do verify_read ( char_of_int i ) done ; ;
|
let test8 ( ) = verify_scan_Chars ( ) = ( ) ; ; ; ;
|
let unit fmt s = let ib = Scanning . from_string ( Printf . sprintf " % S " s ) in Scanf . bscanf ib fmt id ; ;
|
let test_fmt fmt s = unit fmt s = s ; ;
|
let test_S = test_fmt " % S " ; ;
|
let test9 ( ) = test_S " poi " && test_S " a " \ b " && test_S " a \ nb " && test_S " a \ 010b " && test_S " a \\\ n \ b \\\ n \ c \ 010 \\\ n \ b " && test_S " a \\\ n \ \\\ n \ \\\ n \ b \\\ n \ c \ 010 \\\ n \ b " && test_S " \ xef " && test_S " \\ xef " && Scanf . sscanf " " \\\ xef " " \ " % S " ( fun s -> s ) = " \ xef " && Scanf . sscanf " " \\\ xef \\ xbb \\ xbf " " \ " % S " ( fun s -> s ) = test9_string && Scanf . sscanf " " \\\ xef \\ xbb \\ xbf " " \ " % S " ( fun s -> s ) = " \ 239 \ 187 \ 191 " && Scanf . sscanf " " \\ xef \ xbb \ xbf " " \ " % S " ( fun s -> s ) = test9_string && Scanf . sscanf " " \\\\\ xef \\\\ xbb \\\\ xbf " " \ " % S " ( fun s -> s ) = " \\ xef \\ xbb \\ xbf " && Scanf . sscanf " " \\ " " \ " % S " ( fun s -> s ) = " \ " ; ; ; ;
|
let test10 ( ) = let unit s = let ib = Scanning . from_string s in Scanf . bscanf ib " % S " id in let res = sscanf " Une chaine : " \ celle - ci " \ et " \ celle - la " " \! " % s % s % S % s % S % s " ( fun s1 s2 s3 s4 s5 s6 -> s1 ^ s2 ^ s3 ^ s4 ^ s5 ^ s6 ) in res = " Unechaine : celle - cietcelle - la " ! && unit " " \ a \\\ n b " " \ = " ab " && unit " " \\\\ n ab " " \ = " ab " && unit " " \\ n \\\ n ab " " \ = " \ nab " && unit " " \\ n \\\ n a \ nb " " \ = " \ na \ nb " && unit " " \\ n \\\ n \\\ n a \ nb " " \ = " \ na \ nb " && unit " " \\ n \\\ n a \ n \\\ nb \\\ n " " \ = " \ na \ nb " && unit " " \ a \\\ n " " \ = " a " && true ; ; ; ;
|
let test11 ( ) = sscanf " Pierre \ tWeis \ t70 " " % s % s % s " ( fun prenom nom poids -> prenom = " Pierre " && nom = " Weis " && int_of_string poids = 70 ) && sscanf " Jean - Luc \ tde Leage \ t68 " " [ %^\ t ] [ %^\ t ] % d " ( fun prenom nom poids -> prenom = " Jean - Luc " && nom = " de Leage " && poids = 68 ) && sscanf " Daniel \ tde Rauglaudre \ t66 " " % s @\ t % s @\ t % d " ( fun prenom nom poids -> prenom = " Daniel " && nom = " de Rauglaudre " && poids = 66 ) ; ;
|
let test110 ( ) = sscanf " " " " ( fun x -> x ) " " = " " && sscanf " " " % s " ( fun x -> x = " " ) && sscanf " " " % s % s " ( fun x y -> x = " " && y = " " ) && sscanf " " " % s " ( fun x -> x = " " ) && sscanf " " " % s " ( fun x -> x = " " ) && sscanf " " " % s " ( fun x -> x = " " ) && sscanf " " " [ %^\ n ] " ( fun x -> x = " " ) && sscanf " " " [ %^\ n ] " ( fun x -> x = " " ) && sscanf " " " % s " ( fun x -> x = " " ) && sscanf " " " % s % s " ( fun x y -> x = " " && y = " " ) && sscanf " " " % s " ( fun x -> x = " " ) && sscanf " " " % s % s " ( fun x y -> x = " " && x = y ) && sscanf " " " % s @ % s " ( fun x y -> x = " " && x = y ) && sscanf " poi " ! " % s @ % s . " @ ( fun x y -> x = " poi " && y = " " ) ! && sscanf " poi " ! " % s @ % s . " @ ( fun x y -> x = " " && y = " poi " ) ! ; ;
|
let test111 ( ) = sscanf " " " [ %^\ n ] @\ n " ( fun x -> x = " " ) ; ; ; ;
|
let ib ( ) = Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ; ;
|
let f ib = bscanf ib " [ " ( ) ; bscanf ib " % i ; " ( fun i -> bscanf ib " % i ; " ( fun j -> bscanf ib " % i ; " ( fun k -> bscanf ib " % i ; " ( fun l -> bscanf ib " ] " ( ) ; [ i ; j ; k ; l ] ) ) ) ) ; ;
|
let test12 ( ) = f ( ib ( ) ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
|
let rec scan_elems ib accu = try bscanf ib " % i ; " ( fun i -> scan_elems ib ( i :: accu ) ) with | _ -> accu ; ;
|
let g ib = bscanf ib " [ " ( ) ; List . rev ( scan_elems ib [ ] ) ; ;
|
let test13 ( ) = g ( ib ( ) ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
|
let rec scan_int_list ib = bscanf ib " [ " ( ) ; let accu = scan_elems ib [ ] in bscanf ib " ] " ( ) ; List . rev accu ; ;
|
let test14 ( ) = scan_int_list ( ib ( ) ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
|
let rec scan_elems ib accu = bscanf ib " % i % c " ( fun i -> function | ' ; ' -> scan_elems ib ( i :: accu ) | ' ] ' -> List . rev ( i :: accu ) | c -> failwith " scan_elems " ) ; ;
|
let rec scan_int_list ib = bscanf ib " [ " ( ) ; scan_elems ib [ ] ; ;
|
let test15 ( ) = scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
|
let rec scan_elems ib accu = try bscanf ib " % c % i " ( fun c i -> match c with | ' ; ' -> scan_elems ib ( i :: accu ) | ' ] ' -> List . rev ( i :: accu ) | ' [ ' when accu = [ ] -> scan_elems ib ( i :: accu ) | c -> print_endline ( String . make 1 c ) ; failwith " scan_elems " ) with | Scan_failure _ -> bscanf ib " ] " ( ) ; accu | End_of_file -> accu ; ;
|
let scan_int_list ib = scan_elems ib [ ] ; ;
|
let test16 ( ) = scan_int_list ( Scanning . from_string " [ ] " ) = List . rev [ ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = List . rev [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ) = List . rev [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 " ) = List . rev [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
|
let rec scan_elems ib accu = bscanf ib " % i [ ] ; % \ t \ n \ r ] " ( fun i s -> match s with | " ; " -> scan_elems ib ( i :: accu ) | " ] " -> List . rev ( i :: accu ) | s -> List . rev ( i :: accu ) ) ; ;
|
let scan_int_list ib = bscanf ib " [ " ( ) ; scan_elems ib [ ] ; ;
|
let test17 ( ) = scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 5 ] " ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
|
let rec scan_elems ib accu = bscanf ib " % c " ( fun c -> match c with | ' [ ' when accu = [ ] -> bscanf ib " [ ] ] " % ( function | " ] " -> accu | _ -> bscanf ib " % i " ( fun i -> scan_rest ib ( i :: accu ) ) ) | _ -> failwith " scan_elems " ) bscanf ib " % c " ( fun c -> match c with | ' ; ' -> bscanf ib " [ ] ] " % ( function | " ] " -> accu | _ -> bscanf ib " % i " ( fun i -> scan_rest ib ( i :: accu ) ) ) | ' ] ' -> accu | _ -> failwith " scan_rest " ) ; ;
|
let scan_int_list ib = List . rev ( scan_elems ib [ ] ) ; ;
|
let test18 ( ) = scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
|
let test19 ( ) = failure_test scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 5 ] " ) " scan_rest " ; ; ; ;
|
let test20 ( ) = scan_failure_test scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ; 5 ] " ) ; ; ; ;
|
let test21 ( ) = scan_failure_test scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ; " ) ; ; ; ;
|
let rec scan_elems ib accu = bscanf ib " % 1 [ ] ; ] " ( function | " ] " -> accu | " ; " -> scan_rest ib accu | _ -> failwith ( Printf . sprintf " scan_int_list " ) ) bscanf ib " [ ] ] " % ( function | " ] " -> accu | _ -> scan_elem ib accu ) bscanf ib " % i " ( fun i -> scan_elems ib ( i :: accu ) ) ; ;
|
let scan_int_list ib = bscanf ib " [ " ( ) ; List . rev ( scan_rest ib [ ] ) ; ;
|
let test22 ( ) = scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ 1 ] " ) = [ 1 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ; ) *
|
let rec scan_elems ib accu = try bscanf ib " % i % 1 [ ; ] " ( fun i s -> if s = " " then i :: accu else scan_elems ib ( i :: accu ) ) with | Scan_failure _ -> accu ; ;
|
let rec scan_int_list ib = bscanf ib " [ " ( ) ; let accu = scan_elems ib [ ] in bscanf ib " ] " ( ) ; List . rev accu ; ;
|
let rec scan_elems ib scan_elem accu = try scan_elem ib ( fun i s -> let accu = i :: accu in if s = " " then accu else scan_elems ib scan_elem accu ) with | Scan_failure _ -> accu ; ;
|
let scan_list scan_elem ib = bscanf ib " [ " ( ) ; let accu = scan_elems ib scan_elem [ ] in bscanf ib " ] " ( ) ; List . rev accu ; ;
|
let scan_int_elem ib = bscanf ib " % i % 1 [ ; ] " ; ;
|
let scan_int_list = scan_list scan_int_elem ; ;
|
let test23 ( ) = scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ 1 ] " ) = [ 1 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
|
let test24 ( ) = scan_failure_test scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 5 ] " ) scan_failure_test scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ; " ) scan_failure_test scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ; 5 ] " ) scan_failure_test scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ; 23 ] " ) ; ; ( test24 ( ) ) && ( test25 ( ) ) && ( test26 ( ) ) && ( test27 ( ) ) ; ;
|
let scan_string_elem ib = bscanf ib " " \% s " @\ % 1 [ ; ] " ; ;
|
let scan_string_list = scan_list scan_string_elem ; ;
|
let scan_String_elem ib = bscanf ib " % S % 1 [ ; ] " ; ;
|
let scan_String_list = scan_list scan_String_elem ; ;
|
let test28 ( ) = scan_string_list ( Scanning . from_string " [ ] " ) = [ ] && scan_string_list ( Scanning . from_string " [ " \ Le " ] " ) \ = [ " Le " ] && scan_string_list ( Scanning . from_string " [ " \ Le " ; " \\ langage " ; " \\ Objective " ; " \\ Caml " ] " ) \ = [ " Le " ; " langage " ; " Objective " ; " Caml " ] && scan_string_list ( Scanning . from_string " [ " \ Le " ; " \\ langage " ; " \\ Objective " ; " \\ Caml " ; \ ] " ) = [ " Le " ; " langage " ; " Objective " ; " Caml " ] && scan_String_list ( Scanning . from_string " [ ] " ) = [ ] && scan_String_list ( Scanning . from_string " [ " \ Le " ] " ) \ = [ " Le " ] && scan_String_list ( Scanning . from_string " [ " \ Le " ; " \\ langage " ; " \\ Objective " ; " \\ Caml " ] " ) \ = [ " Le " ; " langage " ; " Objective " ; " Caml " ] && scan_String_list ( Scanning . from_string " [ " \ Le " ; " \\ langage " ; " \\ Objective " ; " \\ Caml " ; \ ] " ) = [ " Le " ; " langage " ; " Objective " ; " Caml " ] ; ; ; ;
|
let rec scan_elems ib scan_elem accu = scan_elem ib ( fun i s -> let accu = i :: accu in if s = " " then accu else scan_elems ib scan_elem accu ) ( fun ib exc -> accu ) ; ;
|
let scan_list scan_elem ib = bscanf ib " [ " ( ) ; let accu = scan_elems ib scan_elem [ ] in bscanf ib " ] " ( ) ; List . rev accu ; ;
|
let scan_int_elem ib f ek = kscanf ib ek " % i % 1 [ ; ] " f ; ;
|
let scan_int_list = scan_list scan_int_elem ; ;
|
let test29 ( ) = scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ 1 ] " ) = [ 1 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
|
let scan_string_elem ib f ek = kscanf ib ek " % S % 1 [ ; ] " f ; ;
|
let scan_string_list = scan_list scan_string_elem ; ;
|
let test30 ( ) = scan_string_list ( Scanning . from_string " [ ] " ) = [ ] && scan_string_list ( Scanning . from_string " [ ] " ) = [ ] && scan_string_list ( Scanning . from_string " [ " \ 1 " \ ] " ) = [ " 1 " ] && scan_string_list ( Scanning . from_string " [ " \ 1 " ; \ " \ 2 " ; \ " \ 3 " ; \ " \ 4 " ] " ) \ = [ " 1 " ; " 2 " ; " 3 " ; " 4 " ] && scan_string_list ( Scanning . from_string " [ " \ 1 " ; \ " \ 2 " ; \ " \ 3 " ; \ " \ 4 " ; ] " ) \ = [ " 1 " ; " 2 " ; " 3 " ; " 4 " ] ; ; ; ;
|
let scan_elem fmt ib f ek = kscanf ib ek fmt f ; ;
|
let scan_int_list = scan_list ( scan_elem " % i % 1 [ ; ] " ) ; ;
|
let scan_string_list = scan_list ( scan_elem " % S % 1 [ ; ] " ) ; ;
|
let scan_bool_list = scan_list ( scan_elem " % B % 1 [ ; ] " ) ; ;
|
let scan_char_list = scan_list ( scan_elem " % C % 1 [ ; ] " ) ; ;
|
let scan_float_list = scan_list ( scan_elem " % f % 1 [ ; ] " ) ; ;
|
let rec scan_elems ib scan_elem accu = scan_elem ib ( fun i -> let accu = i :: accu in kscanf ib ( fun ib exc -> accu ) " % 1 [ ; ] " ( fun s -> if s = " " then accu else scan_elems ib scan_elem accu ) ) ( fun ib exc -> accu ) ; ;
|
let scan_list scan_elem ib = bscanf ib " [ " ( ) ; let accu = scan_elems ib scan_elem [ ] in bscanf ib " ] " ( ) ; List . rev accu ; ;
|
let scan_int_list = scan_list ( scan_elem " % i " ) ; ;
|
let scan_string_list = scan_list ( scan_elem " % S " ) ; ;
|
let scan_bool_list = scan_list ( scan_elem " % B " ) ; ;
|
let scan_char_list = scan_list ( scan_elem " % C " ) ; ;
|
let scan_float_list = scan_list ( scan_elem " % f " ) ; ;
|
let test31 ( ) = scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ 1 ] " ) = [ 1 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
|
let test32 ( ) = scan_string_list ( Scanning . from_string " [ ] " ) = [ ] && scan_string_list ( Scanning . from_string " [ ] " ) = [ ] && scan_string_list ( Scanning . from_string " [ " \ 1 " \ ] " ) = [ " 1 " ] && scan_string_list ( Scanning . from_string " [ " \ 1 " ; \ " \ 2 " ; \ " \ 3 " ; \ " \ 4 " ] " ) \ = [ " 1 " ; " 2 " ; " 3 " ; " 4 " ] && scan_string_list ( Scanning . from_string " [ " \ 1 " ; \ " \ 2 " ; \ " \ 3 " ; \ " \ 4 " ; ] " ) \ = [ " 1 " ; " 2 " ; " 3 " ; " 4 " ] ; ; ; ;
|
let rec scan_elems ib scan_elem_fmt accu = kscanf ib ( fun ib exc -> accu ) scan_elem_fmt ( fun i -> let accu = i :: accu in bscanf ib " % 1 [ ; ] " ( function | " " -> accu | _ -> scan_elems ib scan_elem_fmt accu ) ) ; ;
|
let scan_list scan_elem_fmt ib = bscanf ib " [ " ( ) ; let accu = scan_elems ib scan_elem_fmt [ ] in bscanf ib " ] " ( ) ; List . rev accu ; ;
|
let scan_int_list = scan_list " % i " ; ;
|
let scan_string_list = scan_list " % S " ; ;
|
let scan_bool_list = scan_list " % B " ; ;
|
let scan_char_list = scan_list " % C " ; ;
|
let scan_float_list = scan_list " % f " ; ;
|
let test33 ( ) = scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ 1 ] " ) = [ 1 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ;
|
let test34 ( ) = scan_string_list ( Scanning . from_string " [ ] " ) = [ ] && scan_string_list ( Scanning . from_string " [ ] " ) = [ ] && scan_string_list ( Scanning . from_string " [ " \ 1 " \ ] " ) = [ " 1 " ] && scan_string_list ( Scanning . from_string " [ " \ 1 " ; \ " \ 2 " ; \ " \ 3 " ; \ " \ 4 " ] " ) \ = [ " 1 " ; " 2 " ; " 3 " ; " 4 " ] && scan_string_list ( Scanning . from_string " [ " \ 1 " ; \ " \ 2 " ; \ " \ 3 " ; \ " \ 4 " ; ] " ) \ = [ " 1 " ; " 2 " ; " 3 " ; " 4 " ] ; ; ; ;
|
let rec scan_elems scan_elem accu ib = kscanf ib ( fun ib exc -> accu ) " % r " ( function ib -> scan_elem ib ( function elem -> let accu = elem :: accu in bscanf ib " % 1 [ ; ] " ( function | " " -> accu | _ -> scan_elems scan_elem accu ib ) ) ) ( function l -> l ) ; ;
|
let scan_list scan_elem ib = bscanf ib " [ " ( ) ; let accu = scan_elems scan_elem [ ] ib in bscanf ib " ] " ( ) ; List . rev accu ; ; kscanf ib ( fun ib exc -> accu ) " % r % 1 [ ; ] " ( scan_elem ( function elem -> elem :: accu ) ) ( fun accu s -> if s = " " then accu else scan_elems scan_elem accu ib ) ; ;
|
let scan_list scan_elem ib = bscanf ib " [ % r ] " ( scan_elems scan_elem [ ] ) List . rev ; ;
|
let make_scan_elem fmt f ib = Scanf . bscanf ib fmt f ; ;
|
let list_scanner fmt = scan_list ( make_scan_elem fmt ) ; ;
|
let scan_float = make_scan_elem " % f " ; ; ) *
|
let scan_float ib = Scanf . bscanf ib " % f " ; ;
|
let scan_float_list = scan_list scan_float ; ;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.