text stringlengths 0 601k |
|---|
let to_string v = let print_series mark identifiers = match identifiers with | [ ] -> " " | _ -> mark ^ String . concat " . " identifiers in string_of_int v . major ^ " . " ^ string_of_int v . minor ^ " . " ^ string_of_int v . patch ^ print_series " " - v . prerelease ^ print_series " " + v . build |
let pp fmt version = Format . pp_print_string fmt ( to_string version ) |
let is_digit = function ' 0 ' . . ' 9 ' -> true | _ -> false |
let no_leading_zero str = String . length str <= 1 || String . get str 0 != ' 0 ' |
let nat : int Angstrom . t = take_while1 is_digit >>= fun str -> if no_leading_zero str then try return ( int_of_string str ) with _ -> fail ( " invalid version number : " ^ str ) else fail ( " leading 0 in version number : " ^ str ) |
let isOk = function | Ok _ -> true | Error _ -> false |
let dot = char ' . ' |
let base_identifier = take_while1 ( function ' ' - | ' a ' . . ' z ' | ' A ' . . ' Z ' | ' 0 ' . . ' 9 ' -> true | _ -> false ) |
let prerelease_identifier = let verify_numeric str = try let _ = int_of_string str in if no_leading_zero str then return str else fail ( " leading 0 in prerelease numeric identifier : " ^ str ) with _ -> return str in base_identifier >>= verify_numeric |
let identifier_list id_parser sep = char sep *> sep_by1 dot id_parser <|> return [ ] |
let version_parser = lift4 mk_version nat ( dot *> nat ) ( dot *> nat ) ( identifier_list prerelease_identifier ' ' ) - <*> ( identifier_list base_identifier ' ' ) + |
let from_parts major minor patch prerelease build = let check_prerelease_item s = parse_string ~ consume : All prerelease_identifier s |> isOk in let check_build_item s = parse_string ~ consume : All base_identifier s |> isOk in if major >= 0 && minor >= 0 && patch >= 0 && List . for_all check_prerelease_item prereleas... |
let of_string str = match parse_string ~ consume : All version_parser str with | Ok v -> Some v | Error _ -> None |
let is_valid str = match parse_string ~ consume : All version_parser str with | Ok _ -> true | Error _ -> false |
let compare_identifiers ia ib = match parse_string ~ consume : All nat ia , parse_string ~ consume : All nat ib with | Ok na , Ok nb -> compare na nb | Ok _ , _ -> - 1 | _ , Ok _ -> 1 | _ -> compare ia ib |
let rec compare_prerelease is_first pra prb = match pra , prb with | [ ] , [ ] -> 0 | [ ] , _ -> if is_first then 1 else - 1 | _ , [ ] -> if is_first then - 1 else 1 | ia :: ta , ib :: tb -> if compare ia ib != 0 then compare_identifiers ia ib else compare_prerelease false ta tb |
let compare a b = if a . major != b . major then compare a . major b . major else if a . minor != b . minor then compare a . minor b . minor else if a . patch != b . patch then compare a . patch b . patch else compare_prerelease true a . prerelease b . prerelease |
let equal a b = compare a b = 0 |
let less_than a b = compare a b < 0 |
let greater_than a b = compare a b > 0 |
let ( . <> ) f g x = f ( g x ) |
module Value = struct type helo = Domain . t type mail_from = Reverse_path . t * ( string * string option ) list type rcpt_to = Forward_path . t * ( string * string option ) list type auth = PLAIN type pp_220 = string list type pp_221 = string list type pp_250 = string list type tp_354 = string list type code = int * s... |
let src = Logs . Src . create " sendmail " ~ doc " : logs sendmail ' s event " |
module Log = ( val Logs . src_log src : Logs . LOG ) |
module Monad = State . Scheduler ( State . Context ) ( Value ) |
let run : type s flow . s impl -> ( flow , s ) rdwr -> flow -> ( ' a , ' err ) t -> ( ( ' a , ' err ) result , s ) io = fun { bind ; return } rdwr flow m -> let ( >>= ) = bind in let rec go = function | Read { buffer ; off ; len ; k } -> rdwr . rd flow buffer off len >>= fun v -> go ( k v ) | Write { buffer ; off ; len... |
let properly_quit_and_fail ctx err = let open Monad in reword_error ( fun _ -> err ) ( send ctx Value . Quit ( ) >>= fun ( ) -> recv ctx Value . PP_221 >>= fun _ -> fail err ) |
let auth ctx mechanism info = let open Monad in match info with | None -> return ` Anonymous | Some ( username , password ) -> match mechanism with | Value . PLAIN -> ( let * code , txts = send ctx Value . Auth mechanism >>= fun ( ) -> recv ctx Value . Code in match code with | 504 -> properly_quit_and_fail ctx ` Unsup... |
type authentication = { username : string ; password : string ; mechanism : Value . auth ; } |
type mechanism = Value . auth = PLAIN |
type ( ' a , ' s ) stream = unit -> ( ' a option , ' s ) io |
type error = [ ` Protocol of Value . error | ` Unsupported_mechanism | ` Encryption_required | ` Weak_mechanism | ` Authentication_rejected | ` Authentication_failed | ` Authentication_required ] |
let pp_error ppf = function | ` Protocol err -> Value . pp_error ppf err | ` Unsupported_mechanism -> Fmt . pf ppf " Unsupported mechanism " | ` Encryption_required -> Fmt . pf ppf " Encryption required " | ` Weak_mechanism -> Fmt . pf ppf " Weak mechanism " | ` Authentication_rejected -> Fmt . pf ppf " Authentication ... |
let has_8bit_mime_transport_extension = List . exists ( ( = ) " 8BITMIME " ) |
let pp_status ppf = function | ` Anonymous -> Fmt . string ppf " < anonymous " > | ` Authenticated -> Fmt . string ppf " < authenticated " > |
let m0 ctx ? authentication ~ domain sender recipients = let open Monad in recv ctx Value . PP_220 >>= fun _txts -> let * txts = send ctx Value . Helo domain >>= fun ( ) -> recv ctx Value . PP_250 in let has_8bit_mime_transport_extension = has_8bit_mime_transport_extension txts in Log . debug ( fun m -> m " 8BITMIME ex... |
let m1 ctx = let open Monad in let * _txts = send ctx Value . Dot ( ) >>= fun ( ) -> recv ctx Value . PP_250 in let * _txts = send ctx Value . Quit ( ) >>= fun ( ) -> recv ctx Value . PP_221 in return ( ) |
let sendmail ( { bind ; return } as impl ) rdwr flow context ? authentication ~ domain sender recipients mail = let ( >>- ) = bind in let ( >>= ) x f = x >>- function Ok v -> f v | Error _ as err -> return err in let m0 = m0 context ~ domain ? authentication sender recipients in run impl rdwr flow m0 >>= fun ( ) -> let... |
module Lwt_scheduler = Colombe . Sigs . Make ( Lwt ) |
let ( . <> ) f g x = f ( g x ) |
let lwt_bind x f = let open Lwt . Infix in let open Lwt_scheduler in inj ( prj x >>= ( prj . <> f ) ) ; ; |
let lwt = { Colombe . Sigs . bind = lwt_bind ; return = ( fun x -> Lwt_scheduler . inj ( Lwt . return x ) ) } ; ; |
type flow = { ic : Lwt_io . input_channel ; oc : Lwt_io . output_channel } |
let rdwr = { Colombe . Sigs . rd = ( fun { ic ; _ } bytes off len -> let open Lwt . Infix in let res = Lwt_io . read_into ic bytes off len >>= function | 0 -> Lwt . return ` End | len -> Lwt . return ( ` Len len ) in Lwt_scheduler . inj res ) ; wr = ( fun { oc ; _ } bytes off len -> let res = Lwt_io . write_from_exactl... |
let run_with_starttls ~ hostname ? port ~ domain ~ authentication ~ tls_authenticator ~ from ~ recipients ~ mail = let port = match port with | Some port -> port | None -> 465 in let tls = Tls . Config . client ~ authenticator : tls_authenticator ( ) in let ctx = Sendmail_with_starttls . Context_with_tls . make ( ) in ... |
let run ~ hostname ? port ~ domain ~ authentication ~ tls_authenticator ~ from ~ recipients ~ mail = let ( let * ) = Lwt . bind in let port = match port with | Some port -> port | None -> 465 in let ctx = Colombe . State . Context . make ( ) in let * ic , oc = Tls_lwt . connect tls_authenticator ( Domain_name . to_stri... |
let ( . <> ) f g x = f ( g x ) |
module Lwt_scheduler = Sigs . Make ( Lwt ) |
let lwt_bind x f = let open Lwt . Infix in let open Lwt_scheduler in inj ( prj x >>= ( prj . <> f ) ) |
let lwt = { Sigs . bind = lwt_bind ; return = ( fun x -> Lwt_scheduler . inj ( Lwt . return x ) ) } |
type flow = { ic : Lwt_io . input_channel ; oc : Lwt_io . output_channel } |
let rdwr = { Sigs . rd = ( fun { ic ; _ } bytes off len -> let open Lwt . Infix in Lwt_scheduler . inj ( Lwt_io . read_into ic bytes off len >>= function | 0 -> Lwt . return ` End | len -> Lwt . return ( ` Len len ) ) ) ; wr = ( fun { oc ; _ } bytes off len -> let res = Lwt_io . write_from_exactly oc ( Bytes . unsafe_o... |
let sendmail ? encoder ? decoder ~ hostname ( ? port = 465 ) ~ domain ~ authenticator ? authentication sender recipients mail = let hostname = Domain_name . to_string hostname in let ctx = Colombe . State . Context . make ? encoder ? decoder ( ) in let mail ( ) = Lwt_scheduler . inj ( mail ( ) ) in Tls_lwt . connect au... |
let failf fmt = Fmt . kstr ( fun err -> Lwt . fail ( Failure err ) ) fmt |
let resolve host = Lwt_unix . getprotobyname " tcp " >>= fun tcp -> Lwt_unix . getaddrinfo host " submission " Unix . [ AI_PROTOCOL tcp . Unix . p_proto ] >>= function | [ ] -> failf " Submission service is not recognized by your system " | ai :: _ -> Lwt . return ai . ai_addr |
let sendmail_with_starttls ? encoder ? decoder ? queue ~ hostname ? port ~ domain ~ authenticator ? authentication sender recipients mail = resolve ( Domain_name . to_string hostname ) >>= fun addr -> let addr = match ( addr , port ) with | Unix . ADDR_INET ( inet_addr , _ ) , Some port -> Unix . ADDR_INET ( inet_addr ... |
let ( . <> ) f g x = f ( g x ) |
let src = Logs . Src . create " sendmail - with - tls " ~ doc " : logs sendmail ' s event with TLS " |
module Log = ( val Logs . src_log src : Logs . LOG ) |
module type VALUE = sig type ' x send type ' x recv type error val pp_error : error Fmt . t val encode_without_tls : Encoder . encoder -> ' x send -> ' x -> ( unit , [ > ` Protocol of error ] ) t val decode_without_tls : Decoder . decoder -> ' x recv -> ( ' x , [ > ` Protocol of error ] ) t end |
module Value = struct type helo = Domain . t type mail_from = Reverse_path . t * ( string * string option ) list type rcpt_to = Forward_path . t * ( string * string option ) list type auth = Sendmail . mechanism type pp_220 = string list type pp_221 = string list type pp_250 = string list type tp_354 = string list type... |
module Flow = struct type t = unit type error = | type ' + a io = { run : ' r . ( ' a -> ( ' r , error ) State . t ) -> ( ' r , error ) State . t } let bind : ' a io -> ( ' a -> ' b io ) -> ' b io = fun { run = t } f -> { run = ( fun k -> t ( fun x -> ( f x ) . run k ) ) } let return x = { run = ( fun k -> k x ) } let ... |
module StartTLS = Tls_io . Make ( Flow ) |
module Context_with_tls = struct type t = { context : Context . t ; queue : ( char , Bigarray . int8_unsigned_elt ) Ke . Rke . t ; mutable tls : StartTLS . t option ; } type encoder = t type decoder = t let pp ppf t = Fmt . pf ppf " { [ @< hov > context = [ @< hov >% a ] ; @@ tls = # state ] @ } " Context . pp t . cont... |
module Value_without_tls = struct include Value let encode_without_tls ctx w v = let rec go = function | Error err -> Error ( ` Protocol err ) | Read { k ; buffer ; off ; len } -> Read { k = go . <> k ; buffer ; off ; len } | Write { k ; buffer ; off ; len } -> Write { k = go . <> k ; buffer ; off ; len } | Return v ->... |
module type S = sig type ' x send type ' x recv module Value : sig type error end type error = [ ` Protocol of Value . error | ` Tls_alert of Tls . Packet . alert_type | ` Tls_failure of Tls . Engine . failure | ` Tls_closed ] val pp_error : error Fmt . t type encoder type decoder val starttls_as_client : encoder -> Tl... |
module Make_with_tls ( Value : VALUE ) = struct type error = [ ` Protocol of Value . error | ` Tls_alert of Tls . Packet . alert_type | ` Tls_failure of Tls . Engine . failure | ` Tls_closed ] type encoder = Context_with_tls . t type decoder = Context_with_tls . t let pp_error ppf = function | ` Protocol v -> Value . p... |
module Value_with_tls = Make_with_tls ( Value_without_tls ) |
module Monad = State . Scheduler ( Context_with_tls ) ( Value_with_tls ) |
let properly_quit_and_fail ctx err = let open Monad in reword_error ( fun _ -> err ) ( let * _txts = send ctx Value . Quit ( ) >>= fun ( ) -> recv ctx Value . PP_221 in fail err ) |
let auth ctx mechanism info = let open Monad in match info with | None -> return ` Anonymous | Some ( username , password ) -> match mechanism with | Sendmail . PLAIN -> ( let * code , txts = send ctx Value . Auth mechanism >>= fun ( ) -> recv ctx Value . Code in match code with | 504 -> properly_quit_and_fail ctx ` Un... |
type ( ' a , ' s ) stream = unit -> ( ' a option , ' s ) io |
type error = [ ` Tls of [ ` Protocol of Value . error | ` Tls_alert of Tls . Packet . alert_type | ` Tls_failure of Tls . Engine . failure | ` Tls_closed ] | ` Protocol of [ ` Protocol of Value . error | ` Tls_alert of Tls . Packet . alert_type | ` Tls_failure of Tls . Engine . failure | ` Tls_closed ] | ` Unsupported_... |
let pp_error ppf = function | ` Protocol err | ` Tls err -> Value_with_tls . pp_error ppf err | ` Unsupported_mechanism -> Fmt . pf ppf " Unsupported mechanism " | ` Encryption_required -> Fmt . pf ppf " Encryption required " | ` Weak_mechanism -> Fmt . pf ppf " Weak mechanism " | ` Authentication_rejected -> Fmt . pf ... |
let has_8bit_mime_transport_extension = List . exists ( ( = ) " 8BITMIME " ) |
let has_starttls = List . exists ( ( = ) " STARTTLS " ) |
let m0 ctx config ? authentication ~ domain sender recipients = let open Monad in recv ctx Value . PP_220 >>= fun _txts -> let * txts = send ctx Value . Helo domain >>= fun ( ) -> recv ctx Value . PP_250 in let has_starttls = has_starttls txts in if not has_starttls then properly_quit_and_fail ctx ` STARTTLS_unavailabl... |
let m1 ctx = let open Monad in let * _txts = send ctx Value . Dot ( ) >>= fun ( ) -> recv ctx Value . PP_250 in let * _txts = send ctx Value . Quit ( ) >>= fun ( ) -> recv ctx Value . PP_221 in return ( ) |
let run : type s flow . s impl -> ( flow , s ) rdwr -> flow -> ( ' a , ' err ) t -> ( ( ' a , ' err ) result , s ) io = fun { bind ; return } rdwr flow m -> let ( >>= ) = bind in let rec go = function | Read { buffer ; off ; len ; k } -> rdwr . rd flow buffer off len >>= fun len -> go ( k len ) | Write { buffer ; off ;... |
let _dot = Cstruct . of_string " . " |
let sendmail ( { bind ; return } as state ) rdwr flow ctx mail = let ( >>= ) = bind in match ctx . Context_with_tls . tls with | None -> let rec go = function | Some ( buf , off , len ) -> rdwr . wr flow buf off len >>= mail >>= go | None -> return ( Ok ( ) ) in mail ( ) >>= go | Some tls -> let rec go ( ) = mail ( ) >... |
let sendmail ( { bind ; return } as impl ) rdwr flow context config ? authentication ~ domain sender recipients mail : ( ( unit , error ) result , ' s ) io = let ( >>- ) = bind in let ( >>= ) x f = x >>- function Ok v -> f v | Error _ as err -> return err in let m0 = m0 context config ~ domain ? authentication sender r... |
let to_http service region req = let uri = Uri . add_query_params ( Uri . of_string ( Aws . Util . of_option_exn ( Endpoints . url_of service region ) ) ) ( List . append [ ( " Version " , [ " 2012 - 11 - 05 " ] ) ; ( " Action " , [ " SendMessage " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( S... |
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Util . option_bind ( Xml . member " SendMessageResponse " ( snd xml ) ) ( Xml . member " SendMessageResult " ) in try Util . or_error ( Util . option_bind resp SendMessageResult . parse ) ( let open Error in BadResponse { body ; message = " Could ... |
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if ( List . mem var errors ) && ( ( match Errors_internal . to_http_code var with | Some var -> var = code | None -> true ) ) then Some var else None | None -> None |
let to_http service region req = let uri = Uri . add_query_params ( Uri . of_string ( Aws . Util . of_option_exn ( Endpoints . url_of service region ) ) ) ( List . append [ ( " Version " , [ " 2012 - 11 - 05 " ] ) ; ( " Action " , [ " SendMessageBatch " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . rende... |
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Util . option_bind ( Xml . member " SendMessageBatchResponse " ( snd xml ) ) ( Xml . member " SendMessageBatchResult " ) in try Util . or_error ( Util . option_bind resp SendMessageBatchResult . parse ) ( let open Error in BadResponse { body ; mes... |
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if ( List . mem var errors ) && ( ( match Errors_internal . to_http_code var with | Some var -> var = code | None -> true ) ) then Some var else None | None -> None |
type cutter = ? z : float -> float -> Scad . d3 |
module ThroughHole = struct let bulk_model ( ? leg_w = 0 . 5 ) ( ? leg_thickness = 0 . 4 ) ( ? leg_l = 20 . ) ( ? leg_spacing = 1 . ) ( ? leg_bend = 4 . ) ( ? leg_z_offset = - 0 . 2 ) ( ? merge_legs = false ) ( ? body_w = 4 . ) ( ? body_l = 3 . ) ( ? body_thickness = 1 . 5 ) ( ) = let bent_leg = let start = Scad . cube... |
let repeat_till_ENTER_win32 msg f = printf " % s . \ n " %! msg ; let i = ref 0 in while ! i < 200 do f ! i ; incr i done |
let repeat_till_ENTER_unix msg f = let params = Unix . tcgetattr Unix . stdin in Unix . tcsetattr Unix . stdin Unix . TCSAFLUSH { params with Unix . c_icanon = false ; c_echo = false ; c_vmin = 0 ; c_vtime = 0 ; } ; let no_key_pressed ( ) = Unix . read Unix . stdin ( Bytes . create 1 ) 0 1 = 0 in printf " % s ; when fi... |
let repeat_till_ENTER = if Sys . os_type = " Win32 " then repeat_till_ENTER_win32 else repeat_till_ENTER_unix |
let color_sensor = ref true |
let sensors conn = printf " It is assumed that sensors are connected as follows :\ n " ; if ! color_sensor then printf " - port 1 : NXT 2 . 0 color sensor \ n " else printf " - port 1 : NXT 1 . 0 light sensor \ n " ; printf " - port 2 : touch sensor \ n " ; printf " - port 3 : sound sensor \ n " ; printf " - port 4 : u... |
let ( ) = Connect . and_do { Connect . args = [ " -- light " , Arg . Clear color_sensor , " says that the sensor on port 1 is the old light sensor " ] ; f = sensors } |
type raw_symbol = string * Lexing . position * Lexing . position |
type raw_sentence = raw_nonterminal option * raw_terminal list |
type located_raw_sentence = Positions . positions * raw_sentence |
type sentence = Nonterminal . t option * Terminal . t list |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.