text stringlengths 0 601k |
|---|
let render_out_phrase term string = if String . length string >= 100 * 1024 then LTerm . fprint term string else begin let string = fix_string string in let styled = LTerm_text . of_utf8 string in let stylise loc token_style = for i = loc . idx1 to loc . idx2 - 1 do let ch , style = styled . ( i ) in styled . ( i ) <- ... |
let is_implicit_name name = name <> " " && name . [ 0 ] = ' _ ' && try let _ = int_of_string @@ String . sub name 1 ( String . length name - 1 ) in true with Failure _ -> false |
let map_items unwrap wrap items = let rec aux acc = function | [ ] -> acc | item :: items -> let sig_item , _ = unwrap item in let name , rec_status = match sig_item with | Outcometree . Osig_class ( _ , name , _ , _ , rs ) | Outcometree . Osig_class_type ( _ , name , _ , _ , rs ) | Outcometree . Osig_module ( name , _... |
let print_out_signature pp items = if UTop . get_hide_reserved ( ) then orig_print_out_signature pp ( map_items ( fun x -> ( x , ( ) ) ) ( fun x ( ) -> x ) items ) else orig_print_out_signature pp items |
let print_out_phrase pp phrase = if UTop . get_hide_reserved ( ) then let phrase = match phrase with | Outcometree . Ophr_eval _ | Outcometree . Ophr_exception _ -> phrase | Outcometree . Ophr_signature items -> Outcometree . Ophr_signature ( map_items ( fun x -> x ) ( fun x y -> ( x , y ) ) items ) in orig_print_out_p... |
let ( ) = Toploop . print_out_signature := print_out_signature ; Toploop . print_out_phrase := print_out_phrase |
let with_loc loc str = { Location . txt = str ; Location . loc = loc ; } |
type rewrite_rule = { type_to_rewrite : Longident . t ; mutable path_to_rewrite : Path . t option ; required_values : Longident . t list ; rewrite : Location . t -> Parsetree . expression -> Parsetree . expression ; enabled : bool React . signal ; } |
let longident_parse str = let lexbuf = Lexing . from_string str in Parse . longident lexbuf # endif |
let longident_lwt_main_run = Longident . Ldot ( Longident . Lident " Lwt_main " , " run " ) |
let longident_async_thread_safe_block_on_async_exn = Longident . ( Ldot ( Ldot ( Lident " Async " , " Thread_safe " ) , " block_on_async_exn " ) ) |
let longident_unit = Longident . Lident " ( ) " |
let nolabel = Asttypes . Nolabel # else |
let nolabel = " " # endif |
let rewrite_rules = [ { type_to_rewrite = Longident . ( Ldot ( Lident " Lwt " , " t " ) ) ; path_to_rewrite = None ; required_values = [ longident_lwt_main_run ] ; rewrite = ( fun loc e -> let open Ast_helper in with_default_loc loc ( fun ( ) -> Exp . apply ( Exp . ident ( with_loc loc longident_lwt_main_run ) ) [ ( no... |
let lookup_type longident env = Env . find_type_by_name longident env |
let lookup_type longident env = let path = Env . lookup_type longident env in ( path , Env . find_type path env ) # else |
let lookup_type = Env . lookup_type # endif |
let rule_path rule = match rule . path_to_rewrite with | Some _ as x -> x | None -> try let env = ! Toploop . toplevel_env in let path = match lookup_type rule . type_to_rewrite env with | path , { Types . type_kind = Types . Type_abstract ; Types . type_private = Asttypes . Public ; Types . type_manifest = Some ty } -... |
let rec is_persistent_path = function | Path . Pident id -> Ident . persistent id | Path . Pdot ( p , _ ) -> is_persistent_path p # else | Path . Pdot ( p , _ , _ ) -> is_persistent_path p # endif | Path . Papply ( _ , p ) -> is_persistent_path p |
let is_persistent_in_env longident = let lookup_value = Env . find_value_by_name # else Env . lookup_value # endif in try is_persistent_path ( fst ( lookup_value longident ! Toploop . toplevel_env ) ) with Not_found -> false |
let rule_matches rule path = React . S . value rule . enabled && ( match rule_path rule with | None -> false | Some path ' -> Path . same path path ' ) && List . for_all is_persistent_in_env rule . required_values |
let is_eval = function | { Parsetree . pstr_desc = Parsetree . Pstr_eval _ } -> true | _ -> false |
let rule_of_type typ = match get_desc ( Ctype . expand_head ! Toploop . toplevel_env typ ) with | Types . Tconstr ( path , _ , _ ) -> begin try Some ( List . find ( fun rule -> rule_matches rule path ) rewrite_rules ) with _ -> None end | _ -> None |
let rewrite_str_item pstr_item tstr_item = match pstr_item , tstr_item . Typedtree . str_desc with | ( { Parsetree . pstr_desc = Parsetree . Pstr_eval ( e , _ ) ; Parsetree . pstr_loc = loc } , Typedtree . Tstr_eval ( { Typedtree . exp_type = typ } , _ ) ) -> begin match rule_of_type typ with | Some rule -> { Parsetree... |
let type_structure env pstr = let tstr , _ , _ , _ , _ = Typemod . type_structure env pstr in let tstr , _ , _ , _ = Typemod . type_structure env pstr in let tstr , _ , _ , _ = Typemod . type_structure env pstr Location . none in # else let tstr , _ , _ = Typemod . type_structure env pstr Location . none in # endif tst... |
let rewrite phrase = match phrase with | Parsetree . Ptop_def pstr -> if ( UTop . get_auto_run_lwt ( ) || UTop . get_auto_run_async ( ) ) && List . exists is_eval pstr then let tstr = type_structure ! Toploop . toplevel_env pstr in Parsetree . Ptop_def ( List . map2 rewrite_str_item pstr tstr . Typedtree . str_items ) ... |
let add_let binding_name def = let open Parsetree in match def with | { pstr_desc = Pstr_eval ( expr , attr ) ; pstr_loc } -> { pstr_loc ; pstr_desc = Pstr_value ( Asttypes . Nonrecursive , [ { pvb_pat = { ppat_desc = Ppat_var { txt = binding_name ; loc = pstr_loc ; } ; ppat_loc_stack = [ ] ; # endif ppat_loc = pstr_lo... |
let bind_expressions name phrase = match phrase with | Parsetree . Ptop_def pstr -> Parsetree . Ptop_def ( List . map ( add_let name ) pstr ) | Parsetree . Ptop_dir _ -> phrase module Persistent_signature = Persistent_env . Persistent_signature # else module Persistent_signature = Env . Persistent_signature # endif |
let execute_phrase = let new_cmis = ref [ ] in let default_load = ! Persistent_signature . load in let load ~ unit_name = let res = default_load ~ unit_name in ( match res with None -> ( ) | Some x -> new_cmis := x . cmi :: ! new_cmis ) ; res in Persistent_signature . load := load ; let rec collect_printers path signat... |
let execute_phrase = Toploop . execute_phrase # endif |
let rec read_phrase term = Lwt . catch ( fun ( ) -> let read_line = new read_phrase ~ term in ( match ! UTop . edit_mode with | LTerm_editor . Default -> ( ) | LTerm_editor . Vi as mode -> read_line # set_editor_mode mode ) ; let vi_state = read_line # vi_state in vi_state # set_registers ! registers ; read_line # run ... |
let print_error term msg = LTerm . set_style term styles . style_error >>= fun ( ) -> Lwt_io . print msg >>= fun ( ) -> LTerm . set_style term LTerm_style . none >>= fun ( ) -> LTerm . flush term |
let rec loop term = UTop_complete . reset ( ) ; UTop_private . set_count ( S . value UTop_private . count + 1 ) ; LTerm_dlist . iter_l ( fun f -> f ( ) ) UTop . new_command_hooks ; let phrase_opt = Lwt_main . run ( Lwt . finalize ( fun ( ) -> read_phrase term >>= fun ( result , warnings ) -> Lwt_io . print warnings >>=... |
let welcome term = let size = LTerm . size term in let size = { rows = 3 ; cols = size . cols } in let matrix = LTerm_draw . make_matrix size in let ctx = LTerm_draw . context matrix size in let message = Printf . sprintf " Welcome to utop version % s ( using OCaml version % s ) " ! UTop . version Sys . ocaml_version i... |
let read_input_classic prompt buffer len = let rec loop i = if i = len then return ( i , false ) else Lwt_io . read_char_opt Lwt_io . stdin >>= function | Some c -> Bytes . set buffer i c ; if c = ' \ n ' then return ( i + 1 , false ) else loop ( i + 1 ) | None -> return ( i , true ) in Lwt_main . run ( Lwt_io . write ... |
module Emacs ( M : sig end ) = struct let command_oc = Unix . out_channel_of_descr ( Unix . dup Unix . stdout ) let split_at ( ? trim = false ) ch str = let rec aux acc i j = if j = String . length str then if trim && i = j then acc else ( String . sub str i ( j - i ) ) :: acc else if str . [ j ] = ch then aux ( String... |
let typeof sid = let id = longident_parse sid in let env = ! Toploop . toplevel_env in let lookup_value = Env . find_value_by_name and lookup_label = Env . find_label_by_name and lookup_modtype = Env . find_modtype_by_name and lookup_module id env = let path , decl = Env . find_module_by_name id env in ( path , decl . ... |
let default_info = { Toploop . section = " UTop " ; doc = " " ; } |
let ( ) = Toploop . add_directive " typeof " ( Toploop . Directive_string typeof ) default_info |
let emacs_mode = ref false |
let preload = ref [ ] |
let prepare ( ) = Toploop . set_paths ( ) ; try let ok = List . for_all ( function | ` Packages l -> UTop . require l ; true | ` Object fn -> Toploop . load_file Format . err_formatter fn ) # else Topdirs . load_file Format . err_formatter fn ) # endif ( List . rev ! preload ) in if ok then ! Toploop . toplevel_startup... |
let override_argv ( ) = let len = Array . length Sys . argv - ! Arg . current in let copy = Array . init len ( fun i -> Sys . argv . ( i + ! Arg . current ) ) in caml_sys_modify_argv copy ; Arg . current := 0 # else |
let override_argv ( ) = let len = Array . length Sys . argv - ! Arg . current in Array . blit Sys . argv ! Arg . current Sys . argv 0 len ; Obj . truncate ( Obj . repr Sys . argv ) len ; Arg . current := 0 # endif |
let run_script name = Sys . interactive := false ; if not ( prepare ( ) ) then exit 2 ; override_argv ( ) ; Toploop . initialize_toplevel_env ( ) ; Location . input_name := UTop . input_name ; if toploop_use_silently Format . err_formatter name then exit 0 else exit 2 |
let file_argument name = if Filename . check_suffix name " . cmo " || Filename . check_suffix name " . cma " then preload := ` Object name :: ! preload else run_script name |
let print_version ( ) = Printf . printf " The universal toplevel for OCaml , version % s , compiled for OCaml version % s \ n " UTop . version Sys . ocaml_version ; exit 0 |
let print_version_num ( ) = Printf . printf " % s \ n " UTop . version ; exit 0 |
let autoload = ref true |
let args = Arg . align [ " - absname " , Arg . Set Clflags . absname , " Show absolute filenames in error message " ; # else " - absname " , Arg . Set Location . absname , " Show absolute filenames in error message " ; # endif " - I " , Arg . String ( fun dir -> Clflags . include_dirs := dir :: ! Clflags . include_dirs... |
let ( ) = Clflags . real_paths := false |
let app_name = Filename . basename Sys . executable_name |
let usage = Printf . sprintf " Usage : % s < options > < object - files > [ script - file [ arguments ] ] \ noptions are " : app_name |
let load_init_files dir = let files = Sys . readdir dir in Array . sort String . compare files ; Array . iter ( fun fn -> if Filename . check_suffix fn " . ml " then ignore ( toploop_use_silently Format . err_formatter ( Filename . concat dir fn ) : bool ) ) files ; ; |
let common_init ~ initial_env = ( match initial_env with | None -> Toploop . initialize_toplevel_env ( ) | Some env -> Toploop . toplevel_env := env ) ; Location . input_name := UTop . input_name ; Sys . catch_break true ; ( match try Some ( Sys . getenv " OCAML_TOPLEVEL_PATH " ) with Not_found -> None with | Some dir ... |
let load_inputrc ( ) = Lwt . catch LTerm_inputrc . load ( function | Unix . Unix_error ( error , func , arg ) -> Lwt_log . error_f " cannot load key bindings from % S : % s : % s " LTerm_inputrc . default func ( Unix . error_message error ) | LTerm_inputrc . Parse_error ( fname , line , msg ) -> Lwt_log . error_f " err... |
let main_aux ~ initial_env = Arg . parse args file_argument usage ; Topcommon . load_topdirs_signature ( ) ; # endif if not ( prepare ( ) ) then exit 2 ; if ! emacs_mode then begin Printf . printf " protocol - version :% d \ n " %! protocol_version ; UTop_private . set_ui UTop_private . Emacs ; let module Emacs = Emacs... |
let main_internal ~ initial_env = let exit_status = ref 2 in try main_aux ~ initial_env with exn -> ( match exn with | Unix . Unix_error ( error , func , " " ) -> Printf . eprintf " % s : % s : % s \ n " app_name func ( Unix . error_message error ) | Unix . Unix_error ( error , func , arg ) -> Printf . eprintf " % s : ... |
let main ( ) = main_internal ~ initial_env : None |
type value = V : string * _ -> value |
let get_required_label name args = match List . find ( fun ( lab , _ ) -> lab = Asttypes . Labelled name ) args with | _ , x -> x | exception Not_found -> None # else |
let get_required_label name args = match List . find ( fun ( lab , _ , k ) -> lab = " loc " && k = Typedtree . Required ) args with | _ , x , _ -> x | _ -> None | exception Not_found -> None # endif |
let walk dir ~ init ~ f = let rec loop dir acc = let acc = f dir acc in ArrayLabels . fold_left ( Sys . readdir dir ) ~ init : acc ~ f ( : fun acc fn -> let fn = Filename . concat dir fn in match Unix . lstat fn with | { st_kind = S_DIR ; _ } -> loop fn acc | _ -> acc ) in match Unix . lstat dir with | exception Unix .... |
let interact ( ? search_path [ ] ) = ( ? build_dir " = _build " ) ~ unit ~ loc ( : fname , lnum , cnum , _ ) ~ values = let search_path = walk build_dir ~ init : search_path ~ f ( : fun dir acc -> dir :: acc ) in let cmt_fname = try Misc . find_in_path_uncap search_path ( unit ^ " . cmt " ) with Not_found -> Printf . k... |
let ( ) = Location . register_error_of_exn ( function | Envaux . Error err -> Some ( Location . error_of_printer_file Envaux . report_error err ) | _ -> None ) |
let print_fan_error pp exn = Format . fprintf pp " [ @< 0 >% s ] . " @@ ( Printexc . to_string exn ) |
let get_fan_error_message exn = let ( loc , exn ) = match exn with | Locf . Exc_located ( loc , exn ) -> ( ( loc . loc_start . pos_cnum , loc . loc_end . pos_cnum ) , exn ) | exn -> ( ( 0 , 0 ) , exn ) in let msg = UTop . get_message print_fan_error exn in let idx = ref ( String . length msg - 1 ) in begin while ! idx ... |
let revise_parser str _eos_is_error = let eof = ref false in let lexbuf = UTop . lexbuf_of_string eof str in try let stream = Lex_fan . from_lexbuf lexbuf in match Streamf . peek stream with | Some ( ` EOI _ ) -> ( Streamf . junk stream ; raise End_of_file ) | _ -> UTop . Value ( Mktop . toplevel_phrase stream ) with |... |
let normal ( ) = begin UTop . parse_toplevel_phrase := UTop . parse_toplevel_phrase_default ; UTop . parse_use_file := UTop . parse_use_file_default ; end ; ; |
let fan ( ) = begin UTop . parse_toplevel_phrase := revise_parser ; Toploop . parse_use_file := Mktop . wrap Mktop . use_file ~ print_location : Toploop . print_location ; end ; ; begin Hashtbl . replace Toploop . directive_table " fan " ( Toploop . Directive_none ( fun ( ) -> fan ( ) ) ) ; Hashtbl . replace Toploop . ... |
let ( ) = UTop_main . main ( ) ; ; |
let size , set_size = let ev , set_size = E . create ( ) in let init = S . const { LTerm_geom . rows = 25 ; LTerm_geom . cols = 80 } in ( S . switch ( S . hold ~ eq ( : == ) init ev ) , set_size ) |
let key_sequence , set_key_sequence = let ev , set_key_sequence = E . create ( ) in let init = ( S . const ( [ ] : LTerm_key . t list ) ) in ( S . switch ( S . hold ~ eq ( : == ) init ev ) , set_key_sequence ) |
let count , set_count = S . create ( - 1 ) |
type ui = Console | Emacs |
let ui , set_ui = S . create Console |
let error_style = ref LTerm_style . none |
let autoload = ref true |
let margin_function , set_margin_function = S . create ~ eq ( : == ) ( fun ( size : LTerm_geom . size ) -> Some ( min 80 size . cols ) ) |
let margin = S . app margin_function size |
let set_margin pp = match S . value margin with | None -> ( ) | Some n -> if Format . pp_get_margin pp ( ) <> n then Format . pp_set_margin pp n |
let return , ( ) >>= = Lwt . return , Lwt . ( ) >>= |
module String_set = Set . Make ( String ) |
type styles = { mutable style_keyword : LTerm_style . t ; mutable style_symbol : LTerm_style . t ; mutable style_ident : LTerm_style . t ; mutable style_module : LTerm_style . t ; mutable style_constant : LTerm_style . t ; mutable style_char : LTerm_style . t ; mutable style_string : LTerm_style . t ; mutable style_quo... |
let styles = { style_keyword = LTerm_style . none ; style_symbol = LTerm_style . none ; style_ident = LTerm_style . none ; style_module = LTerm_style . none ; style_constant = LTerm_style . none ; style_char = LTerm_style . none ; style_string = LTerm_style . none ; style_quotation = LTerm_style . none ; style_comment ... |
let load ( ) = let fn = Filename . concat LTerm_resources . home " . utoprc " in Lwt . catch ( fun ( ) -> LTerm_resources . load fn >>= fun res -> styles . style_keyword <- LTerm_resources . get_style " keyword " res ; styles . style_symbol <- LTerm_resources . get_style " symbol " res ; styles . style_ident <- LTerm_r... |
let stylise_filter_layout stylise tokens = let aux acc = function | ( Comment ( Comment_reg , _ ) , loc ) -> stylise loc styles . style_comment ; acc | ( Comment ( Comment_doc , _ ) , loc ) -> stylise loc styles . style_doc ; acc | ( Blanks , loc ) -> stylise loc styles . style_blanks ; acc | x -> x :: acc in List . re... |
let rec stylise_rec stylise tokens = match tokens with | [ ] -> ( ) | ( Symbol _ , loc ) :: tokens -> stylise loc styles . style_symbol ; stylise_rec stylise tokens | ( Lident id , loc ) :: tokens -> stylise loc ( if String_set . mem id ! UTop . keywords then styles . style_keyword else styles . style_ident ) ; stylise... |
let stylise stylise tokens = let tokens = stylise_filter_layout stylise tokens in match tokens with | ( Symbol " " , # loc ) :: tokens -> begin stylise loc styles . style_directive ; match tokens with | ( ( Lident id | Uident id ) , loc ) :: tokens -> stylise loc ( if String_set . mem id ! UTop . keywords then styles .... |
type location = { idx1 : int ; idx2 : int ; ofs1 : int ; ofs2 : int ; } |
type t = | Symbol of string | Lident of string | Uident of string | Constant of string | Char | String of int * bool | Comment of comment_kind * bool | Blanks | Error | Quotation of ( quotation_item * location ) list * bool | Comment_reg | Comment_doc | Quot_data | Quot_anti of antiquotation a_opening : location ; a_cl... |
let str_of_name ( u , l ) = str " { % s } % s " u l |
let split_string s sep = let rec split accum j = let i = try ( String . rindex_from s j sep ) with Not_found -> - 1 in if ( i = - 1 ) then let p = String . sub s 0 ( j + 1 ) in if p <> " " then p :: accum else accum else let p = String . sub s ( i + 1 ) ( j - i ) in let accum ' = if p <> " " then p :: accum else accum ... |
let err s = failwith s |
let err_data = " character data not allowed here " |
let err_exp_el_end = " expected end of element " |
let err_exp_data = " expected character data " |
let err_wf = " document not well formed " |
let err_dup n = str " duplicate element ( % s ) " ( str_of_name n ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.