text
stringlengths
12
786k
let find t k = match Map . find t k with | Some x -> x | None -> key_not_in_enumeration t k ; ;
let pair t1 t2 key = function | ` Left _ -> key_not_in_enumeration t2 key | ` Right _ -> key_not_in_enumeration t1 key | ` Both ( v1 , v2 ) -> v1 , v2 ; ;
let iter2 t1 t2 ~ f = Map . iter2 t1 t2 ~ f ( : fun ~ key ~ data -> let v1 , v2 = pair t1 t2 key data in f ~ key v1 v2 ) ; ;
let fold2 t1 t2 ~ init ~ f = Map . fold2 t1 t2 ~ init ~ f ( : fun ~ key ~ data acc -> let v1 , v2 = pair t1 t2 key data in f ~ key v1 v2 acc ) ; ;
let map2 t1 t2 ~ f = Map . merge t1 t2 ~ f ( : fun ~ key v -> let v1 , v2 = pair t1 t2 key v in Some ( f v1 v2 ) ) ; ;
let set t key data = Map . set t ~ key ~ data
module Sequence ( A : Applicative ) = struct let sequence t = List . fold ( Map . to_alist t ) ~ init ( : A . return ( Map . Using_comparator . empty ~ comparator ( : Map . comparator t ) ) ) ~ f ( : fun acc ( key , data ) -> A . map2 acc data ~ f ( : fun acc data...
module type Key = sig type t [ @@ deriving sexp , bin_io , compare , enumerate ] end
module type Key_with_witnesses = sig include Key include Comparator . S with type t := t include Enumeration . S with type t := t end
module type S = sig module Key : Key type comparator_witness type enumeration_witness type nonrec ' a t = ( Key . t , ' a , comparator_witness , enumeration_witness ) t [ @@ deriving sexp , bin_io , compare ] include Applicative with type ' a t := ' a t val create : ( Key . t -> '...
module Make_with_witnesses ( Key : sig include Key include Comparator . S with type t := t include Enumeration . S with type t := t end ) = struct module Key = struct include Key include Comparable . Make_binable_using_comparator ( Key ) end type comparator_witness = Key . comparator_witness type ...
module Make ( Key : Key ) = Make_with_witnesses ( struct include Key include Comparable . Make_binable ( Key ) include Enumeration . Make ( Key ) end )
let repo_docdir_owner_repo_and_path_from_doc_uri uri = let uri_error uri = R . msgf " Could not derive publication directory $ PATH from opam doc \ field value % a ; expected the pattern \ $ SCHEME ://$ OWNER . github . io /$ REPO /$ PATH " String . dump uri in match Topkg_care . Text . split_uri ...
let publish_doc_gh_pages uri name version docdir = Fpath . of_string docdir >>= fun docdir -> repo_docdir_owner_repo_and_path_from_doc_uri uri >>= fun ( owner , repo , dir ) dir -> let remote = strf " git @@ github . com :% s /% s . git " owner repo in let git_for_repo r = Cmd . of_list ( ...
let repo_and_owner_of_uri uri = let uri_error uri = R . msgf " Could not derive owner and repo from opam dev - repo \ field value % a ; expected the pattern \ $ SCHEME ://$ HOST /$ OWNER /$ REPO [ REPO . $ EXT ] EXT [ EXT /$ DIR ] DIR " String . dump uri in match Topkg_care . Text . split_ur...
let steal_opam_publish_github_auth ( ) = let opam = Cmd ( . v " opam ) " in let publish = Fpath . v " plugins / opam - publish " in OS . Cmd . exists opam >>= function | false -> Ok None | true -> OS . Cmd ( . run_out Cmd ( . opam % " var " % " root ) " |> to_string ...
let github_auth ~ owner = match steal_opam_publish_github_auth ( ) |> Logs . on_error_msg ~ use ( : fun _ -> None ) None with | Some auth -> auth | None -> OS . Env ( . value " TOPKG_GITHUB_AUTH " string ~ absent : owner ) owner
let create_release_json version msg = let escape_for_json s = let len = String . length s in let max = len - 1 in let rec escaped_len i l = if i > max then l else match String . get s i with | ' \\ ' | ' " \ ' | ' \ n ' | ' \ r ' | ' \ t ' -> escaped_len ( i + 1 ) 1 ( l...
let run_with_auth auth curl = let auth = strf " - u % s " auth in OS . Cmd ( . in_string auth |> run_io curl ) curl
let curl_create_release curl version msg owner repo = let parse_release_id resp = let headers = String . cuts ~ sep " :\ r \ n " resp in try let not_slash c = not ( Char . equal ' / ' c ) c in let loc = List . find ( String . is_prefix ~ affix " : Location ) " : headers in let id = Stri...
let curl_upload_archive curl archive owner repo release_id = let uri = strf " https :// uploads . github . com / repos /% s /% s / releases /% d / assets ? name =% s " owner repo release_id ( Fpath . filename archive ) archive in let auth = github_auth ~ owner in let data = Cmd ( . v " ...
let publish_distrib uri name version msg archive = let git_for_repo r = Cmd . of_list ( Topkg . Cmd . to_list @@ Topkg . Vcs . cmd r ) r in let curl = Cmd ( . v " curl " % " - L " % " - s " % " - S " % " - K " % ) " " - in Fpath . of_string archive >>= fun archive -> OS . Cm...
let unsupported = Ok 1
let publish = function publish_distrib uri name version msg archive publish_doc_gh_pages uri name version docdir unsupported unsupported
let ipc_cmd args = begin match args with | verbosity :: req -> Logs . level_of_string verbosity >>= fun logs_level -> Topkg . Log . level_of_string verbosity >>= fun topkg_level -> Topkg . Log . set_level topkg_level ; Logs . set_level logs_level ; request req | [ ] -> R . error_msg " malformed...
let main_cmd ( ) = ` Help ( ` Pager , None ) None
let ipc_cmd = let doc = " Delegate request IPCs " in let man = [ ` S " DESCRIPTION " ; ` P " The ( $ tname ) tname command implements the topkg delegate protocol . See topkg - delegate ( delegate7 ) delegate7 and ( $ mname ) mname ( $ b , -- help ) help for more information . "...
let main_cmd = let doc = " Topkg ' s toy GitHub delegate " in let envs = [ Term . env_info " TOPKG_GITHUB_AUTH " ~ doc " : GitHub authentication data , see the section GITHUB AUTHENTICATION for details . " ] in let man_xrefs = [ ` Tool " topkg " ] in let man = [ ` S " DESCRIPTIO...
let main ( ) = Topkg . Private . disable_main ( ) ; match Term . eval_choice main_cmd [ ipc_cmd ] ipc_cmd with | ` Error _ -> exit 3 | ` Ok ret -> exit ret | _ -> exit 0
let ( ) = main ( )
let entity sp = SP . ( nest ( parens ( sp ) ) )
type ' a repr = var_count : int -> SP . t
type ' a observation = SP . t
let lambda f = fun ~ var_count -> let var_name = sprintf " var % d " var_count in let var_repr = fun ~ var_count -> SP . string var_name in let applied = f var_repr ~ var_count ( : var_count + 1 ) in entity SP . ( string " λ " ^^ string var_name ^^ string " " → ^^ applied )
let apply f v = fun ~ var_count -> entity ( SP . separate SP . space [ f ~ var_count ; v ~ var_count ] )
let observe f = f ( ) ~ var_count : 0
let to_unit x = fun ~ var_count -> entity SP . ( x ~ var_count ^^ string " :> unit " )
let list l = fun ~ var_count -> SP . nest ( OCaml . list ( fun a -> a ~ var_count ) l )
let list_map l ~ f = let open SP in fun ~ var_count -> entity ( string " List . map " ^^ nest ( string " ~ f " : ^^ f ~ var_count ) ^^ l ~ var_count ) type t = SP . t let input_value name kv = let open SP in fun ~ var_count -> entity ( ksprintf string " input -% s " name ^^ ( ...
let failwithf fmt = ksprintf failwith fmt
type parameters = { color_input : name : string -> attributes : ( string * string ) list -> string option ; }
let default_parameters = { color_input = ( fun ~ name ~ attributes -> None ) ; }
module Tree = struct type box = { id : string ; name : string ; attributes : ( string * string ) list } type arrow = { label : string ; points_to : t } and t = [ | ` Variable of string * string | ` Lambda of string * string * t | ` Apply of string * t * t | ` String of str...
type ' a repr = var_count : int -> Tree . t
type ' a observation = parameters : parameters -> SmartPrint . t
let lambda f = fun ~ var_count -> let var_name = sprintf " Var_ % d " var_count in let var_repr_fake = fun ~ var_count -> Tree . string var_name in let applied_once = f var_repr_fake ~ var_count ( : var_count + 1 ) in let var_repr = fun ~ var_count -> Tree . variable applied_once var_name in...
let apply f v = fun ~ var_count -> let func = f ~ var_count in let arg = v ~ var_count in Tree . apply func arg
let observe f = f ( ) ~ var_count : 0 |> Tree . to_dot
let to_unit x = x
let list l = fun ~ var_count -> Tree . node " List . make " ( List . mapi ~ f ( : fun i a -> Tree . arrow ( sprintf " L % d " i ) ( a ~ var_count ) ) l )
let list_map l ~ f = fun ~ var_count -> Tree . node " List . map " [ Tree . arrow " list " ( l ~ var_count ) ; Tree . arrow " function " ( f ~ var_count ) ; ] type t = Tree . t let input_value name a ~ var_count = Tree . input_value name ~ a let function_call name param...
module State = struct type t = { mutable last_lifecycle : Bonsai . Private . Lifecycle . Collection . t } let create ( ) = { last_lifecycle = Bonsai . Private . Lifecycle . Collection . empty } end
module Action = struct type ( ' dynamic_action , ' static_action ) t = | Dynamic of ' dynamic_action | Static of ' static_action [ @@ deriving sexp_of ] end
let create_generic computation ~ fresh ~ input ~ model ~ inject_dynamic ~ inject_static ~ apply_static = let environment = Bonsai . Private . Environment . ( empty |> add_exn ~ key : fresh ~ data : input ) in let snapshot = Bonsai . Private . eval ~ environment ~ path : Bonsai . Private...
let convert_generic ( type input model dynamic_action static_action extra ) ~ fresh ( ~ computation : ( model , dynamic_action , static_action , Vdom . Node . t * extra ) Bonsai . Private . Computation . t ) ~ default_model ( ~ dynamic_action_type_id : dynamic_action Type_equal . ...
let convert_with_extra component = let fresh = Type_equal . Id . create ~ name " " : sexp_of_opaque in let var = Bonsai . Private . ( Value . named fresh |> conceal_value ) in let component = component var |> Bonsai . Private . reveal_computation in let ( Bonsai . Private . Computati...
let convert component = convert_with_extra ( Bonsai . Arrow_deprecated . map component ~ f ( : fun r -> r , ( ) ) ) ; ;
let flatten nested_list = List . map ( fun nodes -> Inline nodes ) nested_list
let comma is_last s = if is_last then s else s ^ " , "
let str s = Yojson . Safe . to_string ( ` String s )
let pattern s = sprintf " /% s " / s
let rule s = sprintf " . $% s " s
let pp_conflict ? prefix : _ ( ? is_last = true ) rule_list = let rules = List . map rule rule_list |> String . concat " , " in [ Line ( sprintf " [ % s ] " rules |> comma is_last ) ]
let rec map ( f : ? prefix : string -> ? is_last : bool -> _ -> _ ) xs = match xs with | [ ] -> [ ] | [ x ] -> [ f ~ is_last : true x ] | x :: xs -> f ~ is_last : false x :: map f xs
let string_of_prec_value ( x : prec_value ) = match x with | Num_prec n -> string_of_int n | Named_prec name -> str name
let pp_value ~ is_last ( s : string ) = [ Line ( s |> comma is_last ) ]
let pp_prec_value ~ is_last x = let s = string_of_prec_value x in pp_value ~ is_last s
let rec pp_body ( ? prefix = " " ) ( ? is_last = true ) body = let cons , args = match body with | SYMBOL s -> rule s , None | STRING s -> str s , None | PATTERN s -> pattern s , None | BLANK -> " " " \\ /* blank " , */ None | REPEAT x -> " repeat " , Some ( pp_b...
let pp_rule ? prefix : _ ? is_last ( name , body ) = pp_body ~ prefix ( : sprintf " % s : $ => " name ) ? is_last body
let pp_word ( x : ident option ) = match x with | None -> [ ] | Some s -> [ Line ( sprintf " word : $ => % s , " ( rule s ) ) ]
let string_of_named_prec_level x = match x with | Prec_symbol name -> rule name | Prec_string s -> str s
let pp_precedence_level ? prefix : _ ( ? is_last = true ) level = let level = level |> List . map string_of_named_prec_level |> String . concat " , " in [ Line ( sprintf " [ % s ] " level |> comma is_last ) ]
let pp_grammar ( x : grammar ) : Indent . t = [ Line " // JavaScript grammar recovered from JSON by ' ocaml - tree - sitter to - js ' " ; Line " module . exports = grammar ( { " ; Block [ Line ( sprintf " name : % s , " ( str x . name ) ) ; Inline ( pp_word ...
let run input_path output_path = let grammar = match input_path with | None -> Atdgen_runtime . Util . Json . from_channel Tree_sitter_j . read_grammar stdin | Some file -> Atdgen_runtime . Util . Json . from_file Tree_sitter_j . read_grammar file in let tree = pp_grammar grammar in match output_...
type ' a repr = var_count : int -> json
type ' a observation = json
let lambda f = fun ~ var_count -> let var_name = sprintf " var % d " var_count in let var_repr = fun ~ var_count -> ` String var_name in let applied = f var_repr ~ var_count ( : var_count + 1 ) in ` Assoc [ " lambda " , ` String var_name ; " body " , applied ; ]
let apply f v = fun ~ var_count -> let func = f ~ var_count in let arg = v ~ var_count in ` Assoc [ " function " , func ; " argument " , arg ; ]
let observe f = f ( ) ~ var_count : 0
let to_unit j = j
let list l = fun ~ var_count -> ` List ( List . map ~ f ( : fun a -> a ~ var_count ) l )
let list_map l ~ f = fun ~ var_count -> ` Assoc [ " list - map " , f ~ var_count ; " argument " , l ~ var_count ; ]
module Make_serializer ( How : sig type t val input_value : string -> ( string * string ) list -> var_count : int -> t val function_call : string -> ( string * t ) list -> t val string : string -> t end ) = struct open How let input_url u = input_value " Input " [ " URL " , u ; ...
module Rf = struct let tag ? loc : _ ( ? attrs = [ ] ) a b c = Parsetree . Rtag ( a , attrs , b , c ) end
let rec of_type_desc ? loc typ = match typ with | Ptyp_var None -> Typ . any ? loc ( ) | Ptyp_var ( Some name ) -> Typ . var ? loc name . txt | Ptyp_poly ( _ , typ ) -> of_type_expr typ | Ptyp_arrow ( typ1 , typ2 , _ , label ) -> Typ . arrow ? loc label ( of_type_expr ty...
let of_field_decl { fld_ident = name ; fld_type = typ ; fld_loc = loc ; _ } = Type . field ~ loc name ( of_type_expr typ )
let of_ctor_args = function | Ctor_tuple args -> Parsetree . Pcstr_tuple ( List . map ~ f : of_type_expr args ) | Ctor_record fields -> Parsetree . Pcstr_record ( List . map ~ f : of_field_decl fields )
let of_ctor_decl { ctor_ident = name ; ctor_args = args ; ctor_ret = ret ; ctor_loc = loc } = Type . constructor name ~ loc ~ args ( : of_ctor_args args ) ? res ( : Option . map ~ f : of_type_expr ret )
let of_ctor_decl_ext { ctor_ident = name ; ctor_args = args ; ctor_ret = ret ; ctor_loc = loc } = Te . decl ~ loc ~ args ( : of_ctor_args args ) name ? res ( : Option . map ~ f : of_type_expr ret )
let of_type_decl decl = let loc = decl . tdec_loc in let name = decl . tdec_ident in let params = List . map ~ f ( : fun t -> ( of_type_expr t , Invariant ) ) decl . tdec_params in match decl . tdec_desc with | Pdec_abstract -> Type . mk name ~ loc ~ params | Pdec_alias typ -> Type . ...
let of_literal = function | Int i -> Const . int i | Int32 i -> Const . int32 i | Int64 i -> Const . int64 i | Nativeint i -> Const . nativeint i | Float f -> Const . float ( string_of_float f ) | Char c -> Const . char c | String s -> Const . string s | Bool _ | Field _ -> assert ...
let rec of_pattern_desc ? loc = function | Ppat_any -> Pat . any ? loc ( ) | Ppat_variable str -> Pat . var ? loc str | Ppat_constraint ( p , typ ) -> Pat . constraint_ ? loc ( of_pattern p ) ( of_type_expr typ ) | Ppat_tuple ps -> Pat . tuple ? loc ( List . map ~ f : of_pa...
let exp_of_literal ? loc = function | Bool _ -> failwith " Unhandled boolean literal " | Field _f -> failwith " Unhandled field literal " | ( Int _ | Int32 _ | Int64 _ | Nativeint _ | Float _ | Char _ | String _ ) as l -> Exp . constant ? loc ( of_literal l )
let rec of_expression_desc ? loc = function | Pexp_apply ( f , es ) -> Exp . apply ? loc ( of_expression f ) ( List . map ~ f ( : fun ( label , x ) -> ( label , of_expression x ) ) es ) | Pexp_variable name -> Exp . ident ? loc name | Pexp_integer ( i , suffix ) ->...
let of_conv_type = function | Ptconv_with ( _mode , decl ) -> Some ( of_type_decl decl ) | Ptconv_to _ -> None
let rec of_signature_desc ? loc = function | Psig_value ( name , typ ) | Psig_instance ( name , typ ) -> Sig . value ? loc ( Val . mk ? loc name ( of_type_expr typ ) ) | Psig_type decl -> Sig . type_ ? loc Recursive [ of_type_decl decl ] | Psig_convtype _ -> assert false | Ps...
let rec of_statement_desc ? loc = function | Pstmt_value ( p , e ) -> Str . value ? loc Nonrecursive [ Vb . mk ( of_pattern p ) ( of_expression e ) ] | Pstmt_instance ( name , e ) -> Str . value ? loc Nonrecursive [ Vb . mk ( Pat . var ? loc name ) ( of_expression e ) ...
let of_file = List . map ~ f : of_statement
let sexp_of_month x = CCSexp . atom @@ CCOption . get_exn_or " Expected valid month " @@ Time . abbr_string_of_month x
let sexp_of_weekday x = CCSexp . atom @@ Time . abbr_string_of_weekday x