text
stringlengths 12
786k
|
---|
let typeof sid = let id = longident_parse sid in let env = ! Toploop . toplevel_env in let lookup_value = Env . find_value_by_name and lookup_label = Env . find_label_by_name and lookup_modtype = Env . find_modtype_by_name and lookup_module id env = let path , decl = Env . find_module_by_name id env in ( path , decl . md_type ) # else let lookup_value = Env . lookup_value and lookup_label = Env . lookup_label and lookup_modtype = Env . lookup_modtype and lookup_module id env = let path = Env . lookup_module id env ~ load : true in ( path , ( Env . find_module path env ) . md_type ) # endif in let from_type_desc = function | Types . Tconstr ( path , _ , _ ) -> let typ_decl = Env . find_type path env in path , typ_decl | _ -> assert false in let out_sig_item = try let ( path , ty_decl ) = lookup_type id env in let id = Ident . create_local ( Path . name path ) in # else let id = Ident . create ( Path . name path ) in # endif Some ( Printtyp . tree_of_type_declaration id ty_decl Types . Trec_not ) with Not_found -> try let ( path , val_descr ) = lookup_value id env in let id = Ident . create_local ( Path . name path ) in # else let id = Ident . create ( Path . name path ) in # endif Some ( Printtyp . tree_of_value_description id val_descr ) with Not_found -> try let lbl_desc = lookup_label id env in let ( path , ty_decl ) = from_type_desc ( get_desc lbl_desc . Types . lbl_res ) in let id = Ident . create_local ( Path . name path ) in # else let id = Ident . create ( Path . name path ) in # endif Some ( Printtyp . tree_of_type_declaration id ty_decl Types . Trec_not ) with Not_found -> try let path , mod_typ = lookup_module id env in let id = Ident . create_local ( Path . name path ) in # else let id = Ident . create ( Path . name path ) in # endif Some ( Printtyp . tree_of_module id mod_typ Types . Trec_not ) with Not_found -> try let ( path , mty_decl ) = lookup_modtype id env in let id = Ident . create_local ( Path . name path ) in # else let id = Ident . create ( Path . name path ) in # endif Some ( Printtyp . tree_of_modtype_declaration id mty_decl ) with Not_found -> try # if OCAML_VERSION >= ( 4 , 10 , 0 ) let cstr_desc = Env . find_constructor_by_name id env in # else let cstr_desc = Env . lookup_constructor id env in # endif match cstr_desc . Types . cstr_tag with | _ -> let ( path , ty_decl ) = from_type_desc ( get_desc cstr_desc . Types . cstr_res ) in let id = Ident . create_local ( Path . name path ) in # else let id = Ident . create ( Path . name path ) in # endif Some ( Printtyp . tree_of_type_declaration id ty_decl Types . Trec_not ) with Not_found -> None in match out_sig_item with | None -> Lwt_main . run ( Lazy . force LTerm . stdout >>= fun term -> print_error term " Unknown type \ n " ) | Some osig -> let buf = Buffer . create 128 in let pp = Format . formatter_of_buffer buf in ! Toploop . print_out_signature pp [ osig ] ; Format . pp_print_newline pp ( ) ; let str = Buffer . contents buf in Lwt_main . run ( Lazy . force LTerm . stdout >>= fun term -> render_out_phrase term str ) |
let default_info = { Toploop . section = " UTop " ; doc = " " ; } |
let ( ) = Toploop . add_directive " typeof " ( Toploop . Directive_string typeof ) default_info |
let emacs_mode = ref false |
let preload = ref [ ] |
let prepare ( ) = Toploop . set_paths ( ) ; try let ok = List . for_all ( function | ` Packages l -> UTop . require l ; true | ` Object fn -> Toploop . load_file Format . err_formatter fn ) # else Topdirs . load_file Format . err_formatter fn ) # endif ( List . rev ! preload ) in if ok then ! Toploop . toplevel_startup_hook ( ) ; ok with exn -> try Errors . report_error Format . err_formatter exn ; false with exn -> Format . eprintf " Uncaught exception : % s \ n " ( Printexc . to_string exn ) ; false " caml_sys_modify_argv " |
let override_argv ( ) = let len = Array . length Sys . argv - ! Arg . current in let copy = Array . init len ( fun i -> Sys . argv . ( i + ! Arg . current ) ) in caml_sys_modify_argv copy ; Arg . current := 0 # else |
let override_argv ( ) = let len = Array . length Sys . argv - ! Arg . current in Array . blit Sys . argv ! Arg . current Sys . argv 0 len ; Obj . truncate ( Obj . repr Sys . argv ) len ; Arg . current := 0 # endif |
let run_script name = Sys . interactive := false ; if not ( prepare ( ) ) then exit 2 ; override_argv ( ) ; Toploop . initialize_toplevel_env ( ) ; Location . input_name := UTop . input_name ; if toploop_use_silently Format . err_formatter name then exit 0 else exit 2 |
let file_argument name = if Filename . check_suffix name " . cmo " || Filename . check_suffix name " . cma " then preload := ` Object name :: ! preload else run_script name |
let print_version ( ) = Printf . printf " The universal toplevel for OCaml , version % s , compiled for OCaml version % s \ n " UTop . version Sys . ocaml_version ; exit 0 |
let print_version_num ( ) = Printf . printf " % s \ n " UTop . version ; exit 0 |
let autoload = ref true |
let args = Arg . align [ " - absname " , Arg . Set Clflags . absname , " Show absolute filenames in error message " ; # else " - absname " , Arg . Set Location . absname , " Show absolute filenames in error message " ; # endif " - I " , Arg . String ( fun dir -> Clflags . include_dirs := dir :: ! Clflags . include_dirs ) , " < dir > Add < dir > to the list of include directories " ; " - init " , Arg . String ( fun s -> Clflags . init_file := Some s ) , " < file > Load < file > instead of default init file " ; " - labels " , Arg . Clear Clflags . classic , " Use commuting label mode " ; " - no - app - funct " , Arg . Clear Clflags . applicative_functors , " Deactivate applicative functors " ; " - noassert " , Arg . Set Clflags . noassert , " Do not compile assertion checks " ; " - nolabels " , Arg . Set Clflags . classic , " Ignore non - optional labels in types " ; " - nostdlib " , Arg . Set Clflags . no_std_include , " Do not add default directory to the list of include directories " ; " - ppx " , Arg . String ( fun ppx -> Clflags . all_ppx := ppx :: ! Clflags . all_ppx ) , " < command > Pipe abstract syntax trees through preprocessor < command " ; > " - principal " , Arg . Set Clflags . principal , " Check principality of type inference " ; " - safe - string " , Arg . Clear Clflags . unsafe_string , " Make strings immutable " ; # endif " - short - paths " , Arg . Clear Clflags . real_paths , " Shorten paths in types ( the default ) " ; " - no - short - paths " , Arg . Set Clflags . real_paths , " Do not shorten paths in types " ; " - rectypes " , Arg . Set Clflags . recursive_types , " Allow arbitrary recursive types " ; " - stdin " , Arg . Unit ( fun ( ) -> run_script " " ) , " Read script from standard input " ; " - strict - sequence " , Arg . Set Clflags . strict_sequence , " Left - hand part of a sequence must have type unit " ; " - unsafe " , Arg . Set Clflags . unsafe , " Do not compile bounds checking on array and string access " ; # else " - unsafe " , Arg . Set Clflags . fast , " Do not compile bounds checking on array and string access " ; # endif " - version " , Arg . Unit print_version , " Print version and exit " ; " - vnum " , Arg . Unit print_version_num , " Print version number and exit " ; " - w " , Arg . String ( fun opt -> ignore ( Warnings . parse_options false opt ) ) , Printf . sprintf " < list > Enable or disable warnings according to < list >:\ n \ \ +< spec > enable warnings in < spec >\ n \ \ -< spec > disable warnings in < spec >\ n \ \ @< spec > enable warnings in < spec > and treat them as errors \ n \ \ < spec > can be :\ n \ \ < num > a single warning number \ n \ \ < num1 . . >< num2 > a range of consecutive warning numbers \ n \ \ < letter > a predefined set \ n \ \ default setting is % S " Warnings . defaults_w ; " - warn - error " , Arg . String ( fun opt -> ignore ( Warnings . parse_options true opt ) ) , Printf . sprintf " < list > Enable or disable error status for warnings according to < list >\ n \ \ See option - w for the syntax of < list . >\ n \ \ Default setting is % S " Warnings . defaults_warn_error ; " - warn - help " , Arg . Unit Warnings . help_warnings , " Show description of warning numbers " ; " - emacs " , Arg . Set emacs_mode , " Run in emacs mode " ; " - hide - reserved " , Arg . Unit ( fun ( ) -> UTop . set_hide_reserved true ) , " Hide identifiers starting with a ' _ ' ( the default ) " ; " - show - reserved " , Arg . Unit ( fun ( ) -> UTop . set_hide_reserved false ) , " Show identifiers starting with a ' _ ' " ; " - no - implicit - bindings " , Arg . Unit ( fun ( ) -> UTop . set_create_implicits false ) , " Don ' t add implicit bindings for expressions ( the default ) " ; " - implicit - bindings " , Arg . Unit ( fun ( ) -> UTop . set_create_implicits true ) , " Add implicit bindings : < expr ; ; > -> let _0 = < expr ; ; " ; > " - no - autoload " , Arg . Clear autoload , " Disable autoloading of files in $ OCAML_TOPLEVEL_PATH / autoload " ; " - require " , Arg . String ( fun s -> preload := ` Packages ( UTop . split_words s ) :: ! preload ) , " < package > Load this package " ; " - dparsetree " , Arg . Set Clflags . dump_parsetree , " Dump OCaml AST after rewriting " ; " - dsource " , Arg . Set Clflags . dump_source , " Dump OCaml source after rewriting " ; ] |
let ( ) = Clflags . real_paths := false |
let app_name = Filename . basename Sys . executable_name |
let usage = Printf . sprintf " Usage : % s < options > < object - files > [ script - file [ arguments ] ] \ noptions are " : app_name |
let load_init_files dir = let files = Sys . readdir dir in Array . sort String . compare files ; Array . iter ( fun fn -> if Filename . check_suffix fn " . ml " then ignore ( toploop_use_silently Format . err_formatter ( Filename . concat dir fn ) : bool ) ) files ; ; |
let common_init ~ initial_env = ( match initial_env with | None -> Toploop . initialize_toplevel_env ( ) | Some env -> Toploop . toplevel_env := env ) ; Location . input_name := UTop . input_name ; Sys . catch_break true ; ( match try Some ( Sys . getenv " OCAML_TOPLEVEL_PATH " ) with Not_found -> None with | Some dir -> Topdirs . dir_directory dir ; let autoload_dir = Filename . concat dir " autoload " in if ! autoload && ! UTop_private . autoload && Sys . file_exists autoload_dir then load_init_files autoload_dir | None -> ( ) ) ; let init_fn = match ! Clflags . init_file with | Some fn -> if Sys . file_exists fn then Some fn else ( Printf . eprintf " Init file not found : " \% s " . \\ n " fn ; None ) | None -> if Sys . file_exists " . ocamlinit " && Sys . getcwd ( ) <> LTerm_resources . home then Some " . ocamlinit " else let xdg_fn = LTerm_resources . xdgbd_file ~ loc : LTerm_resources . Config " utop / init . ml " in if Sys . file_exists xdg_fn then Some xdg_fn else let fn = Filename . concat LTerm_resources . home " . ocamlinit " in if Sys . file_exists fn then Some fn else None in ( match init_fn with | None -> ( ) | Some fn -> ignore ( toploop_use_silently Format . err_formatter fn : bool ) ) ; Lwt_main . run ( init_history ( ) ) ; let behavior = Sys . Signal_handle ( fun signo -> raise ( Term signo ) ) in let catch signo = try Sys . set_signal signo behavior with _ -> ( ) in catch Sys . sighup ; catch Sys . sigterm |
let load_inputrc ( ) = Lwt . catch LTerm_inputrc . load ( function | Unix . Unix_error ( error , func , arg ) -> Lwt_log . error_f " cannot load key bindings from % S : % s : % s " LTerm_inputrc . default func ( Unix . error_message error ) | LTerm_inputrc . Parse_error ( fname , line , msg ) -> Lwt_log . error_f " error in key bindings file % S , line % d : % s " fname line msg | exn -> Lwt . fail exn ) |
let main_aux ~ initial_env = Arg . parse args file_argument usage ; Topcommon . load_topdirs_signature ( ) ; # endif if not ( prepare ( ) ) then exit 2 ; if ! emacs_mode then begin Printf . printf " protocol - version :% d \ n " %! protocol_version ; UTop_private . set_ui UTop_private . Emacs ; let module Emacs = Emacs ( struct end ) in Printf . printf " Welcome to utop version % s ( using OCaml version % s ) !\ n \ n " %! UTop . version Sys . ocaml_version ; common_init ~ initial_env ; Emacs . loop ( ) end else begin UTop_private . set_ui UTop_private . Console ; let term = Lwt_main . run ( Lazy . force LTerm . stdout ) in if LTerm . incoming_is_a_tty term && LTerm . outgoing_is_a_tty term then begin UTop_private . set_size ( S . const ( LTerm . size term ) ) ; Lwt_main . run ( Lwt . join [ UTop_styles . load ( ) ; load_inputrc ( ) ] ) ; Lwt_main . run ( welcome term ) ; common_init ~ initial_env ; print_string " \ nType # utop_help for help about using utop . \ n \ n " ; flush stdout ; try loop term with LTerm_read_line . Interrupt -> ( ) end else begin Toploop . read_interactive_input := read_input_classic ; Toploop . loop Format . std_formatter end end ; exit 0 |
let main_internal ~ initial_env = let exit_status = ref 2 in try main_aux ~ initial_env with exn -> ( match exn with | Unix . Unix_error ( error , func , " " ) -> Printf . eprintf " % s : % s : % s \ n " app_name func ( Unix . error_message error ) | Unix . Unix_error ( error , func , arg ) -> Printf . eprintf " % s : % s ( % S ) : % s \ n " app_name func arg ( Unix . error_message error ) | Compenv . Exit_with_status e -> exit_status := e # endif | exn -> Printf . eprintf " Fatal error : exception % s \ n " ( Printexc . to_string exn ) ) ; Printexc . print_backtrace stderr ; flush stderr ; exit ! exit_status |
let main ( ) = main_internal ~ initial_env : None |
type value = V : string * _ -> value |
let get_required_label name args = match List . find ( fun ( lab , _ ) -> lab = Asttypes . Labelled name ) args with | _ , x -> x | exception Not_found -> None # else |
let get_required_label name args = match List . find ( fun ( lab , _ , k ) -> lab = " loc " && k = Typedtree . Required ) args with | _ , x , _ -> x | _ -> None | exception Not_found -> None # endif |
let walk dir ~ init ~ f = let rec loop dir acc = let acc = f dir acc in ArrayLabels . fold_left ( Sys . readdir dir ) ~ init : acc ~ f ( : fun acc fn -> let fn = Filename . concat dir fn in match Unix . lstat fn with | { st_kind = S_DIR ; _ } -> loop fn acc | _ -> acc ) in match Unix . lstat dir with | exception Unix . Unix_error ( ENOENT , _ , _ ) -> init | _ -> loop dir init |
let interact ( ? search_path [ ] ) = ( ? build_dir " = _build " ) ~ unit ~ loc ( : fname , lnum , cnum , _ ) ~ values = let search_path = walk build_dir ~ init : search_path ~ f ( : fun dir acc -> dir :: acc ) in let cmt_fname = try Misc . find_in_path_uncap search_path ( unit ^ " . cmt " ) with Not_found -> Printf . ksprintf failwith " % s . cmt not found in search path " ! unit in let cmt_infos = Cmt_format . read_cmt cmt_fname in let expr next ( e : Typedtree . expression ) = match e . exp_desc with | Texp_apply ( _ , args ) -> begin try match get_required_label " loc " args , get_required_label " values " args with | Some l , Some v -> let pos = l . exp_loc . loc_start in if pos . pos_fname = fname && pos . pos_lnum = lnum && pos . pos_cnum - pos . pos_bol = cnum then raise ( Found v . exp_env ) | _ -> next e with Not_found -> next e end | _ -> next e in let next iterator e = Tast_iterator . default_iterator . expr iterator e in let expr iterator = expr ( next iterator ) in let iter = { Tast_iterator . default_iterator with expr } in let search = iter . structure iter in # else let module Search = TypedtreeIter . MakeIterator ( struct include TypedtreeIter . DefaultIteratorArgument let enter_expression = expr ignore end ) in let search = Search . iter_structure in # endif try begin match cmt_infos . cmt_annots with | Implementation st -> search st | _ -> ( ) end ; failwith " Couldn ' t find location in cmt file " with Found env -> try List . iter Topdirs . dir_directory ( search_path @ cmt_infos . cmt_loadpath ) ; let env = Envaux . env_of_only_summary env in List . iter ( fun ( V ( name , v ) ) -> Toploop . setvalue name ( Obj . repr v ) ) values ; main_internal ~ initial_env ( : Some env ) with exn -> Location . report_exception Format . err_formatter exn ; exit 2 |
let ( ) = Location . register_error_of_exn ( function | Envaux . Error err -> Some ( Location . error_of_printer_file Envaux . report_error err ) | _ -> None ) |
let print_fan_error pp exn = Format . fprintf pp " [ @< 0 >% s ] . " @@ ( Printexc . to_string exn ) |
let get_fan_error_message exn = let ( loc , exn ) = match exn with | Locf . Exc_located ( loc , exn ) -> ( ( loc . loc_start . pos_cnum , loc . loc_end . pos_cnum ) , exn ) | exn -> ( ( 0 , 0 ) , exn ) in let msg = UTop . get_message print_fan_error exn in let idx = ref ( String . length msg - 1 ) in begin while ! idx > 0 && msg . [ ! idx ] = ' \ n ' do decr idx done ; if ! idx + 1 < String . length msg then ( loc , String . sub msg 0 ( ! idx + 1 ) ) else ( loc , msg ) end |
let revise_parser str _eos_is_error = let eof = ref false in let lexbuf = UTop . lexbuf_of_string eof str in try let stream = Lex_fan . from_lexbuf lexbuf in match Streamf . peek stream with | Some ( ` EOI _ ) -> ( Streamf . junk stream ; raise End_of_file ) | _ -> UTop . Value ( Mktop . toplevel_phrase stream ) with | End_of_file | Sys . Break | ( Locf . Exc_located ( _ , ( End_of_file | Sys . Break ) ) ) -> raise UTop . Need_more ( | Locf . Exc_located ( _loc , y ) ) -> ( UTop . Error ( [ ( 0 , 0 ) ] , Printexc . to_string y ) ) |
let normal ( ) = begin UTop . parse_toplevel_phrase := UTop . parse_toplevel_phrase_default ; UTop . parse_use_file := UTop . parse_use_file_default ; end ; ; |
let fan ( ) = begin UTop . parse_toplevel_phrase := revise_parser ; Toploop . parse_use_file := Mktop . wrap Mktop . use_file ~ print_location : Toploop . print_location ; end ; ; begin Hashtbl . replace Toploop . directive_table " fan " ( Toploop . Directive_none ( fun ( ) -> fan ( ) ) ) ; Hashtbl . replace Toploop . directive_table " pwd " ( Toploop . Directive_none ( fun ( ) -> prerr_endline ( Sys . getcwd ( ) ) ) ) ; Hashtbl . replace Toploop . directive_table " normal " ( Toploop . Directive_none ( fun ( ) -> normal ( ) ) ) ; Ast_parsers . use_parsers [ " fan " ] end ; ; begin fan ( ) ; end ; ; |
let ( ) = UTop_main . main ( ) ; ; |
let size , set_size = let ev , set_size = E . create ( ) in let init = S . const { LTerm_geom . rows = 25 ; LTerm_geom . cols = 80 } in ( S . switch ( S . hold ~ eq ( : == ) init ev ) , set_size ) |
let key_sequence , set_key_sequence = let ev , set_key_sequence = E . create ( ) in let init = ( S . const ( [ ] : LTerm_key . t list ) ) in ( S . switch ( S . hold ~ eq ( : == ) init ev ) , set_key_sequence ) |
let count , set_count = S . create ( - 1 ) |
type ui = Console | Emacs |
let ui , set_ui = S . create Console |
let error_style = ref LTerm_style . none |
let autoload = ref true |
let margin_function , set_margin_function = S . create ~ eq ( : == ) ( fun ( size : LTerm_geom . size ) -> Some ( min 80 size . cols ) ) |
let margin = S . app margin_function size |
let set_margin pp = match S . value margin with | None -> ( ) | Some n -> if Format . pp_get_margin pp ( ) <> n then Format . pp_set_margin pp n |
let return , ( ) >>= = Lwt . return , Lwt . ( ) >>= |
module String_set = Set . Make ( String ) |
type styles = { mutable style_keyword : LTerm_style . t ; mutable style_symbol : LTerm_style . t ; mutable style_ident : LTerm_style . t ; mutable style_module : LTerm_style . t ; mutable style_constant : LTerm_style . t ; mutable style_char : LTerm_style . t ; mutable style_string : LTerm_style . t ; mutable style_quotation : LTerm_style . t ; mutable style_comment : LTerm_style . t ; mutable style_doc : LTerm_style . t ; mutable style_blanks : LTerm_style . t ; mutable style_error : LTerm_style . t ; mutable style_directive : LTerm_style . t ; mutable style_paren : LTerm_style . t ; mutable style_font : string option ; mutable style_foreground : LTerm_style . color option ; mutable style_background : LTerm_style . color option ; mutable style_cursor : LTerm_style . color option ; } |
let styles = { style_keyword = LTerm_style . none ; style_symbol = LTerm_style . none ; style_ident = LTerm_style . none ; style_module = LTerm_style . none ; style_constant = LTerm_style . none ; style_char = LTerm_style . none ; style_string = LTerm_style . none ; style_quotation = LTerm_style . none ; style_comment = LTerm_style . none ; style_doc = LTerm_style . none ; style_blanks = LTerm_style . none ; style_error = LTerm_style . none ; style_directive = LTerm_style . none ; style_paren = LTerm_style . none ; style_font = None ; style_foreground = None ; style_background = None ; style_cursor = None ; } |
let load ( ) = let fn = Filename . concat LTerm_resources . home " . utoprc " in Lwt . catch ( fun ( ) -> LTerm_resources . load fn >>= fun res -> styles . style_keyword <- LTerm_resources . get_style " keyword " res ; styles . style_symbol <- LTerm_resources . get_style " symbol " res ; styles . style_ident <- LTerm_resources . get_style " identifier " res ; styles . style_module <- LTerm_resources . get_style " module " res ; styles . style_constant <- LTerm_resources . get_style " constant " res ; styles . style_char <- LTerm_resources . get_style " char " res ; styles . style_string <- LTerm_resources . get_style " string " res ; styles . style_quotation <- LTerm_resources . get_style " quotation " res ; styles . style_comment <- LTerm_resources . get_style " comment " res ; styles . style_doc <- LTerm_resources . get_style " doc " res ; styles . style_blanks <- LTerm_resources . get_style " blanks " res ; styles . style_error <- LTerm_resources . get_style " error " res ; styles . style_directive <- LTerm_resources . get_style " directive " res ; styles . style_paren <- LTerm_resources . get_style " parenthesis " res ; styles . style_font <- ( match LTerm_resources . get " font " res with | " " -> None | str -> Some str ) ; styles . style_foreground <- LTerm_resources . get_color " foreground " res ; styles . style_background <- LTerm_resources . get_color " background " res ; styles . style_cursor <- LTerm_resources . get_color " cursor " res ; ( match String . lowercase_ascii ( LTerm_resources . get " profile " res ) with | " light " -> UTop . set_profile UTop . Light | " dark " -> UTop . set_profile UTop . Dark | " " -> ( ) | str -> raise ( LTerm_resources . Error ( Printf . sprintf " invalid profile % S " str ) ) ) ; UTop_private . error_style := styles . style_error ; UTop_private . autoload := LTerm_resources . get_bool " autoload " res <> Some false ; ( match LTerm_resources . get " external - editor " res with | " " -> ( ) | s -> UTop . set_external_editor s ) ; return ( ) ) ( function | Unix . Unix_error ( Unix . ENOENT , _ , _ ) -> return ( ) | Unix . Unix_error ( error , func , _arg ) -> Lwt_log . error_f " cannot load styles from % S : % s : % s " fn func ( Unix . error_message error ) | exn -> Lwt . fail exn ) |
let stylise_filter_layout stylise tokens = let aux acc = function | ( Comment ( Comment_reg , _ ) , loc ) -> stylise loc styles . style_comment ; acc | ( Comment ( Comment_doc , _ ) , loc ) -> stylise loc styles . style_doc ; acc | ( Blanks , loc ) -> stylise loc styles . style_blanks ; acc | x -> x :: acc in List . rev ( List . fold_left aux [ ] tokens ) |
let rec stylise_rec stylise tokens = match tokens with | [ ] -> ( ) | ( Symbol _ , loc ) :: tokens -> stylise loc styles . style_symbol ; stylise_rec stylise tokens | ( Lident id , loc ) :: tokens -> stylise loc ( if String_set . mem id ! UTop . keywords then styles . style_keyword else styles . style_ident ) ; stylise_rec stylise tokens | ( Uident id , loc ) :: tokens when String_set . mem id ! UTop . keywords -> stylise loc styles . style_keyword ; stylise_rec stylise tokens | ( Uident _id , loc1 ) :: ( Symbol " . " , loc2 ) :: tokens -> stylise loc1 styles . style_module ; stylise loc2 styles . style_symbol ; stylise_rec stylise tokens | ( Uident _id , loc ) :: tokens -> stylise loc styles . style_ident ; stylise_rec stylise tokens | ( Constant _ , loc ) :: tokens -> stylise loc styles . style_constant ; stylise_rec stylise tokens | ( Char , loc ) :: tokens -> stylise loc styles . style_char ; stylise_rec stylise tokens | ( String _ , loc ) :: tokens -> stylise loc styles . style_string ; stylise_rec stylise tokens | ( Quotation ( items , _ ) , _ ) :: tokens -> stylise_quotation_items stylise items ; stylise_rec stylise tokens | ( Error , loc ) :: tokens -> stylise loc styles . style_error ; stylise_rec stylise tokens | ( ( Comment _ | Blanks ) , _ ) :: _ -> assert false match items with | [ ] -> ( ) | ( Quot_data , loc ) :: items -> stylise loc styles . style_quotation ; stylise_quotation_items stylise items | ( Quot_anti anti , _ ) :: items -> stylise anti . a_opening styles . style_symbol ; ( match anti . a_name with | None -> ( ) | Some ( loc1 , loc2 ) -> stylise loc1 styles . style_module ; stylise loc2 styles . style_symbol ) ; let tokens = stylise_filter_layout stylise anti . a_contents in stylise_rec stylise tokens ; ( match anti . a_closing with | None -> ( ) | Some loc -> stylise loc styles . style_symbol ) ; stylise_quotation_items stylise items |
let stylise stylise tokens = let tokens = stylise_filter_layout stylise tokens in match tokens with | ( Symbol " " , # loc ) :: tokens -> begin stylise loc styles . style_directive ; match tokens with | ( ( Lident id | Uident id ) , loc ) :: tokens -> stylise loc ( if String_set . mem id ! UTop . keywords then styles . style_keyword else styles . style_directive ) ; stylise_rec stylise tokens | tokens -> stylise_rec stylise tokens end | tokens -> stylise_rec stylise tokens |
type location = { idx1 : int ; idx2 : int ; ofs1 : int ; ofs2 : int ; } |
type t = | Symbol of string | Lident of string | Uident of string | Constant of string | Char | String of int * bool | Comment of comment_kind * bool | Blanks | Error | Quotation of ( quotation_item * location ) list * bool | Comment_reg | Comment_doc | Quot_data | Quot_anti of antiquotation a_opening : location ; a_closing : location option ; a_name : ( location * location ) option ; a_contents : ( t * location ) list ; } |
let str_of_name ( u , l ) = str " { % s } % s " u l |
let split_string s sep = let rec split accum j = let i = try ( String . rindex_from s j sep ) with Not_found -> - 1 in if ( i = - 1 ) then let p = String . sub s 0 ( j + 1 ) in if p <> " " then p :: accum else accum else let p = String . sub s ( i + 1 ) ( j - i ) in let accum ' = if p <> " " then p :: accum else accum in split accum ' ( i - 1 ) in split [ ] ( String . length s - 1 ) |
let err s = failwith s |
let err_data = " character data not allowed here " |
let err_exp_el_end = " expected end of element " |
let err_exp_data = " expected character data " |
let err_wf = " document not well formed " |
let err_dup n = str " duplicate element ( % s ) " ( str_of_name n ) |
let err_miss_att n = str " missing attribute ( % s ) " n |
let err_att_val v = str " invalid attribute value ( " \% s " ) " \ v |
let err_invalid_cp v = str " invalid code point ( " \% s " ) " \ v |
let err_empty_cps = " empty code point sequence " |
let err_exp_ucd fnd = str " expected ucd element found % s " ( str_of_name fnd ) |
let err_invalid_cp_spec = str " invalid code point specification " |
let err_invalid_name_alias_spec = str " invalid name alias specification " |
module Cp = struct type t = int let compare : int -> int -> int = compare end |
let is_cp i = 0x0000 <= i && i <= 0x10_FFFF |
let is_scalar_value i = ( 0x0000 <= i && i <= 0xD7FF ) || ( 0xE000 <= i && i <= 0x10FFFF ) |
let cp_of_string v = let is_hex c = ( 0x30 <= c && c <= 0x39 ) || ( 0x41 <= c && c <= 0x46 ) in let cp = ref 0 in for k = 0 to ( String . length v ) - 1 do let c = Char . code v . [ k ] in if not ( is_hex c ) then err ( err_invalid_cp v ) else cp := ! cp * 16 + ( if c <= 0x39 then c - 48 else c - 55 ) done ; if is_cp ! cp then ! cp else err ( err_invalid_cp v ) |
let cps_of_string ( ? empty = false ) v = if ( v = " " ) then ( if empty then [ ] else err err_empty_cps ) else List . map cp_of_string ( split_string v ' ' ) |
module Cpmap = Map . Make ( Cp ) |
type script = [ ] |
type block_prop = [ ] |
type value = | ` AL | ` AN | ` B | ` BN | ` CS | ` EN | ` ES | ` ET | ` L | ` LRE | ` LRO | ` NSM | ` ON | ` PDF | ` R | ` RLE | ` RLO | ` S | ` WS | ` LRI | ` RLI | ` FSI | ` PDI ] | ` Can | ` Com | ` Enc | ` Fin | ` Font | ` Fra | ` Init | ` Iso | ` Med | ` Nar | ` Nb | ` Sml | ` Sqr | ` Sub | ` Sup | ` Vert | ` Wide | ` None ] | ` Lu | ` Ll | ` Lt | ` Lm | ` Lo | ` Mn | ` Mc | ` Me | ` Nd | ` Nl | ` No | ` Pc | ` Pd | ` Ps | ` Pe | ` Pi | ` Pf | ` Po | ` Sm | ` Sc | ` Sk | ` So | ` Zs | ` Zl | ` Zp | ` Cc | ` Cf | ` Cs | ` Co | ` Cn ] | ` CN | ` CR | ` EB | ` EBG | ` EM | ` EX | ` GAZ | ` L | ` LF | ` LV | ` LVT | ` PP | ` RI | ` SM | ` T | ` V | ` XX | ` ZWJ ] [ ` Avagraha | ` Bindu | ` Brahmi_Joining_Number | ` Cantillation_Mark | ` Consonant | ` Consonant_Dead | ` Consonant_Final | ` Consonant_Head_Letter | ` Consonant_Initial_Postfixed | ` Consonant_Killer | ` Consonant_Medial | ` Consonant_Placeholder | ` Consonant_Preceding_Repha | ` Consonant_Prefixed | ` Consonant_Repha | ` Consonant_Subjoined | ` Consonant_Succeeding_Repha | ` Consonant_With_Stacker | ` Gemination_Mark | ` Invisible_Stacker | ` Joiner | ` Modifying_Letter | ` Non_Joiner | ` Nukta | ` Number | ` Number_Joiner | ` Other | ` Pure_Killer | ` Register_Shifter | ` Syllable_Modifier | ` Tone_Letter | ` Tone_Mark | ` Virama | ` Visarga | ` Vowel | ` Vowel_Dependent | ` Vowel_Independent ] | ` Right | ` Left | ` Visual_Order_Left | ` Left_And_Right | ` Top | ` Bottom | ` Top_And_Bottom | ` Top_And_Right | ` Top_And_Left | ` Top_And_Left_And_Right | ` Bottom_And_Right | ` Top_And_Bottom_And_Right | ` Overstruck | ` Invisible | ` NA ] | ` Bottom | ` Bottom_And_Left | ` Bottom_And_Right | ` Left | ` Left_And_Right | ` NA | ` Overstruck | ` Right | ` Top | ` Top_And_Bottom | ` Top_And_Bottom_And_Left | ` Top_And_Bottom_And_Right | ` Top_And_Left | ` Top_And_Left_And_Right | ` Top_And_Right | ` Visual_Order_Left ] | ` African_Feh | ` African_Noon | ` African_Qaf | ` Ain | ` Alaph | ` Alef | ` Alef_Maqsurah | ` Beh | ` Beth | ` Burushaski_Yeh_Barree | ` Dal | ` Dalath_Rish | ` E | ` Farsi_Yeh | ` Fe | ` Feh | ` Final_Semkath | ` Gaf | ` Gamal | ` Hah | ` Hanifi_Rohingya_Kinna_Ya | ` Hanifi_Rohingya_Pa | ` Hamza_On_Heh_Goal | ` He | ` Heh | ` Heh_Goal | ` Heth | ` Kaf | ` Kaph | ` Khaph | ` Knotted_Heh | ` Lam | ` Lamadh | ` Malayalam_Bha | ` Malayalam_Ja | ` Malayalam_Lla | ` Malayalam_Llla | ` Malayalam_Nga | ` Malayalam_Nna | ` Malayalam_Nnna | ` Malayalam_Nya | ` Malayalam_Ra | ` Malayalam_Ssa | ` Malayalam_Tta | ` Manichaean_Aleph | ` Manichaean_Ayin | ` Manichaean_Beth | ` Manichaean_Daleth | ` Manichaean_Dhamedh | ` Manichaean_Five | ` Manichaean_Gimel | ` Manichaean_Heth | ` Manichaean_Hundred | ` Manichaean_Kaph | ` Manichaean_Lamedh | ` Manichaean_Mem | ` Manichaean_Nun | ` Manichaean_One | ` Manichaean_Pe | ` Manichaean_Qoph | ` Manichaean_Resh | ` Manichaean_Sadhe | ` Manichaean_Samekh | ` Manichaean_Taw | ` Manichaean_Ten | ` Manichaean_Teth | ` Manichaean_Thamedh | ` Manichaean_Twenty | ` Manichaean_Waw | ` Manichaean_Yodh | ` Manichaean_Zayin | ` Meem | ` Mim | ` No_Joining_Group | ` Noon | ` Nun | ` Nya | ` Pe | ` Qaf | ` Qaph | ` Reh | ` Reversed_Pe | ` Rohingya_Yeh | ` Sad | ` Sadhe | ` Seen | ` Semkath | ` Shin | ` Straight_Waw | ` Swash_Kaf | ` Syriac_Waw | ` Tah | ` Taw | ` Teh_Marbuta | ` Teh_Marbuta_Goal | ` Teth | ` Thin_Yeh | ` Vertical_Tail | ` Waw | ` Yeh | ` Yeh_Barree | ` Yeh_With_Tail | ` Yudh | ` Yudh_He | ` Zain | ` Zhain ] | ` AI | ` AL | ` B2 | ` BA | ` BB | ` BK | ` CB | ` CJ | ` CL | ` CM | ` CP | ` CR | ` EX | ` GL | ` H2 | ` H3 | ` HL | ` HY | ` ID | ` IN | ` IS | ` JL | ` JT | ` JV | ` LF | ` NL | ` NS | ` NU | ` OP | ` PO | ` PR | ` QU | ` RI | ` SA | ` SG | ` SP | ` SY | ` WJ | ` XX | ` ZW | ` EB | ` EM | ` ZWJ ] ( string * [ ` Abbreviation | ` Alternate | ` Control | ` Correction | ` Figment ] ) list | ` AT | ` CL | ` CR | ` EX | ` FO | ` LE | ` LF | ` LO | ` NU | ` SC | ` SE | ` SP | ` ST | ` UP | ` XX ] | ` CR | ` DQ | ` EB | ` EBG | ` EM | ` EX | ` Extend | ` FO | ` GAZ | ` HL | ` KA | ` LE | ` LF | ` MB | ` ML | ` MN | ` NL | ` NU | ` RI | ` SQ | ` WSegSpace | ` XX | ` ZWJ ] |
let o_age = function Age_v v -> v | _ -> assert false |
let o_bidi_class = function Bidi_class_v v -> v | _ -> assert false |
let o_bidi_paired_bracket_type = function Bidi_paired_bracket_type_v v -> v | _ -> assert false |
let o_block = function Block_v v -> v | _ -> assert false |
let o_bool = function Bool_v v -> v | _ -> assert false |
let o_bool_maybe = function Bool_maybe_v v -> v | _ -> assert false |
let o_cp = function Cp_v v -> v | _ -> assert false |
let o_cp_map = function Cp_map_v v -> v | _ -> assert false |
let o_cp_opt = function Cp_opt_v v -> v | _ -> assert false |
let o_decomposition_type = function Decomposition_type_v v -> v | _ -> assert false |
let o_east_asian_width = function East_asian_width_v v -> v | _ -> assert false |
let o_general_category = function General_category_v v -> v | _ -> assert false |
let o_grapheme_cluster_break = function Grapheme_cluster_break_v v -> v | _ -> assert false |
let o_hangul_syllable_type = function Hangul_syllable_type_v v -> v | _ -> assert false |
let o_int = function Int_v v -> v | _ -> assert false |
let o_indic_syllabic_category = function Indic_syllabic_category_v v -> v | _ -> assert false |
let o_indic_matra_category = function Indic_matra_category_v v -> v | _ -> assert false |
let o_indic_positional_category = function Indic_positional_category_v v -> v | _ -> assert false |
let o_joining_group = function Joining_group_v v -> v | _ -> assert false |
let o_joining_type = function Joining_type_v v -> v | _ -> assert false |
let o_line_break = function Line_break_v v -> v | _ -> assert false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.