text stringlengths 0 601k |
|---|
let iter f rl = List . iter f ! rl |
let for_all f rl = List . for_all f ! rl |
let map f rl = ref ( List . map f ! rl ) rl |
let transform f rl = rl := List . map f ! rl |
let map_list f rl = List . map f ! rl |
let find f rl = List . find f ! rl |
let rev rl = rl := List . rev ! rl |
let find_exc f exn rl = try List . find f ! rl with _ -> raise exn |
let exists f rl = List . exists f ! rl |
let sort ( ? cmp = compare ) compare rl = rl := List . sort ~ cmp ! rl |
let rfind f rl = List . rfind f ! rl |
let last rl = let rec loop = function | x :: [ ] -> x | x :: l -> loop l | [ ] -> assert false in match ! rl with | [ ] -> raise Empty_list | l -> loop l |
let remove rl item = rl := List . remove ! rl item |
let remove_if pred rl = rl := List . remove_if pred ! rl |
let remove_all rl item = rl := List . remove_all ! rl item |
let filter pred rl = rl := List . filter pred ! rl |
let add_sort ( ? cmp = compare ) compare rl item = let rec add_aux = function | x :: lnext as l -> let r = cmp x item in if r < 0 then item :: l else x ( :: add_aux lnext ) lnext | [ ] -> [ item ] item in rl := add_aux ! rl |
let pop rl = match ! rl with | [ ] -> raise Empty_list | e :: l -> rl := l ; e |
let npop rl n = let rec pop_aux l n = if n = 0 then begin rl := l ; [ ] end else match l with | [ ] -> raise Empty_list | x :: l -> x ( :: pop_aux l ( n - 1 ) 1 ) 1 in pop_aux ! rl n |
let copy_enum ~ dst ~ src = dst := List . of_enum src |
let enum rl = List . enum ! rl |
let of_enum e = ref ( List . of_enum e ) e |
module Index = struct let remove_at rl pos = let p = ref ( - 1 ) 1 in let rec del_aux = function | x :: l -> incr p ; if ! p = pos then l else x ( :: del_aux l ) l | [ ] -> raise ( Invalid_index pos ) pos in rl := del_aux ! rl let index pred rl = let index = ref ( - 1 ) 1 in List . find ( fun it -> incr index ; pred it... |
type ( ' impl , ' intf ) intf_or_impl = | Impl of ' impl | Intf of ' intf |
module File = struct let of_filename s = if Filename . check_suffix s " . re " then Impl s else if Filename . check_suffix s " . rei " then Intf s else failwith ( sprintf " unknown filename % S " s ) let output_fn = function | Impl fn -> fn ^ " . ml " | Intf fn -> fn ^ " . mli " end |
let ( ) = let set_binary = function | " binary " -> ( ) | _ -> failwith " Only the value ' binary ' is allowed for -- print " in let args = [ " -- print " , Arg . String set_binary , " " ] in let source = ref None in let anon s = match ! source with | None -> source := Some s | Some _ -> failwith " source may be set on... |
let interface = let doc = " parse AST as an interface " in Arg . ( value & opt ( bool ) false & info [ " i " ; " interface " ] ~ doc ) |
let recoverable = let doc = " enable recoverable parser " in Arg . ( value & flag & info [ " r " ; " recoverable " ] ~ doc ) |
let explicit_arity = let doc = " if a constructor ' s argument is a tuple , always interpret it as \ multiple arguments " in Arg . ( value & flag & info [ " e " ; " assume - explicit - arity " ] ~ doc ) |
let parse_ast = let docv = " FORM " in let doc = " parse AST in FORM , which is one of : ( ml | re | \ binary ( for compiler input ) | \ binary_reason ( for interchange between Reason versions ) ) " in let opts = Arg . enum [ " ml " , ` ML ; " re " , ` Reason ; " binary " , ` Binary ; " binary_reason " , ` BinaryReason... |
let print = let docv = " FORM " in let doc = " print AST in FORM , which is one of : ( ml | re ( default ) | \ binary ( for compiler input ) | \ binary_reason ( for interchange between Reason versions ) | \ ast ( print human readable AST directly ) | none ) " in let opts = Arg . enum [ " ml " , ` ML ; " re " , ` Reason... |
let print_width = let docv = " COLS " in let doc = " wrapping width for printing the AST " in Arg . ( value & opt ( int ) ( 80 ) & info [ " w " ; " print - width " ] ~ docv ~ doc ) |
let heuristics_file = let doc = " load path as a heuristics file to specify which constructors carry a tuple \ rather than multiple arguments . Mostly used in removing [ @ implicit_arity ] introduced from \ OCaml conversion . \ n \ t \ texample . txt :\ n \ t \ tConstructor1 \ n \ t \ tConstructor2 " in Arg . ( value &... |
let in_place = let doc = " reformat a file in - place " in Arg . ( value & flag & info [ " in - place " ] ~ doc ) |
let input = let docv = " FILENAMES " in let doc = " input files ; if empty , assume stdin " in Arg . ( value & ( pos_all non_dir_file [ ] ) & info [ ] ~ docv ~ doc ) |
let read_text_lines file = let list = ref [ ] in let chan = open_in file in try while true do list := input_line chan :: ! list done ; [ ] with End_of_file -> close_in chan ; List . rev ! list |
let refmt interface is_recoverable explicit_arity parse_ast print print_width heuristics_file in_place input_files = let refmt_single input_file = let ( use_stdin , input_file ) = match input_file with | Some name -> ( false , name ) | None -> ( true , " " ) in let eol = match use_stdin , input_file with | ( true , _ )... |
let top_level_info = let doc = " Reason ' s Parser & Pretty - printer " in let man = [ ` S " DESCRIPTION " ; ` P " refmt lets you format Reason files , parse them , and convert them between OCaml syntax and Reason syntax . " ] in |
let version = " Reason " ^ Package . version ^ " @ " ^ Package . git_short_version in Term . info " refmt " ~ version ~ doc ~ man |
let refmt_t = let open Term in let open Refmt_args in const refmt $ interface $ recoverable $ explicit_arity $ parse_ast $ print $ print_width $ heuristics_file $ in_place $ input |
let ( ) = match Term . eval ( ( Term . ret refmt_t ) , top_level_info ) with | ` Error _ -> exit 1 | _ -> exit 0 |
let dirs_trustlist = [ " . git " ; " _build " ; " stationary " ; " . un " ~ ; " frontend " ; " external " ; " ocamlformat " ; " node_modules " ; " tablecloth " ; " zexe " ; " proof - systems " ; " snarky " ; " _opam " ] |
let rec fold_over_files ~ path ~ process_path ~ init ~ f = let % bind all = Sys . ls_dir path in Deferred . List . fold all ~ init ~ f ( : fun acc x -> match % bind Sys . is_directory ( path ^/ x ) x with | ` Yes when process_path ` Dir ( path ^/ x ) x -> fold_over_files ~ path ( : path ^/ x ) x ~ process_path ~ init :... |
let main dry_run check path = let % bind _all = fold_over_files ~ path ~ init ( ) : ~ process_path ( : fun kind path -> match kind with | ` Dir -> not ( List . exists dirs_trustlist ~ f ( : fun s -> String . is_suffix ~ suffix : s path ) ) | ` File -> ( not ( List . exists trustlist ~ f ( : fun s -> String . is_suffix ... |
let cli = let open Command . Let_syntax in Command . async ~ summary " : Format all ml and mli files " ( let % map_open path = flag " -- path " ~ aliases [ " : path ] " ~ doc " : Path to traverse " ( required string ) string and dry_run = flag " -- dry - run " ~ aliases [ " : dry - run ] " no_arg ~ doc " : Dry run " an... |
let ( ) = never_returns ( Scheduler . go ( ) ) |
module type REF_CHANNEL = sig type ( ' a , ' b ) reagent type ' a channel val mk_chan : unit -> ' a channel val send : ' a channel -> ( ' a , unit ) reagent val recv : ' a channel -> ( unit , ' a ) reagent end |
module Ref_channel ( Reagents : Reagents . S ) : REF_CHANNEL with type ( ' a , ' b ) reagent = ( ' a , ' b ) Reagents . t = struct type ( ' a , ' b ) reagent = ( ' a , ' b ) Reagents . t open Reagents type ' a channel = ' a option Ref . ref let mk_chan ( ) = Ref . mk_ref None let send r = Ref . upd r ( fun st v -> matc... |
module Scheduler = Sched_ws . Make ( struct let num_domains = 1 let is_affine = false end ) |
module Reagents = Reagents . Make ( Scheduler ) |
let id_str ( ) = sprintf " % d :% d " ( get_qid ( ) ) ( get_tid ( ) ) |
let main ( ) = let c = mk_chan ( ) in fork ( fun ( ) -> Printf . printf " % d \ n " ( run ( recv c ) ( ) ) ) ; run ( send c ) 10 |
let ( ) = Scheduler . run main |
module PersistentHashtbl ( H : Hashtbl . HashedType ) = struct module Table = Hashtbl . Make ( H ) type key = H . t type ' a t = ' a zipper ref and ' a zipper = | Table of ' a Table . t | Add of key * ' a * ' a t | Replace of key * ' a * ' a t | Remove of key * ' a t let create i = ref ( Table ( Table . create i ) ) le... |
type ' a custom_rec = { x : unit ; mutable y : ' a } |
type float_rec = { w : float ; mutable z : float } |
type cst = A | B |
type gen = C | D of string |
type var = [ ` A | ` B ] |
type vargen = [ ` A | ` B of int | ` C ] |
let int_ref = ref 1 ; ; |
let var_ref : var ref = ref ` A ; ; |
let vargen_ref : vargen ref = ref ` A ; ; |
let cst_ref = ref A ; ; |
let gen_ref = ref C ; ; |
let flt_ref = ref 0 . ; ; |
let int_rec = { x = ( ) ; y = 1 } ; ; |
let var_rec : var custom_rec = { x = ( ) ; y = ` A } ; ; |
let vargen_rec : vargen custom_rec = { x = ( ) ; y = ` A } ; ; |
let cst_rec = { x = ( ) ; y = A } ; ; |
let gen_rec = { x = ( ) ; y = C } ; ; |
let flt_rec = { x = ( ) ; y = 0 . } ; ; |
let flt_rec ' = { w = 0 . ; z = 0 . } ; ; |
let set_open_poly ( r [ ` :> Foo ] ref ) y = r := y ; ; |
let set_open_poly ( r [ ` :< Foo ] ref ) y = r := y ; ; |
let set_open_poly ( r [ ` : Foo ] ref ) y = r := y ; ; |
let set_open_poly ( r [ :< ` Bar | ` Foo | ` Baz > ` Foo ` Bar ] ref ) y = r := y ; ; |
let set_open_poly ( r [ ` :> Foo of int ] ref ) y = r := y ; ; |
let set_open_poly ( r [ ` :< Foo of int ] ref ) y = r := y ; ; |
let set_open_poly ( r [ ` : Foo of int ] ref ) y = r := y ; ; |
let set_open_poly ( r [ :< ` Bar | ` Foo of float | ` Baz > ` Foo ` Bar ] ref ) y = r := y ; ; |
module Scheduler = Sched_ws . Make ( struct let num_domains = 1 let is_affine = false end ) |
module Reagents = Reagents . Make ( Scheduler ) |
let id_str ( ) = sprintf " % d :% d " ( get_qid ( ) ) ( get_tid ( ) ) |
let main ( ) = printf " [ % s ] starting main \ n " ( id_str ( ) ) ; printf " **** Test 1 ****\ n " ; %! let r = mk_ref 0 in let foo ov ( ) = if ov = 0 then ( printf " [ % s ] Saw 0 . Blocking . . \ n " %! ( id_str ( ) ) ; None ) else ( printf " [ % s ] Saw 1 . Success . Set to 2 . \ n " %! ( id_str ( ) ) ; Some ( 2 , ... |
let ( ) = Scheduler . run main |
type module_lookup_result = Resolved . Module . t * Cpath . Resolved . module_ * Component . Module . t |
type module_type_lookup_result = Resolved . ModuleType . t * Cpath . Resolved . module_type * Component . ModuleType . t |
type signature_lookup_result = Resolved . Signature . t * Cpath . Resolved . parent * Component . Signature . t |
type datatype_lookup_result = Resolved . DataType . t * Component . TypeDecl . t |
type class_lookup_result = Resolved . Class . t * Component . Class . t |
type class_type_lookup_result = Resolved . ClassType . t * Component . ClassType . t |
type page_lookup_result = Resolved . Page . t * Odoc_model . Lang . Page . t |
type type_lookup_result = [ ` T of datatype_lookup_result | ` C of class_lookup_result | ` CT of class_type_lookup_result ] |
type label_parent_lookup_result = [ ` S of signature_lookup_result | type_lookup_result | ` P of page_lookup_result ] |
type ' a ref_result = ( ' a , Errors . Tools_error . reference_lookup_error ) Result . result |
let kind_of_find_result = function | ` S _ -> ` S | ` T _ -> ` T | ` C _ -> ` C | ` CT _ -> ` CT | ` P _ -> ` Page |
let wrong_kind_error expected r = Error ( ` Wrong_kind ( expected , kind_of_find_result r ) ) |
let signature_lookup_result_of_label_parent : label_parent_lookup_result -> _ = function | ` S r -> Ok r | r -> wrong_kind_error [ ` S ] r |
let class_lookup_result_of_type : type_lookup_result -> _ = function | ` C r -> Ok r | r -> wrong_kind_error [ ` C ] r |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.