text
stringlengths
12
786k
module Transform = struct open Result . Monad_infix let explode_key_value loc s = try let by_space = String . split_on_chars s ~ on [ : ' ' ; ' \ n ' ; ' \ t ' ; ' \ r ' ] r ' |> List . filter ~ f ( : String ( ) . <> ) " " in Ok ( List . map by_space ~ f ( : ...
let error_to_exn e = Error e
let in_channel_to_item_stream ( ? buffer_size = 65536 ) 65536 ? filename ? tags inp = let x = Transform . string_to_item ? filename ? tags ( ) in Tfxm ( . in_channel_strings_to_stream inp x ~ buffer_size ) buffer_size
let in_channel_to_item_stream_exn ? buffer_size ? filename ? tags inp = Stream . result_to_exn ~ error_to_exn ( in_channel_to_item_stream ? filename ? buffer_size ? tags inp ) inp
let in_channel_to_bed_graph ( ? buffer_size = 65536 ) 65536 ? filename ? tags inp = let x = Transform . string_to_item ? filename ? tags ( ) in let y = Transform . item_to_bed_graph ( ) in Tfxm ( . compose_results x y ~ on_error ( : function ` left x -> x | ` right x -> x ) x ...
let in_channel_to_bed_graph_exn ? buffer_size ? filename ? tags inp = Stream . result_to_exn ~ error_to_exn ( in_channel_to_bed_graph ? filename ? buffer_size ? tags inp ) inp
let item_to_string ( ? tags = Tags . default ) default = function | ` comment c -> if tags . Tags . sharp_comments then sprintf " #% s \ n " c else " " | ` variable_step_state_change ( chrom , span ) span -> sprintf " variableStep chrom =% s % s \ n " chrom Option ( . value_map ...
type rope = | Menu_link of string * rope | Leaf of string | Leaf_unquoted of string | Node of rope * rope | Node3 of string * rope list * string | Nodelist of rope list
let reg0 ' = Str . regexp_string " WIKIBACKSLASHWIKI "
let reg0 = Str . regexp_string " " \\
let reg1 = Str . regexp_string " _ "
let reg2 = Str . regexp_string " " $
let reg3 = Str . regexp_string " " &
let reg4 = Str . regexp_string " " %
let reg5 = Str . regexp_string " " #
let reg6 = Str . regexp_string " " ^
let reg7 = Str . regexp_string " " -
let regs = [ ( reg0 , " WIKIBACKSLASHWIKI " ) ; ( reg1 , " \\ _ " ) ; ( reg2 , " " ) ; \\$ ( reg3 , " " ) ; \\& ( reg4 , " " ) ; \\% ( reg5 , " $\\ sharp " ) ; $ ( reg6 , " " ) ; \\^ ( Str . regexp_string " { " , ...
let escape s = List . fold_left ( fun s ( reg , subst ) -> Str . global_replace reg subst s ) s regs
let escape_ref s = let s = Str . global_replace reg1 " " = s in let s = Str . global_replace reg2 " " + s in let s = Str . global_replace reg3 " , " s in let s = Str . global_replace reg4 " ; " s in let s = Str . global_replace reg5 " " * s in s
let escape_label s = List . fold_left ( fun s ( reg , subst ) -> Str . global_replace reg subst s ) s [ reg7 , " " ; : reg1 , " " ; - reg4 , " - pc " ]
let reg_u = Str . regexp_string " " ~>>
let regs_unquoted = [ ( reg_u , " " ) ; >> ]
let escape_code s = List . fold_left ( fun s ( reg , subst ) -> Str . global_replace reg subst s ) s regs_unquoted
let rec print_rope = function | Menu_link _ -> print_string " { \\ bfseries ** Error in menu } " | Leaf s -> print_string ( escape s ) | Leaf_unquoted s -> print_string ( escape_code s ) | Node ( r1 , r2 ) -> print_rope r1 ; print_rope r2 | Node3 ( s1 , rl , s2 ) -> print_s...
let offset = try int_of_string Sys . argv . ( 2 ) with _ -> 0
let label_prefix = escape_label Sys . argv . ( 1 )
let sect n = match n + offset with | 1 -> Leaf_unquoted " \ n \\ part { " | 2 -> Leaf_unquoted " \ n \\ chapter { " | 3 -> Leaf_unquoted " \ n \\ section { " | 4 -> Leaf_unquoted " \ n \\ subsection { " | 5 -> Leaf_unquoted " \ n \\ subsubsection { " | 6 -> Le...
let close_sect ? id ( ) = match id with | Some id -> Node3 ( " } \ n \\ label { " , [ Leaf_unquoted id ] , " } \ n " ) | None -> Leaf_unquoted " } \ n "
let get_id attribs = try Some ( label_prefix ^ " " : ^ escape_label ( List . assoc " id " attribs ) ) with Not_found -> None
let is_inline = ref 0
module LatexBuilder = struct type href = string type param = unit type phrasing_without_interactive = rope Lwt . t type phrasing = rope Lwt . t type flow = rope Lwt . t type flow_without_interactive = rope Lwt . t type uo_list = rope Lwt . t let list x = x let flow x = x let phrasing x = x let sect...
let builder = ( module LatexBuilder : Wikicreole . Builder with type param = unit and type flow = rope Lwt . t )
let tex_of_wiki s = Lwt_list . map_s ( fun x -> x ) ( Wikicreole . from_string ~ sectioning : false ( ) builder s )
let inlinetex_of_wiki s = incr is_inline ; tex_of_wiki s >>= fun r -> decr is_inline ; Lwt . return r
let unsup = " unsupported syntax in menu "
let failed _ _ = failwith unsup
let failed1 _ = failwith unsup
let offset_file = open_out " . latex_of_wiki_offsets "
let item i attribs il = Lwt_list . map_s ( fun x -> x ) il >>= function | Menu_link ( addr , _ ) :: _ -> output_string offset_file addr ; output_string offset_file " " ; output_string offset_file ( string_of_int ( i - 2 ) ) ; output_string offset_file " \ n " ; flush offse...
let plugin_fun = function | _ -> ( true , fun ( ) args content -> ` Phrasing_without_interactive ( Lwt . return ( Leaf " " ) ) )
module LatexMenuBuilder = struct include Wiki_latex . LatexBuilder let p_elem = failed let pre_elem = failed let h1_elem = item 1 let h2_elem = item 2 let h3_elem = item 3 let h4_elem = item 4 let h5_elem = item 5 let h6_elem = item 6 let ol_elem = failed let dl_elem = failed let hr_elem = failed1 l...
let builder = ( module LatexMenuBuilder : Wikicreole . Builder with type param = unit and type flow = rope Lwt . t )
let menu_of_wiki s = Lwt_list . map_s ( fun x -> x ) ( Wikicreole . from_string ~ sectioning : false ( ) builder s )
let rec dir_writer lst = match lst with Root s :: tl -> ( s " " ) ( ^:\\^ dir_writer tl ) | [ CurrentDir Short ] -> " " | lst -> let dir_writer_aux cmp = match cmp with Root s -> s | ParentDir -> " . . " | CurrentDir _ -> " . " | Component s -> s in String . concat "...
let dir_reader str = let fn_part_of_string = function | " . . " -> ParentDir | " . " -> CurrentDir Long | str -> Component str in let fn_part_split str = let lst = List . flatten ( List . map ( StringExt . split ~ map : fn_part_of_string ' ' ) \\ ( StringExt . split ~ map...
let fast_is_current fn = if String . length fn = 0 || fn = " . " then true else if fn . [ 0 ] <> ' . ' then false else raise CannotHandleFast
let fast_is_parent fn = if fn = " . . " then true else if String . length fn < 2 || fn . [ 0 ] <> ' . ' || fn . [ 1 ] <> ' . ' then false else raise CannotHandleFast
let path_writer lst = String . concat " ; " lst
let path_reader str = StringExt . split ~ map ( : fun s -> s ) ' ; ' str
let top_left = I . string A . ( fg blue ) " " ┏
let top_right = I . string A . ( fg blue ) " " ┓
let bottom_right = I . string A . ( fg blue ) " " ┛
let bottom_left = I . string A . ( fg blue ) " " ┗
let top = I . uchar A . ( fg blue ) ( Uchar . of_int 0x2501 )
let side = I . uchar A . ( fg blue ) ( Uchar . of_int 0x2503 )
let left = I . string A . ( fg blue ) " " ┫
let right = I . string A . ( fg blue ) " " ┣
type t = { title : string ; cursor : int ; image : image ; refresh : Goodboy . State . t -> image ; }
let make ~ cursor ~ title ~ refresh state = let image = refresh state in { cursor ; image ; refresh ; title ; }
let down_cursor t i = if t . cursor - i < 0 then { t with cursor = 0 ; } else { t with cursor = t . cursor - i }
let up_cursor t i = let image_h = I . height t . image in if t . cursor + i > image_h then { t with cursor = image_h } else { t with cursor = t . cursor + i }
let set_cursor t i = { t with cursor = i ; }
let refresh t state = { t with image = t . refresh state ; }
let with_window ~ title i = let w = I . width i in let h = I . height i in let title = let title = I . string A . ( fg yellow ) title in I . ( ( hsnap ~ align ` : Middle w ( left <|> title <|> right ) ) </> ( top_left <|> top w 1 <|> top_right ) ) in let bottom = I . ( ...
let render ~ window_h { image ; cursor ; title ; _ } = let image_h = I . height image in let crop_top = if cursor < window_h then 0 else cursor - window_h in let crop_bottom = if cursor + window_h > image_h then 0 else image_h - crop_top - window_h in let i = I . ( vcrop crop_top crop_bot...
module T = struct include Value . Make_subtype ( struct let name = " window " let here = [ % here ] let is_in_subtype = Value . is_window end ) let equal = eq end
type window = t [ @@ deriving sexp_of ]
module Edges = struct type t = { bottom : int ; left : int ; right : int ; top : int } [ @@ deriving sexp_of ] include Valueable . Make ( struct type nonrec t = t let type_ = Value . Type . ( map ( tuple int ( tuple int ( tuple int ( tuple int unit ) ) ) ) ~ name [ :...
module Tree = struct module Direction = struct module T = struct type t = | Left_to_right | Top_to_bottom [ @@ deriving enumerate , sexp_of ] end include T let is_top_to_bottom = function | Left_to_right -> false | Top_to_bottom -> true ; ; include Valueable . Make ( struct type nonrec t = t ...
module type BoundedQueueWithCounter = sig type ' a t val empty : int -> ' a t val create : int -> ' a -> ' a t val is_empty : ' a t -> bool val is_full : ' a t -> bool val size : ' a t -> int val enqueue : ' a -> ' a t -> ' a t val dequeue : ' a t -> ' a option * ' a t val co...
module Window : BoundedQueueWithCounter = struct type ' a t = { data : ( ' a list ) * ( ' a list ) ; maxsize : int ; size : int ; count : int } let empty n = if n = 0 then failwith " Cannot create queue of size 0 " ! else { data = ( [ ] , [ ] ) ; maxsize = n ...
let winnow w h = let global_pos i w = let c = Window . count w in let s = Window . size w in c - ( s - 1 - i ) in let mincheck ( ( minval , minpos ) , count ) x = if x <= minval then ( ( x , count ) , count + 1 ) else ( ( minval , minpos ) , count + 1 ) in let r...
let main ( ) = let top = opentk ( ) in let mbar = Frame . create top [ Relief Raised ; BorderWidth ( Pixels 2 ) ] and dummy = Frame . create top [ Width ( Centimeters 10 . ) ; Height ( Centimeters 5 . ) ] in pack [ mbar ; dummy ] [ Side Side_Top ; Fill Fill_X ] ...
let _ = Printexc . catch main ( )
let of_int = function | 0 -> Some ( Success ) | 1 -> Some ( Invalid_function ) | 2 -> Some ( File_not_found ) | 3 -> Some ( Path_not_found ) | 4 -> Some ( Too_many_open_files ) | 5 -> Some ( Access_denied ) | 6 -> Some ( Invalid_handle ) | 7 -> Some ( Arena_trashed...
type t = | Success | Invalid_function | File_not_found | Path_not_found | Too_many_open_files | Access_denied | Invalid_handle | Arena_trashed | Not_enough_memory | Invalid_block | Bad_environment | Bad_format | Invalid_access | Invalid_data | Outofmemory | Invalid_drive | Current_directory | Not_sam...
type telnet_command = | SUBNEG_END [ @ id 240 ] | NOP [ @ id 241 ] | DATA_MARK [ @ id 242 ] | BREAK [ @ id 243 ] | INTERRUPT_PROCESS [ @ id 244 ] | ABORT_OUTPUT [ @ id 245 ] | ARE_YOU_THERE [ @ id 246 ] | ERASE_CHARACTER [ @ id 247 ] | ERASE_LINE [ @ id 248 ...
type telnet_option = | Binary_Transmission | Echo | Reconnection | Suppress_Go_Ahead | Approx_Message_Size_Negotiation | Status | Timing_Mark | Remote_Controlled_Trans_and_Echo | Output_Line_Width | Output_Page_Size | Output_Carriage_Return_Disposition | Output_Horizontal_Tab_Stops | Output_Horizontal_Tab...
type pc = int * int
let _read_pc conn = let % lwt frag_num = Lwt_io . BE . read_int conn . io . in_ in let % lwt pos = Lwt_io . BE . read_int conn . io . in_ in Lwt . return ( frag_num , pos ) pos
let _write_pc conn ( frag_num , pos ) pos = Lwt_io . BE . write_int conn . io . out frag_num ; % lwt Lwt_io . BE . write_int conn . io . out pos
let set_fork_mode conn mode = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' K ' ; % lwt Lwt_io . BE . write_int conn . io . out ( match mode with ` Fork_child -> 0 | ` Fork_parent -> 1 ) 1 ) 1
let set_event conn pc = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' e ' ; % lwt _write_pc conn pc ) pc
let set_breakpoint conn pc = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' B ' ; % lwt _write_pc conn pc ) pc
let reset_instr conn pc = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' i ' ; % lwt _write_pc conn pc ) pc
let set_trap_barrier conn pos = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' b ' ; % lwt Lwt_io . BE . write_int conn . io . out pos ) pos
let checkpoint conn = Lwt_conn . atomic conn ( fun conn -> if Sys . win32 then raise Operation_system_unsupported else Lwt_io . write_char conn . io . out ' c ' ; % lwt let % lwt pid = Lwt_io . BE . read_int conn . io . in_ in if pid = - 1 then assert false else Lwt . return pid ) pid
type execution_summary = [ ` Event | ` Breakpoint | ` Exited | ` Trap_barrier | ` Uncaught_exc | ` Debug_info of int Ident . Map . t * ( Instruct . debug_event list * string list ) list list | ` Code_loaded of int | ` Code_unloaded of int ]
let go conn steps = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' g ' ; % lwt Lwt_io . BE . write_int conn . io . out steps ; % lwt let % lwt summary = match % lwt Lwt_io . read_char conn . io . in_ with | ' e ' -> Lwt . return ` Event | ' b ' -> Lwt . return `...
let wait conn = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' w ' ) ' w '
let stop conn = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' s ' ) ' s '
let initial_frame conn = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' 0 ' ; % lwt let % lwt stack_pos = Lwt_io . BE . read_int conn . io . in_ in let % lwt pc = _read_pc conn in Lwt . return ( stack_pos , pc ) pc ) pc
let get_frame conn = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' f ' ; % lwt let % lwt stack_pos = Lwt_io . BE . read_int conn . io . in_ in let % lwt pc = _read_pc conn in Lwt . return ( stack_pos , pc ) pc ) pc
let set_frame conn stack_pos = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' S ' ; % lwt Lwt_io . BE . write_int conn . io . out stack_pos ) stack_pos
let up_frame conn stacksize = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' U ' ; % lwt Lwt_io . BE . write_int conn . io . out stacksize ; % lwt let % lwt stack_pos = Lwt_io . BE . read_int conn . io . in_ in let % lwt res = if stack_pos = - 1 then Lwt . return None ...
let _read_remote_value conn = Lwt_io . read_string_exactly conn . io . in_ ( Sys . word_size / 8 ) 8
let _write_remote_value conn rv = Lwt_io . write conn . io . out rv
let get_local conn index = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' L ' ; % lwt Lwt_io . BE . write_int conn . io . out index ; % lwt let % lwt rv = _read_remote_value conn in Lwt . return rv ) rv
let get_environment conn index = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' E ' ; % lwt Lwt_io . BE . write_int conn . io . out index ; % lwt let % lwt rv = _read_remote_value conn in Lwt . return rv ) rv