text
stringlengths 0
601k
|
---|
type word = | Any | A of string | Kind of string | Level of int tag : tag ; word : word ; tag_name : string ; }
|
type pattern = { descr : descr }
|
let string_of_descr ( x : descr ) = match x . word with | Any -> x . tag_name | Kind s -> x . tag_name ^ " " ^ s | A s -> Printf . sprintf " % S " s | Level d -> x . tag_name ^ Printf . sprintf " Level % d " d
|
let string_of_pattern ( x : pattern ) = string_of_descr x . descr
|
let eq_pattern ( x : pattern ) ( y : pattern ) : bool = x . descr = y . descr
|
let quot_expand ( expander ' : a expand_fun ) ( x : quot ) = let loc = Location_util . join { x . loc with loc_start = { x . loc . loc_start with pos_cnum = x . loc . loc_start . pos_cnum + x . shift } } in let content = String . sub x . txt x . shift ( String . length x . txt - x . retract - x . shift ) in expander loc x . meta content
|
let pp_print_quotation : Format . formatter -> quotation -> unit = fun fmt ( ` Quot x ) -> Format . fprintf fmt " [ @< 1 ( ` > Quot % a ) ] " @ pp_print_quot x
|
let pp_print_dir_quotation : Format . formatter -> dir_quotation -> unit = fun fmt ( ` DirQuotation x ) -> Format . fprintf fmt " [ @< 1 ( ` > DirQuotation % a ) ] " @ pp_print_quot x
|
let pp_print_t ( fmt : Format . formatter ) ( x : t ) : unit = match x with | ` Inf x -> Format . fprintf fmt " [ @< 1 ( ` > Inf @ % a ) ] " @ Format . pp_print_string x . txt | ` Pre x -> Format . fprintf fmt " [ @< 1 ( ` > Pre @ % a ) ] " @ Format . pp_print_string x . txt | ` Key x -> Format . fprintf fmt " [ @< 1 ( ` > Key @ % a ) ] " @ Format . pp_print_string x . txt | ` Lid x -> Format . fprintf fmt " [ @< 1 ( ` > Lid @ % a ) ] " @ Format . pp_print_string x . txt | ` Uid x -> Format . fprintf fmt " [ @< 1 ( ` > Uid @ % a ) ] " @ Format . pp_print_string x . txt | ` Int x -> Format . fprintf fmt " [ @< 1 ( ` > Int @ % a ) ] " @ Format . pp_print_string x . txt | ` Int32 x -> Format . fprintf fmt " [ @< 1 ( ` > Int32 @ % a ) ] " @ Format . pp_print_string x . txt | ` Int64 x -> Format . fprintf fmt " [ @< 1 ( ` > Int6 @ % a ) ] " @ Format . pp_print_string x . txt | ` Nativeint x -> Format . fprintf fmt " [ @< 1 ( ` > Nativeint @ % a ) ] " @ Format . pp_print_string x . txt | ` Flo x -> Format . fprintf fmt " [ @< 1 ( ` > Flo @ % a ) ] " @ Format . pp_print_string x . txt | ` Chr x -> Format . fprintf fmt " [ @< 1 ( ` > Chr @ % a ) ] " @ Format . pp_print_string x . txt | ` Str x -> Format . fprintf fmt " [ @< 1 ( ` > Str @ % a ) ] " @ Format . pp_print_string x . txt | ` Label x -> Format . fprintf fmt " [ @< 1 ( ` > Label @ % a ) ] " @ Format . pp_print_string x . txt | ` Optlabel x -> Format . fprintf fmt " [ @< 1 ( ` > Optlabel @ % a ) ] " @ Format . pp_print_string x . txt | # quotation as _a0 -> ( pp_print_quotation fmt _a0 :> unit ) | # dir_quotation as _a0 -> ( pp_print_dir_quotation fmt _a0 :> unit ) | ` Ant x -> Format . fprintf fmt " [ @< 1 ( ` > Ant @ % a @ % a ) ] " @ Format . pp_print_string x . kind Format . pp_print_string x . txt | ` EOI _ -> Format . fprintf fmt " ` EOI "
|
type stream = t Streamf . t
|
type ' a parse = stream -> ' a
|
type ' a lex = Locf . t -> char Streamf . t -> ' a
|
type filter = stream -> stream
|
let to_string = Formatf . to_string pp_print_t
|
let print ppf x = Format . pp_print_string ppf ( to_string x )
|
let strip ( x : t ) : Obj . t = Obj . field ( Obj . repr x ) 1
|
let get_tag ( x : t ) : tag = ( Obj . magic ( Obj . field ( Obj . repr x ) 0 ) : tag )
|
let destruct ( x : t ) = ( ( Obj . magic ( Obj . field ( Obj . repr x ) 0 ) : tag ) , Obj . field ( Obj . repr x ) 1 )
|
let get_string ( x : t ) : string = match x with | ` Pre x | ` Key x | ` Lid x | ` Uid x | ` Int x | ` Int32 x | ` Int64 x | ` Nativeint x | ` Flo x | ` Chr x | ` Str x | ` Label x | ` Optlabel x | ` EOI x -> x . txt | ` Quot x -> x . txt | ` DirQuotation x -> x . txt | ` Ant x -> x . txt | ` Inf x -> x . txt
|
let get_loc ( x : t ) = match x with | ` Key x | ` Lid x | ` Uid x | ` Int x | ` Int32 x | ` Int64 x | ` Nativeint x | ` Flo x | ` Chr x | ` Pre x | ` Str x | ` Label x | ` Optlabel x | ` EOI x -> x . loc | ` Ant x -> x . loc | ` Quot x -> x . loc | ` DirQuotation x -> x . loc | ` Inf x -> x . loc
|
let empty_name : name = { domain = ` Sub [ ] ; name = " " }
|
let name_of_string s : name = match s . [ 0 ] with | ' . ' -> ( match List . rev @@ List . filter Stringf . not_empty ( Stringf . nsplit s " . " ) with | x :: xs -> { domain = ` Absolute ( List . rev xs ) ; name = x } | _ -> assert false ) ' | A ' . . ' Z ' -> ( match List . rev ( List . filter Stringf . not_empty ( Stringf . nsplit s " . " ) ) with | x :: xs -> { domain = ` Sub ( List . rev xs ) ; name = x } | _ -> assert false ) | _ -> { domain = ` Sub [ ] ; name = s }
|
let match_token ( x : pattern ) = let tag = x . descr . tag in let word = x . descr . word in fun ( token_tag , obj ) -> ( tag = token_tag && ( match word with | Any -> true | Kind s -> ( Obj . magic ( Obj . field obj 3 ) : string ) = s | A s -> ( Obj . magic ( Obj . field obj 1 ) : string ) = s | Level i -> ( Obj . magic ( Obj . field obj 2 ) : int ) = i ) )
|
type t = { grant_type : string ; scope : Scopes . t list ; code : string ; client_id : string ; client_secret : string option ; redirect_uri : Uri . t ; }
|
let make ( ~ client : Client . t ) ~ grant_type ~ scope ~ redirect_uri ~ code = { grant_type ; scope ; code ; client_id = client . id ; client_secret = client . secret ; redirect_uri ; }
|
let to_body_string t = [ ( " grant_type " , [ t . grant_type ] ) ; ( " scope " , [ Scopes . to_scope_parameter t . scope ] ) ; ( " code " , [ t . code ] ) ; ( " client_id " , [ t . client_id ] ) ; ( " client_secret " , [ t . client_secret |> ROpt . get_or ~ default " : secret " ] ) ; ( " redirect_uri " , [ t . redirect_uri |> Uri . to_string ] ) ; ] |> Uri . encoded_of_query
|
let of_body_string body = let query = Uri . query_of_encoded body |> Uri . with_query Uri . empty in let gt = Uri . get_query_param query " grant_type " in let s = Uri . get_query_param query " scope " in let c = Uri . get_query_param query " code " in let ci = Uri . get_query_param query " client_id " in let client_secret = Uri . get_query_param query " client_secret " in let ru = Uri . get_query_param query " redirect_uri " in match ( gt , s , c , ci , ru ) with | Some grant_type , Some scope , Some code , Some client_id , Some redirect_uri -> Ok { grant_type ; scope = Scopes . of_scope_parameter scope ; code ; client_id ; client_secret ; redirect_uri = redirect_uri |> Uri . of_string ; } | Some _ , Some _ , Some _ , Some _ , None -> Error ( ` Msg " missing redirect_uri " ) | Some _ , Some _ , Some _ , None , Some _ -> Error ( ` Msg " missing client_id " ) | Some _ , Some _ , None , Some _ , Some _ -> Error ( ` Msg " missing code " ) | Some _ , None , Some _ , Some _ , Some _ -> Error ( ` Msg " missing scope " ) | None , Some _ , Some _ , Some _ , Some _ -> Error ( ` Msg " missing grant_type " ) | _ -> Error ( ` Msg " More than 1 missing " )
|
type t = { token_type : token_type ; scope : Scopes . t list ; expires_in : int option ; access_token : string option ; refresh_token : string option ; id_token : string option ; }
|
let make ( ? token_type = Bearer ) ( ? scope = [ ] ) ? expires_in ? access_token ? refresh_token ? id_token ( ) = { token_type ; scope ; expires_in ; access_token ; refresh_token ; id_token }
|
let of_yojson json = try let module Json = Yojson . Safe . Util in let scope = match Json . member " scope " json with | ` Null -> [ ] | ` String scope -> Scopes . of_scope_parameter scope | ` List json -> List . map Json . to_string json |> List . map Scopes . of_string | json -> raise ( Json . Type_error ( " scope : expected a string or an array of strings " , json ) ) in Ok { token_type = Bearer ; scope ; expires_in = json |> Json . member " expires_in " |> Json . to_int_option ; access_token = json |> Json . member " access_token " |> Json . to_string_option ; refresh_token = json |> Json . member " refresh_token " |> Json . to_string_option ; id_token = json |> Json . member " id_token " |> Json . to_string_option ; } with Yojson . Safe . Util . Type_error ( str , _ ) -> Error str
|
let of_query query = let scope = let qp = Uri . get_query_param query " scope " in Option . value ~ default [ ] : ( Option . map Scopes . of_scope_parameter qp ) in { token_type = Bearer ; scope ; expires_in = Uri . get_query_param query " expires_in " |> Option . map int_of_string ; access_token = Uri . get_query_param query " access_token " ; refresh_token = Uri . get_query_param query " refresh_token " ; id_token = Uri . get_query_param query " id_token " ; }
|
let of_string str = Yojson . Safe . from_string str |> of_yojson
|
let validate ? clock_tolerance ? nonce ~ jwks ( ~ client : Client . t ) ( ~ discovery : Discover . t ) t = match Jose . Jwt . of_string ( Option . get t . id_token ) with | Ok jwt -> ( if jwt . header . alg = ` None then IDToken . validate ? clock_tolerance ? nonce ~ client ~ issuer : discovery . issuer jwt |> Result . map ( fun _ -> t ) else match Jwks . find_jwk ~ jwt jwks with | Some jwk -> IDToken . validate ? clock_tolerance ? nonce ~ client ~ issuer : discovery . issuer ~ jwk jwt |> Result . map ( fun _ -> t ) | None when List . length jwks . keys = 1 -> let jwk = List . hd jwks . keys in IDToken . validate ? clock_tolerance ? nonce ~ client ~ issuer : discovery . issuer ~ jwk jwt |> Result . map ( fun _ -> t ) | None -> Error ( ` Msg " Could not find JWK " ) ) | Error e -> Error e
|
let to_yojson { scope ; expires_in ; access_token ; refresh_token ; id_token ; _ } = let or_null = Option . value ~ default ` : Null in let json_str = Option . map ( fun x -> ` String x ) in ` Assoc [ ( " scope " , match scope with | [ ] -> ` Null | _ -> ` String ( Scopes . to_scope_parameter scope ) ) ; ( " token_type " , ` String " Bearer " ) ; ( " expires_in " , or_null ( Option . map ( fun x -> ` Int x ) expires_in ) ) ; ( " access_token " , or_null ( json_str access_token ) ) ; ( " refresh_token " , or_null ( json_str refresh_token ) ) ; ( " id_token " , or_null ( json_str id_token ) ) ; ]
|
let show input = Eml . Location . reset ( ) ; let underlying = Stream . of_string input in let input_stream = Eml . Location . stream ( fun ( ) -> try Some ( Stream . next underlying ) with _ -> None ) in try input_stream |> Eml . Tokenizer . scan |> List . map Eml . Token . show |> List . iter print_endline with Failure message -> print_endline message show " " ; [ % expect { | ( 1 , 0 ) Code_block } ] | show " " ; [ % expect { | ( 1 , 0 ) Code_block } ] | show " \ n " ; [ % expect { | ( 1 , 0 ) Code_block } ] | show " \ n \ n " ; [ % expect { | ( 1 , 0 ) Code_block } ] | show " let foo =\ n bar \ n " ; [ % expect { | ( 1 , 0 ) Code_block let foo = bar } ] | show " let foo =\ n < bar " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 0 Text { |< bar } | | xxx } ] show " let foo =\ n < bar " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 1 Text { | < bar } | | xxx } ] show " let foo =\ n < bar " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | < bar } | | xxx } ] show " let foo =\ n < bar " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 3 Text { | < bar } | | xxx } ] show " let foo =\ n < html >\ n </ html " ; > [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | < html } >| Newline Text { | </ html } >| | xxx } ] show " let foo =\ n < html >\ n plain " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | < html } >| Newline Text { | plain } | | xxx } ] show " let foo =\ n < html >\ n </ html >\ nlet bar = ( ) \ n " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | < html } >| Newline Text { | </ html } >| Newline ( 4 , 0 ) Code_block let bar = ( ) | xxx } ] show " let foo =\ n <% a %>\ n " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | } | ( 2 , 5 ) Embedded ( ) a Text { } || Newline | xxx } ] show " let foo =\ n <% a % %>\ n " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | } | ( 2 , 5 ) Embedded ( ) a % Text { } || Newline | xxx } ] show " let foo =\ n <% a %%>\ n " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | } | ( 2 , 5 ) Embedded ( ) a % Text { } || Newline | xxx } ] show " let foo =\ n <%= a %>\ n " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | } | ( 2 , 6 ) Embedded ( ) = a Text { } || Newline | xxx } ] show " let foo =\ n <% a \ nb %>\ n " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | } | ( 2 , 5 ) Embedded ( ) a b Text { } || Newline | xxx } ] show " let foo =\ n " ; <% [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | } | ( 2 , 4 ) Embedded ( ) Text { } || | xxx } ] show " let foo =\ n <%\ na " ; %> [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | } | ( 3 , 2 ) Embedded ( a ) Text { } || | xxx } ] show " let foo =\ n <% \ n a " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | } | ( 2 , 5 ) Embedded ( ) a Text { } || | xxx } ] show " let foo =\ n < html >\ n \ na " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | < html } >| Newline Text { } || Newline ( 4 , 0 ) Code_block a | xxx } ] show " let foo =\ n % abc " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = ( 2 , 1 ) Embedded ( ) abc | xxx } ] show " let foo =\ n % abc \ n " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = ( 2 , 1 ) Embedded ( ) abc | xxx } ] show " let foo =\ n % abc \ n % def " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = ( 2 , 1 ) Embedded ( ) abc ( 3 , 1 ) Embedded ( ) def | xxx } ] show " let foo =\ n < html >\ n % abc \ n </ html " ; > [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | < html } >| Newline ( 3 , 1 ) Embedded ( ) abc Text { | </ html } >| | xxx } ] show " let foo =\ n % bar " ; [ % expect { | ( 1 , 0 ) Code_block let foo = % bar } ] | show " let foo =\ n < html >\ n % bar " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | < html } >| Newline ( 3 , 0 ) Code_block % bar | xxx } ] show " let foo \ n < html >\ n \ n % bar " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo Options , 2 Text { | < html } >| Newline Text { } || Newline ( 4 , 1 ) Embedded ( ) bar | xxx } ] show " let foo \ n < html >\ n \ n % bar " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo Options , 2 Text { | < html } >| Newline Text { | } | Newline ( 4 , 1 ) Embedded ( ) bar | xxx } ] show " let foo = \ n < html >\ nbar " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo = Options , 2 Text { | < html } >| Newline ( 3 , 0 ) Code_block bar | xxx } ] show " let foo \ n %% a = b \ n bar " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo Options a = b , 1 Text { | bar } | | xxx } ] show " let foo \ n %% a = b \ n bar \ n %%\ n baz " ; [ % expect { xxx | ( 1 , 0 ) Code_block let foo Options a = b , 1 Text { | bar } | Newline ( 5 , 0 ) Code_block baz | xxx } ] show " let foo \ n %% a = b \ n " ; %% [ % expect { | ( 1 , 0 ) Code_block let foo Options a = b , 1 ( 3 , 0 ) Code_block } ] | show " let foo \ n %% a = b \ n %% c \ n " ; [ % expect { | Line 2 : text following closing ' ' %% } ] |
|
module type TokenKindSig = sig type kind val next : Loc . source -> Lexing . lexbuf -> kind token val kindStr : kind -> string val tokenStr : kind token -> string val isEOF : kind -> bool val getEOF : kind end
|
module TokenStream ( S : TokenKindSig ) = struct type stream = { lexbuf : Lexing . lexbuf ; mutable has_errors : bool ; mutable errors : Error . t list ; mutable peeked : S . kind token ; mutable prev : S . kind token ; source : Loc . source } let backup ( s : stream ) = let lexbuf = Lexing . { refill_buff = s . lexbuf . refill_buff ; lex_buffer = s . lexbuf . lex_buffer ; lex_buffer_len = s . lexbuf . lex_buffer_len ; lex_abs_pos = s . lexbuf . lex_abs_pos ; lex_start_pos = s . lexbuf . lex_start_pos ; lex_curr_pos = s . lexbuf . lex_curr_pos ; lex_last_pos = s . lexbuf . lex_last_pos ; lex_last_action = s . lexbuf . lex_last_action ; lex_eof_reached = s . lexbuf . lex_eof_reached ; lex_mem = s . lexbuf . lex_mem ; lex_start_p = s . lexbuf . lex_start_p ; lex_curr_p = s . lexbuf . lex_curr_p } in { lexbuf ; has_errors = s . has_errors ; errors = s . errors ; peeked = s . peeked ; prev = s . prev ; source = s . source } let skip ( buffer : stream ) : unit = buffer . prev <- buffer . peeked ; buffer . peeked <- S . next buffer . source buffer . lexbuf let current ( buffer : stream ) : S . kind token = buffer . peeked let location ( buffer : stream ) : Loc . t = buffer . peeked . loc let peek ( buffer : stream ) : S . kind = ( current buffer ) . kind let makeError ( buffer : stream ) ( message : string ) : Error . t = Error . PointedError ( Loc . getNext buffer . prev . loc , message ) let setErrors ( buffer : stream ) ( value : bool ) : unit = buffer . has_errors <- value let hasErrors ( buffer : stream ) : bool = buffer . has_errors let getErrors ( buffer : stream ) : Error . t list = buffer . errors let notExpectedError ( token : S . kind token ) : Error . t = let message = Printf . sprintf " Not expecting to find % s " ( S . kindStr token . kind ) in Error . PointedError ( Loc . getNext token . loc , message ) let appendError ( buffer : stream ) ( error : Error . t ) = buffer . errors <- error :: buffer . errors let consume ( buffer : stream ) ( kind : S . kind ) : unit = match buffer . peeked with | t when t . kind = kind -> let _ = buffer . prev <- buffer . peeked in buffer . peeked <- S . next buffer . source buffer . lexbuf | t when S . isEOF t . kind -> let expected = S . kindStr kind in let message = Printf . sprintf " Expecting a % s but the file ended " expected in raise ( ParserError ( makeError buffer message ) ) | got_token -> let expected = S . kindStr kind in let got = S . tokenStr got_token in let message = Printf . sprintf " Expecting a % s but got % s " expected got in raise ( ParserError ( makeError buffer message ) ) let expect ( buffer : stream ) ( kind : S . kind ) : unit = match buffer . peeked with | t when t . kind = kind -> ( ) | t when S . isEOF t . kind -> let expected = S . kindStr kind in let message = Printf . sprintf " Expecting a % s but the file ended " expected in raise ( ParserError ( makeError buffer message ) ) | got_token -> let expected = S . kindStr kind in let got = S . kindStr got_token . kind in let message = Printf . sprintf " Expecting a % s but got % s " expected got in raise ( ParserError ( makeError buffer message ) ) let optConsume ( buffer : stream ) ( kind : S . kind ) : unit = match buffer . peeked with | t when t . kind = kind -> skip buffer | _ -> ( ) let emptyLexedLines ( ) = { current_line = Buffer . create 100 ; all_lines = [ ] } let fromString ? file ( str : string ) : stream = let lexbuf = Lexing . from_string str in let source = match file with | Some f -> let lex_start_p = Lexing . { lexbuf . lex_start_p with pos_fname = f } in let lex_curr_p = Lexing . { lexbuf . lex_curr_p with pos_fname = f } in lexbuf . Lexing . lex_start_p <- lex_start_p ; lexbuf . Lexing . lex_curr_p <- lex_curr_p ; Loc . File f | None -> Loc . Text str in let first = S . next source lexbuf in { lexbuf ; peeked = first ; prev = first ; has_errors = false ; errors = [ ] ; source } let fromChannel ( chan : in_channel ) ( file : string ) : stream = let lexbuf = Lexing . from_channel chan in lexbuf . Lexing . lex_curr_p <- { lexbuf . Lexing . lex_curr_p with Lexing . pos_fname = file } ; let source = Loc . File file in let first = S . next source lexbuf in { lexbuf ; peeked = first ; prev = first ; has_errors = false ; errors = [ ] ; source } end
|
let ttoken = TypApp ( tctoken , [ ] )
|
let ttokengadt a = TypApp ( tctokengadt , [ a ] )
|
let ttokengadtdata token = " T_ " ^ token
|
let tokentypedef grammar = let typerhs = match Settings . token_type_mode with | Settings . TokenTypeOnly | Settings . TokenTypeAndCode -> TDefSum ( List . map ( fun ( tok , typo ) -> { dataname = tok ; datavalparams = ( match typo with None -> [ ] | Some t -> [ TypTextual t ] ) ; datatypeparams = None ; comment = None ; unboxed = false ; } ) ( typed_tokens grammar ) ) | Settings . CodeOnly m -> TAbbrev ( TypApp ( m ^ " . " ^ tctoken , [ ] ) ) in [ IIComment " The type of tokens . " ; IITypeDecls [ { typename = tctoken ; typeparams = [ ] ; typerhs ; typeconstraint = None } ] ]
|
let tokengadtdef grammar = assert Settings . inspection ; let param , typerhs = match Settings . token_type_mode with | Settings . TokenTypeOnly | Settings . TokenTypeAndCode -> let param = " _ " in param , TDefSum ( { dataname = ttokengadtdata " error " ; datavalparams = [ ] ; datatypeparams = Some [ tunit ] ; comment = None ; unboxed = false ; } :: List . map ( fun ( token , typo ) -> { dataname = ttokengadtdata token ; datavalparams = [ ] ; datatypeparams = Some [ match typo with None -> tunit | Some t -> TypTextual t ] ; comment = None ; unboxed = false ; } ) ( typed_tokens grammar ) ) | Settings . CodeOnly m -> let param = " a " in param , TAbbrev ( TypApp ( m ^ " . " ^ tctokengadt , [ TypVar param ] ) ) in [ IIComment " The indexed type of terminal symbols . " ; IITypeDecls [ { typename = tctokengadt ; typeparams = [ param ] ; typerhs ; typeconstraint = None } ] ]
|
let produce_tokentypes grammar = match Settings . token_type_mode with | Settings . TokenTypeOnly -> let i = tokentypedef grammar @ MList . ifnlazy Settings . inspection ( fun ( ) -> tokengadtdef grammar ) in let module P = Printer . Make ( struct let f = open_out ( Settings . base ^ " . mli " ) let locate_stretches = None end ) in P . interface [ IIFunctor ( grammar . parameters , i ) ] ; let module P = Printer . Make ( struct let f = open_out ( Settings . base ^ " . ml " ) let locate_stretches = None end ) in P . program [ SIFunctor ( grammar . parameters , interface_to_structure i ) ] ; exit 0 | Settings . CodeOnly _ | Settings . TokenTypeAndCode -> ( )
|
let tokenprefix id = match Settings . token_type_mode with | Settings . CodeOnly m -> m ^ " . " ^ id | Settings . TokenTypeAndCode -> id | Settings . TokenTypeOnly -> id
|
let tokengadtdata token = tokenprefix ( ttokengadtdata token )
|
type token = Parser . token = | WITH | WHILE | WHEN | VIRTUAL | VAL | UNDERSCORE | UIDENT of string | TYPE | TRY | TRUE | TO | TILDE | THEN | STRUCT | STRING of ( string * Location . t * string option ) | STAR | SIG | SEMISEMI | SEMI | RPAREN | REC | RBRACKET | RBRACE | QUOTED_STRING_ITEM of ( string * Location . t * string * Location . t * string option ) | QUOTED_STRING_EXPR of ( string * Location . t * string * Location . t * string option ) | QUOTE | QUESTION | PRIVATE | PREFIXOP of string | PLUSEQ | PLUSDOT | PLUS | PERCENT | OR | OPTLABEL of string | OPEN | OF | OBJECT | NONREC | NEW | MUTABLE | MODULE | MINUSGREATER | MINUSDOT | MINUS | METHOD | MATCH | LPAREN | LIDENT of string | LETOP of string | LET | LESSMINUS | LESS | LBRACKETPERCENTPERCENT | LBRACKETPERCENT | LBRACKETLESS | LBRACKETGREATER | LBRACKETBAR | LBRACKETATATAT | LBRACKETATAT | LBRACKETAT | LBRACKET | LBRACELESS | LBRACE | LAZY | LABEL of string | INT of ( string * char option ) | INITIALIZER | INHERIT | INFIXOP4 of string | INFIXOP3 of string | INFIXOP2 of string | INFIXOP1 of string | INFIXOP0 of string | INCLUDE | IN | IF | HASHOP of string | HASH | GREATERRBRACKET | GREATERRBRACE | GREATER | FUNCTOR | FUNCTION | FUN | FOR | FLOAT of ( string * char option ) | FALSE | EXTERNAL | EXCEPTION | EQUAL | EOL | EOF | END | ELSE | DOWNTO | DOTOP of string | DOTDOT | DOT | DONE | DOCSTRING of Docstrings . docstring | DO | CONSTRAINT | COMMENT of ( string * Location . t ) | COMMA | COLONGREATER | COLONEQUAL | COLONCOLON | COLON | CLASS | CHAR of char | BEGIN | BARRBRACKET | BARBAR | BAR | BANG | BACKQUOTE | ASSERT | AS | ANDOP of string | AND | AMPERSAND | AMPERAMPER
|
let of_compiler_libs x = x
|
module State ( User : ANY ) = struct type t = { indent : Indent . t ; range : Position . range option ; user : User . t ; } let make ( user : User . t ) : t = { indent = Indent . initial ; range = None ; user } let check_position ( column : int ) ( s : t ) : Indent . expectation option = Indent . check_position column s . indent let expectation ( s : t ) : Indent . expectation option = Indent . expectation s . indent let next ( pos : Position . t ) ( user : User . t ) ( s : t ) : t = let range = match s . range with | None -> pos , pos | Some ( a , _ ) -> a , pos in { user ; range = Some range ; indent = Indent . token ( Position . column pos ) s . indent } let range ( s : t ) : Position . range option = s . range let user ( s : t ) : User . t = s . user let reset_range ( s : t ) : t = { s with range = None } let merge_ranges ( s0 : t ) ( s : t ) : t = match s0 . range , s . range with | None , None | None , Some _ -> s | Some _ , None -> { s with range = s0 . range } | Some ( p1 , _ ) , Some ( _ , p2 ) -> { s with range = Some ( p1 , p2 ) } let put_range ( s0 : t ) ( s : t ) : t = { s with range = s0 . range } let _ = range , reset_range , merge_ranges , put_range let update ( f : User . t -> User . t ) ( s : t ) : t = { s with user = f s . user } let align ( s : t ) : t = { s with indent = Indent . align s . indent } let left_align ( s : t ) : t = { s with indent = Indent . left_align s . indent } let start_detach ( s : t ) : t = { s with indent = Indent . initial } let end_detach ( s0 : t ) ( s : t ) : t = { s with indent = s0 . indent } let start_indent ( i : int ) ( s : t ) : t = assert ( 0 <= i ) ; { s with indent = Indent . start_indent i s . indent } let end_indent ( i : int ) ( s0 : t ) ( s : t ) : t = { s with indent = Indent . end_indent i s0 . indent s . indent } end
|
module Make ( User : ANY ) ( Token : ANY ) ( Final : ANY ) ( Semantic : ANY ) = struct module State = State ( User ) module Tok = struct type t = Token . t Located . t end module Expect = struct type t = String . t * Indent . violation option end module Basic = Generic . Make ( Tok ) ( State ) ( Expect ) ( Semantic ) ( Final ) include Basic module Parser = struct module P0 = Basic . Parser include P0 type state = User . t let state ( p : t ) : User . t = P0 . state p |> State . user end type expect = String . t type state = User . t type semantic = Semantic . t let map_and_update ( _ : User . t -> ' a -> ' b * User . t ) ( _ : ' a t ) : ' b t = assert false let unexpected ( e : String . t ) : ' a t = Basic . unexpected ( e , None ) let ( ) <?> ( p : ' a t ) ( e : String . t ) : ' a t = Basic . ( let * state = get in p <?> ( e , State . expectation state ) ) let get : User . t t = Basic . ( map State . user get ) let update ( f : User . t -> User . t ) : unit t = Basic . update ( State . update f ) let set ( user : User . t ) : unit t = update ( fun _ -> user ) let get_and_update ( f : User . t -> User . t ) : User . t t = Basic . ( map State . user ( get_and_update ( State . update f ) ) ) let state_around ( before : User . t -> User . t ) ( p : ' a t ) ( after : User . t -> ' a -> User . t -> User . t ) : ' a t = Basic . state_around ( State . update before ) p ( fun s0 a s1 -> State . ( update ( after ( user s0 ) a ) s1 ) ) let backtrack ( p : ' a t ) ( e : String . t ) : ' a t = Basic . ( backtrack p ( e , None ) ) let followed_by ( p : ' a t ) ( e : String . t ) : ' a t = Basic . ( followed_by p ( e , None ) ) let not_followed_by ( p : ' a t ) ( e : String . t ) : unit t = Basic . ( not_followed_by p ( e , None ) ) let expect_end ( a : ' a ) : ' a t = Basic . expect_end ( fun _ -> " end of input " , None ) a let step ( expect : String . t ) ( f : User . t -> Position . range -> Token . t -> ( ' a * User . t ) option ) : ' a Basic . t = Basic . step ( fun state -> function | None -> Error ( expect , None ) | Some tok -> let ( p1 , p2 ) , tok = Located . range tok , Located . value tok in let column = Position . column p1 in match State . check_position column state with | None -> begin match f ( State . user state ) ( p1 , p2 ) tok with | None -> Error ( expect , None ) | Some ( a , user ) -> Ok ( a , State . next p1 user state ) end | Some vio -> Error ( expect , Some vio ) ) let indent ( i : int ) ( p : ' a t ) : ' a t = assert ( 0 <= i ) ; let * state = Basic . get_and_update ( State . start_indent i ) in let * a = p in let * _ = Basic . update ( State . end_indent i state ) in return a let align ( p ' : a t ) : ' a t = let * _ = Basic . update State . align in p let left_align ( p ' : a t ) : ' a t = let * _ = Basic . update State . left_align in p let detach ( p : ' a t ) : ' a t = let * state = Basic . get_and_update State . start_detach in let * a = p in let * _ = Basic . update ( State . end_detach state ) in return a let make ( user : User . t ) ( p : Final . t t ) : Parser . t = Basic . make ( State . make user ) p ( fun _ -> " end of input " , None ) end
|
module Stable = struct module V1 = struct type t = | Token_owned of { disable_new_accounts : bool } | Not_owned of { account_disabled : bool } [ @@ deriving compare , equal , sexp , hash , yojson ] yojson let to_latest = Fn . id end end ] end
|
let default = Not_owned { account_disabled = false }
|
let to_input t = let bs = match t with | Token_owned { disable_new_accounts } -> [ true ; disable_new_accounts ] | Not_owned { account_disabled } -> [ false ; account_disabled ] in Random_oracle . Input . Chunked . packed ( Field . project bs , List . length bs ) bs
|
type var = { token_owner : Boolean . var ; token_locked : Boolean . var }
|
let var_of_t = function | Token_owned { disable_new_accounts } -> { token_owner = Boolean . true_ ; token_locked = Boolean . var_of_value disable_new_accounts } | Not_owned { account_disabled } -> { token_owner = Boolean . false_ ; token_locked = Boolean . var_of_value account_disabled }
|
let typ : ( var , t ) t Typ . t = let open Typ in Boolean . typ * Boolean . typ |> Typ . transport_var ~ back ( : fun ( token_owner , token_locked ) token_locked -> { token_owner ; token_locked } ) ~ there ( : fun { token_owner ; token_locked } -> ( token_owner , token_locked ) token_locked ) token_locked |> Typ . transport ~ there ( : function | Token_owned { disable_new_accounts } -> ( true , disable_new_accounts ) disable_new_accounts | Not_owned { account_disabled } -> ( false , account_disabled ) account_disabled ) ~ back ( : fun ( token_owner , token_locked ) token_locked -> if token_owner then Token_owned { disable_new_accounts = token_locked } else Not_owned { account_disabled = token_locked } )
|
let var_to_input { token_owner ; token_locked } = let bs = [ token_owner ; token_locked ] in Random_oracle . Input . Chunked . packed ( Field . Var . project bs , List . length bs ) bs [ %% endif ] endif
|
let gen = let open Quickcheck . Generator . Let_syntax in let % bind token_owner = Quickcheck . Generator . bool in let % map token_locked = Quickcheck . Generator . bool in if token_owner then Token_owned { disable_new_accounts = token_locked } else Not_owned { account_disabled = token_locked }
|
type t = [ ` Int of int | ` Float of float | ` String of string | ` Bool of bool | ` List of t list | ` Assoc of ( string * t ) t list ]
|
let rec of_toml_table v : t = let f ( k , v ) v = ( Toml . Types . Table . Key . to_string k , of_toml_value v ) v in let pairs = List . map f ( Toml . Types . Table . bindings v ) v in ` Assoc pairs | TBool b -> ` Bool b | TInt i -> ` Int i | TFloat f -> ` Float f | TString s -> ` String s | TDate f -> ` Float f | TArray a -> ` List ( of_toml_array a ) a | TTable t -> of_toml_table t | NodeEmpty -> [ ] | NodeBool bs -> List . map ( fun v -> ` Bool v ) v bs | NodeInt is -> List . map ( fun v -> ` Int v ) v is | NodeFloat fs -> List . map ( fun v -> ` Float v ) v fs | NodeString ss -> List . map ( fun v -> ` String v ) v ss | NodeDate fs -> List . map ( fun v -> ` Float v ) v fs | NodeArray arrs -> List . map ( fun v -> ` List ( of_toml_array v ) v ) v arrs | NodeTable ts -> List . map ( fun v -> of_toml_table v ) v ts
|
let source = let module D = CConv . Decode in let rec src = { D . emit = ( fun dec ( x : t ) t -> match x with | ` Bool b -> dec . D . accept_bool src b | ` Int i -> dec . D . accept_int src i | ` Float f -> dec . D . accept_float src f | ` String s -> dec . D . accept_string src s | ` List l -> dec . D . accept_list src l | ` Assoc l -> dec . D . accept_record src l ) } in src
|
let decode dec x = CConv . decode source dec ( of_toml_table x ) x
|
let decode_exn dec x = CConv . decode_exn source dec ( of_toml_table x ) x
|
type metadata = { name : string ; source : string ; license : string ; synopsis : string ; description : string ; lifecycle : string ; }
|
let path = Fpath . v " data / tools . yml "
|
module Lifecycle = struct type t = [ ` Incubate | ` Active | ` Sustain | ` Deprecate ] let to_string = function | ` Incubate -> " incubate " | ` Active -> " active " | ` Sustain -> " sustain " | ` Deprecate -> " deprecate " let of_string = function | " incubate " -> Ok ` Incubate | " active " -> Ok ` Active | " sustain " -> Ok ` Sustain | " deprecate " -> Ok ` Deprecate | s -> Error ( ` Msg ( " Unknown lifecycle type : " ^ s ) s ) s end
|
type t = { name : string ; slug : string ; source : string ; license : string ; synopsis : string ; description : string ; lifecycle : Lifecycle . t ; }
|
let parse s = let yaml = Utils . decode_or_raise Yaml . of_string s in match yaml with | ` O [ ( " tools " , ` A xs ) xs ] -> Ok ( List . map ( fun x -> Utils . decode_or_raise metadata_of_yaml x ) x xs ) xs | _ -> Error ( ` Msg " Expected list of tools ) "
|
let decode s = let yaml = Utils . decode_or_raise Yaml . of_string s in match yaml with | ` O [ ( " tools " , ` A xs ) xs ] -> List . map ( fun x -> try let ( metadata : metadata ) metadata = Utils . decode_or_raise metadata_of_yaml x in let lifecycle = match Lifecycle . of_string metadata . lifecycle with | Ok x -> x | Error ( ` Msg err ) err -> raise ( Exn . Decode_error err ) err in let description = Omd . of_string metadata . description |> Omd . to_html in ( { name = metadata . name ; slug = Utils . slugify metadata . name ; source = metadata . source ; license = metadata . license ; synopsis = metadata . synopsis ; description ; lifecycle ; } : t ) t with e -> print_endline ( Yaml . to_string x |> Result . get_ok ) get_ok ; raise e ) e xs | _ -> raise ( Exn . Decode_error " expected a list of tools ) "
|
let all ( ) = let content = Data . read " tools . yml " |> Option . get in decode content
|
let pp_lifecycle ppf v = Fmt . pf ppf " % s " ( match v with | ` Incubate -> " ` Incubate " | ` Active -> " ` Active " | ` Sustain -> " ` Sustain " | ` Deprecate -> " ` Deprecate ) "
|
let pp ppf v = Fmt . pf ppf { | { name = % a ; slug = % a ; source = % a ; license = % a ; synopsis = % a ; description = % a ; lifecycle = % a } } | Pp . string v . name Pp . string v . slug Pp . string v . source Pp . string v . license Pp . string v . synopsis Pp . string v . description pp_lifecycle v . lifecycle
|
let pp_list = Pp . list pp
|
let template ( ) = Format . asprintf { |
|
type lifecycle = [ ` Incubate | ` Active | ` Sustain | ` Deprecate ]
|
type t = { name : string ; slug : string ; source : string ; license : string ; synopsis : string ; description : string ; lifecycle : lifecycle }
|
let all = % a } | pp_list ( all ( ) )
|
let tool_messages_clicked = new tool_messages_clicked ( ) in let tool_hmessages_clicked = new tool_hmessages_clicked ( ) in let toolbar = GButton . toolbar ~ style ` : ICONS ( ) in let _ = toolbar # set_icon_size ` MENU in let tool_new_file = GButton . tool_button ~ label " : New " ( ) in let _ = tool_new_file # set_icon_widget ( GMisc . image ~ pixbuf : Icons . new_file ( ) ) # coerce in let tool_open_file = GButton . tool_button ~ label " : Open " ( ) in let _ = tool_open_file # set_icon_widget ( GMisc . image ~ pixbuf : Icons . open_file ( ) ) # coerce in let tool_save = GButton . tool_button ~ stock ` : SAVE ~ homogeneous : false ~ label " : Save " ( ) in let tool_save_all = Gmisclib . Toolbar . menu_tool_button ~ homogeneous : false ~ toolbar ~ label " : Save All " ( ) in let tool_close_file = GButton . tool_button ~ stock ` : CLOSE ~ label " : Close " ( ) in let tool_undo = GButton . tool_button ~ stock ` : UNDO ~ label " : Undo " ( ) in let tool_redo = GButton . tool_button ~ stock ` : REDO ~ label " : Redo " ( ) in let tool_find_repl = GButton . tool_button ~ label " : Find and Replace " ( ) in let _ = tool_find_repl # set_icon_widget ( GMisc . image ~ pixbuf : Icons . find_replace ( ) ) # coerce in let tool_item_find_entry = GButton . tool_item ~ homogeneous : false ( ) in let tool_find = GButton . tool_button ~ label " : Find " ( ) in let tool_messages = GButton . toggle_tool_button ~ active : messages # visible ~ label " : Messages " ( ) in let _ = tool_messages # set_icon_widget ( GMisc . image ~ pixbuf : Icons . paned_bottom_large ( ) ) # coerce in let _ = tool_messages # set_homogeneous false in let tool_hmessages = GButton . toggle_tool_button ~ active : messages # visible ~ label " : Messages " ( ) in let _ = tool_hmessages # set_icon_widget ( GMisc . image ~ pixbuf : Icons . paned_right ( ) ) # coerce in let tool_messages_sign = tool_messages # connect # clicked ~ callback ( : fun ( ) -> tool_messages_clicked # call ( not messages # visible ) ) in let tool_hmessages_sign = tool_hmessages # connect # clicked ~ callback ( : fun ( ) -> tool_hmessages_clicked # call ( not hmessages # visible ) ) in let tool_eval = GButton . tool_button ~ label " : Toplevel " ( ) in let _ = tool_eval # set_icon_widget ( GMisc . image ~ pixbuf : Icons . toplevel ( ) ) # coerce in let tool_clean = Gmisclib . Toolbar . menu_tool_button ~ toolbar ~ homogeneous : false ( ) in let tool_targets = GButton . tool_button ~ label " : Targets " ( ) in let tool_compile_file = GButton . tool_button ~ label " : Compile File " ( ) in let tool_compile = Gmisclib . Toolbar . menu_tool_button ~ toolbar ~ homogeneous : false ( ) in let tool_build = Gmisclib . Toolbar . menu_tool_button ~ toolbar ~ homogeneous : false ( ) in let tool_run = Gmisclib . Toolbar . menu_tool_button ~ toolbar ~ homogeneous : false ( ) in let tool_back = Gmisclib . Toolbar . menu_tool_button ~ toolbar ~ label " : Previous Location " ~ homogeneous : false ( ) in let _ = tool_back # set_image ( GMisc . image ~ pixbuf : Icons . go_back ( ) ) # coerce in let tool_forward = Gmisclib . Toolbar . menu_tool_button ~ toolbar ~ label " : Next Location " ~ homogeneous : false ( ) in let _ = tool_forward # set_image ( GMisc . image ~ pixbuf : Icons . go_forward ( ) ) # coerce in let tool_last_edit_loc = GButton . tool_button ~ label " : Last Edit Location " ( ) in let _ = tool_last_edit_loc # set_icon_widget ( GMisc . image ~ pixbuf : Icons . goto_last ( ) ) # coerce in let tool_entry_find = GEdit . combo_box_entry ~ wrap_width : 3 ~ focus_on_click : false ~ model : Find_text . status . Find_text . h_find . Find_text . model ~ text_column : Find_text . status . Find_text . h_find . Find_text . column ~ packing : tool_item_find_entry # add ( ) in let _ = tool_entry_find # entry # set_text begin match Find_text . status . Find_text . h_find . Find_text . model # get_iter_first with | None -> " " | Some row -> Find_text . status . Find_text . h_find . Find_text . model # get ~ row ~ column : Find_text . status . Find_text . h_find . Find_text . column end in let _ = Find_text . status . Find_text . text_find # connect # changed ~ callback : tool_entry_find # entry # set_text in object ( self ) inherit GObj . widget toolbar # as_widget method children = toolbar # children method tool_new_file = tool_new_file method tool_open_file = tool_open_file method tool_save = tool_save method tool_save_all = tool_save_all method tool_close_file = tool_close_file method tool_undo = tool_undo method tool_redo = tool_redo method tool_find_repl = tool_find_repl method tool_entry_find = tool_entry_find method tool_find = tool_find method tool_eval = tool_eval method tool_compile_file = tool_compile_file method tool_targets = tool_targets method tool_back = tool_back method tool_forward = tool_forward method tool_last_edit_loc = tool_last_edit_loc method tool_messages_handler_block ( ) = tool_messages # misc # handler_block tool_messages_sign method tool_messages_handler_unblock ( ) = tool_messages # misc # handler_unblock tool_messages_sign method tool_messages_set_active = tool_messages # set_active method tool_hmessages_handler_block ( ) = tool_hmessages # misc # handler_block tool_hmessages_sign method tool_hmessages_handler_unblock ( ) = tool_hmessages # misc # handler_unblock tool_hmessages_sign method tool_hmessages_set_active = tool_hmessages # set_active method clean_current browser = browser # with_current_project ( fun project -> browser # with_default_target begin fun target -> ignore ( Task_console . exec ~ editor ` CLEAN target ) end ) method clean_menu browser ( label , menu ) = browser # with_current_project ( fun project -> browser # with_default_target begin fun target -> label := Some ( sprintf " Clean \ xC2 \ xAB % s \ xC2 \ xBB " target . Target . name ) ; let targets = project . Prj . targets in List . iter begin fun tg -> let item = GMenu . menu_item ~ label : tg . Target . name ~ packing : menu # add ( ) in ignore ( item # connect # activate ~ callback : begin fun ( ) -> ignore ( Task_console . exec ~ editor ` CLEAN tg ) end ) ; end targets ; let _ = GMenu . separator_item ~ packing : menu # add ( ) in let item = GMenu . menu_item ~ label " : Clean Project " ~ packing : menu # add ( ) in item # connect # activate ~ callback : browser # project_clean |> ignore ; end ) method compile_current browser = browser # with_current_project ( fun project -> browser # with_default_target begin fun target -> ignore ( Task_console . exec ~ editor ` COMPILE_ONLY target ) end ) method compile_menu browser ( label , menu ) = browser # with_current_project ( fun project -> browser # with_default_target begin fun target -> label := Some ( sprintf " Compile \ xC2 \ xAB % s \ xC2 \ xBB " target . Target . name ) ; let targets = project . Prj . targets in List . iter begin fun tg -> let item = GMenu . menu_item ~ label : tg . Target . name ~ packing : menu # add ( ) in ignore ( item # connect # activate ~ callback : begin fun ( ) -> ignore ( Task_console . exec ~ editor ` COMPILE_ONLY tg ) end ) ; end targets ; end ) method build_current browser = browser # with_current_project ( fun project -> browser # with_default_target begin fun target -> ignore ( Task_console . exec ~ editor ` COMPILE target ) end ) method build_menu browser ( label , menu ) = browser # with_current_project ( fun project -> browser # with_default_target begin fun target -> label := Some ( sprintf " Build \ xC2 \ xAB % s \ xC2 \ xBB " target . Target . name ) ; let targets = project . Prj . targets in List . iter begin fun tg -> let item = GMenu . menu_item ~ label : tg . Target . name ~ packing : menu # add ( ) in ignore ( item # connect # activate ~ callback : begin fun ( ) -> ignore ( Task_console . exec ~ editor ` COMPILE tg ) end ) ; ( ) end targets ; end ) method run_current browser = browser # with_current_project ( fun project -> browser # with_default_runtime_config ~ open_dialog : true ( fun rc -> let bc = List . find ( fun b -> b . Target . id = rc . Rconf . target_id ) project . Prj . targets in ignore ( Task_console . exec ~ editor ( ` RCONF rc ) bc ) ) ) method run_menu browser ( label , menu ) = browser # with_current_project ( fun project -> browser # with_default_runtime_config ~ open_dialog : true ( fun default_rc -> label := Some ( sprintf " Run \ xC2 \ xAB % s \ xC2 \ xBB " default_rc . Rconf . name ) ; let targets = project . Prj . targets in List . iter begin fun rc -> let item = GMenu . menu_item ~ label : rc . Rconf . name ~ packing : menu # add ( ) in ignore ( item # connect # activate ~ callback : begin fun ( ) -> try let bc = List . find ( fun b -> b . Target . id = rc . Rconf . target_id ) targets in ignore ( Task_console . exec ~ editor ( ` RCONF rc ) bc ) with Not_found -> ( ) end ) ; end project . Prj . executables ) ) initializer toolbar # insert tool_new_file ; toolbar # insert tool_open_file ; toolbar # insert tool_save ; tool_save # set_icon_widget ( GMisc . image ~ pixbuf : Icons . save_16 ( ) ) # coerce ; toolbar # insert tool_save_all # as_tool_item ; tool_save_all # set_image ( GMisc . image ~ pixbuf : Icons . save_all_16 ( ) ) # coerce ; let _ = GButton . separator_tool_item ~ packing : toolbar # insert ( ) in toolbar # insert tool_undo ; toolbar # insert tool_redo ; let _ = GButton . separator_tool_item ~ packing : toolbar # insert ( ) in toolbar # insert tool_find_repl ; toolbar # insert tool_item_find_entry ; toolbar # insert tool_find ; tool_find # set_icon_widget ( GMisc . image ~ pixbuf : Icons . search_again_16 ( ) ) # coerce ; let _ = GButton . separator_tool_item ~ packing : toolbar # insert ( ) in toolbar # insert tool_messages ; toolbar # insert tool_hmessages ; let _ = GButton . separator_tool_item ~ packing : toolbar # insert ( ) in toolbar # insert tool_eval ; tool_eval # misc # set_tooltip_text " Eval in Toplevel " ; toolbar # insert tool_compile_file ; tool_compile_file # set_icon_widget ( Icons . create Icons . compile_file_16 ) # coerce ; let _ = GButton . separator_tool_item ~ packing : toolbar # insert ( ) in toolbar # insert tool_targets ; tool_targets # set_icon_widget ( Icons . create Icons . target_16 ) # coerce ; let _ = GButton . separator_tool_item ~ packing : toolbar # insert ( ) in toolbar # insert tool_clean # as_tool_item ; tool_clean # set_image ( GMisc . image ~ pixbuf : Icons . clear_build_16 ( ) ) # coerce ; toolbar # insert tool_compile # as_tool_item ; tool_compile # set_image ( GMisc . image ~ pixbuf : Icons . compile_all_16 ( ) ) # coerce ; tool_compile # misc # set_tooltip_text " Compile only " ; toolbar # insert tool_build # as_tool_item ; tool_build # set_image ( GMisc . image ~ pixbuf : Icons . build_16 ( ) ) # coerce ; tool_build # misc # set_tooltip_text " Build " ; toolbar # insert tool_run # as_tool_item ; tool_run # set_image ( GMisc . image ~ icon_size ` : MENU ~ pixbuf : Icons . start_16 ( ) ) # coerce ; let _ = GButton . separator_tool_item ~ packing : toolbar # insert ( ) in toolbar # insert tool_back # as_tool_item ; toolbar # insert tool_forward # as_tool_item ; toolbar # insert tool_last_edit_loc ; let _ = GButton . separator_tool_item ~ draw : false ~ expand : true ~ packing : toolbar # insert ( ) in toolbar # insert tool_close_file ; tool_close_file # set_icon_widget ( GMisc . image ~ pixbuf : Icons . close_16 ( ) ) # coerce ; ( ) method bind_signals : ' a -> unit = fun browser -> ignore ( tool_new_file # connect # clicked ~ callback : browser # dialog_file_new ) ; ignore ( tool_open_file # connect # clicked ~ callback : editor # dialog_file_open ) ; ignore ( tool_save # connect # clicked ~ callback : begin fun ( ) -> Gaux . may ~ f : editor # save ( editor # get_page ` ACTIVE ) end ) ; ignore ( tool_save_all # connect # clicked ~ callback : browser # save_all ) ; ignore ( tool_save_all # connect # show_menu ~ callback : begin fun ( label , menu ) -> List . iter begin fun p -> if p # view # buffer # modified then begin let item = GMenu . menu_item ~ label ( : Filename . basename p # get_filename ) ~ packing : menu # append ( ) in ignore ( item # connect # activate ~ callback : p # save ) ; end end editor # pages ; end ) ; ignore ( tool_close_file # connect # clicked ~ callback ( : fun ( ) -> editor # with_current_page ( fun page -> ignore ( editor # dialog_confirm_close page ) ) ) ) ; ignore ( tool_undo # connect # clicked ~ callback ( : fun ( ) -> editor # with_current_page ( fun p -> p # undo ( ) ) ) ) ; ignore ( tool_redo # connect # clicked ~ callback ( : fun ( ) -> editor # with_current_page ( fun p -> p # redo ( ) ) ) ) ; let search_again ( ) = browser # with_current_project begin fun project -> Find_text . update_status ~ project ~ text_find : tool_entry_find # entry # text ( ) ; Menu_search . search_again editor ; end ; in ignore ( tool_find_repl # connect # clicked ~ callback ( : fun ( ) -> Menu_search . find_replace ? find_all : None ? search_word_at_cursor : None editor ) ) ; ignore ( tool_entry_find # entry # event # connect # key_press ~ callback : begin fun ev -> if GdkEvent . Key . keyval ev = GdkKeysyms . _Return then begin search_again ( ) ; true end else false end ) ; ignore ( tool_find # connect # clicked ~ callback : search_again ) ; ignore ( self # connect # tool_messages_clicked ~ callback ( : fun _ -> ( ( browser # set_vmessages_visible ( not messages # visible ) ) : unit ) ) ) ; ignore ( self # connect # tool_hmessages_clicked ~ callback ( : fun _ -> ( ( browser # set_hmessages_visible ( not hmessages # visible ) ) : unit ) ) ) ; ignore ( tool_eval # connect # clicked ~ callback : begin fun ( ) -> Gaux . may ~ f ( : fun p -> p # ocaml_view # obuffer # send_to_shell ( ) ) ( editor # get_page ` ACTIVE ) end ) ; ignore ( tool_compile_file # connect # clicked ~ callback : begin fun ( ) -> editor # with_current_page begin fun p -> if Preferences . preferences # get . Preferences . pref_editor_save_all_bef_comp then ( editor # save_all ( ) ) ; p # compile_buffer ? join : None ( ) end end ) ; ignore ( tool_targets # connect # clicked ~ callback ( : fun ( ) -> browser # dialog_project_properties ? page_num ( : Some 1 ) ? show ( : Some true ) ( ) ) ) ; ignore ( tool_clean # connect # clicked ~ callback ( : fun ( ) -> self # clean_current browser ) ) ; ignore ( tool_clean # connect # show_menu ~ callback ( : self # clean_menu browser ) ) ; ignore ( tool_compile # connect # clicked ~ callback ( : fun ( ) -> self # compile_current browser ) ) ; ignore ( tool_compile # connect # show_menu ~ callback ( : self # compile_menu browser ) ) ; ignore ( tool_build # connect # clicked ~ callback ( : fun ( ) -> self # build_current browser ) ) ; ignore ( tool_build # connect # show_menu ~ callback ( : self # build_menu browser ) ) ; ignore ( tool_run # connect # clicked ~ callback ( : fun ( ) -> self # run_current browser ) ) ; ignore ( tool_run # connect # show_menu ~ callback ( : self # run_menu browser ) ) ; tool_back # connect # clicked ~ callback ( : fun ( ) -> browser # goto_location ` PREV ) ; tool_forward # connect # clicked ~ callback ( : fun ( ) -> browser # goto_location ` NEXT ) ; tool_last_edit_loc # connect # clicked ~ callback ( : fun ( ) -> browser # goto_location ` LAST ) ; tool_back # connect # show_menu ~ callback ( : fun ( dir , menu ) -> browser # create_menu_history ` BACK ~ menu ) ; tool_forward # connect # show_menu ~ callback ( : fun ( dir , menu ) -> browser # create_menu_history ` FORWARD ~ menu ) ; ( ) method update current_project = let dbf = match current_project with None -> None | Some x -> Project . default_target x in let editor_empty = List . length editor # pages = 0 in let current_modified = match editor # get_page ` ACTIVE with Some p when p # buffer # modified -> true | _ -> false in tool_messages # misc # set_sensitive true ; tool_hmessages # misc # set_sensitive true ; tool_new_file # misc # set_sensitive ( current_project <> None ) ; tool_open_file # misc # set_sensitive ( current_project <> None ) ; tool_save # misc # set_sensitive ( current_project <> None && current_modified ) ; tool_close_file # misc # set_sensitive ( not editor_empty ) ; tool_find_repl # misc # set_sensitive ( current_project <> None && not editor_empty ) ; tool_find # misc # set_sensitive ( current_project <> None && not editor_empty ) ; tool_item_find_entry # misc # set_sensitive ( current_project <> None && not editor_empty ) ; tool_targets # misc # set_sensitive ( current_project <> None ) ; tool_clean # misc # set_sensitive ( current_project <> None && dbf <> None ) ; tool_compile # misc # set_sensitive ( current_project <> None && dbf <> None ) ; tool_build # misc # set_sensitive ( current_project <> None && dbf <> None ) ; tool_run # misc # set_sensitive ( current_project <> None && dbf <> None ) ; editor # with_current_page begin fun p -> let name = Filename . basename p # get_filename in if name ^^^ " . ml " || name ^^^ " . mli " then begin kprintf tool_compile_file # misc # set_tooltip_text " Compile \ xC2 \ xAB % s \ xC2 \ xBB " name ; tool_compile_file # misc # set_sensitive true end else begin tool_compile_file # misc # set_tooltip_text " " ; tool_compile_file # misc # set_sensitive false end end ; begin let back , forward , last = editor # location_history_is_empty ( ) in try tool_back # misc # set_sensitive ( not back ) ; tool_forward # misc # set_sensitive ( not forward ) ; tool_last_edit_loc # misc # set_sensitive ( not last ) ; with _ -> ( ) end ; method connect = new signals ~ tool_messages_clicked ~ tool_hmessages_clicked end object inherit ml_signals [ tool_messages_clicked # disconnect ; tool_hmessages_clicked # disconnect ] method tool_messages_clicked = tool_messages_clicked # connect ~ after method tool_hmessages_clicked = tool_hmessages_clicked # connect ~ after end
|
type icon = P of GdkPixbuf . pixbuf | S of GtkStock . id | N
|
type kind = B | BM | M | I
|
type ' a item = { id : int ; tag : ' a ; kind : kind ; pixbuf : icon ; label : string ; check : GMenu . check_menu_item ; mutable tool_widget : GObj . widget option ; mutable tool_callback : ( unit -> unit ) ; mutable tool_callback_menu : ( string option ref * GMenu . menu -> unit ) option ; }
|
let pixbuf_empty = let pixbuf = GdkPixbuf . create ~ width : 1 ~ height : 16 ~ has_alpha : true ( ) in GdkPixbuf . fill pixbuf 0l ; let pixbuf = GdkPixbuf . add_alpha ~ transparent ( : 0 , 0 , 0 ) pixbuf in pixbuf
|
let specs ~ browser = let editor : Editor . editor = browser # editor in [ 100 , ` NEW_FILE , B , P Icons . new_file , " New File . . . " , ( fun _ -> browser # dialog_file_new ( ) ) , None ; 200 , ` OPEN_FILE , B , P Icons . open_file , " Open File . . . " , ( fun _ -> editor # dialog_file_open ( ) ) , None ; 300 , ` SAVE , B , P Icons . save_16 , " Save " , ( fun _ -> Gaux . may ~ f : editor # save ( editor # get_page ` ACTIVE ) ) , None ; 400 , ` SAVE_ALL , B , P Icons . save_all_16 , " Save All " , ( fun _ -> browser # save_all ( ) ) , None ; 500 , ` CLOSE , B , S ` CLOSE , " Close Current File " , ( fun _ -> editor # with_current_page ( fun p -> ignore ( editor # dialog_confirm_close p ) ) ) , None ; 600 , ` SEP , I , N , " " , ignore , None ; 700 , ` FIND_REPL , B , P Icons . find_replace , " Find and Replace " , begin fun _ -> Menu_search . find_replace ? find_all : None ? search_word_at_cursor : None editor end , None ; 800 , ` SEARCH_AGAIN , B , P Icons . search_again_16 , " Search Again " , ( fun _ -> Menu_search . search_again editor ) , None ; 900 , ` SEP , I , N , " " , ignore , None ; 1000 , ` VIEW_MESSAGES , B , P Icons . paned_bottom , " View Messages " , ( fun _ -> browser # set_vmessages_visible ( not Messages . vmessages # visible ) ) , None ; 1100 , ` VIEW_HMESSAGES , B , P Icons . paned_right , " View Messages ( Right Pane ) " , ( fun _ -> browser # set_hmessages_visible ( not Messages . hmessages # visible ) ) , None ; 1200 , ` SEP , I , N , " " , ignore , None ; 1300 , ` EVAL_TOPLEVEL , B , P Icons . toplevel , " Eval in Toplevel " , ( fun _ -> editor # with_current_page ( fun page -> page # ocaml_view # obuffer # send_to_shell ( ) ) ) , None ; 1400 , ` COMPILE_FILE , B , P Icons . compile_file_16 , " Compile Current File " , begin fun _ -> browser # editor # with_current_page begin fun p -> if Preferences . preferences # get . Preferences . pref_editor_save_all_bef_comp then ( editor # save_all ( ) ) ; p # compile_buffer ? join : None ( ) end end , None ; 1500 , ` SEP , I , N , " " , ignore , None ; 1600 , ` SHOW_TARGETS , B , P Icons . target_16 , " Targets " , begin fun _ -> browser # dialog_project_properties ? page_num ( : Some 1 ) ? show ( : Some true ) ( ) end , None ; 1700 , ` SEP , I , N , " " , ignore , None ; 1750 , ` CLEAN_PROJ , B , N , " Clean Project " , browser # project_clean , None ; 1800 , ` CLEAN , BM , P Icons . clear_build_16 , " Clean . . . " , ( fun ( ) -> browser # toolbar # clean_current browser ) , Some ( browser # toolbar # clean_menu browser ) ; 1900 , ` COMPILE , BM , P Icons . compile_all_16 , " Compile . . . " , ( fun ( ) -> browser # toolbar # compile_current browser ) , Some ( browser # toolbar # compile_menu browser ) ; 2000 , ` BUILD , BM , P Icons . build_16 , " Build . . . " , ( fun ( ) -> browser # toolbar # build_current browser ) , Some ( browser # toolbar # build_menu browser ) ; 2100 , ` BUILD_DEP , M , N , " Build Dep . " , begin fun ( ) -> browser # with_current_project begin fun project -> browser # with_default_target begin fun target -> ignore ( Task_console . exec ~ editor ~ with_deps : true ` COMPILE target ) end end end , Some ( begin fun ( label , menu ) -> browser # with_current_project begin fun project -> browser # with_default_target begin fun target -> label := None ; end ; List . iter begin fun tg -> let item = GMenu . menu_item ~ label : tg . Target . name ~ packing : menu # add ( ) in ignore ( item # connect # activate ~ callback : begin fun ( ) -> ignore ( Task_console . exec ~ editor ~ with_deps : true ` COMPILE tg ) end ) ; end project . Prj . targets ; end end ) ; 2200 , ` RUN , BM , P Icons . start_16 , " Run . . . " , ( fun ( ) -> browser # toolbar # run_current browser ) , Some ( browser # toolbar # run_menu browser ) ; ]
|
let items ~ browser = let items = List . map ( fun ( id , tag , kind , pixbuf , label , tool_callback , tool_callback_menu ) -> { id ; tag ; kind ; pixbuf ; label ; check = GMenu . check_menu_item ~ active : false ( ) ; tool_widget = None ; tool_callback ; tool_callback_menu ; } ) ( specs ~ browser ) in items , fun tag -> try let item = List . find ( fun it -> it . tag = tag ) items in item . tool_widget with Not_found -> assert false
|
let create_tool ( ~ toolbox : GPack . box ) item = let image = match item . pixbuf with | P _ when item . tag = ` VIEW_MESSAGES -> Some ( GMisc . image ~ pixbuf : Icons . paned_bottom_large ( ) ) | P pixbuf -> Some ( GMisc . image ~ pixbuf ( ) ) | S stock -> Some ( GMisc . image ~ stock ~ icon_size ` : SMALL_TOOLBAR ( ) ) | N -> None in match item . kind with | I -> ( GMisc . separator ` VERTICAL ~ packing : toolbox # pack ( ) ) # coerce | BM -> let tool = Gmisclib . Button . button_menu ~ relief ` : NONE ~ spacing : 1 ~ packing : toolbox # pack ( ) in Gaux . may image ~ f ( : fun image -> tool # set_image image # coerce ) ; tool # button # misc # set_name " menubar_button " ; tool # button_menu # misc # set_name " menubar_button_arrow " ; tool # button # set_focus_on_click false ; tool # button # misc # modify_fg [ ` PRELIGHT , ` BLACK ] ; tool # button_menu # misc # modify_fg [ ` PRELIGHT , ` BLACK ] ; tool # connect # clicked ~ callback ( : fun ( ) -> Gmisclib . Idle . add item . tool_callback ) |> ignore ; Gaux . may item . tool_callback_menu ~ f ( : fun callback -> tool # connect # show_menu ~ callback ) |> ignore ; tool # coerce | M -> let tool = Gmisclib . Button . button_menu ~ label : item . label ~ relief ` : NONE ~ packing : toolbox # pack ( ) in Gaux . may image ~ f ( : fun image -> tool # set_image image # coerce ) ; tool # button # misc # set_name " menubar_button " ; tool # button_menu # misc # set_name " menubar_button " ; tool # button # set_focus_on_click false ; tool # set_menu_only ( ) ; tool # connect # clicked ~ callback ( : fun ( ) -> Gmisclib . Idle . add item . tool_callback ) |> ignore ; Gaux . may item . tool_callback_menu ~ f ( : fun callback -> tool # connect # show_menu ~ callback ) |> ignore ; tool # coerce | B -> let button = GButton . button ~ relief ` : NONE ~ packing : toolbox # pack ( ) in begin match image with | Some image -> button # set_image image # coerce | _ -> button # set_label item . label end ; button # misc # set_name " menubar_button " ; button # set_focus_on_click false ; button # child # misc # modify_fg [ ` PRELIGHT , ` BLACK ] ; let callback = fun ( ) -> Gmisclib . Idle . add item . tool_callback in button # connect # clicked ~ callback |> ignore ; button # coerce ; ;
|
let create_item ~ menu ( ~ toolbox : GPack . box ) ~ pos item = menu # add ( item . check :> GMenu . menu_item ) ; item . check # event # connect # button_release ~ callback : begin fun _ -> item . check # set_active ( not item . check # active ) ; true ; end |> ignore ; item . check # connect # toggled ~ callback : begin fun ( ) -> let add_pref ( ) = preferences # get . pref_general_menubar_buttons <- item . id :: ( List . filter ( ( ) <> item . id ) preferences # get . pref_general_menubar_buttons ) ; in match item . check # active with | true when item . tool_widget <> None -> Gaux . may item . tool_widget ~ f ( : fun w -> w # misc # show ( ) ) ; add_pref ( ) ; | true -> assert false | false -> Gaux . may item . tool_widget ~ f ( : fun w -> w # misc # hide ( ) ) ; preferences # get . pref_general_menubar_buttons <- List . filter ( ( ) <> item . id ) preferences # get . pref_general_menubar_buttons ; end |> ignore ; let box = GPack . hbox ~ packing : item . check # add ( ) in let text , image = match item . pixbuf with | P pixbuf -> item . label , GMisc . image ~ pixbuf ~ xpad : 8 ~ packing : box # pack ( ) | S stock -> item . label , GMisc . image ~ stock ~ icon_size ` : SMALL_TOOLBAR ~ xpad : 8 ~ packing : box # pack ( ) | N when item . kind = I -> let image = GMisc . image ~ pixbuf : pixbuf_empty ~ packing : box # pack ~ xpad : 3 ( ) in let _ = GMisc . separator ` HORIZONTAL ~ packing : box # add ( ) in " " , image | N -> let image = GMisc . image ~ pixbuf : pixbuf_empty ~ packing : box # pack ~ xpad : 3 ( ) in item . label , image in let _ = GMisc . label ~ text ~ xalign : 0 . 0 ~ packing : box # add ( ) in item . tool_widget <- Some ( create_tool ~ toolbox item ) ; let active = List . mem item . id preferences # get . pref_general_menubar_buttons in item . check # set_active ( not active ) ; item . check # set_active active ; ; ;
|
let populate ~ browser ~ packing = let toolbox = GPack . hbox ~ border_width : 2 ~ spacing : 3 ~ packing ( ) in let button_menu = GButton . button ~ relief ` : NONE ~ packing : toolbox # pack ( ) in button_menu # misc # set_name " smallbutton " ; button_menu # set_focus_on_click false ; let arrow = GMisc . arrow ~ kind ` : DOWN ~ width : 8 ~ height : 8 ~ packing : button_menu # add ( ) in arrow # misc # modify_fg [ ` PRELIGHT , ` BLACK ] ; let menu = GMenu . menu ~ border_width : 3 ( ) in let items , find = items ~ browser in List . iteri ( fun pos item -> create_item ~ menu ~ toolbox ~ pos ( : pos + 2 ) item ) items ; button_menu # event # connect # button_press ~ callback : begin fun ev -> let time = GdkEvent . Button . time ev in let pos ~ x ~ y ~ pushed_in = let xP , yP = Gdk . Window . get_pointer_location button_menu # misc # window in let xA , yA = button_menu # misc # allocation . Gtk . x , button_menu # misc # allocation . Gtk . y in let x ' = x - xP + xA in let y ' = y - yP + yA + button_menu # misc # allocation . Gtk . height in x ' , y ' , pushed_in in GtkMenu . Menu . popup_at menu # as_menu ~ time ~ button : 1 pos ; Gmisclib . Idle . add ~ prio : 300 begin fun ( ) -> Gdk . Window . set_cursor menu # misc # window ( Gdk . Cursor . create ` ARROW ) end ; false ; end |> ignore ; let cursor = Gdk . Cursor . create ` ARROW in button_menu # event # connect # motion_notify ~ callback : begin fun _ -> Gdk . Window . set_cursor button_menu # misc # window cursor ; false ; end |> ignore ; menu # event # connect # motion_notify ~ callback : begin fun _ -> Gdk . Window . set_cursor menu # misc # window cursor ; false ; end |> ignore ; menu # connect # deactivate ~ callback : Preferences . save |> ignore ; find
|
let space_re = Str . regexp " " +
|
let edges = Hashtbl . create 128
|
let edge_count = Hashtbl . create 128
|
let chop s = try let i = String . rindex s ' . ' in String . sub s 0 i with Not_found -> s
|
let add_edge target dep = if target <> dep then ( Hashtbl . replace edges dep ( target :: ( try Hashtbl . find edges dep with Not_found -> [ ] ) ) ; Hashtbl . replace edge_count target ( 1 + try Hashtbl . find edge_count target with Not_found -> 0 ) ; if not ( Hashtbl . mem edge_count dep ) then Hashtbl . add edge_count dep 0 )
|
let sort l = let res = ref [ ] in List . iter ( fun ( target , deps ) -> let target = chop target in if not ( Hashtbl . mem edge_count target ) then Hashtbl . add edge_count target 0 ; List . iter ( fun dep -> add_edge target ( chop dep ) ) deps ) l ; let q = Queue . create ( ) in Hashtbl . iter ( fun target count -> if count = 0 then Queue . add target q ) edge_count ; while not ( Queue . is_empty q ) do let n = Queue . take q in res := n :: ! res ; let l = try Hashtbl . find edges n with Not_found -> [ ] in Hashtbl . remove edges n ; List . iter ( fun target -> let c = Hashtbl . find edge_count target - 1 in Hashtbl . replace edge_count target c ; if c = 0 then Queue . add target q ) l done ; if Hashtbl . length edges <> 0 then ( Format . eprintf " Dependency loop . " ; !@ exit 1 ) ; List . rev ! res
|
let _ = let ch = open_in Sys . argv . ( 1 ) in let lst = ref [ ] in ( try while true do let l = input_line ch in let l = Str . split space_re l in match l with | target :: " " : :: deps -> lst := ( target , deps ) :: ! lst | _ -> assert false done with End_of_file -> ( ) ) ; let lst = sort ! lst in let files = Hashtbl . create 128 in for i = 2 to Array . length Sys . argv - 1 do Hashtbl . add files ( chop Sys . argv . ( i ) ) Sys . argv . ( i ) done ; List . iter ( fun f -> try Format . printf " % s . " @ ( Hashtbl . find files f ) with Not_found -> ( ) ) lst
|
module Make ( Structure : Structure . S ) = struct open Structure ; value empty_entry ename _ _ _ = raise ( Stream . Error ( " entry [ " ^ ename ^ " ] is empty " ) ) ; value is_level_labelled n lev = match lev . lname with [ Some n1 -> n = n1 | None -> False ] ; value warning_verbose = ref True ; value rec get_token_list entry tokl last_tok tree = match tree with [ Node { node = ( Stoken _ | Skeyword _ as tok ) ; son = son ; brother = DeadEnd } -> get_token_list entry [ last_tok :: tokl ] tok son | _ -> if tokl = [ ] then None else Some ( List . rev [ last_tok :: tokl ] , last_tok , tree ) ] ; value is_antiquot s = let len = String . length s in len > 1 && s . [ 0 ] = ' ' ; $ value eq_Stoken_ids s1 s2 = not ( is_antiquot s1 ) && not ( is_antiquot s2 ) && s1 = s2 ; value logically_eq_symbols entry = let rec eq_symbols s1 s2 = match ( s1 , s2 ) with [ ( Snterm e1 , Snterm e2 ) -> e1 . ename = e2 . ename | ( Snterm e1 , Sself ) -> e1 . ename = entry . ename | ( Sself , Snterm e2 ) -> entry . ename = e2 . ename | ( Snterml e1 l1 , Snterml e2 l2 ) -> e1 . ename = e2 . ename && l1 = l2 | ( Slist0 s1 , Slist0 s2 ) -> eq_symbols s1 s2 | ( Slist0sep s1 sep1 , Slist0sep s2 sep2 ) -> eq_symbols s1 s2 && eq_symbols sep1 sep2 | ( Slist1 s1 , Slist1 s2 ) -> eq_symbols s1 s2 | ( Slist1sep s1 sep1 , Slist1sep s2 sep2 ) -> eq_symbols s1 s2 && eq_symbols sep1 sep2 | ( Sopt s1 , Sopt s2 ) -> eq_symbols s1 s2 | ( Stree t1 , Stree t2 ) -> eq_trees t1 t2 | ( Stoken ( _ , s1 ) , Stoken ( _ , s2 ) ) -> eq_Stoken_ids s1 s2 | _ -> s1 = s2 ] and eq_trees t1 t2 = match ( t1 , t2 ) with [ ( Node n1 , Node n2 ) -> eq_symbols n1 . node n2 . node && eq_trees n1 . son n2 . son && eq_trees n1 . brother n2 . brother | ( LocAct _ _ | DeadEnd , LocAct _ _ | DeadEnd ) -> True | _ -> False ] in eq_symbols ; value rec eq_symbol s1 s2 = match ( s1 , s2 ) with [ ( Snterm e1 , Snterm e2 ) -> e1 == e2 | ( Snterml e1 l1 , Snterml e2 l2 ) -> e1 == e2 && l1 = l2 | ( Slist0 s1 , Slist0 s2 ) -> eq_symbol s1 s2 | ( Slist0sep s1 sep1 , Slist0sep s2 sep2 ) -> eq_symbol s1 s2 && eq_symbol sep1 sep2 | ( Slist1 s1 , Slist1 s2 ) -> eq_symbol s1 s2 | ( Slist1sep s1 sep1 , Slist1sep s2 sep2 ) -> eq_symbol s1 s2 && eq_symbol sep1 sep2 | ( Sopt s1 , Sopt s2 ) -> eq_symbol s1 s2 | ( Stree _ , Stree _ ) -> False | ( Stoken ( _ , s1 ) , Stoken ( _ , s2 ) ) -> eq_Stoken_ids s1 s2 | _ -> s1 = s2 ] ; end ;
|
let json_format = !!% " % a . " @ Tiny_json . Json . format
|
let ocaml_format_with f = !!% " % a . " @ ( Ocaml . format_no_poly_with f )
|
let get_current_user o = let open Job in do_ ; x <-- Test . login o ; return ( object method id = x # id method username = x # username end )
|
let uploadable_by_name s = let _ , ext = Filename . split_extension s in match String . lowercase ext with | " . jpg " | " . jpeg " | " . gif " | " . png " | " . tif " | " . tiff " -> Some ` Image | " . wmv " | " . mp4 " | " . avi " | " . mpg " | " . mpeg " | " . mov " | " . 3gp " -> Some ` Movie | _ -> None
|
let delete_dups_in_sets o = let open Job in do_ ; ( _info , psets ) <-- Photosets . getList ' o ; flip mapM_ psets & fun set -> do_ ; let set_id = set # id in let set_title = set # title in [ % p ? ( _ , photos ) ] <-- Photosets . getPhotos ' set_id o ; let photos = List . map ( fun x -> ( x # title , x # id ) ) photos in let tbl = Hashtbl . create 107 in ( ) ; List . iter ( fun ( title , id ) -> Hashtbl . alter tbl title ( function | None -> Some [ id ] | Some ids -> Some ( id :: ids ) ) ) photos ; flip mapM_ ( Hashtbl . to_list tbl ) & fun ( title , ids ) -> match ids with | [ ] -> assert false | [ _ ] -> return ( ) | xs -> !!% " Dups : set : % s ( % s ) title : % s ids : % s . " @ set_title set_id title ( String . concat " , " xs ) ; if title <> " " then flip mapM_ ( List . tl xs ) & fun photo_id -> !!% " Deleting % s : % s . " @ title photo_id ; Photos . delete photo_id o >>| fun ( ) -> !!% " Deleted . " @ else return ( )
|
let uploads ( ? remove_non_local = false ) ~ photoset ~ existing img_files o = let open Job in do_ ; ( _info , psets ) <-- Photosets . getList ' o ; ( ) ; !!% " Got existing photosets ( % d ) . " @ & List . length psets ; let psid_opt = ref ( List . find_opt ( fun pset -> pset # title = photoset ) psets |> Option . fmap ( fun pset -> pset # id ) ) in photos <-- begin match ! psid_opt with | None -> return [ ] | Some psid -> do_ ; ( ) ; !!% " Getting photos of photoset % s ( id =% s ) . " @ photoset psid ; [ % p ? ( _ , ps ) ] <-- Photosets . getPhotos ' psid o ; return & List . map ( fun p -> ( p # title , p # id ) ) ps end ; let photos = ref photos in let up ~ title img_file = do_ ; ( ) ; !!% " Uploading % s . " @ img_file ; photo_id <-- Upload . upload ~ is_family : true ~ title img_file ~ tags [ " : uploading " ; " photoset_ " ^ photoset ] o ; ( ) ; photos := ( title , photo_id ) :: ! photos ; begin match ! psid_opt with | None -> do_ ; ( ) ; !!% " Creating new photoset % s with photo % s . " @ photoset img_file ; res <-- Photosets . create ~ title : photoset ~ primary_photo_id : photo_id o ; ( ) ; psid_opt := Some res # id ; return ( ) | Some psid -> !!% " Adding % s to photoset % s . " @ img_file photoset ; Photosets . addPhoto psid ~ photo_id o end ; Photos . setTags photo_id [ " photoset_ " ^ photoset ] o ; return photo_id in flip mapM_ img_files ( fun img_file -> let title = Filename . ( basename *> split_extension *> fst ) img_file in if List . mem_assoc title ! photos then begin return ( ) end else begin up ~ title img_file >>| !!% " Uploaded as id = % s . " @ end ) ; let gone = let img_file_tbl = let tbl = Hashtbl . create 107 in flip iter existing ( fun img_file -> let title = Filename . ( basename *> split_extension *> fst ) img_file in Hashtbl . replace tbl title img_file ) ; tbl in flip filter ! photos ( fun ( title , _phid ) -> not & Hashtbl . mem img_file_tbl title ) in ( ) ; flip iter gone ( fun ( title , phid ) -> !!% " Photo % s ( % s ) is gone from the local dir . " @ title phid ) ; ( ) ; if gone <> [ ] && not remove_non_local then !!% " You can remove these % d not - in - local photos with - remove - non - local . " @ ( length gone ) ; if gone <> [ ] && remove_non_local then begin !!% " Removing those % d not - in - local photos from the photoset . . . . " @ ( length gone ) ; match ! psid_opt with | None -> assert false | Some psid -> Photosets . removePhotos psid ( List . map snd gone ) o end else return ( ) ; match ! psid_opt with | None -> return ( ) | Some psid -> do_ ; [ % p ? ( _ , ps ) ] <-- Photosets . getPhotos ' psid ~ extras [ " : date_taken " ] o ; let ps ' = let open List in sort ( fun ( _ , t1 ) ( _ , t2 ) -> compare t1 t2 ) & filter_map ( fun p -> Option . do_ ; dt <-- assoc_opt " datetaken " p # extras ; match dt with | Tiny_json . Json . String s -> return ( p , s ) | _ -> None ) ps in ( ) ; flip List . iter ps ' ( fun ( p , t ) -> Format . eprintf " % s : % s : % s . " @ p # id p # title t ) ; ( ) ; Format . eprintf " Reordering . . . . " ; @ Photosets . reorderPhotos psid ( List . map ( fun ( p , _ ) -> p # id ) ps ' ) o ; ( ) ; Format . eprintf " Reordered . " ; @ ) * return ( )
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.