text
stringlengths
12
786k
let rcut ~ sep ( : sep , sep_start , sep_stop ) ( s , start , stop ) = let sep_len = sep_stop - sep_start in if sep_len = 0 then invalid_arg Astring_base . err_empty_sep else let max_sep_zidx = sep_len - 1 in let max_s_idx = stop - 1 in let rec check_sep i k = if k > max_sep_zidx then Some ( ( s , start , i ) , ( s , i + sep_len , stop ) ) else if sunsafe_get s ( i + k ) = sunsafe_get sep ( sep_start + k ) then check_sep i ( k + 1 ) else rscan ( i - 1 ) and rscan i = if i < start then None else if sunsafe_get s i = sunsafe_get sep sep_start then check_sep i 1 else rscan ( i - 1 ) in rscan ( max_s_idx - max_sep_zidx )
let cut ( ? rev = false ) ~ sep s = match rev with
let add_sub ~ no_empty s ~ start ~ stop acc = if start = stop then ( if no_empty then acc else ( s , start , start ) :: acc ) else ( s , start , stop ) :: acc
let fcuts ~ no_empty ~ sep ( : sep , sep_start , sep_stop ) ( s , start , stop as sub ) = let sep_len = sep_stop - sep_start in if sep_len = 0 then invalid_arg Astring_base . err_empty_sep else let s_len = stop - start in let max_sep_zidx = sep_len - 1 in let max_s_idx = stop - sep_len in let rec check_sep sstart i k acc = if k > max_sep_zidx then let new_start = i + sep_len in scan new_start new_start ( add_sub ~ no_empty s ~ start : sstart ~ stop : i acc ) else if sunsafe_get s ( i + k ) = sunsafe_get sep ( sep_start + k ) then check_sep sstart i ( k + 1 ) acc else scan sstart ( i + 1 ) acc and scan sstart i acc = if i > max_s_idx then if sstart = start then ( if no_empty && s_len = 0 then [ ] else [ sub ] ) else List . rev ( add_sub ~ no_empty s ~ start : sstart ~ stop acc ) else if sunsafe_get s i = sunsafe_get sep sep_start then check_sep sstart i 1 acc else scan sstart ( i + 1 ) acc in scan start start [ ]
let rcuts ~ no_empty ~ sep ( : sep , sep_start , sep_stop ) ( s , start , stop as sub ) = let sep_len = sep_stop - sep_start in if sep_len = 0 then invalid_arg Astring_base . err_empty_sep else let s_len = stop - start in let max_sep_zidx = sep_len - 1 in let max_s_idx = stop - 1 in let rec check_sep sstop i k acc = if k > max_sep_zidx then let start = i + sep_len in rscan i ( i - sep_len ) ( add_sub ~ no_empty s ~ start ~ stop : sstop acc ) else if sunsafe_get s ( i + k ) = sunsafe_get sep ( sep_start + k ) then check_sep sstop i ( k + 1 ) acc else rscan sstop ( i - 1 ) acc and rscan sstop i acc = if i < start then if sstop = stop then ( if no_empty && s_len = 0 then [ ] else [ sub ] ) else add_sub ~ no_empty s ~ start ~ stop : sstop acc else if sunsafe_get s i = sunsafe_get sep sep_start then check_sep sstop i 1 acc else rscan sstop ( i - 1 ) acc in rscan stop ( max_s_idx - max_sep_zidx ) [ ]
let cuts ( ? rev = false ) ( ? empty = true ) ~ sep s = match rev with
let fields ( ? empty = false ) ( ? is_sep = Astring_char . Ascii . is_white ) ( s , start , stop as sub ) = let no_empty = not empty in let max_pos = stop in let rec loop i end_pos acc = if i < start then begin if end_pos = max_pos then ( if no_empty && max_pos = start then [ ] else [ sub ] ) else add_sub ~ no_empty s ~ start ~ stop : end_pos acc end else begin if not ( is_sep ( sunsafe_get s i ) ) then loop ( i - 1 ) end_pos acc else loop ( i - 1 ) i ( add_sub ~ no_empty s ~ start ( : i + 1 ) ~ stop : end_pos acc ) end in loop ( max_pos - 1 ) max_pos [ ]
let ffind sat ( s , start , stop ) = let max_idx = stop - 1 in let rec loop i = if i > max_idx then None else if sat ( sunsafe_get s i ) then Some ( s , i , i + 1 ) else loop ( i + 1 ) in loop start
let rfind sat ( s , start , stop ) = let rec loop i = if i < start then None else if sat ( sunsafe_get s i ) then Some ( s , i , i + 1 ) else loop ( i - 1 ) in loop ( stop - 1 )
let find ( ? rev = false ) sat sub = match rev with
let ffind_sub ~ sub ( : sub , sub_start , sub_stop ) ( s , start , stop ) = let len_sub = sub_stop - sub_start in let len_s = stop - start in if len_sub > len_s then None else let max_zidx_sub = len_sub - 1 in let max_idx_s = start + len_s - len_sub in let rec loop i k = if i > max_idx_s then None else if k > max_zidx_sub then Some ( s , i , i + len_sub ) else if k > 0 then if sunsafe_get sub ( sub_start + k ) = sunsafe_get s ( i + k ) then loop i ( k + 1 ) else loop ( i + 1 ) 0 else if sunsafe_get sub sub_start = sunsafe_get s i then loop i 1 else loop ( i + 1 ) 0 in loop start 0
let rfind_sub ~ sub ( : sub , sub_start , sub_stop ) ( s , start , stop ) = let len_sub = sub_stop - sub_start in let len_s = stop - start in if len_sub > len_s then None else let max_zidx_sub = len_sub - 1 in let rec loop i k = if i < start then None else if k > max_zidx_sub then Some ( s , i , i + len_sub ) else if k > 0 then if sunsafe_get sub ( sub_start + k ) = sunsafe_get s ( i + k ) then loop i ( k + 1 ) else loop ( i - 1 ) 0 else if sunsafe_get sub sub_start = sunsafe_get s i then loop i 1 else loop ( i - 1 ) 0 in loop ( stop - len_sub ) 0
let find_sub ( ? rev = false ) ~ sub start = match rev with
let filter sat ( s , start , stop ) = let len = stop - start in if len = 0 then empty else let b = Bytes . create len in let max_idx = stop - 1 in let rec loop b k i = if i > max_idx then ( ( if k = len then bytes_unsafe_to_string b else Bytes . sub_string b 0 k ) , 0 , k ) else let c = sunsafe_get s i in if sat c then ( bytes_unsafe_set b k c ; loop b ( k + 1 ) ( i + 1 ) ) else loop b k ( i + 1 ) in loop b 0 start
let filter_map f ( s , start , stop ) = let len = stop - start in if len = 0 then empty else let b = Bytes . create len in let max_idx = stop - 1 in let rec loop b k i = if i > max_idx then ( ( if k = len then bytes_unsafe_to_string b else Bytes . sub_string b 0 k ) , 0 , k ) else match f ( sunsafe_get s i ) with | None -> loop b k ( i + 1 ) | Some c -> bytes_unsafe_set b k c ; loop b ( k + 1 ) ( i + 1 ) in loop b 0 start
let map f ( s , start , stop ) = let len = stop - start in if len = 0 then empty else let b = Bytes . create len in for i = 0 to len - 1 do bytes_unsafe_set b i ( f ( sunsafe_get s ( start + i ) ) ) done ; ( bytes_unsafe_to_string b , 0 , len )
let mapi f ( s , start , stop ) = let len = stop - start in if len = 0 then empty else let b = Bytes . create len in for i = 0 to len - 1 do bytes_unsafe_set b i ( f i ( sunsafe_get s ( start + i ) ) ) done ; ( bytes_unsafe_to_string b , 0 , len )
let fold_left f acc ( s , start , stop ) = Astring_base . fold_left f acc s ~ first : start ~ last ( : stop - 1 )
let fold_right f ( s , start , stop ) acc = Astring_base . fold_right f s acc ~ first : start ~ last ( : stop - 1 )
let iter f ( s , start , stop ) = for i = start to stop - 1 do f ( sunsafe_get s i ) done
let iteri f ( s , start , stop ) = for i = start to stop - 1 do f ( i - start ) ( sunsafe_get s i ) done
let pp ppf s = Format . pp_print_string ppf ( to_string s )
let dump ppf s = Format . pp_print_char ppf ' " ' ; Format . pp_print_string ppf ( Astring_escape . escape_string ( to_string s ) ) ; Format . pp_print_char ppf ' " ' ; ( )
let dump_raw ppf ( s , start , stop ) = Format . fprintf ppf " [ @< 1 ( [ >@< 1 ( > base @ " \% s " ) ] \@@ [ @< 1 ( > start @ % d ) ] @@ \ [ ( @ stop @ % d ) ] ) ] " @@ ( Astring_escape . escape_string s ) start stop
let of_char c = v ( Astring_base . of_char c )
let to_char s = Astring_base . to_char ( to_string s )
let of_bool b = v ( Astring_base . of_bool b )
let to_bool s = Astring_base . to_bool ( to_string s )
let of_int i = v ( Astring_base . of_int i )
let to_int s = Astring_base . to_int ( to_string s )
let of_nativeint i = v ( Astring_base . of_nativeint i )
let to_nativeint s = Astring_base . to_nativeint ( to_string s )
let of_int32 i = v ( Astring_base . of_int32 i )
let to_int32 s = Astring_base . to_int32 ( to_string s )
let of_int64 i = v ( Astring_base . of_int64 i )
let to_int64 s = Astring_base . to_int64 ( to_string s )
let of_float f = v ( Astring_base . of_float f )
let to_float s = Astring_base . to_float ( to_string s )
type ' a with_loc = ' a Location . loc
type lid = Longident . t with_loc
type str = string with_loc
type str_opt = string option with_loc
type attrs = attribute list
let default_loc = ref Location . none
let with_default_loc l f = Misc . protect_refs [ Misc . R ( default_loc , l ) ] f
module Const = struct let integer ? suffix i = Pconst_integer ( i , suffix ) let int ? suffix i = integer ? suffix ( Int . to_string i ) let int32 ( ? suffix ' = l ' ) i = integer ~ suffix ( Int32 . to_string i ) let int64 ( ? suffix ' = L ' ) i = integer ~ suffix ( Int64 . to_string i ) let nativeint ( ? suffix ' = n ' ) i = integer ~ suffix ( Nativeint . to_string i ) let float ? suffix f = Pconst_float ( f , suffix ) let char c = Pconst_char c let string ? quotation_delimiter ( ? loc = ! default_loc ) s = Pconst_string ( s , loc , quotation_delimiter ) end
module Attr = struct let mk ( ? loc = ! default_loc ) name payload = { attr_name = name ; attr_payload = payload ; attr_loc = loc } end
module Typ = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) d = { ptyp_desc = d ; ptyp_loc = loc ; ptyp_loc_stack = [ ] ; ptyp_attributes = attrs } let attr d a = { d with ptyp_attributes = d . ptyp_attributes @ [ a ] } let any ? loc ? attrs ( ) = mk ? loc ? attrs Ptyp_any let var ? loc ? attrs a = mk ? loc ? attrs ( Ptyp_var a ) let arrow ? loc ? attrs a b c = mk ? loc ? attrs ( Ptyp_arrow ( a , b , c ) ) let tuple ? loc ? attrs a = mk ? loc ? attrs ( Ptyp_tuple a ) let constr ? loc ? attrs a b = mk ? loc ? attrs ( Ptyp_constr ( a , b ) ) let object_ ? loc ? attrs a b = mk ? loc ? attrs ( Ptyp_object ( a , b ) ) let class_ ? loc ? attrs a b = mk ? loc ? attrs ( Ptyp_class ( a , b ) ) let alias ? loc ? attrs a b = mk ? loc ? attrs ( Ptyp_alias ( a , b ) ) let variant ? loc ? attrs a b c = mk ? loc ? attrs ( Ptyp_variant ( a , b , c ) ) let poly ? loc ? attrs a b = mk ? loc ? attrs ( Ptyp_poly ( a , b ) ) let package ? loc ? attrs a b = mk ? loc ? attrs ( Ptyp_package ( a , b ) ) let extension ? loc ? attrs a = mk ? loc ? attrs ( Ptyp_extension a ) let force_poly t = match t . ptyp_desc with | Ptyp_poly _ -> t | _ -> poly ~ loc : t . ptyp_loc [ ] t let varify_constructors var_names t = let check_variable vl loc v = if List . mem v vl then raise Syntaxerr . ( Error ( Variable_in_scope ( loc , v ) ) ) in let var_names = List . map ( fun v -> v . txt ) var_names in let rec loop t = let desc = match t . ptyp_desc with | Ptyp_any -> Ptyp_any | Ptyp_var x -> check_variable var_names t . ptyp_loc x ; Ptyp_var x | Ptyp_arrow ( label , core_type , core_type ' ) -> Ptyp_arrow ( label , loop core_type , loop core_type ' ) | Ptyp_tuple lst -> Ptyp_tuple ( List . map loop lst ) | Ptyp_constr ( { txt = Longident . Lident s } , [ ] ) when List . mem s var_names -> Ptyp_var s | Ptyp_constr ( longident , lst ) -> Ptyp_constr ( longident , List . map loop lst ) | Ptyp_object ( lst , o ) -> Ptyp_object ( List . map loop_object_field lst , o ) | Ptyp_class ( longident , lst ) -> Ptyp_class ( longident , List . map loop lst ) | Ptyp_alias ( core_type , string ) -> check_variable var_names t . ptyp_loc string ; Ptyp_alias ( loop core_type , string ) | Ptyp_variant ( row_field_list , flag , lbl_lst_option ) -> Ptyp_variant ( List . map loop_row_field row_field_list , flag , lbl_lst_option ) | Ptyp_poly ( string_lst , core_type ) -> List . iter ( fun v -> check_variable var_names t . ptyp_loc v . txt ) string_lst ; Ptyp_poly ( string_lst , loop core_type ) | Ptyp_package ( longident , lst ) -> Ptyp_package ( longident , List . map ( fun ( n , typ ) -> ( n , loop typ ) ) lst ) | Ptyp_extension ( s , arg ) -> Ptyp_extension ( s , arg ) in { t with ptyp_desc = desc } and loop_row_field field = let prf_desc = match field . prf_desc with | Rtag ( label , flag , lst ) -> Rtag ( label , flag , List . map loop lst ) | Rinherit t -> Rinherit ( loop t ) in { field with prf_desc ; } and loop_object_field field = let pof_desc = match field . pof_desc with | Otag ( label , t ) -> Otag ( label , loop t ) | Oinherit t -> Oinherit ( loop t ) in { field with pof_desc ; } in loop t end
module Pat = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) d = { ppat_desc = d ; ppat_loc = loc ; ppat_loc_stack = [ ] ; ppat_attributes = attrs } let attr d a = { d with ppat_attributes = d . ppat_attributes @ [ a ] } let any ? loc ? attrs ( ) = mk ? loc ? attrs Ppat_any let var ? loc ? attrs a = mk ? loc ? attrs ( Ppat_var a ) let alias ? loc ? attrs a b = mk ? loc ? attrs ( Ppat_alias ( a , b ) ) let constant ? loc ? attrs a = mk ? loc ? attrs ( Ppat_constant a ) let interval ? loc ? attrs a b = mk ? loc ? attrs ( Ppat_interval ( a , b ) ) let tuple ? loc ? attrs a = mk ? loc ? attrs ( Ppat_tuple a ) let construct ? loc ? attrs a b = mk ? loc ? attrs ( Ppat_construct ( a , b ) ) let variant ? loc ? attrs a b = mk ? loc ? attrs ( Ppat_variant ( a , b ) ) let record ? loc ? attrs a b = mk ? loc ? attrs ( Ppat_record ( a , b ) ) let array ? loc ? attrs a = mk ? loc ? attrs ( Ppat_array a ) let or_ ? loc ? attrs a b = mk ? loc ? attrs ( Ppat_or ( a , b ) ) let constraint_ ? loc ? attrs a b = mk ? loc ? attrs ( Ppat_constraint ( a , b ) ) let type_ ? loc ? attrs a = mk ? loc ? attrs ( Ppat_type a ) let lazy_ ? loc ? attrs a = mk ? loc ? attrs ( Ppat_lazy a ) let unpack ? loc ? attrs a = mk ? loc ? attrs ( Ppat_unpack a ) let open_ ? loc ? attrs a b = mk ? loc ? attrs ( Ppat_open ( a , b ) ) let exception_ ? loc ? attrs a = mk ? loc ? attrs ( Ppat_exception a ) let extension ? loc ? attrs a = mk ? loc ? attrs ( Ppat_extension a ) end
module Exp = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) d = { pexp_desc = d ; pexp_loc = loc ; pexp_loc_stack = [ ] ; pexp_attributes = attrs } let attr d a = { d with pexp_attributes = d . pexp_attributes @ [ a ] } let ident ? loc ? attrs a = mk ? loc ? attrs ( Pexp_ident a ) let constant ? loc ? attrs a = mk ? loc ? attrs ( Pexp_constant a ) let let_ ? loc ? attrs a b c = mk ? loc ? attrs ( Pexp_let ( a , b , c ) ) let fun_ ? loc ? attrs a b c d = mk ? loc ? attrs ( Pexp_fun ( a , b , c , d ) ) let function_ ? loc ? attrs a = mk ? loc ? attrs ( Pexp_function a ) let apply ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_apply ( a , b ) ) let match_ ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_match ( a , b ) ) let try_ ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_try ( a , b ) ) let tuple ? loc ? attrs a = mk ? loc ? attrs ( Pexp_tuple a ) let construct ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_construct ( a , b ) ) let variant ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_variant ( a , b ) ) let record ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_record ( a , b ) ) let field ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_field ( a , b ) ) let setfield ? loc ? attrs a b c = mk ? loc ? attrs ( Pexp_setfield ( a , b , c ) ) let array ? loc ? attrs a = mk ? loc ? attrs ( Pexp_array a ) let ifthenelse ? loc ? attrs a b c = mk ? loc ? attrs ( Pexp_ifthenelse ( a , b , c ) ) let sequence ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_sequence ( a , b ) ) let while_ ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_while ( a , b ) ) let for_ ? loc ? attrs a b c d e = mk ? loc ? attrs ( Pexp_for ( a , b , c , d , e ) ) let constraint_ ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_constraint ( a , b ) ) let coerce ? loc ? attrs a b c = mk ? loc ? attrs ( Pexp_coerce ( a , b , c ) ) let send ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_send ( a , b ) ) let new_ ? loc ? attrs a = mk ? loc ? attrs ( Pexp_new a ) let setinstvar ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_setinstvar ( a , b ) ) let override ? loc ? attrs a = mk ? loc ? attrs ( Pexp_override a ) let letmodule ? loc ? attrs a b c = mk ? loc ? attrs ( Pexp_letmodule ( a , b , c ) ) let letexception ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_letexception ( a , b ) ) let assert_ ? loc ? attrs a = mk ? loc ? attrs ( Pexp_assert a ) let lazy_ ? loc ? attrs a = mk ? loc ? attrs ( Pexp_lazy a ) let poly ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_poly ( a , b ) ) let object_ ? loc ? attrs a = mk ? loc ? attrs ( Pexp_object a ) let newtype ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_newtype ( a , b ) ) let pack ? loc ? attrs a = mk ? loc ? attrs ( Pexp_pack a ) let open_ ? loc ? attrs a b = mk ? loc ? attrs ( Pexp_open ( a , b ) ) let letop ? loc ? attrs let_ ands body = mk ? loc ? attrs ( Pexp_letop { let_ ; ands ; body } ) let extension ? loc ? attrs a = mk ? loc ? attrs ( Pexp_extension a ) let unreachable ? loc ? attrs ( ) = mk ? loc ? attrs Pexp_unreachable let case lhs ? guard rhs = { pc_lhs = lhs ; pc_guard = guard ; pc_rhs = rhs ; } let binding_op op pat exp loc = { pbop_op = op ; pbop_pat = pat ; pbop_exp = exp ; pbop_loc = loc ; } end
module Mty = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) d = { pmty_desc = d ; pmty_loc = loc ; pmty_attributes = attrs } let attr d a = { d with pmty_attributes = d . pmty_attributes @ [ a ] } let ident ? loc ? attrs a = mk ? loc ? attrs ( Pmty_ident a ) let alias ? loc ? attrs a = mk ? loc ? attrs ( Pmty_alias a ) let signature ? loc ? attrs a = mk ? loc ? attrs ( Pmty_signature a ) let functor_ ? loc ? attrs a b = mk ? loc ? attrs ( Pmty_functor ( a , b ) ) let with_ ? loc ? attrs a b = mk ? loc ? attrs ( Pmty_with ( a , b ) ) let typeof_ ? loc ? attrs a = mk ? loc ? attrs ( Pmty_typeof a ) let extension ? loc ? attrs a = mk ? loc ? attrs ( Pmty_extension a ) end
let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) d = { pmod_desc = d ; pmod_loc = loc ; pmod_attributes = attrs } let attr d a = { d with pmod_attributes = d . pmod_attributes @ [ a ] } let ident ? loc ? attrs x = mk ? loc ? attrs ( Pmod_ident x ) let structure ? loc ? attrs x = mk ? loc ? attrs ( Pmod_structure x ) let functor_ ? loc ? attrs arg body = mk ? loc ? attrs ( Pmod_functor ( arg , body ) ) let apply ? loc ? attrs m1 m2 = mk ? loc ? attrs ( Pmod_apply ( m1 , m2 ) ) let constraint_ ? loc ? attrs m mty = mk ? loc ? attrs ( Pmod_constraint ( m , mty ) ) let unpack ? loc ? attrs e = mk ? loc ? attrs ( Pmod_unpack e ) let extension ? loc ? attrs a = mk ? loc ? attrs ( Pmod_extension a ) end
module Sig = struct let mk ( ? loc = ! default_loc ) d = { psig_desc = d ; psig_loc = loc } let value ? loc a = mk ? loc ( Psig_value a ) let type_ ? loc rec_flag a = mk ? loc ( Psig_type ( rec_flag , a ) ) let type_subst ? loc a = mk ? loc ( Psig_typesubst a ) let type_extension ? loc a = mk ? loc ( Psig_typext a ) let exception_ ? loc a = mk ? loc ( Psig_exception a ) let module_ ? loc a = mk ? loc ( Psig_module a ) let mod_subst ? loc a = mk ? loc ( Psig_modsubst a ) let rec_module ? loc a = mk ? loc ( Psig_recmodule a ) let modtype ? loc a = mk ? loc ( Psig_modtype a ) let open_ ? loc a = mk ? loc ( Psig_open a ) let include_ ? loc a = mk ? loc ( Psig_include a ) let class_ ? loc a = mk ? loc ( Psig_class a ) let class_type ? loc a = mk ? loc ( Psig_class_type a ) let extension ? loc ( ? attrs = [ ] ) a = mk ? loc ( Psig_extension ( a , attrs ) ) let attribute ? loc a = mk ? loc ( Psig_attribute a ) let text txt = let f_txt = List . filter ( fun ds -> docstring_body ds <> " " ) txt in List . map ( fun ds -> attribute ~ loc ( : docstring_loc ds ) ( text_attr ds ) ) f_txt end
module Str = struct let mk ( ? loc = ! default_loc ) d = { pstr_desc = d ; pstr_loc = loc } let eval ? loc ( ? attrs = [ ] ) a = mk ? loc ( Pstr_eval ( a , attrs ) ) let value ? loc a b = mk ? loc ( Pstr_value ( a , b ) ) let primitive ? loc a = mk ? loc ( Pstr_primitive a ) let type_ ? loc rec_flag a = mk ? loc ( Pstr_type ( rec_flag , a ) ) let type_extension ? loc a = mk ? loc ( Pstr_typext a ) let exception_ ? loc a = mk ? loc ( Pstr_exception a ) let module_ ? loc a = mk ? loc ( Pstr_module a ) let rec_module ? loc a = mk ? loc ( Pstr_recmodule a ) let modtype ? loc a = mk ? loc ( Pstr_modtype a ) let open_ ? loc a = mk ? loc ( Pstr_open a ) let class_ ? loc a = mk ? loc ( Pstr_class a ) let class_type ? loc a = mk ? loc ( Pstr_class_type a ) let include_ ? loc a = mk ? loc ( Pstr_include a ) let extension ? loc ( ? attrs = [ ] ) a = mk ? loc ( Pstr_extension ( a , attrs ) ) let attribute ? loc a = mk ? loc ( Pstr_attribute a ) let text txt = let f_txt = List . filter ( fun ds -> docstring_body ds <> " " ) txt in List . map ( fun ds -> attribute ~ loc ( : docstring_loc ds ) ( text_attr ds ) ) f_txt end
module Cl = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) d = { pcl_desc = d ; pcl_loc = loc ; pcl_attributes = attrs ; } let attr d a = { d with pcl_attributes = d . pcl_attributes @ [ a ] } let constr ? loc ? attrs a b = mk ? loc ? attrs ( Pcl_constr ( a , b ) ) let structure ? loc ? attrs a = mk ? loc ? attrs ( Pcl_structure a ) let fun_ ? loc ? attrs a b c d = mk ? loc ? attrs ( Pcl_fun ( a , b , c , d ) ) let apply ? loc ? attrs a b = mk ? loc ? attrs ( Pcl_apply ( a , b ) ) let let_ ? loc ? attrs a b c = mk ? loc ? attrs ( Pcl_let ( a , b , c ) ) let constraint_ ? loc ? attrs a b = mk ? loc ? attrs ( Pcl_constraint ( a , b ) ) let extension ? loc ? attrs a = mk ? loc ? attrs ( Pcl_extension a ) let open_ ? loc ? attrs a b = mk ? loc ? attrs ( Pcl_open ( a , b ) ) end
module Cty = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) d = { pcty_desc = d ; pcty_loc = loc ; pcty_attributes = attrs ; } let attr d a = { d with pcty_attributes = d . pcty_attributes @ [ a ] } let constr ? loc ? attrs a b = mk ? loc ? attrs ( Pcty_constr ( a , b ) ) let signature ? loc ? attrs a = mk ? loc ? attrs ( Pcty_signature a ) let arrow ? loc ? attrs a b c = mk ? loc ? attrs ( Pcty_arrow ( a , b , c ) ) let extension ? loc ? attrs a = mk ? loc ? attrs ( Pcty_extension a ) let open_ ? loc ? attrs a b = mk ? loc ? attrs ( Pcty_open ( a , b ) ) end
module Ctf = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) d = { pctf_desc = d ; pctf_loc = loc ; pctf_attributes = add_docs_attrs docs attrs ; } let inherit_ ? loc ? attrs a = mk ? loc ? attrs ( Pctf_inherit a ) let val_ ? loc ? attrs a b c d = mk ? loc ? attrs ( Pctf_val ( a , b , c , d ) ) let method_ ? loc ? attrs a b c d = mk ? loc ? attrs ( Pctf_method ( a , b , c , d ) ) let constraint_ ? loc ? attrs a b = mk ? loc ? attrs ( Pctf_constraint ( a , b ) ) let extension ? loc ? attrs a = mk ? loc ? attrs ( Pctf_extension a ) let attribute ? loc a = mk ? loc ( Pctf_attribute a ) let text txt = let f_txt = List . filter ( fun ds -> docstring_body ds <> " " ) txt in List . map ( fun ds -> attribute ~ loc ( : docstring_loc ds ) ( text_attr ds ) ) f_txt let attr d a = { d with pctf_attributes = d . pctf_attributes @ [ a ] } end
module Cf = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) d = { pcf_desc = d ; pcf_loc = loc ; pcf_attributes = add_docs_attrs docs attrs ; } let inherit_ ? loc ? attrs a b c = mk ? loc ? attrs ( Pcf_inherit ( a , b , c ) ) let val_ ? loc ? attrs a b c = mk ? loc ? attrs ( Pcf_val ( a , b , c ) ) let method_ ? loc ? attrs a b c = mk ? loc ? attrs ( Pcf_method ( a , b , c ) ) let constraint_ ? loc ? attrs a b = mk ? loc ? attrs ( Pcf_constraint ( a , b ) ) let initializer_ ? loc ? attrs a = mk ? loc ? attrs ( Pcf_initializer a ) let extension ? loc ? attrs a = mk ? loc ? attrs ( Pcf_extension a ) let attribute ? loc a = mk ? loc ( Pcf_attribute a ) let text txt = let f_txt = List . filter ( fun ds -> docstring_body ds <> " " ) txt in List . map ( fun ds -> attribute ~ loc ( : docstring_loc ds ) ( text_attr ds ) ) f_txt let virtual_ ct = Cfk_virtual ct let concrete o e = Cfk_concrete ( o , e ) let attr d a = { d with pcf_attributes = d . pcf_attributes @ [ a ] } end
module Val = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? prim = [ ] ) name typ = { pval_name = name ; pval_type = typ ; pval_attributes = add_docs_attrs docs attrs ; pval_loc = loc ; pval_prim = prim ; } end
module Md = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? text = [ ] ) name typ = { pmd_name = name ; pmd_type = typ ; pmd_attributes = add_text_attrs text ( add_docs_attrs docs attrs ) ; pmd_loc = loc ; } end
module Ms = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? text = [ ] ) name syn = { pms_name = name ; pms_manifest = syn ; pms_attributes = add_text_attrs text ( add_docs_attrs docs attrs ) ; pms_loc = loc ; } end
module Mtd = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? text = [ ] ) ? typ name = { pmtd_name = name ; pmtd_type = typ ; pmtd_attributes = add_text_attrs text ( add_docs_attrs docs attrs ) ; pmtd_loc = loc ; } end
module Mb = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? text = [ ] ) name expr = { pmb_name = name ; pmb_expr = expr ; pmb_attributes = add_text_attrs text ( add_docs_attrs docs attrs ) ; pmb_loc = loc ; } end
module Opn = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? override = Fresh ) expr = { popen_expr = expr ; popen_override = override ; popen_loc = loc ; popen_attributes = add_docs_attrs docs attrs ; } end
module Incl = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) mexpr = { pincl_mod = mexpr ; pincl_loc = loc ; pincl_attributes = add_docs_attrs docs attrs ; } end
module Vb = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? text = [ ] ) pat expr = { pvb_pat = pat ; pvb_expr = expr ; pvb_attributes = add_text_attrs text ( add_docs_attrs docs attrs ) ; pvb_loc = loc ; } end
module Ci = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? text = [ ] ) ( ? virt = Concrete ) ( ? params = [ ] ) name expr = { pci_virt = virt ; pci_params = params ; pci_name = name ; pci_expr = expr ; pci_attributes = add_text_attrs text ( add_docs_attrs docs attrs ) ; pci_loc = loc ; } end
module Type = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? text = [ ] ) ( ? params = [ ] ) ( ? cstrs = [ ] ) ( ? kind = Ptype_abstract ) ( ? priv = Public ) ? manifest name = { ptype_name = name ; ptype_params = params ; ptype_cstrs = cstrs ; ptype_kind = kind ; ptype_private = priv ; ptype_manifest = manifest ; ptype_attributes = add_text_attrs text ( add_docs_attrs docs attrs ) ; ptype_loc = loc ; } let constructor ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? info = empty_info ) ( ? args = Pcstr_tuple [ ] ) ? res name = { pcd_name = name ; pcd_args = args ; pcd_res = res ; pcd_loc = loc ; pcd_attributes = add_info_attrs info attrs ; } let field ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? info = empty_info ) ( ? mut = Immutable ) name typ = { pld_name = name ; pld_mutable = mut ; pld_type = typ ; pld_loc = loc ; pld_attributes = add_info_attrs info attrs ; } end
module Te = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? params = [ ] ) ( ? priv = Public ) path constructors = { ptyext_path = path ; ptyext_params = params ; ptyext_constructors = constructors ; ptyext_private = priv ; ptyext_loc = loc ; ptyext_attributes = add_docs_attrs docs attrs ; } let mk_exception ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) constructor = { ptyexn_constructor = constructor ; ptyexn_loc = loc ; ptyexn_attributes = add_docs_attrs docs attrs ; } let constructor ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? info = empty_info ) name kind = { pext_name = name ; pext_kind = kind ; pext_loc = loc ; pext_attributes = add_docs_attrs docs ( add_info_attrs info attrs ) ; } let decl ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? info = empty_info ) ( ? args = Pcstr_tuple [ ] ) ? res name = { pext_name = name ; pext_kind = Pext_decl ( args , res ) ; pext_loc = loc ; pext_attributes = add_docs_attrs docs ( add_info_attrs info attrs ) ; } let rebind ( ? loc = ! default_loc ) ( ? attrs = [ ] ) ( ? docs = empty_docs ) ( ? info = empty_info ) name lid = { pext_name = name ; pext_kind = Pext_rebind lid ; pext_loc = loc ; pext_attributes = add_docs_attrs docs ( add_info_attrs info attrs ) ; } end
module Csig = struct let mk self fields = { pcsig_self = self ; pcsig_fields = fields ; } end
module Cstr = struct let mk self fields = { pcstr_self = self ; pcstr_fields = fields ; } end
module Rf = struct let mk ( ? loc = ! default_loc ) ( ? attrs = [ ] ) desc = { prf_desc = desc ; prf_loc = loc ; prf_attributes = attrs ; } let tag ? loc ? attrs label const tys = mk ? loc ? attrs ( Rtag ( label , const , tys ) ) let inherit_ ? loc ty = mk ? loc ( Rinherit ty ) end
module Of = struct let mk ( ? loc = ! default_loc ) ( ? attrs [ ] ) = desc = { pof_desc = desc ; pof_loc = loc ; pof_attributes = attrs ; } let tag ? loc ? attrs label ty = mk ? loc ? attrs ( Otag ( label , ty ) ) let inherit_ ? loc ty = mk ? loc ( Oinherit ty ) end
let empty_record loc = err loc " Records cannot be empty . "
let invalid_tuple loc = err loc " Tuples must have at least 2 components . "
let no_args loc = err loc " Function application with no argument . "
let empty_let loc = err loc " Let with no bindings . "
let empty_type loc = err loc " Type declarations cannot be empty . "
let complex_id loc = err loc " Functor application not allowed here . "
let simple_longident id = let rec is_simple = function | Longident . Lident _ -> true | Longident . Ldot ( id , _ ) -> is_simple id | Longident . Lapply _ -> false in if not ( is_simple id . txt ) then complex_id id . loc
let iterator = let super = Ast_iterator . default_iterator in let type_declaration self td = super . type_declaration self td ; let loc = td . ptype_loc in match td . ptype_kind with | Ptype_record [ ] -> empty_record loc | _ -> ( ) in let typ self ty = super . typ self ty ; let loc = ty . ptyp_loc in match ty . ptyp_desc with | Ptyp_tuple ( [ ] | [ _ ] ) -> invalid_tuple loc | Ptyp_package ( _ , cstrs ) -> List . iter ( fun ( id , _ ) -> simple_longident id ) cstrs | _ -> ( ) in let pat self pat = begin match pat . ppat_desc with | Ppat_construct ( _ , Some ( { ppat_desc = Ppat_tuple _ } as p ) ) when Builtin_attributes . explicit_arity pat . ppat_attributes -> super . pat self p | _ -> super . pat self pat end ; let loc = pat . ppat_loc in match pat . ppat_desc with | Ppat_tuple ( [ ] | [ _ ] ) -> invalid_tuple loc | Ppat_record ( [ ] , _ ) -> empty_record loc | Ppat_construct ( id , _ ) -> simple_longident id | Ppat_record ( fields , _ ) -> List . iter ( fun ( id , _ ) -> simple_longident id ) fields | _ -> ( ) in let expr self exp = begin match exp . pexp_desc with | Pexp_construct ( _ , Some ( { pexp_desc = Pexp_tuple _ } as e ) ) when Builtin_attributes . explicit_arity exp . pexp_attributes -> super . expr self e | _ -> super . expr self exp end ; let loc = exp . pexp_loc in match exp . pexp_desc with | Pexp_tuple ( [ ] | [ _ ] ) -> invalid_tuple loc | Pexp_record ( [ ] , _ ) -> empty_record loc | Pexp_apply ( _ , [ ] ) -> no_args loc | Pexp_let ( _ , [ ] , _ ) -> empty_let loc | Pexp_ident id | Pexp_construct ( id , _ ) | Pexp_field ( _ , id ) | Pexp_setfield ( _ , id , _ ) | Pexp_new id -> simple_longident id | Pexp_record ( fields , _ ) -> List . iter ( fun ( id , _ ) -> simple_longident id ) fields | _ -> ( ) in let extension_constructor self ec = super . extension_constructor self ec ; match ec . pext_kind with | Pext_rebind id -> simple_longident id | _ -> ( ) in let class_expr self ce = super . class_expr self ce ; let loc = ce . pcl_loc in match ce . pcl_desc with | Pcl_apply ( _ , [ ] ) -> no_args loc | Pcl_constr ( id , _ ) -> simple_longident id | _ -> ( ) in let module_type self mty = super . module_type self mty ; match mty . pmty_desc with | Pmty_alias id -> simple_longident id | _ -> ( ) in let open_description self opn = super . open_description self opn in let with_constraint self wc = super . with_constraint self wc ; match wc with | Pwith_type ( id , _ ) | Pwith_module ( id , _ ) -> simple_longident id | _ -> ( ) in let module_expr self me = super . module_expr self me ; match me . pmod_desc with | Pmod_ident id -> simple_longident id | _ -> ( ) in let structure_item self st = super . structure_item self st ; let loc = st . pstr_loc in match st . pstr_desc with | Pstr_type ( _ , [ ] ) -> empty_type loc | Pstr_value ( _ , [ ] ) -> empty_let loc | _ -> ( ) in let signature_item self sg = super . signature_item self sg ; let loc = sg . psig_loc in match sg . psig_desc with | Psig_type ( _ , [ ] ) -> empty_type loc | _ -> ( ) in let row_field self field = super . row_field self field ; let loc = field . prf_loc in match field . prf_desc with | Rtag _ -> ( ) | Rinherit _ -> if field . prf_attributes = [ ] then ( ) else err loc " In variant types , attaching attributes to inherited \ subtypes is not allowed . " in let object_field self field = super . object_field self field ; let loc = field . pof_loc in match field . pof_desc with | Otag _ -> ( ) | Oinherit _ -> if field . pof_attributes = [ ] then ( ) else err loc " In object types , attaching attributes to inherited \ subtypes is not allowed . " in { super with type_declaration ; typ ; pat ; expr ; extension_constructor ; class_expr ; module_expr ; module_type ; open_description ; with_constraint ; structure_item ; signature_item ; row_field ; object_field }
let structure st = iterator . structure iterator st
let signature sg = iterator . signature iterator sg
type iterator = { attribute : iterator -> attribute -> unit ; attributes : iterator -> attribute list -> unit ; binding_op : iterator -> binding_op -> unit ; case : iterator -> case -> unit ; cases : iterator -> case list -> unit ; class_declaration : iterator -> class_declaration -> unit ; class_description : iterator -> class_description -> unit ; class_expr : iterator -> class_expr -> unit ; class_field : iterator -> class_field -> unit ; class_signature : iterator -> class_signature -> unit ; class_structure : iterator -> class_structure -> unit ; class_type : iterator -> class_type -> unit ; class_type_declaration : iterator -> class_type_declaration -> unit ; class_type_field : iterator -> class_type_field -> unit ; constructor_declaration : iterator -> constructor_declaration -> unit ; expr : iterator -> expression -> unit ; extension : iterator -> extension -> unit ; extension_constructor : iterator -> extension_constructor -> unit ; include_declaration : iterator -> include_declaration -> unit ; include_description : iterator -> include_description -> unit ; label_declaration : iterator -> label_declaration -> unit ; location : iterator -> Location . t -> unit ; module_binding : iterator -> module_binding -> unit ; module_declaration : iterator -> module_declaration -> unit ; module_substitution : iterator -> module_substitution -> unit ; module_expr : iterator -> module_expr -> unit ; module_type : iterator -> module_type -> unit ; module_type_declaration : iterator -> module_type_declaration -> unit ; open_declaration : iterator -> open_declaration -> unit ; open_description : iterator -> open_description -> unit ; pat : iterator -> pattern -> unit ; payload : iterator -> payload -> unit ; signature : iterator -> signature -> unit ; signature_item : iterator -> signature_item -> unit ; structure : iterator -> structure -> unit ; structure_item : iterator -> structure_item -> unit ; typ : iterator -> core_type -> unit ; row_field : iterator -> row_field -> unit ; object_field : iterator -> object_field -> unit ; type_declaration : iterator -> type_declaration -> unit ; type_extension : iterator -> type_extension -> unit ; type_exception : iterator -> type_exception -> unit ; type_kind : iterator -> type_kind -> unit ; value_binding : iterator -> value_binding -> unit ; value_description : iterator -> value_description -> unit ; with_constraint : iterator -> with_constraint -> unit ; }
let iter_fst f ( x , _ ) = f x
let iter_snd f ( _ , y ) = f y
let iter_tuple f1 f2 ( x , y ) = f1 x ; f2 y
let iter_tuple3 f1 f2 f3 ( x , y , z ) = f1 x ; f2 y ; f3 z
let iter_opt f = function None -> ( ) | Some x -> f x
let iter_loc sub { loc ; txt = _ } = sub . location sub loc
module T = struct let row_field sub { prf_desc ; prf_loc ; prf_attributes ; } = sub . location sub prf_loc ; sub . attributes sub prf_attributes ; match prf_desc with | Rtag ( _ , _ , tl ) -> List . iter ( sub . typ sub ) tl | Rinherit t -> sub . typ sub t let object_field sub { pof_desc ; pof_loc ; pof_attributes ; } = sub . location sub pof_loc ; sub . attributes sub pof_attributes ; match pof_desc with | Otag ( _ , t ) -> sub . typ sub t | Oinherit t -> sub . typ sub t let iter sub { ptyp_desc = desc ; ptyp_loc = loc ; ptyp_attributes = attrs } = sub . location sub loc ; sub . attributes sub attrs ; match desc with | Ptyp_any | Ptyp_var _ -> ( ) | Ptyp_arrow ( _lab , t1 , t2 ) -> sub . typ sub t1 ; sub . typ sub t2 | Ptyp_tuple tyl -> List . iter ( sub . typ sub ) tyl | Ptyp_constr ( lid , tl ) -> iter_loc sub lid ; List . iter ( sub . typ sub ) tl | Ptyp_object ( ol , _o ) -> List . iter ( object_field sub ) ol | Ptyp_class ( lid , tl ) -> iter_loc sub lid ; List . iter ( sub . typ sub ) tl | Ptyp_alias ( t , _ ) -> sub . typ sub t | Ptyp_variant ( rl , _b , _ll ) -> List . iter ( row_field sub ) rl | Ptyp_poly ( _ , t ) -> sub . typ sub t | Ptyp_package ( lid , l ) -> iter_loc sub lid ; List . iter ( iter_tuple ( iter_loc sub ) ( sub . typ sub ) ) l | Ptyp_extension x -> sub . extension sub x let iter_type_declaration sub { ptype_name ; ptype_params ; ptype_cstrs ; ptype_kind ; ptype_private = _ ; ptype_manifest ; ptype_attributes ; ptype_loc } = iter_loc sub ptype_name ; List . iter ( iter_fst ( sub . typ sub ) ) ptype_params ; List . iter ( iter_tuple3 ( sub . typ sub ) ( sub . typ sub ) ( sub . location sub ) ) ptype_cstrs ; sub . type_kind sub ptype_kind ; iter_opt ( sub . typ sub ) ptype_manifest ; sub . location sub ptype_loc ; sub . attributes sub ptype_attributes let iter_type_kind sub = function | Ptype_abstract -> ( ) | Ptype_variant l -> List . iter ( sub . constructor_declaration sub ) l | Ptype_record l -> List . iter ( sub . label_declaration sub ) l | Ptype_open -> ( ) let iter_constructor_arguments sub = function | Pcstr_tuple l -> List . iter ( sub . typ sub ) l | Pcstr_record l -> List . iter ( sub . label_declaration sub ) l let iter_type_extension sub { ptyext_path ; ptyext_params ; ptyext_constructors ; ptyext_private = _ ; ptyext_loc ; ptyext_attributes } = iter_loc sub ptyext_path ; List . iter ( sub . extension_constructor sub ) ptyext_constructors ; List . iter ( iter_fst ( sub . typ sub ) ) ptyext_params ; sub . location sub ptyext_loc ; sub . attributes sub ptyext_attributes let iter_type_exception sub { ptyexn_constructor ; ptyexn_loc ; ptyexn_attributes } = sub . extension_constructor sub ptyexn_constructor ; sub . location sub ptyexn_loc ; sub . attributes sub ptyexn_attributes let iter_extension_constructor_kind sub = function Pext_decl ( ctl , cto ) -> iter_constructor_arguments sub ctl ; iter_opt ( sub . typ sub ) cto | Pext_rebind li -> iter_loc sub li let iter_extension_constructor sub { pext_name ; pext_kind ; pext_loc ; pext_attributes } = iter_loc sub pext_name ; iter_extension_constructor_kind sub pext_kind ; sub . location sub pext_loc ; sub . attributes sub pext_attributes end
module CT = struct let iter sub { pcty_loc = loc ; pcty_desc = desc ; pcty_attributes = attrs } = sub . location sub loc ; sub . attributes sub attrs ; match desc with | Pcty_constr ( lid , tys ) -> iter_loc sub lid ; List . iter ( sub . typ sub ) tys | Pcty_signature x -> sub . class_signature sub x | Pcty_arrow ( _lab , t , ct ) -> sub . typ sub t ; sub . class_type sub ct | Pcty_extension x -> sub . extension sub x | Pcty_open ( o , e ) -> sub . open_description sub o ; sub . class_type sub e let iter_field sub { pctf_desc = desc ; pctf_loc = loc ; pctf_attributes = attrs } = sub . location sub loc ; sub . attributes sub attrs ; match desc with | Pctf_inherit ct -> sub . class_type sub ct | Pctf_val ( _s , _m , _v , t ) -> sub . typ sub t | Pctf_method ( _s , _p , _v , t ) -> sub . typ sub t | Pctf_constraint ( t1 , t2 ) -> sub . typ sub t1 ; sub . typ sub t2 | Pctf_attribute x -> sub . attribute sub x | Pctf_extension x -> sub . extension sub x let iter_signature sub { pcsig_self ; pcsig_fields } = sub . typ sub pcsig_self ; List . iter ( sub . class_type_field sub ) pcsig_fields end
let iter_functor_param sub = function | Unit -> ( ) | Named ( name , mty ) -> iter_loc sub name ; sub . module_type sub mty
module MT = struct let iter sub { pmty_desc = desc ; pmty_loc = loc ; pmty_attributes = attrs } = sub . location sub loc ; sub . attributes sub attrs ; match desc with | Pmty_ident s -> iter_loc sub s | Pmty_alias s -> iter_loc sub s | Pmty_signature sg -> sub . signature sub sg | Pmty_functor ( param , mt2 ) -> iter_functor_param sub param ; sub . module_type sub mt2 | Pmty_with ( mt , l ) -> sub . module_type sub mt ; List . iter ( sub . with_constraint sub ) l | Pmty_typeof me -> sub . module_expr sub me | Pmty_extension x -> sub . extension sub x let iter_with_constraint sub = function | Pwith_type ( lid , d ) -> iter_loc sub lid ; sub . type_declaration sub d | Pwith_module ( lid , lid2 ) -> iter_loc sub lid ; iter_loc sub lid2 | Pwith_typesubst ( lid , d ) -> iter_loc sub lid ; sub . type_declaration sub d | Pwith_modsubst ( s , lid ) -> iter_loc sub s ; iter_loc sub lid let iter_signature_item sub { psig_desc = desc ; psig_loc = loc } = sub . location sub loc ; match desc with | Psig_value vd -> sub . value_description sub vd | Psig_type ( _ , l ) | Psig_typesubst l -> List . iter ( sub . type_declaration sub ) l | Psig_typext te -> sub . type_extension sub te | Psig_exception ed -> sub . type_exception sub ed | Psig_module x -> sub . module_declaration sub x | Psig_modsubst x -> sub . module_substitution sub x | Psig_recmodule l -> List . iter ( sub . module_declaration sub ) l | Psig_modtype x -> sub . module_type_declaration sub x | Psig_open x -> sub . open_description sub x | Psig_include x -> sub . include_description sub x | Psig_class l -> List . iter ( sub . class_description sub ) l | Psig_class_type l -> List . iter ( sub . class_type_declaration sub ) l | Psig_extension ( x , attrs ) -> sub . attributes sub attrs ; sub . extension sub x | Psig_attribute x -> sub . attribute sub x end
module M = struct let iter sub { pmod_loc = loc ; pmod_desc = desc ; pmod_attributes = attrs } = sub . location sub loc ; sub . attributes sub attrs ; match desc with | Pmod_ident x -> iter_loc sub x | Pmod_structure str -> sub . structure sub str | Pmod_functor ( param , body ) -> iter_functor_param sub param ; sub . module_expr sub body | Pmod_apply ( m1 , m2 ) -> sub . module_expr sub m1 ; sub . module_expr sub m2 | Pmod_constraint ( m , mty ) -> sub . module_expr sub m ; sub . module_type sub mty | Pmod_unpack e -> sub . expr sub e | Pmod_extension x -> sub . extension sub x let iter_structure_item sub { pstr_loc = loc ; pstr_desc = desc } = sub . location sub loc ; match desc with | Pstr_eval ( x , attrs ) -> sub . attributes sub attrs ; sub . expr sub x | Pstr_value ( _r , vbs ) -> List . iter ( sub . value_binding sub ) vbs | Pstr_primitive vd -> sub . value_description sub vd | Pstr_type ( _rf , l ) -> List . iter ( sub . type_declaration sub ) l | Pstr_typext te -> sub . type_extension sub te | Pstr_exception ed -> sub . type_exception sub ed | Pstr_module x -> sub . module_binding sub x | Pstr_recmodule l -> List . iter ( sub . module_binding sub ) l | Pstr_modtype x -> sub . module_type_declaration sub x | Pstr_open x -> sub . open_declaration sub x | Pstr_class l -> List . iter ( sub . class_declaration sub ) l | Pstr_class_type l -> List . iter ( sub . class_type_declaration sub ) l | Pstr_include x -> sub . include_declaration sub x | Pstr_extension ( x , attrs ) -> sub . attributes sub attrs ; sub . extension sub x | Pstr_attribute x -> sub . attribute sub x end
module E = struct let iter sub { pexp_loc = loc ; pexp_desc = desc ; pexp_attributes = attrs } = sub . location sub loc ; sub . attributes sub attrs ; match desc with | Pexp_ident x -> iter_loc sub x | Pexp_constant _ -> ( ) | Pexp_let ( _r , vbs , e ) -> List . iter ( sub . value_binding sub ) vbs ; sub . expr sub e | Pexp_fun ( _lab , def , p , e ) -> iter_opt ( sub . expr sub ) def ; sub . pat sub p ; sub . expr sub e | Pexp_function pel -> sub . cases sub pel | Pexp_apply ( e , l ) -> sub . expr sub e ; List . iter ( iter_snd ( sub . expr sub ) ) l | Pexp_match ( e , pel ) -> sub . expr sub e ; sub . cases sub pel | Pexp_try ( e , pel ) -> sub . expr sub e ; sub . cases sub pel | Pexp_tuple el -> List . iter ( sub . expr sub ) el | Pexp_construct ( lid , arg ) -> iter_loc sub lid ; iter_opt ( sub . expr sub ) arg | Pexp_variant ( _lab , eo ) -> iter_opt ( sub . expr sub ) eo | Pexp_record ( l , eo ) -> List . iter ( iter_tuple ( iter_loc sub ) ( sub . expr sub ) ) l ; iter_opt ( sub . expr sub ) eo | Pexp_field ( e , lid ) -> sub . expr sub e ; iter_loc sub lid | Pexp_setfield ( e1 , lid , e2 ) -> sub . expr sub e1 ; iter_loc sub lid ; sub . expr sub e2 | Pexp_array el -> List . iter ( sub . expr sub ) el | Pexp_ifthenelse ( e1 , e2 , e3 ) -> sub . expr sub e1 ; sub . expr sub e2 ; iter_opt ( sub . expr sub ) e3 | Pexp_sequence ( e1 , e2 ) -> sub . expr sub e1 ; sub . expr sub e2 | Pexp_while ( e1 , e2 ) -> sub . expr sub e1 ; sub . expr sub e2 | Pexp_for ( p , e1 , e2 , _d , e3 ) -> sub . pat sub p ; sub . expr sub e1 ; sub . expr sub e2 ; sub . expr sub e3 | Pexp_coerce ( e , t1 , t2 ) -> sub . expr sub e ; iter_opt ( sub . typ sub ) t1 ; sub . typ sub t2 | Pexp_constraint ( e , t ) -> sub . expr sub e ; sub . typ sub t | Pexp_send ( e , _s ) -> sub . expr sub e | Pexp_new lid -> iter_loc sub lid | Pexp_setinstvar ( s , e ) -> iter_loc sub s ; sub . expr sub e | Pexp_override sel -> List . iter ( iter_tuple ( iter_loc sub ) ( sub . expr sub ) ) sel | Pexp_letmodule ( s , me , e ) -> iter_loc sub s ; sub . module_expr sub me ; sub . expr sub e | Pexp_letexception ( cd , e ) -> sub . extension_constructor sub cd ; sub . expr sub e | Pexp_assert e -> sub . expr sub e | Pexp_lazy e -> sub . expr sub e | Pexp_poly ( e , t ) -> sub . expr sub e ; iter_opt ( sub . typ sub ) t | Pexp_object cls -> sub . class_structure sub cls | Pexp_newtype ( _s , e ) -> sub . expr sub e | Pexp_pack me -> sub . module_expr sub me | Pexp_open ( o , e ) -> sub . open_declaration sub o ; sub . expr sub e | Pexp_letop { let_ ; ands ; body } -> sub . binding_op sub let_ ; List . iter ( sub . binding_op sub ) ands ; sub . expr sub body | Pexp_extension x -> sub . extension sub x | Pexp_unreachable -> ( ) let iter_binding_op sub { pbop_op ; pbop_pat ; pbop_exp ; pbop_loc } = iter_loc sub pbop_op ; sub . pat sub pbop_pat ; sub . expr sub pbop_exp ; sub . location sub pbop_loc end
module P = struct let iter sub { ppat_desc = desc ; ppat_loc = loc ; ppat_attributes = attrs } = sub . location sub loc ; sub . attributes sub attrs ; match desc with | Ppat_any -> ( ) | Ppat_var s -> iter_loc sub s | Ppat_alias ( p , s ) -> sub . pat sub p ; iter_loc sub s | Ppat_constant _ -> ( ) | Ppat_interval _ -> ( ) | Ppat_tuple pl -> List . iter ( sub . pat sub ) pl | Ppat_construct ( l , p ) -> iter_loc sub l ; iter_opt ( sub . pat sub ) p | Ppat_variant ( _l , p ) -> iter_opt ( sub . pat sub ) p | Ppat_record ( lpl , _cf ) -> List . iter ( iter_tuple ( iter_loc sub ) ( sub . pat sub ) ) lpl | Ppat_array pl -> List . iter ( sub . pat sub ) pl | Ppat_or ( p1 , p2 ) -> sub . pat sub p1 ; sub . pat sub p2 | Ppat_constraint ( p , t ) -> sub . pat sub p ; sub . typ sub t | Ppat_type s -> iter_loc sub s | Ppat_lazy p -> sub . pat sub p | Ppat_unpack s -> iter_loc sub s | Ppat_exception p -> sub . pat sub p | Ppat_extension x -> sub . extension sub x | Ppat_open ( lid , p ) -> iter_loc sub lid ; sub . pat sub p end
module CE = struct let iter sub { pcl_loc = loc ; pcl_desc = desc ; pcl_attributes = attrs } = sub . location sub loc ; sub . attributes sub attrs ; match desc with | Pcl_constr ( lid , tys ) -> iter_loc sub lid ; List . iter ( sub . typ sub ) tys | Pcl_structure s -> sub . class_structure sub s | Pcl_fun ( _lab , e , p , ce ) -> iter_opt ( sub . expr sub ) e ; sub . pat sub p ; sub . class_expr sub ce | Pcl_apply ( ce , l ) -> sub . class_expr sub ce ; List . iter ( iter_snd ( sub . expr sub ) ) l | Pcl_let ( _r , vbs , ce ) -> List . iter ( sub . value_binding sub ) vbs ; sub . class_expr sub ce | Pcl_constraint ( ce , ct ) -> sub . class_expr sub ce ; sub . class_type sub ct | Pcl_extension x -> sub . extension sub x | Pcl_open ( o , e ) -> sub . open_description sub o ; sub . class_expr sub e let iter_kind sub = function | Cfk_concrete ( _o , e ) -> sub . expr sub e | Cfk_virtual t -> sub . typ sub t let iter_field sub { pcf_desc = desc ; pcf_loc = loc ; pcf_attributes = attrs } = sub . location sub loc ; sub . attributes sub attrs ; match desc with | Pcf_inherit ( _o , ce , _s ) -> sub . class_expr sub ce | Pcf_val ( s , _m , k ) -> iter_loc sub s ; iter_kind sub k | Pcf_method ( s , _p , k ) -> iter_loc sub s ; iter_kind sub k | Pcf_constraint ( t1 , t2 ) -> sub . typ sub t1 ; sub . typ sub t2 | Pcf_initializer e -> sub . expr sub e | Pcf_attribute x -> sub . attribute sub x | Pcf_extension x -> sub . extension sub x let iter_structure sub { pcstr_self ; pcstr_fields } = sub . pat sub pcstr_self ; List . iter ( sub . class_field sub ) pcstr_fields let class_infos sub f { pci_virt = _ ; pci_params = pl ; pci_name ; pci_expr ; pci_loc ; pci_attributes } = List . iter ( iter_fst ( sub . typ sub ) ) pl ; iter_loc sub pci_name ; f pci_expr ; sub . location sub pci_loc ; sub . attributes sub pci_attributes end
let default_iterator = { structure = ( fun this l -> List . iter ( this . structure_item this ) l ) ; structure_item = M . iter_structure_item ; module_expr = M . iter ; signature = ( fun this l -> List . iter ( this . signature_item this ) l ) ; signature_item = MT . iter_signature_item ; module_type = MT . iter ; with_constraint = MT . iter_with_constraint ; class_declaration = ( fun this -> CE . class_infos this ( this . class_expr this ) ) ; class_expr = CE . iter ; class_field = CE . iter_field ; class_structure = CE . iter_structure ; class_type = CT . iter ; class_type_field = CT . iter_field ; class_signature = CT . iter_signature ; class_type_declaration = ( fun this -> CE . class_infos this ( this . class_type this ) ) ; class_description = ( fun this -> CE . class_infos this ( this . class_type this ) ) ; type_declaration = T . iter_type_declaration ; type_kind = T . iter_type_kind ; typ = T . iter ; row_field = T . row_field ; object_field = T . object_field ; type_extension = T . iter_type_extension ; type_exception = T . iter_type_exception ; extension_constructor = T . iter_extension_constructor ; value_description = ( fun this { pval_name ; pval_type ; pval_prim = _ ; pval_loc ; pval_attributes } -> iter_loc this pval_name ; this . typ this pval_type ; this . location this pval_loc ; this . attributes this pval_attributes ; ) ; pat = P . iter ; expr = E . iter ; binding_op = E . iter_binding_op ; module_declaration = ( fun this { pmd_name ; pmd_type ; pmd_attributes ; pmd_loc } -> iter_loc this pmd_name ; this . module_type this pmd_type ; this . location this pmd_loc ; this . attributes this pmd_attributes ; ) ; module_substitution = ( fun this { pms_name ; pms_manifest ; pms_attributes ; pms_loc } -> iter_loc this pms_name ; iter_loc this pms_manifest ; this . location this pms_loc ; this . attributes this pms_attributes ; ) ; module_type_declaration = ( fun this { pmtd_name ; pmtd_type ; pmtd_attributes ; pmtd_loc } -> iter_loc this pmtd_name ; iter_opt ( this . module_type this ) pmtd_type ; this . location this pmtd_loc ; this . attributes this pmtd_attributes ; ) ; module_binding = ( fun this { pmb_name ; pmb_expr ; pmb_attributes ; pmb_loc } -> iter_loc this pmb_name ; this . module_expr this pmb_expr ; this . location this pmb_loc ; this . attributes this pmb_attributes ; ) ; open_declaration = ( fun this { popen_expr ; popen_override = _ ; popen_attributes ; popen_loc } -> this . module_expr this popen_expr ; this . location this popen_loc ; this . attributes this popen_attributes ) ; open_description = ( fun this { popen_expr ; popen_override = _ ; popen_attributes ; popen_loc } -> iter_loc this popen_expr ; this . location this popen_loc ; this . attributes this popen_attributes ) ; include_description = ( fun this { pincl_mod ; pincl_attributes ; pincl_loc } -> this . module_type this pincl_mod ; this . location this pincl_loc ; this . attributes this pincl_attributes ) ; include_declaration = ( fun this { pincl_mod ; pincl_attributes ; pincl_loc } -> this . module_expr this pincl_mod ; this . location this pincl_loc ; this . attributes this pincl_attributes ) ; value_binding = ( fun this { pvb_pat ; pvb_expr ; pvb_attributes ; pvb_loc } -> this . pat this pvb_pat ; this . expr this pvb_expr ; this . location this pvb_loc ; this . attributes this pvb_attributes ) ; constructor_declaration = ( fun this { pcd_name ; pcd_args ; pcd_res ; pcd_loc ; pcd_attributes } -> iter_loc this pcd_name ; T . iter_constructor_arguments this pcd_args ; iter_opt ( this . typ this ) pcd_res ; this . location this pcd_loc ; this . attributes this pcd_attributes ) ; label_declaration = ( fun this { pld_name ; pld_type ; pld_loc ; pld_mutable = _ ; pld_attributes } -> iter_loc this pld_name ; this . typ this pld_type ; this . location this pld_loc ; this . attributes this pld_attributes ) ; cases = ( fun this l -> List . iter ( this . case this ) l ) ; case = ( fun this { pc_lhs ; pc_guard ; pc_rhs } -> this . pat this pc_lhs ; iter_opt ( this . expr this ) pc_guard ; this . expr this pc_rhs ) ; location = ( fun _this _l -> ( ) ) ; extension = ( fun this ( s , e ) -> iter_loc this s ; this . payload this e ) ; attribute = ( fun this a -> iter_loc this a . attr_name ; this . payload this a . attr_payload ; this . location this a . attr_loc ) ; attributes = ( fun this l -> List . iter ( this . attribute this ) l ) ; payload = ( fun this -> function | PStr x -> this . structure this x | PSig x -> this . signature this x | PTyp x -> this . typ this x | PPat ( x , g ) -> this . pat this x ; iter_opt ( this . expr this ) g ) ; }
type mapper = { attribute : mapper -> attribute -> attribute ; attributes : mapper -> attribute list -> attribute list ; binding_op : mapper -> binding_op -> binding_op ; case : mapper -> case -> case ; cases : mapper -> case list -> case list ; class_declaration : mapper -> class_declaration -> class_declaration ; class_description : mapper -> class_description -> class_description ; class_expr : mapper -> class_expr -> class_expr ; class_field : mapper -> class_field -> class_field ; class_signature : mapper -> class_signature -> class_signature ; class_structure : mapper -> class_structure -> class_structure ; class_type : mapper -> class_type -> class_type ; class_type_declaration : mapper -> class_type_declaration -> class_type_declaration ; class_type_field : mapper -> class_type_field -> class_type_field ; constant : mapper -> constant -> constant ; constructor_declaration : mapper -> constructor_declaration -> constructor_declaration ; expr : mapper -> expression -> expression ; extension : mapper -> extension -> extension ; extension_constructor : mapper -> extension_constructor -> extension_constructor ; include_declaration : mapper -> include_declaration -> include_declaration ; include_description : mapper -> include_description -> include_description ; label_declaration : mapper -> label_declaration -> label_declaration ; location : mapper -> Location . t -> Location . t ; module_binding : mapper -> module_binding -> module_binding ; module_declaration : mapper -> module_declaration -> module_declaration ; module_substitution : mapper -> module_substitution -> module_substitution ; module_expr : mapper -> module_expr -> module_expr ; module_type : mapper -> module_type -> module_type ; module_type_declaration : mapper -> module_type_declaration -> module_type_declaration ; open_declaration : mapper -> open_declaration -> open_declaration ; open_description : mapper -> open_description -> open_description ; pat : mapper -> pattern -> pattern ; payload : mapper -> payload -> payload ; signature : mapper -> signature -> signature ; signature_item : mapper -> signature_item -> signature_item ; structure : mapper -> structure -> structure ; structure_item : mapper -> structure_item -> structure_item ; typ : mapper -> core_type -> core_type ; type_declaration : mapper -> type_declaration -> type_declaration ; type_extension : mapper -> type_extension -> type_extension ; type_exception : mapper -> type_exception -> type_exception ; type_kind : mapper -> type_kind -> type_kind ; value_binding : mapper -> value_binding -> value_binding ; value_description : mapper -> value_description -> value_description ; with_constraint : mapper -> with_constraint -> with_constraint ; }