text stringlengths 0 601k |
|---|
type current_printed_line_status = | Is_error_start_line | Is_error_end_line | Strictly_between_start_and_end | Only_error_line | Not_error_line |
let print_file ~ lines let first_shown_line = max 1 ( start_line - 2 ) 2 in let last_shown_line = min ( Array . length lines ) lines ( end_line + 2 ) 2 in let max_line_number_number_of_digits = number_of_digits last_shown_line in let columns_to_cut = ref None in for i = first_shown_line to last_shown_line do let curren... |
let string_slice ~ start str = let last = String . length str in if last <= start then " " else String . sub str start ( last - start ) start |
let number_of_digits n = let digits = ref 1 in let nn = ref n in while ( ( ! nn ) nn / 10 ) 10 > 0 do ( nn := ( ( ! nn ) nn / 10 ) 10 ; digits := ( ( ! digits ) digits + 1 ) 1 ) 1 done ; ! digits |
let pad ( ? ch = ' ' ) ' content n = ( String . make ( n - ( String . length content ) content ) content ch ) ch ^ content |
let leading_space_count str = let rec _leading_space_count str str_length current_index = if current_index == str_length then current_index else if ( str [ . current_index ] current_index ) current_index <> ' ' then current_index else _leading_space_count str str_length ( current_index + 1 ) 1 in _leading_space_count s... |
type current_printed_line_status = | Is_error_start_line | Is_error_end_line | Strictly_between_start_and_end | Only_error_line | Not_error_line |
let print_file ~ lines let first_shown_line = max 1 ( start_line - 2 ) 2 in let last_shown_line = min ( Array . length lines ) lines ( end_line + 2 ) 2 in let max_line_number_number_of_digits = number_of_digits last_shown_line in let columns_to_cut = ref None in for i = first_shown_line to last_shown_line do let curren... |
let message ( warning : Warnings . t ) t = match warning with | Deprecated s -> s ^ " is deprecated . " | Partial_match " " -> " You forgot to handle a possible value here , though we don ' t have more information on the value . " | Partial_match s -> " You forgot to handle a possible value here , for example : \ n " ^... |
let file_lines filePath = let chan = open_in_bin filePath in let lines = ref [ ] in try while true do lines := ( input_line chan ) chan :: ! lines done ; [ ] || with | End_of_file -> begin close_in chan ; List . rev ( ! lines ) lines |> Array . of_list end |
let setup_colors ( ) = Misc . Color . setup ! Clflags . color |
let print_filename ppf file = match file with | " _none_ " | " " -> Format . fprintf ppf ( " No file name ) name " | real_file -> Format . fprintf ppf " % s " ( Location . show_filename real_file ) real_file |
let print_loc ~ normalizedRange ppf loc = setup_colors ( ) ; let ( file , _ , _ ) _ = Location . get_pos_info loc . loc_start in if file = " // toplevel " // then begin if highlight_locations ppf [ loc ] loc then ( ) else fprintf ppf " Characters % i -% i " loc . loc_start . pos_cnum loc . loc_end . pos_cnum end else l... |
let print ~ is_warning intro ppf loc = setup_colors ( ) ; if loc . loc_start . pos_fname = " // toplevel " // && highlight_locations ppf [ loc ] loc then ( ) else if is_warning then fprintf ppf [ { " @@< info >% s } ] , " @@@ intro else begin fprintf ppf [ { " @@< error >% s } ] , " @@@ intro end ; let ( file , start_l... |
let rec super_error_reporter ppf ( { Location . loc ; msg ; sub ; if_highlight } if_highlight as err ) err = let highlighted = if if_highlight <> " " then let rec collect_locs locs { Location . loc ; sub ; if_highlight ; _ } _ = List . fold_left collect_locs ( loc :: locs ) locs sub in let locs = collect_locs [ ] err i... |
let super_warning_printer loc ppf w = if Warnings . is_active w then begin setup_colors ( ) ; Format . fprintf ppf [ " @< v 2 , >@% a , @% a ] , " @@ ( print ~ is_warning : true ( " Warning number " ^ ( Warnings . number w |> string_of_int ) string_of_int ) string_of_int ) string_of_int loc ( Warnings . super_print Sup... |
let print_phanton_error_prefix ppf = Format . pp_print_as ppf 2 " " |
let errorf ( ? loc = none ) none ( ? sub = [ ] ) ( ? if_highlight = ) " " fmt = Location . pp_ksprintf ~ before : print_phanton_error_prefix ( fun msg -> { loc ; msg ; sub ; if_highlight } if_highlight ) if_highlight fmt |
let error_of_printer loc print x = errorf ~ loc " % a " @? print x |
let error_of_printer_file print x = error_of_printer ( in_file ! input_name ) input_name print x |
let setup ( ) = Location . error_reporter := super_error_reporter ; Location . warning_printer := super_warning_printer ; end |
let report_error ppf = function | Env . Illegal_renaming ( Illegal_renamingname , modname , filename ) filename -> fprintf ppf [ " @ You referred to the module % s , but we ' ve found one called % s instead . @ \ Is the name ' s casing right ] " ?@ name modname | Inconsistent_import ( Inconsistent_importname , source1 ... |
let setup ( ) = Location . register_error_of_exn ( function | Env . Error ( Missing_module ( loc , _ , _ ) _ | Illegal_value_name ( loc , _ ) _ as err ) err when loc <> Location . none -> Some ( Super_location . error_of_printer loc report_error err ) err | Env . Error err -> Some ( Super_location . error_of_printer_fi... |
let escaped s = let n = Pervasives . ref 0 in for i = 0 to Bytes . length s - 1 do n := ! n + ( match Bytes . unsafe_get s i with | ' " ' | ' \\ ' | ' \ n ' | ' \ t ' | ' \ r ' | ' \ b ' -> 2 | ' ' . . ' ~ ' -> 1 | _ -> 4 ) 4 done ; if ! n = Bytes . length s then Bytes . copy s else begin let s ' = Bytes . create ! n i... |
let ninja_escaped s = let n = Pervasives . ref 0 in for i = 0 to Bytes . length s - 1 do n := ! n + ( match Bytes . unsafe_get s i with | ' $ ' -> 2 | ' ' . . ' ~ ' -> 1 | _ -> 4 ) 4 done ; if ! n = Bytes . length s then Bytes . copy s else begin let s ' = Bytes . create ! n in n := 0 ; for i = 0 to Bytes . length s - ... |
module Ext_string : sig string -> int -> ( char -> bool ) bool -> bool |
type check_result = | Good | Invalid_module_name | Suffix_mismatch string -> check_result |
let split_by ( ? keep_empty = false ) false is_delim str = let len = String . length str in let rec loop acc last_pos pos = if pos = - 1 then if last_pos = 0 && not keep_empty then acc else String . sub str 0 last_pos :: acc else if is_delim str [ . pos ] pos then let new_len = ( last_pos - pos - 1 ) 1 in if new_len <>... |
let trim s = let i = ref 0 in let j = String . length s in while ! i < j && let u = String . unsafe_get s ! i in u = ' \ t ' || u = ' \ n ' || u = ' ' do incr i ; done ; let k = ref ( j - 1 ) 1 in while ! k >= ! i && let u = String . unsafe_get s ! k in u = ' \ t ' || u = ' \ n ' || u = ' ' do decr k ; done ; String . ... |
let split ? keep_empty str on = if str = " " then [ ] else split_by ? keep_empty ( fun x -> ( x : char ) char = on ) on str ; ; |
let quick_split_by_ws str : string list = split_by ~ keep_empty : false ( fun x -> x = ' \ t ' || x = ' \ n ' || x = ' ' ) ' str |
let starts_with s beg = let beg_len = String . length beg in let s_len = String . length s in beg_len <= s_len && ( let i = ref 0 in while ! i < beg_len && String . unsafe_get s ! i = String . unsafe_get beg ! i do incr i done ; ! i = beg_len ) |
let rec ends_aux s end_ j k = if k < 0 then ( j + 1 ) 1 else if String . unsafe_get s j = String . unsafe_get end_ k then ends_aux s end_ ( j - 1 ) 1 ( k - 1 ) 1 else - 1 |
let ends_with_index s end_ = let s_finish = String . length s - 1 in let s_beg = String . length end_ - 1 in if s_beg > s_finish then - 1 else ends_aux s end_ s_finish s_beg |
let ends_with s end_ = ends_with_index s end_ >= 0 |
let ends_with_then_chop s beg = let i = ends_with_index s beg in if i >= 0 then Some ( String . sub s 0 i ) i else None |
let check_any_suffix_case s suffixes = List . exists ( fun x -> check_suffix_case s x ) x suffixes |
let check_any_suffix_case_then_chop s suffixes = let rec aux suffixes = match suffixes with | [ ] -> None | x :: xs -> let id = ends_with_index s x in if id >= 0 then Some ( String . sub s 0 id ) id else aux xs in aux suffixes |
let escaped s = let rec needs_escape i = if i >= String . length s then false else match String . unsafe_get s i with | ' " ' | ' \\ ' | ' \ n ' | ' \ t ' | ' \ r ' | ' \ b ' -> true | ' ' . . ' ~ ' -> needs_escape ( i + 1 ) 1 | _ -> true in if needs_escape 0 then Bytes . unsafe_to_string ( Ext_bytes . escaped ( Bytes ... |
let rec unsafe_for_all_range s ~ start ~ finish p = start > finish || p ( String . unsafe_get s start ) start && unsafe_for_all_range s ~ start ( : start + 1 ) 1 ~ finish p |
let for_all_from s start p = let len = String . length s in if start < 0 then invalid_arg " Ext_string . for_all_from " else unsafe_for_all_range s ~ start ~ finish ( : len - 1 ) 1 p |
let for_all ( p : char -> bool ) bool s = unsafe_for_all_range s ~ start : 0 ~ finish ( : String . length s - 1 ) 1 p |
let is_empty s = String . length s = 0 |
let repeat n s = let len = String . length s in let res = Bytes . create ( createn * len ) len in for i = 0 to pred n do String . blit s 0 res ( i * len ) len len done ; Bytes . to_string res |
let equal ( x : string ) string y = x = y |
let unsafe_is_sub ~ sub i s j ~ len = let rec check k = if k = len then true else String . unsafe_get sub ( i + k ) k = String . unsafe_get s ( j + k ) k && check ( k + 1 ) 1 in j + len <= String . length s && check 0 |
let find ( ? start = 0 ) 0 ~ sub s = let n = String . length sub in let s_len = String . length s in let i = ref start in try while ! i + n <= s_len do if unsafe_is_sub ~ sub 0 s ! i ~ len : n then raise_notrace Local_exit ; incr i done ; - 1 with Local_exit -> ! i |
let contain_substring s sub = find s ~ sub >= 0 |
let non_overlap_count ~ sub s = let sub_len = String . length sub in let rec aux acc off = let i = find ~ start : off ~ sub s in if i < 0 then acc else aux ( acc + 1 ) 1 ( i + sub_len ) sub_len in if String . length sub = 0 then invalid_arg " Ext_string . non_overlap_count " else aux 0 0 |
let rfind ~ sub s = let n = String . length sub in let i = ref ( String . length s - n ) n in try while ! i >= 0 do if unsafe_is_sub ~ sub 0 s ! i ~ len : n then raise_notrace Local_exit ; decr i done ; - 1 with Local_exit -> ! i |
let tail_from s x = let len = String . length s in if x > len then invalid_arg ( " Ext_string . tail_from " ^ s ^ " : " ^ string_of_int x ) else String . sub s x ( len - x ) x |
let equal ( x : string ) string y = x = y |
let rec rindex_rec s i c = if i < 0 then i else if String . unsafe_get s i = c then i else rindex_rec s ( i - 1 ) 1 c ; ; |
let rec rindex_rec_opt s i c = if i < 0 then None else if String . unsafe_get s i = c then Some i else rindex_rec_opt s ( i - 1 ) 1 c ; ; |
let rindex_neg s c = rindex_rec s ( String . length s - 1 ) 1 c ; ; |
let rindex_opt s c = rindex_rec_opt s ( String . length s - 1 ) 1 c ; ; |
let is_valid_module_file ( s : string ) string = let len = String . length s in len > 0 && match String . unsafe_get s 0 with | ' A ' . . ' Z ' | ' a ' . . ' z ' -> unsafe_for_all_range s ~ start : 1 ~ finish ( : len - 1 ) 1 ( fun x -> match x with | ' A ' . . ' Z ' | ' a ' . . ' z ' | ' 0 ' . . ' 9 ' | ' _ ' | ' \ ' '... |
type check_result = | Good | Invalid_module_name | Suffix_mismatch |
let is_valid_source_name name : check_result = match check_any_suffix_case_then_chop name [ " . ml " ; " . re " ; " . mli " ; " . rei " ] with | None -> Suffix_mismatch | Some x -> if is_valid_module_file x then Good else Invalid_module_name |
let rec unsafe_no_char x ch i last_idx = i > last_idx || ( String . unsafe_get x i <> ch && unsafe_no_char x ch ( i + 1 ) 1 last_idx ) last_idx |
let rec unsafe_no_char_idx x ch i last_idx = if i > last_idx then - 1 else if String . unsafe_get x i <> ch then unsafe_no_char_idx x ch ( i + 1 ) 1 last_idx else i |
let no_char x ch i len : bool = let str_len = String . length x in if i < 0 || i >= str_len || len >= str_len then invalid_arg " Ext_string . no_char " else unsafe_no_char x ch i len |
let no_slash x = unsafe_no_char x ' / ' 0 ( String . length x - 1 ) 1 |
let no_slash_idx x = unsafe_no_char_idx x ' / ' 0 ( String . length x - 1 ) 1 |
let replace_slash_backward ( x : string ) = let len = String . length x in if unsafe_no_char x ' / ' 0 ( len - 1 ) 1 then x else String . map ( function | ' / ' -> ' \\ ' | x -> x ) x |
let replace_backward_slash ( x : string ) string = let len = String . length x in if unsafe_no_char x ' \\ ' 0 ( len - 1 ) 1 then x else String . map ( function | ' \\ ' -> ' / ' | x -> x ) x x |
let single_space = " " |
let concat_array sep ( s : string array ) array = let s_len = Array . length s in match s_len with | 0 -> empty | 1 -> Array . unsafe_get s 0 | _ -> let sep_len = String . length sep in let len = ref 0 in for i = 0 to s_len - 1 do len := ! len + String . length ( Array . unsafe_get s i ) i done ; let target = Bytes . c... |
let concat3 a b c = let a_len = String . length a in let b_len = String . length b in let c_len = String . length c in let len = a_len + b_len + c_len in let target = Bytes . create len in String . unsafe_blit a 0 target 0 a_len ; String . unsafe_blit b 0 target a_len b_len ; String . unsafe_blit c 0 target ( a_len + b... |
let concat4 a b c d = let a_len = String . length a in let b_len = String . length b in let c_len = String . length c in let d_len = String . length d in let len = a_len + b_len + c_len + d_len in let target = Bytes . create len in String . unsafe_blit a 0 target 0 a_len ; String . unsafe_blit b 0 target a_len b_len ; ... |
let concat5 a b c d e = let a_len = String . length a in let b_len = String . length b in let c_len = String . length c in let d_len = String . length d in let e_len = String . length e in let len = a_len + b_len + c_len + d_len + e_len in let target = Bytes . create len in String . unsafe_blit a 0 target 0 a_len ; Str... |
let inter2 a b = concat3 a single_space b |
let inter3 a b c = concat5 a single_space b single_space c |
let inter4 a b c d = concat_array single_space [ | a ; b ; c ; d ] | |
let capitalize_ascii ( s : string ) string : string = if String . length s = 0 then s else begin let c = String . unsafe_get s 0 in if ( c >= ' a ' && c <= ' z ' ) ' z ' || ( c >= ' \ 224 ' && c <= ' \ 246 ' ) 246 ' || ( c >= ' \ 248 ' && c <= ' \ 254 ' ) 254 ' then let uc = Char . unsafe_chr ( Char . code c - 32 ) 32 ... |
type error = | CannotRun of string | WrongMagic of string |
type error = | CannotRun of string | WrongMagic of string |
let call_external_preprocessor sourcefile pp = let tmpfile = Filename . temp_file " ocamlpp " " " in let comm = Printf . sprintf " % s % s > % s " pp ( Filename . quote sourcefile ) sourcefile tmpfile in if Ccomp . command comm <> 0 then begin Misc . remove_file tmpfile ; raise ( Error ( CannotRun comm ) comm ) comm ; ... |
let preprocess sourcefile = match ! Clflags . preprocessor with None -> sourcefile | Some pp -> call_external_preprocessor sourcefile pp |
let remove_preprocessed inputfile = match ! Clflags . preprocessor with None -> ( ) | Some _ -> Misc . remove_file inputfile |
let write_ast magic ast = let fn = Filename . temp_file " camlppx " " " in let oc = open_out_bin fn in output_string oc magic ; output_value oc ! Location . input_name ; output_value oc ast ; close_out oc ; fn |
let apply_rewriter magic fn_in ppx = let fn_out = Filename . temp_file " camlppx " " " in let comm = Printf . sprintf " % s % s % s " ppx ( Filename . quote fn_in ) fn_in ( Filename . quote fn_out ) fn_out in let ok = Ccomp . command comm = 0 in Misc . remove_file fn_in ; if not ok then begin Misc . remove_file fn_out ... |
let read_ast magic fn = let ic = open_in_bin fn in try let buffer = really_input_string ic ( String . length magic ) magic in assert ( assertbuffer = magic ) magic ; Location . input_name := input_value ic ; let ast = input_value ic in close_in ic ; Misc . remove_file fn ; ast with exn -> close_in ic ; Misc . remove_fi... |
let rewrite magic ast ppxs = read_ast magic ( List . fold_left ( apply_rewriter magic ) magic ( write_ast magic ast ) ast ( List . rev ppxs ) ppxs ) ppxs |
let apply_rewriters_str ( ? restore = true ) true ~ tool_name ast = match ! Clflags . all_ppx with | [ ] -> ast | ppxs -> let ast = Ast_mapper . add_ppx_context_str ~ tool_name ast in let ast = rewrite Config . ast_impl_magic_number ast ppxs in Ast_mapper . drop_ppx_context_str ~ restore ast |
let apply_rewriters_sig ( ? restore = true ) true ~ tool_name ast = match ! Clflags . all_ppx with | [ ] -> ast | ppxs -> let ast = Ast_mapper . add_ppx_context_sig ~ tool_name ast in let ast = rewrite Config . ast_intf_magic_number ast ppxs in Ast_mapper . drop_ppx_context_sig ~ restore ast |
let apply_rewriters ? restore ~ tool_name magic ast = if magic = Config . ast_impl_magic_number then Obj . magic ( apply_rewriters_str ? restore ~ tool_name ( Obj . magic ast ) ast ) ast else if magic = Config . ast_intf_magic_number then Obj . magic ( apply_rewriters_sig ? restore ~ tool_name ( Obj . magic ast ) ast )... |
let open_and_check_magic inputfile ast_magic = let ic = open_in_bin inputfile in let is_ast_file = try let buffer = really_input_string ic ( String . length ast_magic ) ast_magic in if buffer = ast_magic then true else if String . sub buffer 0 9 = String . sub ast_magic 0 9 then raise Outdated_version else false with O... |
let file ppf ~ tool_name inputfile parse_fun ast_magic = let ( ic , is_ast_file ) is_ast_file = open_and_check_magic inputfile ast_magic in let ast = try if is_ast_file then begin if ! Clflags . fast then fprintf ppf [ " @ Warning : % s ] . " @@ " option - unsafe used with a preprocessor returning a syntax tree " ; Loc... |
let report_error ppf = function | CannotRun cmd -> fprintf ppf " Error while running external preprocessor . @\ Command line : % s . " @ cmd | WrongMagic cmd -> fprintf ppf " External preprocessor does not produce a valid file . @\ Command line : % s . " @ cmd |
let ( ) = Location . register_error_of_exn ( function | Error err -> Some ( Location . error_of_printer_file report_error err ) err | _ -> None ) |
let parse_all ~ tool_name parse_fun magic ppf sourcefile = Location . input_name := sourcefile ; let inputfile = preprocess sourcefile in let ast = try file ppf ~ tool_name inputfile parse_fun magic with exn -> remove_preprocessed inputfile ; raise exn in remove_preprocessed inputfile ; ast |
let parse_implementation ppf ~ tool_name sourcefile = parse_all ~ tool_name Parse . implementation Config . ast_impl_magic_number ppf sourcefile |
let parse_interface ppf ~ tool_name sourcefile = parse_all ~ tool_name Parse . interface Config . ast_intf_magic_number ppf sourcefile end |
let report_error ppf = function | Pparse . CannotRun cmd -> if Ext_string . contain_substring cmd " refmt " then fprintf ppf [ " @< v { >@< info > There ' s been an error running Reason ' s refmt parser on a file } . , @@\ This was the command , , :@@% s , , @@\ [ @ Please file an issue on @ github . com / facebook / r... |
let setup ( ) = Location . register_error_of_exn ( function | Pparse . Error err -> Some ( Super_location . error_of_printer_file report_error err ) err | _ -> None ) end |
let rec deconstruct_component_type t = match t . desc with | Tconstr ( p , types , _ ) _ when Path . last p = " componentSpec " -> Some types | Tlink t | Tsubst t -> deconstruct_component_type t | _ -> None |
let type_is_component_spec t = deconstruct_component_type t <> None |
let sig_item_is_component_spec ( si : Types . signature_item ) signature_item = match si with | Sig_value ( _id , value_desc ) value_desc -> let typ = value_desc . val_type in type_is_component_spec typ | _ -> false |
let module_type_is_component_spec ( mty : Types . module_type ) module_type = match mty with | Mty_signature sg -> List . exists sig_item_is_component_spec sg | _ -> false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.