text
stringlengths
0
601k
let ctyp_ident = Grammar . Entry . create gram " ctyp_ident " ; ;
let mksequence2 _ = function Qast . VaVal ( Qast . List [ e ] ) -> e | el -> Qast . Node ( " ExSeq " , [ Qast . Loc ; el ] ) ; ;
let mksequence _ = function Qast . List [ e ] -> e | el -> Qast . Node ( " ExSeq " , [ Qast . Loc ; Qast . VaVal el ] ) ; ;
let mkmatchcase _ p aso w e = let p = match aso with Qast . Option ( Some p2 ) -> Qast . Node ( " PaAli " , [ Qast . Loc ; p ; p2 ] ) | Qast . Option None -> p | _ -> Qast . Node ( " PaAli " , [ Qast . Loc ; p ; aso ] ) in Qast . Tuple [ p ; w ; e ] ; ;
let neg_string n = let x = let len = String . length n in if len > 0 && n . [ 0 ] = ' ' - then String . sub n 1 ( len - 1 ) else " " - ^ n in Qast . Str x ; ;
let mklistexp _ last = let rec loop top = function [ ] -> begin match last with Qast . Option ( Some e ) -> e | Qast . Option None -> Qast . Node ( " ExLong " , [ Qast . Loc ; Qast . Node ( " LiUid " , [ Qast . Loc ; Qast . VaVal ( Qast . Str " [ ] " ) ] ) ] ) | a -> a end | e1 :: el -> Qast . Node ( " ExApp " , [ Qast...
let mklistpat _ last = let rec loop top = function [ ] -> begin match last with Qast . Option ( Some p ) -> p | Qast . Option None -> Qast . Node ( " PaLong " , [ Qast . Loc ; Qast . Node ( " LiUid " , [ Qast . Loc ; Qast . VaVal ( Qast . Str " [ ] " ) ] ) ; Qast . VaVal ( Qast . List [ ] ) ] ) | a -> a end | p1 :: pl ...
let mktupexp _ e el = Qast . Node ( " ExTup " , [ Qast . Loc ; Qast . VaVal ( Qast . Cons ( e , Qast . List el ) ) ] ) ; ;
let mktuppat _ p pl = Qast . Node ( " PaTup " , [ Qast . Loc ; Qast . VaVal ( Qast . Cons ( p , Qast . List pl ) ) ] ) ; ;
let mktuptyp _ t tl = Qast . Node ( " TyTup " , [ Qast . Loc ; Qast . VaVal ( Qast . Cons ( t , Qast . List tl ) ) ] ) ; ;
let mklabdecl _ i mf t attrs = Qast . Tuple [ Qast . Loc ; Qast . Str i ; Qast . Bool mf ; t ; attrs ] ; ;
let mkident i = Qast . Str i ; ;
let generalized_type_of_type t = let rec gen = function Qast . Node ( " TyArr " , [ _ ; t1 ; t2 ] ) -> let ( tl , rt ) = gen t2 in t1 :: tl , rt | t -> [ ] , t in let ( tl , rt ) = gen t in Qast . List tl , rt ; ;
let greek_ascii_equiv s = Qast . Str ( Pcaml . greek_ascii_equiv s ) ; ;
let warned = ref false ; ;
let warning_deprecated_since_6_00 loc = if not ! warned then begin ( ! Pcaml . warning ) loc " syntax deprecated since version 6 . 00 " ; warned := true end ; ;
let check_let_exception_f strm = match Stream . npeek 2 strm with [ " " , " let " ; " " , " exception " ] -> ( ) | _ -> raise Stream . Failure ; ;
let check_let_exception = Grammar . Entry . of_parser gram " check_let_exception " check_let_exception_f ; ;
let check_let_not_exception_f strm = match Stream . npeek 2 strm with [ " " , " let " ; " " , " exception " ] -> raise Stream . Failure | [ " " , " let " ; _ ] -> ( ) | _ -> raise Stream . Failure ; ;
let check_let_not_exception = Grammar . Entry . of_parser gram " check_let_not_exception " check_let_not_exception_f ; ;
let stream_peek_nth n strm = let rec loop n = function [ ] -> None | [ x ] -> if n == 1 then Some x else None | _ :: l -> loop ( n - 1 ) l in loop n ( Stream . npeek n strm ) ; ;
let word_keywordp s = let rec wrec ( strm__ : _ Stream . t ) = match Stream . peek strm__ with Some ( ' a ' . . ' z ' | ' A ' . . ' Z ' | ' _ ' | ' 0 ' . . ' 9 ' ) -> Stream . junk strm__ ; let strm = strm__ in wrec strm | _ -> let strm = strm__ in Stream . empty strm ; true in let check ( strm__ : _ Stream . t ) = mat...
let is_type_decl_not_extension strm = let rec wrec n = match stream_peek_nth n strm with None -> assert false | Some ( " " , " " = | " " , " " := | " " , " ; " | " " , " ; ; " ) -> true | Some ( " " , s ) when word_keywordp s -> true | Some ( " EOI " , " " ) -> true | Some ( " " , " " ) += -> false | Some ( " " , _ | "...
let check_type_decl_f strm = if is_type_decl_not_extension strm then ( ) else raise Stream . Failure ; ;
let check_type_decl = Grammar . Entry . of_parser gram " check_type_decl " check_type_decl_f ; ;
let check_type_extension_f strm = if not ( is_type_decl_not_extension strm ) then ( ) else raise Stream . Failure ; ;
let check_type_extension = Grammar . Entry . of_parser gram " check_type_extension " check_type_extension_f ; ;
let stream_npeek n ( strm : ( string * string ) Stream . t ) = Stream . npeek n strm ; ;
let check_dot_uid_f strm = match stream_npeek 5 strm with ( " " , " . " ) :: ( " UIDENT " , _ ) :: _ -> ( ) | ( " " , " . " ) :: ( " ANTIQUOT " , qs ) :: _ when prefix_eq " longid " : qs || prefix_eq " _longid " : qs || prefix_eq " uid " : qs || prefix_eq " _uid " : qs -> ( ) | ( " " , " . " ) :: ( " " , " " ) $ :: ( "...
let check_dot_uid = Grammar . Entry . of_parser gram " check_dot_uid " check_dot_uid_f ; ;
let check_uident_coloneq_f strm = match stream_npeek 2 strm with [ " UIDENT " , _ ; " " , " " ] := -> ( ) | [ " ANTIQUOT " , qs ; " " , " " ] := when prefix_eq " uid " : qs || prefix_eq " _uid " : qs -> ( ) | _ -> raise Stream . Failure ; ;
let check_uident_coloneq = Grammar . Entry . of_parser gram " check_uident_coloneq " check_uident_coloneq_f ; ;
let dotop = Grammar . Entry . of_parser gram " dotop " ( fun ( strm__ : _ Stream . t ) -> match Stream . peek strm__ with Some ( " " , x ) when is_dotop x -> Stream . junk strm__ ; Qast . Str x | _ -> raise Stream . Failure ) ; ;
let is_lparen_f strm = match Stream . npeek 1 strm with [ " " , " ( " ] -> true | _ -> false ; ;
let is_lparen_type_f strm = is_lparen_f strm && ( match Stream . npeek 2 strm with [ " " , " ( " ; " " , " type " ] -> true | _ -> false ) ; ;
let check_lparen_type_f strm = if is_lparen_type_f strm then ( ) else raise Stream . Failure ; ;
let check_lparen_type = Grammar . Entry . of_parser gram " check_lparen_type " check_lparen_type_f ; ;
let is_type_binder_f strm = check_fsm type_binder_fsm strm ; ;
let check_type_binder_f strm = if is_type_binder_f strm then ( ) else raise Stream . Failure ; ;
let check_type_binder = Grammar . Entry . of_parser gram " check_type_binder " check_type_binder_f ; ; Grammar . safe_extend ( let _ = ( sig_item : ' sig_item Grammar . Entry . e ) and _ = ( str_item : ' str_item Grammar . Entry . e ) and _ = ( ctyp : ' ctyp Grammar . Entry . e ) and _ = ( patt : ' patt Grammar . Entry...
let antiquot_xtr loc n a = if ( ! Pcaml . strict_mode ) then Qast . Node ( n , [ Qast . Loc ; Qast . VaAnt ( " xtr " , loc , a ) ; Qast . Option None ] ) else Qast . Apply ( " failwith " , [ Qast . Str " antiquotation not authorized " ] ) ; ; Grammar . safe_extend [ Grammar . extension ( module_expr : ' module_expr Gra...
let quot_mod = ref [ ] ; ;
let any_quot_mod = ref " MLast " ; ;
let set_qmod s = match try Some ( String . index s ' , ' ) with Not_found -> None with Some i -> let q = String . sub s 0 i in let m = String . sub s ( i + 1 ) ( String . length s - i - 1 ) in quot_mod := ( q , m ) :: ! quot_mod | None -> any_quot_mod := s ; ; ( function Some ( MLast . ExStr ( _ , s ) ) -> set_qmod s |...
let separate_locate s = let len = String . length s in if len > 0 && s . [ 0 ] = ' ' @ then String . sub s 1 ( len - 1 ) , true else s , false ; ;
let apply_entry e q = let f s = Grammar . Entry . parse e ( Stream . of_string s ) in let m ( ) = try List . assoc q ! quot_mod with Not_found -> ! any_quot_mod in let expr s = let ( s , locate ) = separate_locate s in Qast . to_expr ( m ( ) ) ( f s ) in let patt s = let ( s , locate ) = separate_locate s in let qast =...
let attribute_body_eoi = Grammar . Entry . create gram " attribute_body_eoi " in
let class_expr_eoi = Grammar . Entry . create gram " class_expr_eoi " in
let class_sig_item_eoi = Grammar . Entry . create gram " class_sig_item_eoi " in
let class_str_item_eoi = Grammar . Entry . create gram " class_str_item_eoi " in
let class_type_eoi = Grammar . Entry . create gram " class_type_eoi " in
let ctyp_eoi = Grammar . Entry . create gram " ctyp_eoi " in
let expr_eoi = Grammar . Entry . create gram " expr_eoi " in
let extended_longident_eoi = Grammar . Entry . create gram " extended_longident_eoi " in
let extension_constructor_eoi = Grammar . Entry . create gram " extension_constructor_eoi " in
let constructor_eoi = Grammar . Entry . create gram " constructor_eoi " in
let longident_eoi = Grammar . Entry . create gram " longident_eoi " in
let module_expr_eoi = Grammar . Entry . create gram " module_expr_eoi " in
let module_type_eoi = Grammar . Entry . create gram " module_type_eoi " in
let patt_eoi = Grammar . Entry . create gram " patt_eoi " in
let poly_variant_eoi = Grammar . Entry . create gram " poly_variant_eoi " in
let sig_item_eoi = Grammar . Entry . create gram " sig_item_eoi " in
let str_item_eoi = Grammar . Entry . create gram " str_item_eoi " in
let type_decl_eoi = Grammar . Entry . create gram " type_decl_eoi " in
let type_extension_eoi = Grammar . Entry . create gram " type_extension_eoi " in
let with_constr_eoi = Grammar . Entry . create gram " with_constr_eoi " in Grammar . safe_extend [ Grammar . extension ( attribute_body_eoi : ' attribute_body_eoi Grammar . Entry . e ) None [ None , None , [ Grammar . production ( Grammar . r_next ( Grammar . r_next Grammar . r_stop ( Grammar . s_nterm ( attribute_body...
let expr_eoi = Grammar . Entry . create Pcaml . gram " expr_eoi " in Grammar . safe_extend [ Grammar . extension ( expr_eoi : ' expr_eoi Grammar . Entry . e ) None [ None , None , [ Grammar . production ( Grammar . r_next ( Grammar . r_next Grammar . r_stop ( Grammar . s_token ( " ANTIQUOT_LOC " , " " ) ) ) ( Grammar ....
let expr s = Ploc . call_with Plexer . force_antiquot_loc true ( Grammar . Entry . parse expr_eoi ) ( Stream . of_string s ) in
let patt_eoi = Grammar . Entry . create Pcaml . gram " patt_eoi " in Grammar . safe_extend [ Grammar . extension ( patt_eoi : ' patt_eoi Grammar . Entry . e ) None [ None , None , [ Grammar . production ( Grammar . r_next ( Grammar . r_next Grammar . r_stop ( Grammar . s_token ( " ANTIQUOT_LOC " , " " ) ) ) ( Grammar ....
let patt s = Ploc . call_with Plexer . force_antiquot_loc true ( Grammar . Entry . parse patt_eoi ) ( Stream . of_string s ) in
type instance = { name : string ; code : string ; expect : string } ; assert_equal { ~ msg " = not equal " } { ~ printer = fmt_string } i . expect ( pr ( pa1 i . code ) ) ] ) ; [ { name = " prototype " ; code = { foo || foo } ; expect = { foo || foo } } ; { name = " expr - simplest " ; code = { foo | <: expr < 1 >> ; |...
Qast . Node " Sexp . Nil " [ ] ; Qast . Node " Sexp . Cons " [ e1 ; e2 ] ; EXTEND GLOBAL : sexp_eoi ; sexp : [ [ a = SV atom " atom " -> expr_atom a | " ( " ; l1 = LIST1 sv_sexp ; opt_e2 = OPT [ " . " ; e2 = sv_sexp -> e2 ] ; " ) " -> match opt_e2 with [ None -> List . fold_right ( fun vse1 se2 -> Qast . Node " Sexp . ...
type r2 = { to_r2 : out_channel ; of_r2 : in_channel ; err : in_channel ; }
let find_null data ~ pos ~ len = let rec find pos = if pos < len then if Bytes . get data pos = ' \ 000 ' then Some pos else find ( pos + 1 ) else None in find pos
let fdr r2 = Unix . descr_of_in_channel r2 . of_r2
let rec read_spin fd data = match Unix . read fd data 0 ( Bytes . length data ) with | exception ( Unix . Unix_error ( ( Unix . EAGAIN | EWOULDBLOCK ) , _ , _ ) ) -> read_spin fd data | 0 -> raise No_input | n -> n
let read r2 = let buf = Buffer . create bufsize in let data = Bytes . create bufsize in let rec fill ( ) = let len = read_spin ( fdr r2 ) data in match find_null data ~ pos : 0 ~ len with | None -> Buffer . add_subbytes buf data 0 len ; fill ( ) | Some pos -> Buffer . add_subbytes buf data 0 pos in fill ( ) ; Buffer . ...
let send_command r2 cmd = Printf . fprintf r2 . to_r2 " % s \ n " %! cmd ; read r2
let command ~ r2 cmd = send_command r2 cmd
let parse_json s = ( Yojson . Safe . from_string s :> Yojson . t )
let command_json ~ r2 cmd = try send_command r2 cmd |> parse_json with Yojson . Json_error _ -> raise ( Invalid_argument " Output wasn ' t JSON parsable , \ make sure you used / j " )
module Version : sig val supported : unit Lazy . t end let system_error msg = invalid_arg ( " Failed to run radare2 : " ^ Unix . error_message msg ) let try_finally f x ~ finally = try let r = f x in finally x ; r with exn -> finally x ; raise exn let read_version ( ) = match Unix . open_process_in " radare2 - qv " wit...
let close ( { of_r2 ; to_r2 ; err } as r2 ) = let _ : string = command ~ r2 " q " in match Unix . close_process_full ( of_r2 , to_r2 , err ) with | Unix . WEXITED 0 -> ( ) | Unix . WEXITED n -> failwith ( " radare2 terminated with a non - zero exit code : " ^ string_of_int n ) | Unix . WSIGNALED _ | Unix . WSTOPPED _ -...
let readall ch = let buf = Buffer . create bufsize in let rec read ( ) = Buffer . add_channel buf ch bufsize ; read ( ) in try read ( ) with End_of_file -> Buffer . contents buf
let open_file f_name = let lazy ( ) = Version . supported in if not ( Sys . file_exists f_name ) then raise ( Invalid_argument " Non - existent file " ) else let env = Unix . environment ( ) in let cmd = Printf . sprintf " radare2 - q0 % s " f_name in let of_r2 , to_r2 , err = Unix . open_process_full cmd env in Unix ....
let with_command ~ cmd f_name = let r2 = open_file f_name in let output = command ~ r2 cmd in close r2 ; output
let with_command_j ~ cmd f_name = let r2 = open_file f_name in let output = command ~ r2 cmd in close r2 ; output |> parse_json
" simplest " >:: ( fun [ _ -> assert_equal { ~ msg " = not equal " } { ~ printer ( = fun [ x -> x ] ) } { foo ( | begin 1 2 ) 3 | foo } ( pr ( pa1 " do { 1 ; 2 } ; 3 ; value x = 1 ; " ) ) ] ) ; " simple module " >:: ( fun [ _ -> assert_equal { ~ msg " = not equal " } { ~ printer ( = fun [ x -> x ] ) } { foo ( | module ...
let main ( ) = let waiter , wakener = wait ( ) in let vbox = new vbox in let result_int = ( new label " 1 " ) in let result_string = ( new label " foo " ) in let group_int = new radiogroup in let group_string = new radiogroup in let callback_int = function | Some n -> result_int # set_text ( string_of_int n ) | None ->...
let ( ) = Lwt_main . run ( main ( ) )
module Raft_general = struct type state = { multiple_13 : int ; multiple_20 : int ; } type states = ( int , state list ) list Hashtbl . t let register_state ( s : int ) int ( x : state ) state h = try let l = Hashtbl . find h s in if not ( List . mem x l ) l then Hashtbl . replace h s ( x :: l ) l with Not_found -> Has...
type s = [ ` | RestartElection ` | StartElection ` | Startup ` | StepDown_from_Candidate ` | StepDown_from_Leader ` | WinElection ` | Recover ]
type t = { raft_general : Raft_general . states ; }
let pagefn ( oc : out_channel ) out_channel = ( )
let set_cfn _ _ = ( )
let init ( ) = { raft_general = Raft_general . init ( ) ; }
let tick s x = let r = match x with ` | RestartElection -> { s with raft_general = ( Raft_general . tick ` RestartElection s . raft_general ) raft_general ; } ` | StartElection -> { s with raft_general = ( Raft_general . tick ` StartElection s . raft_general ) raft_general ; } ` | Startup -> { s with raft_general = ( R...
let ( ) = Random . self_init ( )
let rec ( ) -- a b = if a > b then [ ] else a :: succ a -- b
let uchar x = I . uchar ( Uchar . of_int x ) x