text
stringlengths
12
786k
let rec add_size bv s = match s . desc with | Sconst _ -> ( ) | Sname id -> add bv id | Sop ( _ , s1 , s2 ) -> add_size bv s1 ; add_size bv s2
let rec add_type_expr bv ty = match ty . desc with | Etypevar _ -> ( ) | Etypeconstr ( id , tel ) -> add bv id ; List . iter ( add_type_expr bv ) tel | Etypetuple tl -> List . iter ( add_type_expr bv ) tl | Etypevec ( ty , s ) -> add_type_expr bv ty ; add_size bv s | Etypefu...
let rec add_interface bv i = match i . desc with | Einter_open s -> if not ( StringSet . mem s ! bv ) then bv := StringSet . add s ! bv | Einter_typedecl ( _ , _ , tdl ) -> add_type_decl bv tdl | Einter_constdecl ( _ , te ) -> add_type_expr bv te match td . desc with | Eabstract_...
let file traverse initial_structures file = let bv = ref initial_structures in List . iter ( traverse bv ) file ; ! bv
let source_file ( ? initial_structures = StringSet . empty ) source = file add_implem initial_structures source
let interface_file ( ? initial_structures = StringSet . empty ) interface = file add_interface initial_structures interface
type char_prop = | Printable of int | Other | Null
let to_array t = Array . of_list ( Zed_utf8 . explode t ) t
let zero = String . make 1 ( Char . chr 0 ) 0
let core t = Zed_utf8 . unsafe_extract t 0
let combined t = List . tl ( Zed_utf8 . explode t ) t
let prop_uChar uChar = match CharInfo_width . width uChar with | - 1 -> Other | 0 -> if UChar . code uChar = 0 then Null else Printable 0 | w -> Printable w
let prop t = prop_uChar ( Zed_utf8 . unsafe_extract t 0 ) 0
let is_printable uChar = match prop_uChar uChar with | Printable _ -> true | _ -> false
let is_printable_core uChar = match prop_uChar uChar with | Printable w when w > 0 -> true | _ -> false
let is_combining_mark uChar = match prop_uChar uChar with | Printable w when w = 0 -> true | _ -> false
let width t = CharInfo_width . width ( Zed_utf8 . unsafe_extract t 0 ) 0
let out_of_range t i = i < 0 || i >= size t
let get_opt t i = try Some ( get t i ) i with _ -> None
let append ch mark = match prop_uChar mark with | Printable 0 -> ch ^ ( Zed_utf8 . singleton mark ) mark | _ -> failwith " combining mark expected "
let compare_core t1 t2 = let core1 = Zed_utf8 . unsafe_extract t1 0 and core2 = Zed_utf8 . unsafe_extract t2 0 in UChar . compare core1 core2
let mix_uChar zChar uChar = match prop_uChar uChar with | Printable 0 -> Ok ( zChar ^ ( Zed_utf8 . singleton uChar ) uChar ) uChar | _ -> Error ( Zed_utf8 . singleton uChar ) uChar
let first_core ( ? trim = false ) false uChars = let rec aux uChars = match uChars with | [ ] -> None , [ ] | uChar :: tl -> let prop = prop_uChar uChar in match prop with | Printable w -> if w > 0 then Some ( prop , uChar ) uChar , tl else aux tl | Other -> Some ( prop , uChar...
let rec subsequent uChars = match uChars with | [ ] -> [ ] , [ ] | uChar :: tl -> let prop = prop_uChar uChar in match prop with | Printable w -> if w > 0 then [ ] , uChars else let seq , remain = subsequent tl in uChar :: seq , remain | _ -> [ ] , uChars
let of_uChars ( ? trim = false ) false ( ? indv_combining = true ) true uChars = match uChars with | [ ] -> None , [ ] | uChar :: tl -> match first_core ~ trim uChars with | None , _ -> if indv_combining then Some ( Zed_utf8 . singleton uChar ) uChar , tl else None , uChars ...
let zChars_of_uChars ( ? trim = false ) false ( ? indv_combining = true ) true uChars = let rec aux zChars uChars = match of_uChars ~ trim ~ indv_combining uChars with | None , tl -> List . rev zChars , tl | Some zChar , tl -> aux ( zChar :: zChars ) zChars tl in aux [ ] uChars
let unsafe_of_utf8 : string -> t = fun str -> if String . length str > 0 then str else failwith " malformed Zed_char sequence "
let of_utf8 ( ? indv_combining = true ) true str = match of_uChars ~ indv_combining ( Zed_utf8 . explode str ) str with | Some zChar , [ ] -> zChar | _ -> failwith " malformed Zed_char sequence "
let to_utf8 : t -> string = id
let unsafe_of_char c = Zed_utf8 . singleton ( UChar . of_char c ) c
let unsafe_of_uChar uChar = Zed_utf8 . singleton uChar
module US ( USUS : UnicodeString . Type ) Type = struct module Convert = Zed_utils . Convert ( ConvertUS ) ConvertUS let of_t t = Zed_utf8 . explode t |> Convert . of_list let to_t us = let len = US . length us in let rec create i = if i < len then US . get us i :: create ( i + 1 ) 1 el...
type changes = { position : int ; added : int ; removed : int ; added_width : int ; removed_width : int ; }
type action = | User_move of int | Text_modification of changes
type t = { position : int signal ; send : action -> unit ; length : int ref ; changes : changes event ; get_lines : unit -> Zed_lines . t ; coordinates : ( int * int ) int signal ; coordinates_display : ( int * int ) int signal ; line : int signal ; column : int signal ; colu...
let create length changes get_lines position wanted_column = if position < 0 || position > length then raise Out_of_bounds ; let length = ref length in let user_moves , send = E . create ( ) in let update_position position action = match action with | User_move pos -> pos | Text_modification changes...
let copy cursor = create ( ! cursor . length ) length cursor . changes cursor . get_lines ( S . value cursor . position ) position ( S . value cursor . wanted_column ) wanted_column
let position cursor = cursor . position
let get_position cursor = S . value cursor . position
let line cursor = cursor . line
let get_line cursor = S . value cursor . line
let column cursor = cursor . column
let column_display cursor = cursor . column_display
let get_column cursor = S . value cursor . column
let get_column_display cursor = S . value cursor . column_display
let coordinates cursor = cursor . coordinates
let coordinates_display cursor = cursor . coordinates
let get_coordinates cursor = S . value cursor . coordinates
let get_coordinates_display cursor = S . value cursor . coordinates_display
let wanted_column cursor = cursor . wanted_column
let get_wanted_column cursor = S . value cursor . wanted_column
let set_wanted_column cursor column = cursor . set_wanted_column column
let move cursor ( ? set_wanted_column = true ) true delta = let new_position = S . value cursor . position + delta in if new_position < 0 || new_position > ( ! cursor . length ) length then raise Out_of_bounds else begin cursor . send ( User_move new_position ) new_position ; if set_wanted_...
let goto cursor ( ? set_wanted_column = true ) true position = if position < 0 || position > ( ! cursor . length ) length then raise Out_of_bounds else begin cursor . send ( User_move position ) position ; if set_wanted_column then cursor . set_wanted_column ( S . value cursor . column_d...
type clipboard = { clipboard_get : unit -> Zed_rope . t ; clipboard_set : Zed_rope . t -> unit ; }
type ' a t = { mutable data : ' a option ; mutable text : Zed_rope . t ; mutable lines : Zed_lines . t ; changes : Zed_cursor . changes event ; send_changes : Zed_cursor . changes -> unit ; erase_mode : bool signal ; set_erase_mode : bool -> unit ; editable : int -> int -> bool ; ...
let dummy_cursor = Zed_cursor . create 0 E . never ( fun ( ) -> Zed_lines . empty ) empty 0 0
let match_by_regexp_core re rope idx = match Zed_re . Core . regexp_match ~ sem ` : Longest re rope idx with | None -> None | Some arr -> match arr ( . 0 ) 0 with | Some ( Some_zip1 , zip2 ) zip2 -> Some ( SomeZed_rope . Zip . offset zip2 ) zip2 | None -> None
let match_by_regexp_raw re rope idx = match Zed_re . Raw . regexp_match ~ sem ` : Longest re rope idx with | None -> None | Some arr -> match arr ( . 0 ) 0 with | Some ( Some_zip1 , zip2 ) zip2 -> Some ( SomeZed_rope . Zip_raw . offset zip2 ) zip2 | None -> None
let regexp_word_core = let set = UCharInfo . load_property_set ` Alphabetic in let set = List . fold_left ( fun set ch -> USet . add ( UChar . of_char ch ) ch set ) set set [ ' 0 ' ; ' 1 ' ; ' 2 ' ; ' 3 ' ; ' 4 ' ; ' 5 ' ; ' 6 ' ; ' 7 ' ; ' 8 ' ; ' 9 ' ] ' 9 ...
let regexp_word_raw = let set = UCharInfo . load_property_set ` Alphabetic in let set = List . fold_left ( fun set ch -> USet . add ( UChar . of_char ch ) ch set ) set set [ ' 0 ' ; ' 1 ' ; ' 2 ' ; ' 3 ' ; ' 4 ' ; ' 5 ' ; ' 6 ' ; ' 7 ' ; ' 8 ' ; ' 9 ' ] ' 9 '...
let new_clipboard ( ) = let r = ref ( Zed_rope . empty ( ) ) in { clipboard_get = ( fun ( ) -> ! r ) r ; clipboard_set = ( fun x -> r := x ) x }
let create ( ? editable = fun _pos _len -> true ) true ( ? move = ( ) ) + ? clipboard ( ? match_word = match_by_regexp_core regexp_word_core ) regexp_word_core ( ? locale = S . const None ) None ( ? undo_size = 1000 ) 1000 ( ) = let _ = move in let changes , send_chang...
let get_data engine = match engine . data with | Some data -> data | None -> raise Not_found
let set_data engine data = engine . data <- Some data
let clear_data engine = engine . data <- None
let text engine = engine . text
let lines engine = engine . lines
let changes engine = engine . changes
let erase_mode engine = engine . erase_mode
let get_erase_mode engine = S . value engine . erase_mode
let set_erase_mode engine state = engine . set_erase_mode state
let mark engine = engine . mark
let selection engine = engine . selection
let get_selection engine = S . value engine . selection
let set_selection engine state = engine . set_selection state
let get_line e i = let txt = text e in let lines = lines e in let start = Zed_lines . line_start lines i in let stop = Zed_lines . line_stop lines i in Zed_rope . sub txt start ( stop - start ) start
let update engine cursors = E . select ( E . stamp engine . changes ( ) :: E . stamp ( S . changes engine . selection ) selection ( ) :: E . stamp ( S . changes ( Zed_cursor . position engine . mark ) mark ) mark ( ) :: List . map ( fun cursor -> E . stamp ( S . cha...
let new_cursor engine = Zed_cursor . create ( Zed_rope . length engine . text ) text engine . changes ( fun ( ) -> engine . lines ) lines 0 0
type ' a context = { edit : ' a t ; cursor : Zed_cursor . t ; check : bool ; }
let context ( ? check = true ) true edit cursor = { edit ; cursor ; check }
let edit ctx = ctx . edit
let cursor ctx = ctx . cursor
let check ctx = ctx . check
let with_check check ctx = { ctx with check }
let goto ctx ? set_wanted_column new_position = Zed_cursor . goto ctx . cursor ? set_wanted_column new_position
let set_position ctx new_position = Zed_cursor . goto ctx . cursor ~ set_wanted_column : false new_position
let move ctx ? set_wanted_column delta = Zed_cursor . move ctx . cursor ? set_wanted_column delta
let next_line_n ctx n = let index = Zed_cursor . get_line ctx . cursor in if index + n > Zed_lines . count ctx . edit . lines then goto ctx ~ set_wanted_column : false ( Zed_rope . length ctx . edit . text ) text else begin let stop = if index + n = Zed_lines . count ctx . edit . lines then Zed...
let prev_line_n ctx n = let index = Zed_cursor . get_line ctx . cursor in if index - n < 0 then begin goto ctx ~ set_wanted_column : false 0 end else begin let stop = Zed_lines . line_start ctx . edit . lines ( index - ( n - 1 ) 1 ) 1 - 1 in let wanted_idx = Zed_lines . get_idx_by_width ct...
let move_line ctx delta = match delta with | _ when delta < 0 -> prev_line_n ctx ( - delta ) delta | _ when delta > 0 -> next_line_n ctx delta | _ -> ( )
let position ctx = Zed_cursor . get_position ctx . cursor
let line ctx = Zed_cursor . get_line ctx . cursor
let column ctx = Zed_cursor . get_column ctx . cursor
let column_display ctx = Zed_cursor . get_column_display ctx . cursor
let at_bol ctx = Zed_cursor . get_column ctx . cursor = 0
let at_eol ctx = let position = Zed_cursor . get_position ctx . cursor in let index = Zed_cursor . get_line ctx . cursor in if index = Zed_lines . count ctx . edit . lines then position = Zed_rope . length ctx . edit . text else position = Zed_lines . line_start ctx . edit . lines ( index + 1 ) 1 ...
let at_bot ctx = Zed_cursor . get_position ctx . cursor = 0
let at_eot ctx = Zed_cursor . get_position ctx . cursor = Zed_rope . length ctx . edit . text
let modify { edit ; _ } text lines position new_position added removed added_width removed_width = if edit . undo_size > 0 then begin edit . undo ( . edit . undo_index ) undo_index <- ( text , lines , position , new_position , added , removed , added_width , removed_width ) remov...