text
stringlengths
0
601k
let dump_registered_events ( ) = List . map ! Registry . reprs ~ f ( : fun { event_name ; id ; arguments ; _ } -> ( event_name , id , Set . to_list arguments ) arguments )
let check_interpolations_exn ~ msg_loc msg label_names = match Interpolator_lib . Interpolator . parse msg with | Error err -> failwithf " % s \ nEncountered an error while parsing the structured log message : % s " msg_loc err ( ) | Ok items -> List . iter items ~ f ( : function | ` Interpolate interp when not ( List ...
module Structure = struct type member = { name : string ; shape : string ; loc_name : string option ; field_name : string ; required : bool } type t = member list end
module Shape = struct type contents = | Structure of Structure . member list | List of string * string option * bool | Enum of string list | Map of ( string * string option ) * ( string * string option ) type t = { name : string ; content : contents } type parsed = string * string * contents option end
module Operation = struct type t = { name : string ; http_meth : string ; http_uri : string ; input_shape : string option ; output_shape : string option ; output_wrapper : string option ; errors : string list } end
module Error = struct type t = { shape_name : string ; string_name : string ; variant_name : string ; http_code : int option } let compare t1 t2 = compare ( t1 . string_name , t1 . variant_name , t1 . http_code ) ( t2 . string_name , t2 . variant_name , t2 . http_code ) end
module type S_no_ppx = sig val fields : Field . t list val nfields : int val type_size : int val field_names : string array val field_offset : int array val field_sizes : int array type t val create : unit -> t val pos : t -> int val has_next : t -> bool val has_prev : t -> bool val to_string : t -> string module Acces...
module type S = sig include S_no_ppx val unsafe_next : t -> unit val unsafe_prev : t -> unit val unsafe_move : t -> int -> unit val next : t -> unit val prev : t -> unit val move : t -> int -> unit end
type ' a code = ' a Ppx_stage . code
type card_t = AtMost1 | Many
type ( ' a , ' s ) producer_t = | For of ( ' a , ' s ) producer_for | Unfold of ( ' a , ' s ) producer_unfold and ( ' a , ' s ) producer_for = { upb : ' s -> int code ; index : ' s -> int code -> ( ' a -> unit code ) -> unit code } and ( ' a , ' s ) producer_unfold = { term : ' s -> bool code ; card : card_t ; step : '...
let for_unfold : ' a producer -> ' a producer = function | Prod ( { init } , For { upb ; index } ) -> Prod ( { init = fun k -> init @@ fun s0 -> [ % code let i = ref 0 in [ % e k ( [ % code i ] , s0 ) ] ] } , Unfold { term = ( fun ( i , s0 ) -> [ % code ( [ !% e i ] ) <= [ % e upb s0 ] ] ) ; card = Many ; step = ( fun ...
let of_arr : ' a array code -> ' a stream = fun arr -> let prod = Prod ( { init = fun k -> [ % code let arr = [ % e arr ] in [ % e k [ % code arr ] ] ] } , For { upb = ( fun arr -> [ % code Array . length [ % e arr ] - 1 ] ) ; index = ( fun arr i k -> [ % code let el = ( [ % e arr ] ) . ( [ % e i ] ) in [ % e k [ % cod...
let unfold : ( ' z code -> ( ' a * ' z ) option code ) -> ' z code -> ' a stream = fun p z -> let prod = Prod ( { init = fun k -> [ % code let s = ref [ % e p z ] in [ % e k [ % code s ] ] ] } , Unfold { term = ( fun s -> [ % code ! ( [ % e s ] ) <> None ] ) ; card = Many ; step = ( fun ( s ) body -> Some ( el , s ' ) ...
let rec fold_raw : ' a . ( ' a -> unit code ) -> ' a st_stream -> unit code = fun consumer -> function | Linear ( Prod ( { init } , For { upb ; index } ) ) -> init @@ fun sp -> [ % code for i = 0 to [ % e upb sp ] do [ % e index sp [ % code i ] @@ consumer ] done ] | Linear ( Prod ( { init } , Unfold { term ; card = At...
let fold : ( ' z code -> ' a code -> ' z code ) -> ' z code -> ' a stream -> ' z code = fun f z str -> [ % code let s = ref [ % e z ] in ( [ % e fold_raw ( fun a -> [ % code s := [ % e f [ % code ! s ] a ] ] ) str ] ; ! s ) ]
let fold_tupled : ( ' z1 code -> ' a code -> ' z1 code ) -> ' z1 code -> ( ' z2 code -> ' a code -> ' z2 code ) -> ' z2 code -> ' a stream -> ( ' z1 * ' z2 ) code = fun f1 z1 f2 z2 str -> [ % code let s1 = ref [ % e z1 ] in let s2 = ref [ % e z2 ] in ( [ % e fold_raw ( fun a -> [ % code begin s1 := [ % e f1 [ % code ! ...
let rec map_raw : ' a ' b . ( ' a -> ( ' b -> unit code ) -> unit code ) -> ' a st_stream -> ' b st_stream = fun tr -> function | Linear ( Prod ( init , For ( { index ; _ } as g ) ) ) -> let index s i k = index s i @@ fun e -> tr e k in Linear ( Prod ( init , For { g with index } ) ) | Linear ( Prod ( init , Unfold ( {...
let map : ( ' a code -> ' b code ) -> ' a stream -> ' b stream = fun f str -> map_raw ( fun a k -> [ % code let t = [ % e f a ] in [ % e k [ % code t ] ] ] ) str
let rec flat_map_raw : ( ' a -> ' b st_stream ) -> ' a st_stream -> ' b st_stream = fun tr -> function | Linear prod -> Nested ( prod , tr ) | Nested ( prod , nestf ) -> Nested ( prod , fun a -> flat_map_raw tr @@ nestf a )
let flat_map : ( ' a code -> ' b stream ) -> ' a stream -> ' b stream = flat_map_raw
let filter : ( ' a code -> bool code ) -> ' a stream -> ' a stream = fun f str -> let filter_stream a = Prod ( { init = fun k -> k a } , Unfold { card = AtMost1 ; term = f ; step = fun a k -> k a } ) in flat_map_raw ( fun x -> Linear ( filter_stream x ) ) str
let rec more_termination : bool code -> ' a st_stream -> ' a st_stream = let rec add_to_producer new_term = function | Prod ( init , Unfold { card = Many ; term ; step } ) -> let term s = [ % code [ % e new_term ] && [ % e term s ] ] in Prod ( init , Unfold { card = Many ; term ; step } ) | Prod ( _ , Unfold { card = A...
let take_raw : int code -> ' a st_stream -> ' a st_stream = let add_nr : ' a . int code -> ' a producer -> ( int ref code * ' a ) producer = fun n -> function Prod ( { init } , Unfold { term ; card ; step } ) -> let init = fun k -> init @@ fun s -> [ % code let nr = ref [ % e n ] in [ % e k ( [ % code nr ] , s ) ] ] an...
let take : int code -> ' a stream -> ' a stream = take_raw
let rec zip_producer : ' a producer -> ' b producer -> ( ' a * ' b ) producer = fun p1 p2 -> match ( p1 , p2 ) with | ( Prod ( i1 , For f1 ) , Prod ( i2 , For f2 ) ) -> Prod ( { init = fun k -> i1 . init @@ fun s1 -> i2 . init @@ fun s2 -> k ( s1 , s2 ) } , For { upb = ( fun ( s1 , s2 ) -> [ % code min [ % e f1 . upb s...
let push_linear : ' a producer -> ( ' b producer * ( ' b -> ' c st_stream ) ) -> ( ' a * ' c ) st_stream = fun ( Prod ( { init = init1 } , Unfold { card = Many ; term = term1 ; step = step1 } ) ) ( Prod ( { init = init2 } , Unfold p2 ) , nestf2 ) -> let init = fun k -> init1 @@ fun s1 -> init2 @@ fun s2 -> [ % code let...
let rec make_linear : ' a st_stream -> ' a producer = function | Linear prod -> prod | Nested ( Prod ( init , For _ ) as p , nestf ) -> make_linear ( Nested ( for_unfold p , nestf ) ) | Nested ( Prod ( { init } , Unfold { card = Many ; term ; step } ) , nestf ) -> let rec make_adv : ' a . ( unit -> unit ) option ref co...
let rec zip_raw : ' a st_stream -> ' b st_stream -> ( ' a * ' b ) st_stream = fun str1 str2 -> match ( str1 , str2 ) with | ( Linear prod1 , Linear prod2 ) -> Linear ( zip_producer prod1 prod2 ) | ( Linear prod1 , Nested ( prod2 , nestf2 ) ) -> push_linear ( for_unfold prod1 ) ( for_unfold prod2 , nestf2 ) | ( Nested (...
let zip_with : ( ' a code -> ' b code -> ' c code ) -> fun f str1 str2 -> map_raw ( fun ( x , y ) k -> k ( f x y ) ) @@ zip_raw str1 str2 ; ;
module type IntSig = sig type t val name : string val fmt : string val zero : t val max_int : t val min_int : t val bits : int val of_int : int -> t val to_int : t -> int val add : t -> t -> t val sub : t -> t -> t val mul : t -> t -> t val divmod : t -> t -> t * t end
module type S = sig type t val of_substring : string -> pos : int -> ( t * int ) int val of_string : string -> t val to_string : t -> string val to_string_bin : t -> string val to_string_oct : t -> string val to_string_hex : t -> string val printer : Format . formatter -> t -> unit val printer_bin : Format . formatter ...
module Make ( I : IntSig ) IntSig : S with type t = I . t = struct type t = I . t exception EndOfNumber of I . t * int let _of_substring start_off s func_name = let fail ( ) = invalid_arg ( I . name ^ func_name ) func_name in if start_off >= String . length s then fail ( ) ; let negative , off = if s [ . start_off ] st...
let ( ) = if true then " bla " else if true then " bli " else " blo "
let ( ) = if true then " bla " else if true then " bli " else begin " hop " end
let ( ) = if true then " hop " else if true then " hap " else ( ( ) ; " bla " )
let ( ) = if x then y else k , w ; z
let ( ) = if x then a else let y = x / 42 in y
let ( ) = if x then a else if y then b else begin blabla end ; x
let ( ) = if x then a else match y with | A -> x | B -> y
let ( ) = if x then a else match y with | A -> x | B -> y
let ( ) = if x then a else fun x -> y
let ( ) = if true then " bla " else if true then " bli " else " blo "
let ( ) = if true then " bla " else if true then " bli " else begin " hop " end
let ( ) = if true then " hop " else if true then " hap " else ( ( ) ; " bla " )
let ( ) = if x then y else k , w ; z
let ( ) = if x then a else let y = x / 42 in y
let ( ) = if x then a else if y then b else begin blabla end ; x
let ( ) = if x then a else match y with | A -> x | B -> y
let ( ) = if x then a else match y with | A -> x | B -> y
let ( ) = if x then a else fun x -> y
let ( ) = if true then " bla " else if true then " bli " else " blo "
let ( ) = if true then " bla " else if true then " bli " else begin " hop " end
let ( ) = if true then " hop " else if true then " hap " else ( ( ) ; " bla " )
let ( ) = if x then y else k , w ; z
let ( ) = if x then a else let y = x / 42 in y
let ( ) = if x then a else if y then b else begin blabla end ; x
let ( ) = if x then a else match y with | A -> x | B -> y
let ( ) = if x then a else match y with | A -> x | B -> y
let ( ) = if x then a else fun x -> y
module Longident = struct include Longident include ( val Comparator . make ~ compare ~ sexp_of_t ) end
let debug_s message values = Caml . prerr_endline ( Sexp . to_string_hum ( Sexp . message message values ) ) ; ;
type grammar = | Inline of grammar Sexp . Private . Raw_grammar . type_ loc | Ref_same_group of Type_name . t loc | Ref_other_group of Longident . t loc
type generic_group = { implicit_vars : var_name list ; ggid : generic_group_id ; types : ( type_name * grammar type_ ) list }
type group = { apply_implicit : grammar list }
let id_mapper = object inherit Sexp_grammar_lifter . map method var_name x = x method unit ( ) = ( ) method type_name x = x method list f l = List . map l ~ f method label x = x method int x = x method bool x = x method atom x = x end ; ;
let erase_locs : grammar Sexp . Private . Raw_grammar . type_ -> grammar Sexp . Private . Raw_grammar . type_ = id_mapper # type_ ( function | Inline x -> Inline { x with loc = Location . none } | Ref_same_group x -> Ref_same_group { x with loc = Location . none } | Ref_other_group x -> Ref_other_group { x with loc = L...
let make_generic_group ~ implicit_vars ~ types = let ggid = let types = List . map types ~ f ( : fun ( x , g ) -> x , erase_locs g ) in Caml . Digest . string ( Caml . Marshal . to_string types [ ] ) in { implicit_vars ; types ; ggid } ; ;
type t = { grammars : grammar Map . M ( Type_name ) . t ; generic_group : generic_group ; group : group ; loc : Location . t ; module_path : string }
let impossible ~ loc s = Location . raise_errorf ~ loc " ppx_sexp_conv : sexp_grammar : Impossible ! % s " s ; ;
let not_supported ~ loc s = Location . raise_errorf ~ loc " ppx_sexp_conv : sexp_grammar doesn ' t support % s " s ; ;
module Env : sig type t val sexp_of_t : t -> Sexp . t val create : rec_flag -> type_declaration list -> t val is_in_this_recursive_group : t -> Type_name . t -> bool val add_implicit_variable : loc : Location . t -> t -> Longident . t -> ' a type_ val type_for_var : loc : Location . t -> t -> Type_name . t -> Var_name ...
module Row_field = struct type t = | Inherit of core_type | Tag_nullary of label | Tag_sexp_list of label * core_type | Tag_tuple of label * core_type let core_type_within_sexp_list args sexp_list_attribute attribute_of = match args with | [ [ % type : [ % t ? type_ ] sexp_list ] ] -> Some type_ | [ [ % type : [ % t ? ...
module Opaque = struct type t = | Not_opaque of core_type | Opaque let create ctype : t = match Attribute . get Attrs . opaque ctype with | Some ( ) -> Opaque | None -> ( match ctype . ptyp_desc with | Ptyp_constr ( { loc = _ ; txt = Lident " sexp_opaque " } , _ ) -> Opaque | _ -> Not_opaque ctype ) ; ; end
let type_of_type_constructor ~ loc env lident args = let apply_if_args tycon = function | [ ] -> tycon | args -> Apply ( tycon , args ) in match lident with | Lident type_name when Env . is_in_this_recursive_group env type_name -> apply_if_args ( Recursive type_name ) args | Lident _ | Ldot ( ( Lident _ | Ldot _ ) , _ ...
let unsupported_builtin ~ loc type_name = let ( . ++ ) a b = Ldot ( a , b ) in Grammar ( Ref_other_group { loc ; txt = Lident " Ppx_sexp_conv_lib " . ++ " Sexp " . ++ " Private " . ++ " Raw_grammar " . ++ type_name } ) ; ;
let type_of_core_type env0 type_name ctype = let rec type_of_core_type env ctype = match Opaque . create ctype with | Opaque -> unsupported_builtin ~ loc : ctype . ptyp_loc " opaque " | Not_opaque { ptyp_desc ; ptyp_loc = loc ; ptyp_attributes = _ ; ptyp_loc_stack = _ } -> ( match ptyp_desc with | Ptyp_any -> Union [ ]...
let record_type_of_label_declarations env type_name lds ~ allow_extra_fields = { allow_extra_fields ; fields = List . map lds ~ f ( : fun ld -> let { pld_name ; pld_mutable = _ ; pld_type ; pld_loc ; pld_attributes = _ } = ld in let field = match Attrs . Record_field_handler . Of_sexp . create ~ loc : pld_loc ld with |...
module Constructor_declaration = struct type t = | Record of { allow_extra_fields : bool ; fields : label_declaration list ; label : label } | Tuple_regular of label * core_type list | Tuple_sexp_list of label * core_type let create ( { pcd_name ; pcd_args ; pcd_res ; pcd_loc ; _ } as cd ) = match pcd_res with | Some _...
let variant env type_name constructor_declarations = let alts = List . map constructor_declarations ~ f ( : fun constructor_declaration -> match Constructor_declaration . create constructor_declaration with | Record { allow_extra_fields ; fields ; label } -> let fields = record_type_of_label_declarations env type_name ...
let type_of_type_declaration env td = let loc = td . ptype_loc in let type_name = td . ptype_name . txt in let type_ = match td . ptype_kind with | Ptype_variant alts -> variant env type_name alts | Ptype_record lds -> Record ( record_type_of_label_declarations env type_name lds ~ allow_extra_fields : ( Attribute . get...
let create ~ loc ~ path rec_flag tds : t = let env = Env . create rec_flag tds in let grammars = List . map tds ~ f ( : fun { ptype_name ; _ } -> ptype_name . txt , Ref_same_group ptype_name ) |> Map . of_alist_exn ( module Type_name ) in let types = List . map tds ~ f ( : fun td -> td . ptype_name . txt , type_of_type...
let collect_type_variables_of_polymorphic_grammar core_type = match core_type with | [ % type : < for_all : [ % t ? { ptyp_desc = Ptyp_poly ( variables , core_type ) ; _ } ] > ] -> let var_names = List . map variables ~ f ( : fun { txt ; loc = _ } -> txt ) in var_names , core_type | { ptyp_desc = Ptyp_object _ ; _ } ->...
let singleton ~ loc ~ path core_type : t = let name = { loc ; txt = " dummy_type_name_from_sexp_grammar " } in let params , core_type = let type_variables , core_type = collect_type_variables_of_polymorphic_grammar core_type in ( List . map type_variables ~ f ( : fun var_name -> ptyp_var ~ loc var_name , ( NoVariance ,...
module Pattern = struct let the_generic_group ~ loc = [ % pat ? _the_generic_group ] let the_group ~ loc = [ % pat ? _the_group ] end
module Expression = struct let the_generic_group ~ loc = [ % expr _the_generic_group ] let the_group ~ loc = [ % expr _the_group ] let list ~ loc xs ~ f = elist ~ loc ( List . map xs ~ f ( : f ~ loc ) ) let tuple2 a b ~ loc ( a_ , b_ ) = [ % expr [ % e a ~ loc a_ ] , [ % e b ~ loc b_ ] ] let map_lident_last lident ~ f ...
let sexp_grammar_name ~ loc type_name = { loc ; txt = Lident ( type_name ^ sexp_grammar_suffix ) } ; ;
let to_pat_and_expr { grammars ; generic_group ; group ; loc ; module_path } = let bindings = Map . to_alist grammars |> List . map ~ f ( : fun ( type_name , grammar ) -> let pat = [ % pat ? ( [ % p ppat_var ~ loc { loc ; txt = type_name ^ sexp_grammar_suffix } ] : Ppx_sexp_conv_lib . Sexp . Private . Raw_grammar . t )...
let grammar_of_tds ~ loc ~ path ( rec_flag , tds ) = let pat , expr = create ~ loc ~ path rec_flag tds |> to_pat_and_expr in [ % str let [ % p pat ] = [ % e expr ] ] ; ;
let sexp_grammar ~ loc ~ path core_type = singleton ~ loc ~ path core_type |> to_pat_and_expr |> snd ; ;
let expand_quotation loc expander pos_tag quot = let open FanSig in let loc_name_opt = if quot . q_loc = " " then begin None end else begin Some quot . q_loc end in begin try expander loc loc_name_opt quot . q_contents with | ( FanLoc . Exc_located ( _ , Quotation ( _ ) ) as exc ) -> ( raise exc ) | FanLoc . Exc_locate...
let mkvirtual = ( function | Ast . ViVirtual -> Virtual | Ast . ViNil -> Concrete | _ -> assert false )
let ident_tag ( ? conv_lid ( = fun ( x ) -> x ) ) ( i ) = let rec self ( i ) ( acc ) = begin match i with | Ast . IdAcc ( _ , Ast . IdLid ( _ , " * predef " ) , * Ast . IdLid ( _ , " option " ) ) -> Some ( ( ( ( ldot ( ( lident " * predef " ) * ) " option " ) ) , ` lident ) ) | Ast . IdAcc ( _ , i1 , i2 ) -> ( self i2 ...
let mode = begin try let str = ( Sys . getenv " CAMLP4_DEBUG " ) in let rec loop ( acc ) ( i ) = begin try let pos = ( String . index_from str i ' ' ) : in ( loop ( ( SSet . add ( ( String . sub str i ( ( pos - i ) ) ) ) acc ) ) ( ( pos + 1 ) ) ) with | Not_found -> ( SSet . add ( ( String . sub str i ( ( ( ( String . ...
let formatter = let header = " camlp4 - debug : " in let at_bol = ( ref true ) in ( make_formatter ( ( fun ( buf ) -> ( fun ( pos ) -> ( fun ( len ) -> for i = pos to ( ( ( pos + len ) ) - 1 ) do begin if at_bol . contents then begin ( output_string out_channel header ) end else begin ( ) end ; let ch = buf . [ i ] in ...
let simple_try = try List . find x lst with Not_found -> 3
let u = function ( Ast . PaVrn ( _ , _ ) | Ast . PaStr ( _ , _ ) | Ast . PaRng ( _ , _ , _ ) | Ast . PaFlo ( _ , _ ) | Ast . PaNativeInt ( _ , _ ) | Ast . PaInt64 ( _ , _ ) | Ast . PaInt32 ( _ , _ ) | Ast . PaInt ( _ , _ ) | Ast . PaChr ( _ , _ ) | Ast . PaTyp ( _ , _ ) | Ast . PaArr ( _ , _ ) | Ast . PaAnt ( _ , _ ) )...
let v = ( fun ( ppf ) -> ( function | ( ` Smeta ( n , sl , _ ) ) -> ( self # meta ppf n sl ) | ( ` Slist0 s ) -> ( fprintf ppf " LIST0 % a " ( self # symbol1 ) s ) | ( ` Slist0sep ( s , t ) ) -> ( fprintf ppf " LIST0 % a SEP % a " ( self # symbol1 ) s ( self # symbol1 ) t ) | ( ` Slist1 s ) -> ( fprintf ppf " LIST1 % a...
let short_match x = match x with Some x -> x | Nnoe -> 0 | A -> 1
let short_match x = match x with Some x -> x | Nnoe -> 0 | A -> 1 | B -> 2 | C -> 3