text
stringlengths
0
601k
type syntax_map = string Hstr . t
let driver : syntax_map = Hstr . create 16
let ( ) = List . iter ( fun ( x , y ) -> Hstr . add driver x y ) [ ( " integer " , " int " ) ; ( " int " , " int " ) ; ( " " , + " infix " ) ; + ( " " , * " infix " ) ; * ( " " , - " infix " ) ; - ( " " , / " infix " ) ; / ( " infix mod " , " infix " ) ; % ( " " , <= " infix " ) ; <= ( " " , >= " infix " ) ; >= ( " " ,...
let query_syntax str = Hstr . find_opt driver str
type ' a widget = { config : Otoml . t ; func : Defaults . env -> Otoml . t -> ' a Soup . node -> ( unit , string ) result }
type ' a widgets = string list * ( string , ' a widget ) Hashtbl . t
let find_widget plugins name = let plugin_w = Hashtbl . find_opt plugins name in let builtin_w = List . assoc_opt name Builtin_widgets . widgets in match plugin_w , builtin_w with | Some p , Some _ -> let ( ) = Logs . warn @@ fun m -> m " Widget name % s is redefined by a plugin " name in Some p | Some p , None -> Some...
let get_widget_config config widget = let widget_tbl = Config . find_table_opt [ Defaults . widgets_table ; widget ] config in match widget_tbl with | Some widget_tbl -> widget_tbl | None -> failwith @@ Printf . sprintf " Trying to lookup a non - existent widget % s " widget
let list_widgets config = let ws = Config . find_table_opt [ Defaults . widgets_table ] config >>= ( fun x -> Some ( Otoml . list_table_keys x ) ) in match ws with | None -> [ ] | Some ws ' -> ws '
let add_widget hash name widget_func widget_config = let widget_rec = { config = widget_config ; func = widget_func } in Hashtbl . add hash name widget_rec
let rec _load_widgets settings config plugins ws hash = match ws with | [ ] -> ( ) | w :: ws ' -> let widget_config = get_widget_config config w in let name = OH . find_string_opt widget_config [ " widget " ] in let fail msg = Printf . ksprintf failwith " Error in [ widgets . % s ] : % s " w msg in begin match name wit...
let get_widget_order hash = let format_bad_deps ds = let format_bad_dep ( n , ns ) = Printf . sprintf " Widget " \% s " \ depends on non - existent widgets : % s " n ( String . concat " , " ns ) in let bad_deps = List . map format_bad_dep ds |> String . concat " \ n " in Printf . sprintf " Found dependencies on non - e...
let partition_widgets all_widgets index_deps = let rec aux index_deps before_index after_index = match index_deps , after_index with | [ ] , ws -> Ok ( List . rev before_index , ws ) | _ , w :: ws ' -> let index_deps = CCList . remove ~ eq ( ) := ~ key : w index_deps in aux index_deps ( w :: before_index ) ws ' | _ as ...
let load_widgets settings config plugins = let widgets_hash = Hashtbl . create 1024 in match config with | None -> Ok widgets_hash | Some config -> let ws = list_widgets config in try let ( ) = _load_widgets settings config plugins ws widgets_hash in Ok widgets_hash with Failure msg -> Error msg
let get_widgets settings config plugins index_deps = let ( let ) * = Stdlib . Result . bind in let * wh = load_widgets settings config plugins in let * wo = get_widget_order wh in let * before_index , after_index = partition_widgets wo index_deps in let ( ) = Logs . debug @@ fun m -> m " Widget processing order : % s "...
let widget_should_run settings name widget build_profiles site_dir page_file = let disabled = Config . find_bool_or ~ default : false widget . config [ " disabled " ] in if disabled then let ( ) = Logs . debug @@ fun m -> m " Widget " \% s " \ is disabled in the configuration " name in false else let options = Config ....
type handler = { suffix : string ; label : string ; export : string -> unit }
type configuration = { id : string ; handlers : handler list ; show : bool React . signal }
let export_format_id ( configuration : configuration ) : string = Format . sprintf " export_ % s_select " configuration . id
let export_filename_id ( configuration : configuration ) : string = Format . sprintf " export_ % s_filename " configuration . id
let export_button_id ( configuration : configuration ) : string = Format . sprintf " export_ % s_button " configuration . id
let export_data_label ( configuration : configuration ) : string = Format . sprintf " export_ % s_label " configuration . id
let export_form_id ( configuration : configuration ) : string = Format . sprintf " export_ % s_form " configuration . id
let inline_content ( configuration : configuration ) = let export_filename = Html . input ~ a [ : Html . a_id ( export_filename_id configuration ) ; Html . a_input_type ` Text ; Html . a_class [ " form - control " ] ; Html . a_placeholder " file name " ] ( ) in let export_button = Html . button ~ a [ : Html . a_id ( ex...
let content configuration = Html . form ~ a [ : Html . a_id ( export_form_id configuration ) ; Html . a_class [ " form - inline " ] ; ] ( inline_content configuration )
let onload ( configuration : configuration ) = let export_button : Dom_html . buttonElement Js . t = Ui_common . id_dom ( export_button_id configuration ) in let export_filename : Dom_html . inputElement Js . t = Ui_common . id_dom ( export_filename_id configuration ) in let export_format : Dom_html . selectElement Js ...
let export_svg ? svg_style_id ( ~ svg_div_id : string ) ( ) : handler = { suffix = " svg " ; label = " svg " ; export = fun filename -> Common . plotSVG ? plotStyleId : svg_style_id svg_div_id filename filename }
let export_png ? svg_style_id ( ~ svg_div_id : string ) ( ) : handler = { suffix = " png " ; label = " png " ; export = fun filename -> Common . plotPNG ? plotStyleId : svg_style_id svg_div_id filename filename }
let export_json ( ~ serialize_json : unit -> string ) : handler = { suffix = " json " ; label = " json " ; export = fun filename -> let data = Js . string ( serialize_json ( ) ) in Common . saveFile ~ data ~ mime " : application / json " ~ filename : filename }
type comment = [ ]
type variable_step = [ ]
type fixed_step = [ ]
type bed_graph_value = string * int * int * float
type item = [ comment | variable_step | fixed_step | ` bed_graph_value of bed_graph_value ]
let module_error e = Error ( ` wig e ) e
module Tags = struct type t = { allow_empty_lines : bool ; sharp_comments : bool ; } [ @@ deriving sexp ] sexp let default = { allow_empty_lines = false ; sharp_comments = true } true let to_string t = sexp_of_t t |> Sexplib . Sexp . to_string let of_string s = try Ok ( Sexplib . Sexp . of_string s |> t_of_sexp ) t_of_...
module Error = struct type parsing = [ | ` cannot_parse_key_values of Pos . t * string | ` empty_line of Pos . t | ` incomplete_input of Pos . t * string list * string option | ` missing_chrom_value of Pos . t * string | ` missing_start_value of Pos . t * string | ` missing_step_value of Pos . t * string | ` wrong_star...
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 ( : fun s -> begin match String . split ~ on : ' = ' s with | [ k...
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 |> in_channel_strings_to_stream ~ buffer_si...
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 ~ default " " : span ~ f ( : sprintf " sp...
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 " { " , " { " ) ; \\ ( Str . regexp_string " } " , " } " ) ; \\ ( Str . regexp_string " " , ~ " { \\ texttildelow }...
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_string s1 ; List . iter print_rope rl ; 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 -> Leaf_unquoted " \ n \\ paragraph { " | _ -> Leaf_unquoted " \ ...
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 section_elem _ x = Lwt_li...
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 offset_file ; Lwt . return ( Node3 ( " \\ input { " ...
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 let table_elem = fail...
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 " " \\ ( List . map dir_writer_aux lst )
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 ( : fun s -> s ) ' ' / str ) ) in match lst wit...
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 ; }