text stringlengths 12 786k |
|---|
let setup_app level port host application_id https = let u2f = U2f . create application_id in let level = match level with None -> None | Some Logs . Debug -> Some ` Debug | Some Info -> Some ` Info | Some Warning -> Some ` Warning | Some Error -> Some ` Error | Some App -> None in Dream . i... |
let port = let doc = " port " in Arg . ( value & opt int 4000 & info [ " p " ; " port " ] ~ doc ) |
let host = let doc = " host " in Arg . ( value & opt string " 0 . 0 . 0 . 0 " & info [ " h " ; " host " ] ~ doc ) |
let application_id = let doc = " the u2f application id - usually protocol :// host ( : port ) " in Arg . ( value & opt string " https :// u2f - demo . robur . coop " & info [ " application - id " ] ~ doc ) |
let tls = let doc = " tls " in Arg . ( value & flag & info [ " tls " ] ~ doc ) |
let ( ) = let term = Term . ( pure setup_app $ Logs_cli . level ( ) $ port $ host $ application_id $ tls ) in let info = Term . info " U2f app " ~ doc " : U2f app " ~ man [ ] : in match Term . eval ( term , info ) with | ` Ok ( ) -> exit 0 | ` Error _ -> e... |
let is_spec attr = attr . attr_name . txt = " gospel " |
let rec get_spec_attr = function | [ ] -> ( None , [ ] ) | h :: t when is_spec h -> ( Some h , t ) | h :: t -> let elt , rest = get_spec_attr t in ( elt , h :: rest ) |
let get_spec_content attr = match attr . attr_payload with | PStr [ { pstr_desc = Pstr_eval ( { pexp_desc = Pexp_constant ( Pconst_string ( spec , _ , _ ) ) ; _ } , _ ) ; _ ; } ; ] -> ( spec , attr . attr_loc ) | _ -> assert false |
let get_inner_spec attr = match attr . attr_payload with | PStr [ { pstr_desc = Pstr_eval ( _ , attrs ) ; _ } ] -> get_spec_attr attrs | _ -> assert false |
let set_position ( lexbuf : Lexing . lexbuf ) ( position : Lexing . position ) = lexbuf . lex_curr_p <- { position with pos_fname = lexbuf . lex_curr_p . pos_fname } ; lexbuf . lex_abs_pos <- position . pos_cnum |
let set_filename ( lexbuf : Lexing . lexbuf ) ( fname : string ) = lexbuf . lex_curr_p <- { lexbuf . lex_curr_p with pos_fname = fname } |
let parse_gospel ~ filename parse attr = let spec , _ = get_spec_content attr in let lb = Lexing . from_string spec in set_position lb attr . attr_loc . loc_start ; set_filename lb filename ; try ( spec , parse Ulexer . token lb ) with Uparser . Error -> let loc = { loc_start = lb . le... |
let type_declaration ~ filename t = let spec_attr , other_attrs = get_spec_attr t . ptype_attributes in let parse attr = let ty_text , spec = parse_gospel ~ filename Uparser . type_spec attr in { spec with ty_text ; ty_loc = attr . attr_loc } in let spec = Option . map parse spec_attr in { t... |
let val_description ~ filename v = let spec_attr , other_attrs = get_spec_attr v . pval_attributes in let parse attr = let sp_text , spec = parse_gospel ~ filename Uparser . val_spec attr in { spec with sp_text ; sp_loc = attr . attr_loc } in let spec = Option . map parse spec_attr in { vnam... |
let ghost_spec ~ filename attr = let spec , loc = get_spec_content attr in let lb = Lexing . from_string spec in let sigs = try Parse . interface lb with _ -> W . error ~ loc W . Syntax_error in match sigs with | [ { psig_desc = Psig_type ( r , [ t ] ) ; _ } ] -> let type_ = t... |
let floating_spec ~ filename a = try let fun_text , fun_ = parse_gospel ~ filename Uparser . func a in let fun_ = { fun_ with fun_text } in if fun_ . fun_spec = None then let fun_spec = get_inner_spec a |> fst |> Option . map ( parse_gospel ~ filename Uparser . func_spec ) |> Option . map... |
let with_constraint c = let no_spec_type_decl t = { tname = t . ptype_name ; tparams = t . ptype_params ; tcstrs = t . ptype_cstrs ; tkind = t . ptype_kind ; tprivate = t . ptype_private ; tmanifest = t . ptype_manifest ; tattributes = t . ptype_attributes ; tspec = None ; tloc... |
let rec signature_item_desc ~ filename = function | Psig_value v -> Sig_val ( val_description ~ filename v ) | Psig_type ( r , tl ) -> Sig_type ( r , List . map ( type_declaration ~ filename ) tl ) | Psig_attribute a -> if not ( is_spec a ) then Sig_attribute a else floating_spec ~ ... |
let err_no_pred = " U + 0000 has no predecessor " |
let err_no_succ = " U + 10FFFF has no successor " |
let err_not_sv i = format_int " % X " i ^ " is not an Unicode scalar value " |
let err_not_latin1 u = " U " + ^ format_int " % 04X " u ^ " is not a latin1 character " |
let succ u = if u = lo_bound then hi_bound else if u = max then invalid_arg err_no_succ else u + 1 |
let pred u = if u = hi_bound then lo_bound else if u = min then invalid_arg err_no_pred else u - 1 |
let is_valid i = ( min <= i && i <= lo_bound ) || ( hi_bound <= i && i <= max ) |
let of_int i = if is_valid i then i else invalid_arg ( err_not_sv i ) |
let is_char u = u < 256 |
let of_char c = Char . code c |
let to_char u = if u > 255 then invalid_arg ( err_not_latin1 u ) else Char . unsafe_chr u |
let equal : int -> int -> bool = ( = ) |
let compare : int -> int -> int = Stdlib . compare |
let log_err s = Printf . printf " % s : % s \ n " %! ( Filename . basename Sys . executable_name ) s |
let is_white = function ' ' | ' \ t ' . . ' \ r ' -> true | _ -> false |
let is_digit = function ' 0 ' . . ' 9 ' -> true | _ -> false |
let hex_digit_value c = let c = Char . code c in if c <= 0x39 then c - 48 else if c <= 0x46 then c - 55 else c - 87 |
let str_starts s pre = let plen = String . length pre in let slen = String . length s in if plen > slen then false else try for i = 0 to plen - 1 do if pre . [ i ] <> s . [ i ] then raise Exit ; done ; true with Exit -> false |
let str_is_ascii s = let max = String . length s - 1 in let rec loop s i = if i > max then true else if Char . code s . [ i ] > 0x7F then false else loop s ( i + 1 ) in loop s 0 |
let esc_non_ascii s = let b = Buffer . create 255 in let add_byte = function | c when Char . code c > 0x7F -> Buffer . add_string b ( strf " \\ x % 02X " ( Char . code c ) ) | c -> Buffer . add_char b c in String . iter add_byte s ; Buffer . contents b |
let uchars_to_utf_bytes utf uchars = let b = Buffer . create 255 in let add_utf = match utf with | ` UTF_8 -> Uutf . Buffer . add_utf_8 | ` UTF_16BE -> Uutf . Buffer . add_utf_16be | ` UTF_16LE -> Uutf . Buffer . add_utf_16le in List . iter ( add_utf b ) uchars ; Buffer . content... |
let uchars_to_utf_bytes_esc utf uchars = let utf = uchars_to_utf_bytes utf uchars in let b = Buffer . create 255 in let add_byte c = Buffer . add_string b ( strf " \\ x % 02X " ( Char . code c ) ) in String . iter add_byte utf ; Buffer . contents b |
let uchars_to_cps uchars = let to_str u = strf " U +% 04X " ( Uchar . to_int u ) in String . concat " " ( List . map to_str uchars ) |
let uchars_to_named_cps uchars = let to_str u = strf " % s ( U +% 04X ) " ( Uucp . Name . name u ) ( Uchar . to_int u ) in String . concat " " ( List . map to_str uchars ) |
let uchar_of_utf utf s = let fold = match utf with | ` UTF_8 -> Uutf . String . fold_utf_8 | ` UTF_16BE -> Uutf . String . fold_utf_16be | ` UTF_16LE -> Uutf . String . fold_utf_16le in match fold ( fun acc _ decode -> decode :: acc ) [ ] s with | [ ` Uchar u ] -> Some u | ... |
let try_uchar_of_utfs s = let rec try_decs s = function | [ ] -> None | enc :: encs -> match uchar_of_utf enc s with | None -> try_decs s encs | Some _ as u -> u in try_decs s [ ` UTF_8 ; ` UTF_16BE ; ` UTF_16LE ] |
let parse_decimal_esc s = let max = String . length s - 1 in let rec loop s i acc = match i = max with | true -> if s . [ max ] = ' ; ' && Uchar . is_valid acc then Some ( Uchar . of_int acc ) else None | false -> if not ( is_digit s . [ i ] ) then None else loop s ( i + 1... |
let parse_hex_esc s ~ finish = let max = String . length s - 1 in let parse_hex s start = let rec loop s i acc = if i > max then acc , max else if not ( is_hex_digit s . [ i ] ) then acc , i - 1 else loop s ( i + 1 ) ( acc * 16 + hex_digit_value s . [ i ] ) in loop s start 0... |
let uchar_of_uchar_esc s = let prefixes = [ " U " ; + " u " ; + " U " ; " u " ; " \\ u { " ; " \\ U { " ; " \\ u " ; " \\ U " ; " &# x " ; " " &# ] in match try Some ( List . find ( str_starts s ) prefixes ) with Not_found -> None wi... |
let uchar_of_utf_8_bytes_esc s = let b = Buffer . create 255 in let max = String . length s - 1 in let parse_hex_byte s i = match i + 1 <= max && is_hex_digit s . [ i ] && is_hex_digit s . [ i + 1 ] with | false -> None | true -> Some ( 16 * ( hex_digit_value s . [ i ] ) ... |
let guess_spec s = match str_is_ascii s with match uchar_of_uchar_esc s with | Some _ as u -> u | None -> uchar_of_utf_8_bytes_esc s |
let parse_spec spec_fmt s = match spec_fmt with |
let unicode_version ( ) = Printf . printf " % s \ n " %! Uucp . unicode_version |
type out_fmt = { ascii : bool ; no_labels : bool ; raw_bytes : bool ; } |
let str ( pp , key ) ( out_fmt : out_fmt ) u = strf " % a " pp ( key u ) |
let str_bool key ( out_fmt : out_fmt ) u = strf " % b " ( key u ) |
let str_int key ( out_fmt : out_fmt ) u = strf " % d " ( key u ) |
let str_uchar ( out_fmt : out_fmt ) u = uchars_to_cps [ u ] |
let str_str key ( out_fmt : out_fmt ) u = key u |
let str_utf utf out_fmt u = match out_fmt . raw_bytes with |
let str_cps out_fmt uchars = let cps = uchars_to_cps uchars in match out_fmt . ascii with | true -> cps | false -> let utf_8 = uchars_to_utf_bytes ` UTF_8 uchars in strf " % s ( % s ) " utf_8 cps |
let str_case_map map ( out_fmt : out_fmt ) u = let uchars = match map u with ` Self -> [ u ] | ` Uchars uchars -> uchars in str_cps out_fmt uchars |
let str_decomposition_mapping ( out_fmt : out_fmt ) u = let uchars = match Uunf . decomp u with | [ ] || -> [ u ] | a -> let to_uchar i u = match i = 0 with | true -> Uunf . d_uchar u | false -> Uchar . of_int u in Array . ( to_list @@ mapi to_uchar a ) in str_cps out_fmt uchars |
let str_name_alias key ( out_fmt : out_fmt ) u = let str_alias ( t , n ) = strf " % s ( % a ) " n Uucp . Name . pp_alias_tag t in String . concat " , " ( List . map str_alias ( key u ) ) |
let str_script_extensions key ( out_fmt : out_fmt ) u = String . concat " , " ( List . map ( strf " % a " Uucp . Script . pp ) ( key u ) ) |
let all_keys = [ ` P " Age " , str Uucp . Age . ( pp , age ) ; ` P " Alphabetic " , str_bool Uucp . Alpha . is_alphabetic ; ` P " Block " , str Uucp . Block . ( pp , block ) ; ` P " Line_Break " , str Uucp . Break . ( pp_line , line ) ; ` P ... |
let compare_key ( k0 , _ ) ( k1 , _ ) = match k0 , k1 with |
let eq_key k ( k ' , _ ) = match k ' with String . ( compare ( lowercase_ascii k ) ( lowercase_ascii k ' ) = 0 ) |
let exist_key k = List . exists ( eq_key k ) all_keys |
let find_key k = List . find ( eq_key k ) all_keys |
let key_id ( k , _ ) = match k with ` P k | ` N k | ` H k -> k |
let list_keys ( ) = let keys = List . sort compare_key all_keys in let pr_key_name ( n , _ ) = match n with | ` P k -> Printf . printf " % s ( UCD ) \ n " k | ` N k -> Printf . printf " % s \ n " k | ` H k -> Printf . printf " % s ( Uucp library heuristic ) \ n ... |
let get_keys keys = try Ok ( List . map find_key keys ) with let _ , not = List . partition exist_key keys in match not with | [ p ] -> Error ( strf " Unknown key : % s " p ) | ps -> Error ( strf " Unknown keys : % s " ( String . concat " , " ps ) ) |
let default_keys = [ " Name " ; " Uchar " ; " Age " ; " Block " ; " Script " ; " Script_extensions " ; " General_Category " ; " Decomposition_Mapping " ; " UTF - 8 " ; " UTF - 16BE " ; " UTF - 16LE " ] |
let case_keys = [ " Lowercase " ; " Uppercase " ; " Cased " ; " Case_ignorable " ; " Lowercase_Mapping " ; " Uppercase_Mapping " ; " Titlecase_Mapping " ; " Case_Folding " ; " NFKC_Casefold " ] |
let cjk_keys = [ " Ideographic " ; " IDS_Binary_Operator " ; " IDS_Trinary_Operator " ; " Radical " ; " Unified_Ideograph " ] |
let emoji_keys = [ " Emoji " ; " Emoji_Presentation " ; " Emoji_Modifier " ; " Emoji_Modifier_Base " ; " Emoji_Component " ; " Extended_Pictographic " ] |
let id_keys = [ " ID_Start " ; " ID_Continue " ; " XID_Start " ; " XID_Continue " ; " Pattern_Syntax " ; " Pattern_White_Space " ] |
let num_keys = [ " ASCII_Hex_Digit " ; " Hex_Digit " ; " Numeric_Type " ; " Numeric_Value " ] |
let output_key out_fmt uchar ( k , str ) = match out_fmt . no_labels with let l = match k with ` P k | ` N k | ` H k -> k in Printf . printf " % s : % s \ n " l ( str out_fmt uchar ) |
let query_keys keys out_fmt uchar = match get_keys keys with |
let ucharinfo cmd keys spec_fmt out_fmt uspec = match cmd with match uspec with | None -> log_err " No character specified . " ; 1 | Some uspec -> match parse_spec spec_fmt uspec with | None -> log_err ( strf " Could not parse % s from ' % s ' \ n " %! ( str_of_spec_fmt spec_fmt ) ( ... |
let cmd = let doc = " List available keys . " in let list_keys = ` List_keys , Arg . info [ " l " ; " key - list " ] ~ doc in let doc = " Output supported Unicode version . " in let unicode_version = ` Unicode_version , Arg . info [ " unicode - version " ] ~ doc in... |
let spec_fmt = let spec_fmt = [ " UTF - 8 " , ` UTF_8 ; " UTF - 16BE " , ` UTF_16BE ; " UTF - 16LE " , ` UTF_16LE ; " uchar - esc " , ` Uchar_esc ; " bytes - esc " , ` Bytes_esc ; " guess " , ` Guess ] in let doc = strf " The character specifica... |
let out_fmt = let no_labels = let doc = " Output key values without labels . " in Arg . ( value & flag & info [ " n " ; " no - labels " ] ~ doc ) in let raw_bytes = let doc = " Output byte sequences unescaped . " in Arg . ( value & flag & info [ " b " ; " raw - ... |
let keys = let all = let doc = " Output value of all keys in alphabetic order . " in Arg . ( value & flag & info [ " all " ] ~ doc ) in let default = let doc = " Output default information . " in Arg . ( value & flag & info [ " d " ; " default " ] ~ doc ) in let ... |
let uspec = let doc = " The character specification . See CHARACTER SPECIFICATION for details . " in Arg . ( value & pos 0 ( some string ) None & info [ ] ~ doc ~ docv " : UCHAR " ) |
let doc = " Query Unicode character information " |
let exits = Term . exit_info 1 ~ doc " : if the character specification is invalid . " :: Term . exit_info 2 ~ doc " : if a key doesn ' t exist . " :: Term . default_exits |
let man = [ ` S Manpage . s_description ; ` P " ( $ mname ) outputs information about an Unicode character specified on the command line . " ; ` P " The information to output is selected by specifying keys , use the ( $ b , - l ) option to list them . By default the tool outputs ... |
let ucharinfo = Term . ( const ucharinfo $ cmd $ keys $ spec_fmt $ out_fmt $ uspec ) , Term . info " ucharinfo " ~ version " :%% VERSION " %% ~ doc ~ exits ~ man |
let ( ) = Term . ( exit_status @@ eval ucharinfo ) |
type ' a tbl = ' a Tbl31 . tbl |
type ' a t = ' a tbl |
let get tbl u = Tbl31 . get tbl ( UChar . uint_code u ) u |
module type Type = sig type elt type t = elt tbl val get : elt tbl -> UChar . t -> elt val of_map : elt -> elt UMap . t -> t end |
module Make ( H : Hashtbl . HashedType ) HashedType = struct module T31 = Tbl31 . Make ( H ) H type elt = T31 . elt type t = H . t tbl let get = get let of_map v m = T31 . of_map v ( UMap . imap_of_umap m ) m end |
module Bool = struct type t = Tbl31 . Bool . t let get tbl u = Tbl31 . Bool . get tbl ( UChar . uint_code u ) u let of_set s = Tbl31 . Bool . of_set ( USet . iset_of_uset s ) s end |
module Bits = struct type t = Tbl31 . Bits . t let get tbl u = Tbl31 . Bits . get tbl ( UChar . uint_code u ) u let of_map v m = Tbl31 . Bits . of_map v ( UMap . imap_of_umap m ) m end |
module Bytes = struct type t = Tbl31 . Bytes . t let get tbl u = Tbl31 . Bytes . get tbl ( UChar . uint_code u ) u let of_map v m = Tbl31 . Bytes . of_map v ( UMap . imap_of_umap m ) m end |
module Char = struct type t = Tbl31 . Char . t let get tbl u = Tbl31 . Char . get tbl ( UChar . uint_code u ) u let of_map v m = Tbl31 . Char . of_map v ( UMap . imap_of_umap m ) m end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.