text stringlengths 0 601k |
|---|
let decodes_non_null_scalars ( ) = test_exp ( { | { " variousScalars " : { " nullableString " : " a nullable string " , " string " : " a string " , " nullableInt " : 456 , " int " : 123 , " nullableFloat " : 678 . 5 , " float " : 1234 . 5 , " nullableBoolean " : false , " boolean " : true , " nullableID " : " a nullabl... |
let decodes_null_scalars ( ) = test_exp ( { | { " variousScalars " : { " nullableString " : null , " string " : " a string " , " nullableInt " : null , " int " : 123 , " nullableFloat " : null , " float " : 1234 . 5 , " nullableBoolean " : null , " boolean " : true , " nullableID " : null , " id " : " an ID " } } } | |... |
let decodes_omitted_scalars ( ) = test_exp ( { | { " variousScalars " : { " string " : " a string " , " int " : 123 , " float " : 1234 . 5 , " boolean " : true , " id " : " an ID " } } } | |> Json . Read . from_string |> MyQuery . unsafe_fromJson |> MyQuery . parse ) { variousScalars = { nullableString = None ; string ... |
let tests = [ ( " Decodes non - null scalars " , decodes_non_null_scalars ) ; ( " Decodes null scalars " , decodes_null_scalars ) ; ( " Decodes omitted scalars " , decodes_omitted_scalars ) ; ] |
module MyQuery = [ % graphql { | query ( $ nullableString : String , $ string : String , ! $ nullableInt : Int , $ int : Int , ! $ nullableFloat : Float , $ float : Float , ! $ nullableBoolean : Boolean , $ boolean : Boolean , ! $ nullableID : ID , $ id : ID , ! ) { scalarsInput ( arg : { nullableString : $ nullableStr... |
let allows_you_to_omit_nullable_arguments ( ) = test_json_ ( MyQuery . makeVariables ~ string " : a string " ~ int : 123 ~ float : 1234 . 5 ~ boolean : true ~ id " : an ID " ( ) |> MyQuery . serializeVariables |> MyQuery . variablesToJson ) ( Json . Read . from_string { | { " nullableString " : null , " string " : " a ... |
let includes_non_nulled_arguments ( ) = test_json_ ( MyQuery . makeVariables ~ nullableString " : a nullable string " ~ string " : a string " ~ nullableInt : 456 ~ int : 123 ~ nullableFloat : 567 . 5 ~ float : 1234 . 5 ~ nullableBoolean : false ~ boolean : true ~ nullableID " : a nullable ID " ~ id " : an ID " ( ) |> M... |
let tests = [ ( " Allows you to omit nullable arguments " , allows_you_to_omit_nullable_arguments ) ; ( " Includes non - nulled arguments " , includes_non_nulled_arguments ) ; ] |
let to_field_checked ' ( type f ) f ( ? num_bits = num_bits ) num_bits ( module Impl : Snarky_backendless . Snark_intf . Run with type field = f ) f { SC . inner = ( scalar : Impl . Field . t ) t } = let open Impl in let neg_one = Field . Constant ( . negate one ) one in let a_func = function | 0 -> Field . Constant . ... |
let to_field_checked ( type f ) f ? num_bits ( module Impl : Snarky_backendless . Snark_intf . Run with type field = f ) f ~ endo ( { SC . inner = ( scalar : Impl . Field . t ) t } as s ) s = let open Impl in let a , b , n = to_field_checked ' ? num_bits ( module Impl ) Impl s in Field . Assert . equal n scalar ; Field... |
let to_field_constant ( type f ) f ~ endo ( module F : Plonk_checks . Field_intf with type t = f ) f { SC . inner = c } = let bits = Array . of_list ( Challenge . Constant . to_bits c ) c in let a = ref ( F . of_int 2 ) 2 in let b = ref ( F . of_int 2 ) 2 in let one = F . of_int 1 in let neg_one = F ( . of_int 0 - one ... |
let test ( type f ) f ( module Impl : Snarky_backendless . Snark_intf . Run with type field = f ) f ( ~ endo : f ) f = let open Impl in let module T = Internal_Basic in let n = 128 in Quickcheck . test ~ trials : 10 ( Quickcheck . Generator . list_with_length n Bool . quickcheck_generator ) quickcheck_generator ~ f ( :... |
module Make ( Impl : Snarky_backendless . Snark_intf . Run ) Run ( G : Intf . Group ( GroupImpl ) GroupImpl . S with type t = Impl . Field . t * Impl . Field . t ) t ( Challenge : Challenge . S with module Impl := Impl ) Impl ( Endo : sig val base : Impl . Field . Constant . t val scalar : G . Constant . Scalar . t end... |
type ( ' a , ' b , ' c , ' d , ' e , ' f ) format6 = ( ' a , ' b , ' c , ' d , ' e , ' f ) Stdlib . format6 |
module type SCANNING = sig type in_channel type scanbuf = in_channel type file_name = string val stdin : in_channel val stdib : in_channel val next_char : scanbuf -> char val invalidate_current_char : scanbuf -> unit val peek_char : scanbuf -> char val checked_peek_char : scanbuf -> char val store_char : int -> scanbuf... |
module Scanning : SCANNING = struct type file_name = string type in_channel_name = | From_channel of Stdlib . in_channel | From_file of file_name * Stdlib . in_channel | From_function | From_string type in_channel = { mutable ic_eof : bool ; mutable ic_current_char : char ; mutable ic_current_char_is_valid : bool ; mut... |
type ( ' a , ' b , ' c , ' d ) scanner = ( ' a , Scanning . in_channel , ' b , ' c , ' a -> ' d , ' d ) format6 -> ' c |
let bad_input s = raise ( Scan_failure s ) |
let bad_input_escape c = bad_input ( Printf . sprintf " illegal escape character % C " c ) |
let bad_token_length message = bad_input ( Printf . sprintf " scanning of % s failed : \ the specified length was too short for token " message ) |
let bad_end_of_input message = bad_input ( Printf . sprintf " scanning of % s failed : \ premature end of file occurred before end of token " message ) |
let bad_float ( ) = bad_input " no dot or exponent part found in float token " |
let bad_hex_float ( ) = bad_input " not a valid float in hexadecimal notation " |
let character_mismatch_err c ci = Printf . sprintf " looking for % C , found % C " c ci |
let character_mismatch c ci = bad_input ( character_mismatch_err c ci ) |
let rec skip_whites ib = let c = Scanning . peek_char ib in if not ( Scanning . eof ib ) then begin match c with | ' ' | ' \ t ' | ' \ n ' | ' \ r ' -> Scanning . invalidate_current_char ib ; skip_whites ib | _ -> ( ) end |
let rec check_char ib c = match c with | ' ' -> skip_whites ib | ' \ n ' -> check_newline ib | c -> check_this_char ib c let ci = Scanning . checked_peek_char ib in if ci = c then Scanning . invalidate_current_char ib else character_mismatch c ci let ci = Scanning . checked_peek_char ib in match ci with | ' \ n ' -> Sc... |
let token_char ib = ( Scanning . token ib ) . [ 0 ] |
let token_bool ib = match Scanning . token ib with | " true " -> true | " false " -> false | s -> bad_input ( Printf . sprintf " invalid boolean ' % s ' " s ) |
type integer_conversion = | B_conversion | D_conversion | I_conversion | O_conversion | U_conversion | X_conversion |
let integer_conversion_of_char = function | ' b ' -> B_conversion | ' d ' -> D_conversion | ' i ' -> I_conversion | ' o ' -> O_conversion | ' u ' -> U_conversion | ' x ' | ' X ' -> X_conversion | _ -> assert false |
let token_int_literal conv ib = let tok = match conv with | D_conversion | I_conversion -> Scanning . token ib | U_conversion -> " 0u " ^ Scanning . token ib | O_conversion -> " 0o " ^ Scanning . token ib | X_conversion -> " 0x " ^ Scanning . token ib | B_conversion -> " 0b " ^ Scanning . token ib in let l = String . l... |
let token_int conv ib = int_of_string ( token_int_literal conv ib ) |
let token_float ib = float_of_string ( Scanning . token ib ) = " caml_nativeint_of_string " = " caml_int32_of_string " = " caml_int64_of_string " |
let token_nativeint conv ib = nativeint_of_string ( token_int_literal conv ib ) |
let token_int32 conv ib = int32_of_string ( token_int_literal conv ib ) |
let token_int64 conv ib = int64_of_string ( token_int_literal conv ib ) |
let rec scan_decimal_digit_star width ib = if width = 0 then width else let c = Scanning . peek_char ib in if Scanning . eof ib then width else match c with | ' 0 ' . . ' 9 ' as c -> let width = Scanning . store_char width ib c in scan_decimal_digit_star width ib | ' _ ' -> let width = Scanning . ignore_char width ib i... |
let scan_decimal_digit_plus width ib = if width = 0 then bad_token_length " decimal digits " else let c = Scanning . checked_peek_char ib in match c with | ' 0 ' . . ' 9 ' -> let width = Scanning . store_char width ib c in scan_decimal_digit_star width ib | c -> bad_input ( Printf . sprintf " character % C is not a dec... |
let scan_digit_star digitp width ib = let rec scan_digits width ib = if width = 0 then width else let c = Scanning . peek_char ib in if Scanning . eof ib then width else match c with | c when digitp c -> let width = Scanning . store_char width ib c in scan_digits width ib | ' _ ' -> let width = Scanning . ignore_char w... |
let scan_digit_plus basis digitp width ib = if width = 0 then bad_token_length " digits " else let c = Scanning . checked_peek_char ib in if digitp c then let width = Scanning . store_char width ib c in scan_digit_star digitp width ib else bad_input ( Printf . sprintf " character % C is not a valid % s digit " c basis ... |
let is_binary_digit = function | ' 0 ' . . ' 1 ' -> true | _ -> false |
let scan_binary_int = scan_digit_plus " binary " is_binary_digit |
let is_octal_digit = function | ' 0 ' . . ' 7 ' -> true | _ -> false |
let scan_octal_int = scan_digit_plus " octal " is_octal_digit |
let is_hexa_digit = function | ' 0 ' . . ' 9 ' | ' a ' . . ' f ' | ' A ' . . ' F ' -> true | _ -> false |
let scan_hexadecimal_int = scan_digit_plus " hexadecimal " is_hexa_digit |
let scan_sign width ib = let c = Scanning . checked_peek_char ib in match c with | ' ' + -> Scanning . store_char width ib c | ' ' - -> Scanning . store_char width ib c | _ -> width |
let scan_optionally_signed_decimal_int width ib = let width = scan_sign width ib in scan_unsigned_decimal_int width ib |
let scan_unsigned_int width ib = match Scanning . checked_peek_char ib with | ' 0 ' as c -> let width = Scanning . store_char width ib c in if width = 0 then width else let c = Scanning . peek_char ib in if Scanning . eof ib then width else begin match c with | ' x ' | ' X ' -> scan_hexadecimal_int ( Scanning . store_c... |
let scan_optionally_signed_int width ib = let width = scan_sign width ib in scan_unsigned_int width ib |
let scan_int_conversion conv width ib = match conv with | B_conversion -> scan_binary_int width ib | D_conversion -> scan_optionally_signed_decimal_int width ib | I_conversion -> scan_optionally_signed_int width ib | O_conversion -> scan_octal_int width ib | U_conversion -> scan_unsigned_decimal_int width ib | X_conver... |
let scan_fractional_part width ib = if width = 0 then width else let c = Scanning . peek_char ib in if Scanning . eof ib then width else match c with | ' 0 ' . . ' 9 ' as c -> scan_decimal_digit_star ( Scanning . store_char width ib c ) ib | _ -> width |
let scan_exponent_part width ib = if width = 0 then width else let c = Scanning . peek_char ib in if Scanning . eof ib then width else match c with | ' e ' | ' E ' as c -> scan_optionally_signed_decimal_int ( Scanning . store_char width ib c ) ib | _ -> width |
let scan_integer_part width ib = let width = scan_sign width ib in scan_decimal_digit_star width ib |
let scan_float width precision ib = let width = scan_integer_part width ib in if width = 0 then width , precision else let c = Scanning . peek_char ib in if Scanning . eof ib then width , precision else match c with | ' . ' -> let width = Scanning . store_char width ib c in let precision = min width precision in let wi... |
let check_case_insensitive_string width ib error str = let lowercase c = match c with | ' A ' . . ' Z ' -> char_of_int ( int_of_char c - int_of_char ' A ' + int_of_char ' a ' ) | _ -> c in let len = String . length str in let width = ref width in for i = 0 to len - 1 do let c = Scanning . peek_char ib in if lowercase c... |
let scan_hex_float width precision ib = if width = 0 || Scanning . end_of_input ib then bad_hex_float ( ) ; let width = scan_sign width ib in if width = 0 || Scanning . end_of_input ib then bad_hex_float ( ) ; match Scanning . peek_char ib with | ' 0 ' as c -> ( let width = Scanning . store_char width ib c in if width ... |
let scan_caml_float_rest width precision ib = if width = 0 || Scanning . end_of_input ib then bad_float ( ) ; let width = scan_decimal_digit_star width ib in if width = 0 || Scanning . end_of_input ib then bad_float ( ) ; let c = Scanning . peek_char ib in match c with | ' . ' -> let width = Scanning . store_char width... |
let scan_caml_float width precision ib = if width = 0 || Scanning . end_of_input ib then bad_float ( ) ; let width = scan_sign width ib in if width = 0 || Scanning . end_of_input ib then bad_float ( ) ; match Scanning . peek_char ib with | ' 0 ' as c -> ( let width = Scanning . store_char width ib c in if width = 0 || ... |
let scan_string stp width ib = let rec loop width = if width = 0 then width else let c = Scanning . peek_char ib in if Scanning . eof ib then width else match stp with | Some c ' when c = c ' -> Scanning . skip_char width ib | Some _ -> loop ( Scanning . store_char width ib c ) | None -> match c with | ' ' | ' \ t ' | ... |
let scan_char width ib = Scanning . store_char width ib ( Scanning . checked_peek_char ib ) |
let char_for_backslash = function | ' n ' -> ' \ 010 ' | ' r ' -> ' \ 013 ' | ' b ' -> ' \ 008 ' | ' t ' -> ' \ 009 ' | c -> c |
let decimal_value_of_char c = int_of_char c - int_of_char ' 0 ' |
let char_for_decimal_code c0 c1 c2 = let c = 100 * decimal_value_of_char c0 + 10 * decimal_value_of_char c1 + decimal_value_of_char c2 in if c < 0 || c > 255 then bad_input ( Printf . sprintf " bad character decimal encoding \\% c % c % c " c0 c1 c2 ) else char_of_int c |
let hexadecimal_value_of_char c = let d = int_of_char c in if d >= int_of_char ' a ' then d - 87 else if d >= int_of_char ' A ' then d - 55 else d - int_of_char ' 0 ' |
let char_for_hexadecimal_code c1 c2 = let c = 16 * hexadecimal_value_of_char c1 + hexadecimal_value_of_char c2 in if c < 0 || c > 255 then bad_input ( Printf . sprintf " bad character hexadecimal encoding \\% c % c " c1 c2 ) else char_of_int c |
let check_next_char message width ib = if width = 0 then bad_token_length message else let c = Scanning . peek_char ib in if Scanning . eof ib then bad_end_of_input message else c |
let check_next_char_for_char = check_next_char " a Char " |
let check_next_char_for_string = check_next_char " a String " |
let scan_backslash_char width ib = match check_next_char_for_char width ib with | ' ' \\ | ' ' ' \ | ' " ' \ | ' n ' | ' t ' | ' b ' | ' r ' as c -> Scanning . store_char width ib ( char_for_backslash c ) | ' 0 ' . . ' 9 ' as c -> let get_digit ( ) = let c = Scanning . next_char ib in match c with | ' 0 ' . . ' 9 ' as ... |
let scan_caml_char width ib = let rec find_start width = match Scanning . checked_peek_char ib with | ' ' ' \ -> find_char ( Scanning . ignore_char width ib ) | c -> character_mismatch ' ' ' \ c and find_char width = match check_next_char_for_char width ib with | ' ' \\ -> find_stop ( scan_backslash_char ( Scanning . i... |
let scan_caml_string width ib = let rec find_start width = match Scanning . checked_peek_char ib with | ' " ' \ -> find_stop ( Scanning . ignore_char width ib ) | c -> character_mismatch ' " ' \ c and find_stop width = match check_next_char_for_string width ib with | ' " ' \ -> Scanning . ignore_char width ib | ' ' \\ ... |
let scan_bool ib = let c = Scanning . checked_peek_char ib in let m = match c with | ' t ' -> 4 | ' f ' -> 5 | c -> bad_input ( Printf . sprintf " the character % C cannot start a boolean " c ) in scan_string None m ib |
let scan_chars_in_char_set char_set scan_indic width ib = let rec scan_chars i stp = let c = Scanning . peek_char ib in if i > 0 && not ( Scanning . eof ib ) && is_in_char_set char_set c && int_of_char c <> stp then let _ = Scanning . store_char max_int ib c in scan_chars ( i - 1 ) stp in match scan_indic with | None -... |
let scanf_bad_input ib = function | Scan_failure s | Failure s -> let i = Scanning . char_count ib in bad_input ( Printf . sprintf " scanf : bad input at char number % i : % s " i s ) | x -> raise x |
let get_counter ib counter = match counter with | Line_counter -> Scanning . line_count ib | Char_counter -> Scanning . char_count ib | Token_counter -> Scanning . token_count ib |
let width_of_pad_opt pad_opt = match pad_opt with | None -> max_int | Some width -> width |
let stopper_of_formatting_lit fmting = if fmting = Escaped_percent then ' ' , % " " else let str = string_of_formatting_lit fmting in let stp = str . [ 1 ] in let sub_str = String . sub str 2 ( String . length str - 2 ) in stp , sub_str |
let rec take_format_readers : type a c d e f . ( ( d , e ) heter_list -> e ) -> ( a , Scanning . in_channel , c , d , e , f ) fmt -> d = | Reader fmt_rest -> fun reader -> let new_k readers_rest = k ( Cons ( reader , readers_rest ) ) in take_format_readers new_k fmt_rest | Char rest -> take_format_readers k rest | Caml... |
let rec make_scanf : type a c d e f . Scanning . in_channel -> ( a , Scanning . in_channel , c , d , e , f ) fmt -> ( d , e ) heter_list -> ( a , f ) heter_list = | Char rest -> let _ = scan_char 0 ib in let c = token_char ib in Cons ( c , make_scanf ib rest readers ) | Caml_char rest -> let _ = scan_caml_char 0 ib in ... |
type ' a kscanf_result = Args of ' a | Exc of exn |
let kscanf ib ef ( Format ( fmt , str ) ) = let rec apply : type a b . a -> ( a , b ) heter_list -> b = fun f args -> match args with | Cons ( x , r ) -> apply ( f x ) r | Nil -> f in let k readers f = Scanning . reset_token ib ; match try Args ( make_scanf ib fmt readers ) with | ( Scan_failure _ | Failure _ | End_of_... |
let bscanf ib fmt = kbscanf ib scanf_bad_input fmt |
let ksscanf s ef fmt = kbscanf ( Scanning . from_string s ) ef fmt |
let sscanf s fmt = kbscanf ( Scanning . from_string s ) scanf_bad_input fmt |
let scanf fmt = kscanf Scanning . stdib scanf_bad_input fmt |
let bscanf_format : Scanning . in_channel -> ( ' a , ' b , ' c , ' d , ' e , ' f ) format6 -> ( ( ' a , ' b , ' c , ' d , ' e , ' f ) format6 -> ' g ) -> ' g = fun ib format f -> let _ = scan_caml_string max_int ib in let str = token_string ib in let fmt ' = try format_of_string_format str format with Failure msg -> ba... |
let sscanf_format : string -> ( ' a , ' b , ' c , ' d , ' e , ' f ) format6 -> ( ( ' a , ' b , ' c , ' d , ' e , ' f ) format6 -> ' g ) -> ' g = fun s format f -> bscanf_format ( Scanning . from_string s ) format f |
let format_from_string s fmt = sscanf_format ( " " " \ ^ String . escaped s ^ " " " ) \ fmt ( fun x -> x ) |
let unescaped s = sscanf ( " " " \ ^ s ^ " " " ) \ " % S " %! ( fun x -> x ) |
let kfscanf ic ef fmt = kbscanf ( Scanning . memo_from_channel ic ) ef fmt |
let fscanf ic fmt = kscanf ( Scanning . memo_from_channel ic ) scanf_bad_input fmt |
let tscanf_data_file_lines = [ " Objective " , " Caml " ; ] ; ; |
let create_tscanf_data ob lines = let add_line ( p , e ) e = Buffer . add_string ob ( Printf . sprintf " % S " p ) p ; Buffer . add_string ob " -> " ; Buffer . add_string ob ( Printf . sprintf " % S " e ) e ; Buffer . add_string ob " ; \ n " in List . iter add_line lines ; ; |
let write_tscanf_data_file fname lines = let oc = open_out fname in let ob = Buffer . create 42 in create_tscanf_data ob lines ; Buffer . output_buffer oc ob ; close_out oc ; ; |
let get_lines fname = let ib = Scanf . Scanning . from_file fname in let l = ref [ ] in try while not ( Scanf . Scanning . end_of_input ib ) ib do Scanf . bscanf ib " % S -> % S ; " ( fun x y -> l := ( x , y ) y :: ! l ) l done ; List . rev ! l with | Scanf . Scan_failure s -> failwith ( Printf . sprintf " in file % s ... |
let add_digest_ib ob ib = let digest s = String . uppercase ( Digest . to_hex ( Digest . string s ) s ) s in let scan_line ib f = Scanf . bscanf ib [ " %^\ n \ r ] r \ n " f in let output_line_digest s = Buffer . add_string ob s ; Buffer . add_char ob ' # ' ; Buffer . add_string ob ( digest s ) s ; Buffer . add_char ob... |
let digest_file fname = let ib = Scanf . Scanning . from_file fname in let ob = Buffer . create 42 in add_digest_ib ob ib ; Buffer . contents ob ; ; |
let test54 ( ) = get_lines tscanf_data_file = tscanf_data_file_lines ; ; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.