text
stringlengths
0
601k
let freduce ? max ~ sat ( s , start , stop as sub ) = if start = stop then sub else let min_idx = match max with | None -> start | Some max when max < 0 -> invalid_arg ( Astring_base . err_neg_max max ) | Some max -> let i = stop - max in if i < start then start else i in let rec loop i = if i < min_idx then ( s , star...
let rreduce ? max ~ sat ( s , start , stop as sub ) = if start = stop then sub else let max_idx = stop - 1 in let max_idx = match max with | None -> max_idx | Some max when max < 0 -> invalid_arg ( Astring_base . err_neg_max max ) | Some max -> let i = start + max - 1 in if i > max_idx then max_idx else i in let rec lo...
let reduce ( ? rev = false ) ? max ( ? sat = ( fun _ -> true ) ) sub = match rev with
let extent ( s0 , start0 , stop0 ) ( s1 , start1 , stop1 ) = if s0 != s1 then invalid_arg err_base else let start = if start0 < start1 then start0 else start1 in let stop = if stop0 < stop1 then stop1 else stop0 in ( s0 , start , stop )
let overlap ( s0 , start0 , stop0 ) ( s1 , start1 , stop1 ) = if s0 != s1 then invalid_arg err_base else if not ( start0 <= stop1 && start1 <= stop0 ) then None else let start = if start0 < start1 then start1 else start0 in let stop = if stop0 < stop1 then stop0 else stop1 in Some ( s0 , start , stop )
let append ( s0 , start0 , _ as sub0 ) ( s1 , start1 , _ as sub1 ) = let l0 = length sub0 in if l0 = 0 then rebase sub1 else let l1 = length sub1 in if l1 = 0 then rebase sub0 else let len = l0 + l1 in let b = Bytes . create len in bytes_unsafe_blit_string s0 start0 b 0 l0 ; bytes_unsafe_blit_string s1 start1 b l0 l1 ;...
let concat ? sep ( : sep , sep_start , _ as sep_sub = empty ) = function let sub_len = length sub in let sep_len = length sep_sub in let rec cat_len sep_count l ss = if l < 0 then l else match ss with | s :: ss -> cat_len ( sep_count + 1 ) ( l + length s ) ss | [ ] -> if sep_len = 0 then l else let max_sep_count = Sys ...
let is_empty ( _ , start , stop ) = stop - start = 0
let is_prefix ~ affix ( : affix , astart , _ as affix_sub ) ( s , sstart , _ as s_sub ) = let len_a = length affix_sub in let len_s = length s_sub in if len_a > len_s then false else let max_zidx = len_a - 1 in let rec loop i = if i > max_zidx then true else if sunsafe_get affix ( astart + i ) <> sunsafe_get s ( sstart...
let is_infix ~ affix ( : affix , astart , _ as affix_sub ) ( s , sstart , _ as s_sub ) = let len_a = length affix_sub in let len_s = length s_sub in if len_a > len_s then false else let max_zidx_a = len_a - 1 in let max_zidx_s = len_s - len_a in let rec loop i k = if i > max_zidx_s then false else if k > max_zidx_a the...
let is_suffix ~ affix ( : affix , _ , astop as affix_sub ) ( s , _ , sstop as s_sub ) = let len_a = length affix_sub in let len_s = length s_sub in if len_a > len_s then false else let max_zidx = len_a - 1 in let max_idx_a = astop - 1 in let max_idx_s = sstop - 1 in let rec loop i = if i > max_zidx then true else if su...
let for_all sat ( s , start , stop ) = Astring_base . for_all sat s ~ first : start ~ last ( : stop - 1 )
let exists sat ( s , start , stop ) = Astring_base . exists sat s ~ first : start ~ last ( : stop - 1 )
let same_base ( s0 , _ , _ ) ( s1 , _ , _ ) = s0 == s1
let equal_bytes ( s0 , start0 , stop0 ) ( s1 , start1 , stop1 ) = if s0 == s1 && start0 = start1 && stop0 = stop1 then true else let len0 = stop0 - start0 in let len1 = stop1 - start1 in if len0 <> len1 then false else let max_zidx = len0 - 1 in let rec loop i = if i > max_zidx then true else if sunsafe_get s0 ( start0...
let compare_bytes ( s0 , start0 , stop0 ) ( s1 , start1 , stop1 ) = if s0 == s1 && start0 = start1 && stop0 = stop1 then 0 else let len0 = stop0 - start0 in let len1 = stop1 - start1 in let min_len = if len0 < len1 then len0 else len1 in let max_i = min_len - 1 in let rec loop i = if i > max_i then compare len0 len1 el...
let eq_pos : int -> int -> bool = fun p0 p1 -> p0 = p1
let equal ( s0 , start0 , stop0 ) ( s1 , start1 , stop1 ) = if s0 != s1 then invalid_arg err_base else eq_pos start0 start1 && eq_pos stop0 stop1
let compare_pos : int -> int -> int = compare
let compare ( s0 , start0 , stop0 ) ( s1 , start1 , stop1 ) = if s0 != s1 then invalid_arg err_base else let c = compare_pos start0 start1 in if c <> 0 then c else compare_pos stop0 stop1
let with_range ( ? first = 0 ) ( ? len = max_int ) ( s , start , stop ) = if len < 0 then invalid_arg ( Astring_base . err_neg_len len ) else let s_len = stop - start in let max_idx = s_len - 1 in let empty = function | first when first < 0 -> ( s , start , start ) | first when first > max_idx -> ( s , stop , stop ) | ...
let with_index_range ( ? first = 0 ) ? last ( s , start , stop ) = let s_len = stop - start in let max_idx = s_len - 1 in let empty = function | first when first < 0 -> ( s , start , start ) | first when first > max_idx -> ( s , stop , stop ) | first -> ( s , start + first , start + first ) in let last = match last wit...
let trim ( ? drop = Astring_char . Ascii . is_white ) ( s , start , stop as sub ) = let len = stop - start in if len = 0 then sub else let max_pos = stop in let max_idx = stop - 1 in let rec left_pos i = if i > max_idx then max_pos else if drop ( sunsafe_get s i ) then left_pos ( i + 1 ) else i in let rec right_pos i =...
let fspan ~ min ~ max ~ sat ( s , start , stop as sub ) = if min < 0 then invalid_arg ( Astring_base . err_neg_min min ) else if max < 0 then invalid_arg ( Astring_base . err_neg_max max ) else if min > max || max = 0 then ( ( s , start , start ) , sub ) else let max_idx = stop - 1 in let max_idx = let k = start + max ...
let rspan ~ min ~ max ~ sat ( s , start , stop as sub ) = if min < 0 then invalid_arg ( Astring_base . err_neg_min min ) else if max < 0 then invalid_arg ( Astring_base . err_neg_max max ) else if min > max || max = 0 then ( sub , ( s , stop , stop ) ) else let max_idx = stop - 1 in let min_idx = let k = stop - max in ...
let span ( ? rev = false ) ( ? min = 0 ) ( ? max = max_int ) ( ? sat = fun _ -> true ) sub = match rev with | true -> rspan ~ min ~ max ~ sat sub | false -> fspan ~ min ~ max ~ sat sub
let take ( ? rev = false ) ? min ? max ? sat s = ( if rev then snd else fst ) @@ span ~ rev ? min ? max ? sat s
let drop ( ? rev = false ) ? min ? max ? sat s = ( if rev then fst else snd ) @@ span ~ rev ? min ? max ? sat s
let fcut ~ sep ( : sep , sep_start , sep_stop ) ( s , start , stop ) = let sep_len = sep_stop - sep_start in if sep_len = 0 then invalid_arg Astring_base . err_empty_sep else let max_sep_zidx = sep_len - 1 in let max_s_idx = stop - sep_len in let rec check_sep i k = if k > max_sep_zidx then Some ( ( s , start , i ) , (...
let rcut ~ sep ( : sep , sep_start , sep_stop ) ( s , start , stop ) = let sep_len = sep_stop - sep_start in if sep_len = 0 then invalid_arg Astring_base . err_empty_sep else let max_sep_zidx = sep_len - 1 in let max_s_idx = stop - 1 in let rec check_sep i k = if k > max_sep_zidx then Some ( ( s , start , i ) , ( s , i...
let cut ( ? rev = false ) ~ sep s = match rev with
let add_sub ~ no_empty s ~ start ~ stop acc = if start = stop then ( if no_empty then acc else ( s , start , start ) :: acc ) else ( s , start , stop ) :: acc
let fcuts ~ no_empty ~ sep ( : sep , sep_start , sep_stop ) ( s , start , stop as sub ) = let sep_len = sep_stop - sep_start in if sep_len = 0 then invalid_arg Astring_base . err_empty_sep else let s_len = stop - start in let max_sep_zidx = sep_len - 1 in let max_s_idx = stop - sep_len in let rec check_sep sstart i k a...
let rcuts ~ no_empty ~ sep ( : sep , sep_start , sep_stop ) ( s , start , stop as sub ) = let sep_len = sep_stop - sep_start in if sep_len = 0 then invalid_arg Astring_base . err_empty_sep else let s_len = stop - start in let max_sep_zidx = sep_len - 1 in let max_s_idx = stop - 1 in let rec check_sep sstop i k acc = if...
let cuts ( ? rev = false ) ( ? empty = true ) ~ sep s = match rev with
let fields ( ? empty = false ) ( ? is_sep = Astring_char . Ascii . is_white ) ( s , start , stop as sub ) = let no_empty = not empty in let max_pos = stop in let rec loop i end_pos acc = if i < start then begin if end_pos = max_pos then ( if no_empty && max_pos = start then [ ] else [ sub ] ) else add_sub ~ no_empty s ...
let ffind sat ( s , start , stop ) = let max_idx = stop - 1 in let rec loop i = if i > max_idx then None else if sat ( sunsafe_get s i ) then Some ( s , i , i + 1 ) else loop ( i + 1 ) in loop start
let rfind sat ( s , start , stop ) = let rec loop i = if i < start then None else if sat ( sunsafe_get s i ) then Some ( s , i , i + 1 ) else loop ( i - 1 ) in loop ( stop - 1 )
let find ( ? rev = false ) sat sub = match rev with
let ffind_sub ~ sub ( : sub , sub_start , sub_stop ) ( s , start , stop ) = let len_sub = sub_stop - sub_start in let len_s = stop - start in if len_sub > len_s then None else let max_zidx_sub = len_sub - 1 in let max_idx_s = start + len_s - len_sub in let rec loop i k = if i > max_idx_s then None else if k > max_zidx_...
let rfind_sub ~ sub ( : sub , sub_start , sub_stop ) ( s , start , stop ) = let len_sub = sub_stop - sub_start in let len_s = stop - start in if len_sub > len_s then None else let max_zidx_sub = len_sub - 1 in let rec loop i k = if i < start then None else if k > max_zidx_sub then Some ( s , i , i + len_sub ) else if k...
let find_sub ( ? rev = false ) ~ sub start = match rev with
let filter sat ( s , start , stop ) = let len = stop - start in if len = 0 then empty else let b = Bytes . create len in let max_idx = stop - 1 in let rec loop b k i = if i > max_idx then ( ( if k = len then bytes_unsafe_to_string b else Bytes . sub_string b 0 k ) , 0 , k ) else let c = sunsafe_get s i in if sat c then...
let filter_map f ( s , start , stop ) = let len = stop - start in if len = 0 then empty else let b = Bytes . create len in let max_idx = stop - 1 in let rec loop b k i = if i > max_idx then ( ( if k = len then bytes_unsafe_to_string b else Bytes . sub_string b 0 k ) , 0 , k ) else match f ( sunsafe_get s i ) with | Non...
let map f ( s , start , stop ) = let len = stop - start in if len = 0 then empty else let b = Bytes . create len in for i = 0 to len - 1 do bytes_unsafe_set b i ( f ( sunsafe_get s ( start + i ) ) ) done ; ( bytes_unsafe_to_string b , 0 , len )
let mapi f ( s , start , stop ) = let len = stop - start in if len = 0 then empty else let b = Bytes . create len in for i = 0 to len - 1 do bytes_unsafe_set b i ( f i ( sunsafe_get s ( start + i ) ) ) done ; ( bytes_unsafe_to_string b , 0 , len )
let fold_left f acc ( s , start , stop ) = Astring_base . fold_left f acc s ~ first : start ~ last ( : stop - 1 )
let fold_right f ( s , start , stop ) acc = Astring_base . fold_right f s acc ~ first : start ~ last ( : stop - 1 )
let iter f ( s , start , stop ) = for i = start to stop - 1 do f ( sunsafe_get s i ) done
let iteri f ( s , start , stop ) = for i = start to stop - 1 do f ( i - start ) ( sunsafe_get s i ) done
let pp ppf s = Format . pp_print_string ppf ( to_string s )
let dump ppf s = Format . pp_print_char ppf ' " ' ; Format . pp_print_string ppf ( Astring_escape . escape_string ( to_string s ) ) ; Format . pp_print_char ppf ' " ' ; ( )
let dump_raw ppf ( s , start , stop ) = Format . fprintf ppf " [ @< 1 ( [ >@< 1 ( > base @ " \% s " ) ] \@@ [ @< 1 ( > start @ % d ) ] @@ \ [ ( @ stop @ % d ) ] ) ] " @@ ( Astring_escape . escape_string s ) start stop
let of_char c = v ( Astring_base . of_char c )
let to_char s = Astring_base . to_char ( to_string s )
let of_bool b = v ( Astring_base . of_bool b )
let to_bool s = Astring_base . to_bool ( to_string s )
let of_int i = v ( Astring_base . of_int i )
let to_int s = Astring_base . to_int ( to_string s )
let of_nativeint i = v ( Astring_base . of_nativeint i )
let to_nativeint s = Astring_base . to_nativeint ( to_string s )
let of_int32 i = v ( Astring_base . of_int32 i )
let to_int32 s = Astring_base . to_int32 ( to_string s )
let of_int64 i = v ( Astring_base . of_int64 i )
let to_int64 s = Astring_base . to_int64 ( to_string s )
let of_float f = v ( Astring_base . of_float f )
let to_float s = Astring_base . to_float ( to_string s )
type ' a with_loc = ' a Location . loc
type lid = Longident . t with_loc
type str = string with_loc
type str_opt = string option with_loc
type attrs = attribute list
let default_loc = ref Location . none
let with_default_loc l f = Misc . protect_refs [ Misc . R ( default_loc , l ) ] f
module Const = struct let integer ? suffix i = Pconst_integer ( i , suffix ) let int ? suffix i = integer ? suffix ( Int . to_string i ) let int32 ( ? suffix ' = l ' ) i = integer ~ suffix ( Int32 . to_string i ) let int64 ( ? suffix ' = L ' ) i = integer ~ suffix ( Int64 . to_string i ) let nativeint ( ? suffix ' = n ...
module Attr = struct let mk ( ? loc = ! default_loc ) name payload = { attr_name = name ; attr_payload = payload ; attr_loc = loc } end
module Typ = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) d = { ptyp_desc = d ; ptyp_loc = loc ; ptyp_loc_stack = [ ] ; ptyp_attributes = attrs } let attr d a = { d with ptyp_attributes = d . ptyp_attributes @ [ a ] } let any ? loc ? attrs ( ) = mk ? loc ? attrs Ptyp_any let var ? loc ? attrs a = mk ? loc ...
module Pat = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) d = { ppat_desc = d ; ppat_loc = loc ; ppat_loc_stack = [ ] ; ppat_attributes = attrs } let attr d a = { d with ppat_attributes = d . ppat_attributes @ [ a ] } let any ? loc ? attrs ( ) = mk ? loc ? attrs Ppat_any let var ? loc ? attrs a = mk ? loc ...
module Exp = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) d = { pexp_desc = d ; pexp_loc = loc ; pexp_loc_stack = [ ] ; pexp_attributes = attrs } let attr d a = { d with pexp_attributes = d . pexp_attributes @ [ a ] } let ident ? loc ? attrs a = mk ? loc ? attrs ( Pexp_ident a ) let constant ? loc ? attrs ...
module Mty = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) d = { pmty_desc = d ; pmty_loc = loc ; pmty_attributes = attrs } let attr d a = { d with pmty_attributes = d . pmty_attributes @ [ a ] } let ident ? loc ? attrs a = mk ? loc ? attrs ( Pmty_ident a ) let alias ? loc ? attrs a = mk ? loc ? attrs ( Pmt...
let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) d = { pmod_desc = d ; pmod_loc = loc ; pmod_attributes = attrs } let attr d a = { d with pmod_attributes = d . pmod_attributes @ [ a ] } let ident ? loc ? attrs x = mk ? loc ? attrs ( Pmod_ident x ) let structure ? loc ? attrs x = mk ? loc ? attrs ( Pmod_structure x ) ...
module Sig = struct let mk ( ? loc = ! default_loc ) d = { psig_desc = d ; psig_loc = loc } let value ? loc a = mk ? loc ( Psig_value a ) let type_ ? loc rec_flag a = mk ? loc ( Psig_type ( rec_flag , a ) ) let type_subst ? loc a = mk ? loc ( Psig_typesubst a ) let type_extension ? loc a = mk ? loc ( Psig_typext a ) le...
module Str = struct let mk ( ? loc = ! default_loc ) d = { pstr_desc = d ; pstr_loc = loc } let eval ? loc ( ? attrs = [ ] ) a = mk ? loc ( Pstr_eval ( a , attrs ) ) let value ? loc a b = mk ? loc ( Pstr_value ( a , b ) ) let primitive ? loc a = mk ? loc ( Pstr_primitive a ) let type_ ? loc rec_flag a = mk ? loc ( Pstr...
module Cl = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) d = { pcl_desc = d ; pcl_loc = loc ; pcl_attributes = attrs ; } let attr d a = { d with pcl_attributes = d . pcl_attributes @ [ a ] } let constr ? loc ? attrs a b = mk ? loc ? attrs ( Pcl_constr ( a , b ) ) let structure ? loc ? attrs a = mk ? loc ? ...
module Cty = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) d = { pcty_desc = d ; pcty_loc = loc ; pcty_attributes = attrs ; } let attr d a = { d with pcty_attributes = d . pcty_attributes @ [ a ] } let constr ? loc ? attrs a b = mk ? loc ? attrs ( Pcty_constr ( a , b ) ) let signature ? loc ? attrs a = mk ?...
module Ctf = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) d = { pctf_desc = d ; pctf_loc = loc ; pctf_attributes = add_docs_attrs docs attrs ; } let inherit_ ? loc ? attrs a = mk ? loc ? attrs ( Pctf_inherit a ) let val_ ? loc ? attrs a b c d = mk ? loc ? attrs ( Pctf_val ( a , b , ...
module Cf = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) d = { pcf_desc = d ; pcf_loc = loc ; pcf_attributes = add_docs_attrs docs attrs ; } let inherit_ ? loc ? attrs a b c = mk ? loc ? attrs ( Pcf_inherit ( a , b , c ) ) let val_ ? loc ? attrs a b c = mk ? loc ? attrs ( Pcf_val ( ...
module Val = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? prim = [ ] ) name typ = { pval_name = name ; pval_type = typ ; pval_attributes = add_docs_attrs docs attrs ; pval_loc = loc ; pval_prim = prim ; } end
module Md = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? text = [ ] ) name typ = { pmd_name = name ; pmd_type = typ ; pmd_attributes = add_text_attrs text ( add_docs_attrs docs attrs ) ; pmd_loc = loc ; } end
module Ms = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? text = [ ] ) name syn = { pms_name = name ; pms_manifest = syn ; pms_attributes = add_text_attrs text ( add_docs_attrs docs attrs ) ; pms_loc = loc ; } end
module Mtd = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? text = [ ] ) ? typ name = { pmtd_name = name ; pmtd_type = typ ; pmtd_attributes = add_text_attrs text ( add_docs_attrs docs attrs ) ; pmtd_loc = loc ; } end
module Mb = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? text = [ ] ) name expr = { pmb_name = name ; pmb_expr = expr ; pmb_attributes = add_text_attrs text ( add_docs_attrs docs attrs ) ; pmb_loc = loc ; } end
module Opn = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? override = Fresh ) expr = { popen_expr = expr ; popen_override = override ; popen_loc = loc ; popen_attributes = add_docs_attrs docs attrs ; } end
module Incl = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) mexpr = { pincl_mod = mexpr ; pincl_loc = loc ; pincl_attributes = add_docs_attrs docs attrs ; } end
module Vb = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? text = [ ] ) pat expr = { pvb_pat = pat ; pvb_expr = expr ; pvb_attributes = add_text_attrs text ( add_docs_attrs docs attrs ) ; pvb_loc = loc ; } end
module Ci = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? text = [ ] ) ( ? virt = Concrete ) ( ? params = [ ] ) name expr = { pci_virt = virt ; pci_params = params ; pci_name = name ; pci_expr = expr ; pci_attributes = add_text_attrs text ( add_docs_attrs docs attrs ) ; pci_loc =...
module Type = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? text = [ ] ) ( ? params = [ ] ) ( ? cstrs = [ ] ) ( ? kind = Ptype_abstract ) ( ? priv = Public ) ? manifest name = { ptype_name = name ; ptype_params = params ; ptype_cstrs = cstrs ; ptype_kind = kind ; ptype_private = ...
module Te = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? params = [ ] ) ( ? priv = Public ) path constructors = { ptyext_path = path ; ptyext_params = params ; ptyext_constructors = constructors ; ptyext_private = priv ; ptyext_loc = loc ; ptyext_attributes = add_docs_attrs docs...
module Csig = struct let mk self fields = { pcsig_self = self ; pcsig_fields = fields ; } end
module Cstr = struct let mk self fields = { pcstr_self = self ; pcstr_fields = fields ; } end