text
stringlengths
0
601k
let parse_char c pos max s = if pos > max then error_pos max ` Eoi else if s . [ pos ] = c then ( ) else error_pos pos ( ` Exp_chars [ c ] )
let parse_dt_sep ~ strict pos max s = let is_dt_sep = function | ' T ' -> true | ' t ' | ' ' when not strict -> true | _ -> false in if pos > max then error_pos max ` Eoi else if is_dt_sep s . [ pos ] then ( ) else error_pos pos ( ` Exp_chars ( [ ' T ' ] @ if strict then [ ] else [ ' t ' ; ' ' ] ) )
let decide_frac_or_tz ~ strict pos max s = if pos > max then error_pos max ` Eoi else match s . [ pos ] with | ' . ' -> ` Frac | ' ' + | ' ' - | ' Z ' -> ` Tz | ' z ' when not strict -> ` Tz | c -> let chars = [ ' . ' ; ' ' ; + ' ' ; - ' Z ' ] @ if strict then [ ] else [ ' z ' ] in error_pos pos ( ` Exp_chars chars )
let parse_frac_ps pos max s = if pos > max then error_pos max ` Eoi else if not ( is_digit s . [ pos ] ) then error_exp_digit pos else let rec loop k acc pow = if k > max then error_pos max ` Eoi else if not ( is_digit s . [ k ] ) then ( Some acc ) , k else let count = k - pos + 1 in if count > 12 then loop ( k + 1 ) a...
let parse_tz_s ~ strict pos max s = let parse_tz_mag sign pos = let hh_pos = pos in let mm_pos = hh_pos + 3 in let hh = parse_digits ~ count : 2 hh_pos max s in parse_char ' ' : ( mm_pos - 1 ) max s ; let mm = parse_digits ~ count : 2 mm_pos max s in if hh > 23 then error ( hh_pos , hh_pos + 1 ) ` Invalid_stamp else if...
let of_rfc3339 ( ? strict = false ) ( ? sub = false ) ( ? start = 0 ) s = try let s_len = String . length s in let max = s_len - 1 in if s_len = 0 || start < 0 || start > max then error_pos start ` Eoi else let y_pos = start in let m_pos = y_pos + 5 in let d_pos = m_pos + 3 in let hh_pos = d_pos + 3 in let mm_pos = hh_...
let rfc3339_adjust_tz_offset tz_offset_s = let min = - 86340 in let max = + 86340 in if min <= tz_offset_s && tz_offset_s <= max && tz_offset_s mod 60 = 0 then tz_offset_s , false else 0 , true
let s_frac_of_ps frac ps = Int64 . ( div ( rem ps ps_count_in_s ) Span . frac_div . ( frac ) )
let to_rfc3339 ( ? space = false ) ? frac_s ( : frac = 0 ) ? tz_offset_s ( _ , ps as t ) = let buf = Buffer . create 255 in let tz_offset_s , tz_unknown = match tz_offset_s with | Some tz -> rfc3339_adjust_tz_offset tz | None -> 0 , true in let ( y , m , d ) , ( ( hh , ss , mm ) , tz_offset_s ) = to_date_time ~ tz_offs...
let pp_rfc3339 ? space ? frac_s ? tz_offset_s ( ) ppf t = Format . fprintf ppf " % s " ( to_rfc3339 ? space ? frac_s ? tz_offset_s t )
let pp_human ? frac_s ( : frac = 0 ) ? tz_offset_s ( ) ppf ( _ , ps as t ) = let tz_offset_s , tz_unknown = match tz_offset_s with | Some tz -> rfc3339_adjust_tz_offset tz | None -> 0 , true in let ( y , m , d ) , ( ( hh , ss , mm ) , tz_offset_s ) = to_date_time ~ tz_offset_s t in Format . fprintf ppf " % 04d -% 02d -...
let pp = pp_human ~ tz_offset_s : 0 ( )
type module_kind = [ ` Module | ` Let_module | ` Let_cont | ` Anon_module | ` Open_struct ]
module Ppx_mod_top_common ( M : sig type t val add_from_sub : module_kind -> string -> t list -> t list struct type items = M . t list type t = | Root of items | Module of t * module_kind * string * items let state = ref ( Root [ ] ) let get_entries ( ) = match ! state with | Root x -> List . rev x | Module _ -> error ...
module Make_ocaml_types ( ) = struct type typ = | Simple | Poly type tree = | Type_def of typ * string | Sub_module of string * tree list module Tree = Ppx_mod_top_common ( struct type t = tree let add_from_sub _ n l = [ Sub_module ( n , List . rev l ) ] end ) let add_poly s = Tree . add_entry ( Type_def ( Poly , s ) )...
module OSTypes_visible = struct include Make_ocaml_types ( ) let with_dont_save_types f = let cur_state = ! Tree . state in Std . finally ~ h ( : fun ( ) -> Tree . state := cur_state ) f let cond_save_types x f = if x then f ( ) else with_dont_save_types f let open_last ( ) = open_last ` Body let open_declaration_s l =...
module OSTypes_all = struct open Ast_helper include Make_ocaml_types ( ) let build_top_include name = let idl = Incl . mk ( Mty . typeof_ ( Mod . ident ( U . mk_lid name ) ) ) in let typ = Mty . signature [ Sig . include_ idl ] in Str . modtype ( Mtd . mk ~ typ ( U . mk_loc ! Lconst . type_modtype_name ) ) let open_las...
module Ppx_mod_top_parsetree = struct open Ast_helper type t = structure_item let add_from_sub k s l = if Hashtbl . mem Keywords . htl_modules s then error " module name % S is reserved " s ; ( match k with | ` Let_cont | ` Anon_module | ` Open_struct -> ( ) | ` Module | ` Let_module -> let pre = Myconst . private_pref...
module Ppx_mod_main_common ( M : sig val name_f : unit -> string struct module Structure = Ppx_mod_top_common ( Ppx_mod_top_parsetree ) open Structure let get_mod_path ( ) = let rec iter accu = function | Root _ -> M . name_f ( ) :: accu | Module ( t , _ , s , _ ) -> iter ( s :: accu ) t in iter [ ] ! state let create_...
let check_name is_fun name = if name = " " || name = " _ " then error " variable name empty " ; let f = name . [ 0 ] in if is_fun = false && not ( ( f >= ' a ' && f <= ' z ' ) || f = ' _ ' ) then error " prefix or infix symbols are not allowed here " ; if Hashtbl . mem Keywords . htl name then error " % S is predefined...
module Impl_mod = struct include Ppx_mod_main_common ( struct let name_f ( ) = ! Lconst . impl_mod_name end ) let add_entry = Structure . add_entry module Ur = Uniq_ref let add_named ? constr ( ? name_check = true ) ? attrs ~ retype name expr = if name_check then check_name false name ; let mod_path = get_mod_path ( ) ...
module Type_mod = struct include Ppx_mod_main_common ( struct let name_f ( ) = ! Lconst . type_mod_name end ) let add_entry = Structure . add_entry end
module Topscript = struct module Structure_extract_phase0 = Ppx_mod_top_common ( Ppx_mod_top_parsetree ) module Structure_extract = Ppx_mod_top_common ( Ppx_mod_top_parsetree ) module Structure_build_external = Ppx_mod_top_common ( Ppx_mod_top_parsetree ) let add_help f = let last_loc = ref ! Ast_helper . default_loc i...
module Mod_structure = struct module type h = sig val open_module : module_kind -> string -> unit val close_module : Ast_helper . loc -> unit val clear : unit -> unit val cur_is_empty : unit -> bool end let l : ( module h ) list = [ ( module ( Topscript . Structure_build_external : h ) ) ; ( module ( Topscript . Struct...
module Order = struct module Private = struct let pos = ref 0 let last_abstract_type = ref None let first_abstract_type = ref None let n_abstract_types = ref 0 let last_derived_type = ref None let first_derived_type = ref None let n_derived_types = ref 0 let first_types_hidden_pos = ref None let last_expr = ref None le...
module OSTypes = struct module O = Order let remove_alias_types = O . remove_alias_types let delete_os_inside_type_mod = O . delete_os_inside_type_mod let with_open_module n f = OSTypes_visible . Tree . open_module ` Module n ; OSTypes_all . Tree . open_module ` Module n ; Std . finally f ~ h ( : fun ( ) -> let loc = !...
module Modules = struct let is_primitive_module_expr x = match x . pmod_desc with | Pmod_ident _ | Pmod_structure _ -> true | Pmod_functor _ | Pmod_apply _ | Pmod_unpack _ | Pmod_extension _ | Pmod_constraint _ -> false let types_hidden = Order . types_hidden let pstr_module x mapper_f = let is_prim = is_primitive_modu...
let type_mod_is_used ( ) = Ocaml_config . use_open_struct ( ) && Order . write_type_module ( ) && Type_mod . Structure . get_entries ( ) <> [ ]
let all_top_modules l = let module A = Ast_helper in let make_module name l = let ms = A . Mod . structure l in let mb = A . Mb . mk ( U . mk_oloc name ) ms in A . Str . module_ mb in let uos = Ocaml_config . use_open_struct ( ) in let write_type_mod = Order . write_type_module ( ) in let loc = ! Ast_helper . default_l...
let all_top_modules ( ) = match Impl_mod . Structure . get_entries ( ) with | [ ] -> [ ] | l -> all_top_modules l
let clear ( ) = Mod_structure . clear ( ) ; Order . clear ( )
type lexed_lines = { current_line : Buffer . t ; mutable all_lines : string list }
type token_enum = | EOF | INT | REAL | FIXED | ID | STRING | FUN | MEM | VAL | RET | IF | THEN | ELSE | LBRACE | RBRACE | LBRACK | RBRACK | LPAREN | RPAREN | LSEQ | RSEQ | COLON | SEMI | COMMA | EQUAL | OP | AT | DOT | WHILE | TYPE | LARR | RARR | TRUE | FALSE | AND | WILD | EXTERNAL | TICK | ARROW | BANG | TABLE
type ' kind token = { kind : ' kind ; value : string ; loc : Loc . t }
type ' kind stream = { lexbuf : Lexing . lexbuf ; mutable has_errors : bool ; mutable errors : Error . t list ; mutable peeked : ' kind token ; mutable prev : ' kind token ; lines : lexed_lines }
let { Logger . log } = Logger . for_section " ptyp of type "
let var_of_id id = Location . mknoloc @@ Ident . name id
type signature_elt = | Item of Types . signature_item | Type of Asttypes . rec_flag * Parsetree . type_declaration list
let rec module_type = let open Ast_helper in function | Mty_for_hole -> failwith " Holes are not allowed in module types " | Mty_signature signature_items -> Mty . signature @@ signature signature_items | Mty_ident path -> Ast_helper . Mty . ident ( Location . mknoloc ( Untypeast . lident_of_path path ) ) | Mty_alias p...
let dead_rules = " dead rules "
let dead_agents = " dead agents "
let hyp = " site graph "
let refinement = " site graph list "
let domain_name = " domain name "
let refinements_list = " refinements list "
let position_list = " location list "
let side_effect = " side effect "
let target_map = " target map "
let location_pair_list = " location pair list "
let nodesofinfluencemap " = nodes of influence map "
let wakeup = " wake - up map "
let inhibition = " inhibition map "
type accuracy_level = Low | Medium | High | Full
let accuracy_levels = [ Low ; Medium ; High ; Full ]
let contact_map_accuracy_levels = [ Low ; High ]
let influence_map_accuracy_levels = [ Low ; Medium ; High ]
let reduction_accuracy_levels = [ Low ; High ]
let accuracy_to_string = function | Low -> " low " | Medium -> " medium " | High -> " high " | Full -> " full "
let accuracy_to_json x = JsonUtil . of_string ( accuracy_to_string x )
let accuracy_of_string = function | " low " -> Some Low | " medium " -> Some Medium | " high " -> Some High | " full " -> Some Full | _ -> None
let accuracy_of_json json = match accuracy_of_string ( JsonUtil . to_string json ) with | Some x -> x | None -> raise ( Yojson . Basic . Util . Type_error ( JsonUtil . build_msg " accuracy level " , json ) )
module AccuracySetMap = SetMap . Make ( struct type t = accuracy_level let compare a b = match a , b with | Low , Low -> 0 | Low , _ -> - 1 | _ , Low -> 1 | Medium , Medium -> 0 | Medium , _ -> - 1 | _ , Medium -> 1 | High , High -> 0 | High , _ -> - 1 | _ , High -> 1 | Full , Full -> 0 let print f = function | Full ->...
let site_type_to_json = function | User_graph . Counter i -> ` List [ ` String " counter " ; ` Int i ] | User_graph . Port p -> ` List [ ` String " port " ; ` Assoc [ sitelinks , ( match p . User_graph . port_links with | User_graph . LINKS l -> JsonUtil . of_list ( fun ( ( xl , xr ) , y ) -> ` List [ ` List [ ` Int xl...
let site_to_json site = ` Assoc [ sitename , JsonUtil . of_string site . User_graph . site_name ; sitetype , site_type_to_json site . User_graph . site_type ]
let site_type_of_json = function | ` List [ ` String " counter " ; ` Int i ] -> User_graph . Counter i | ` List [ ` String " port " ; ` Assoc l ] as x -> begin try let port_links = let json = List . assoc sitelinks l in User_graph . links_of_yojson json in let port_states = let json = List . assoc sitestates l in JsonU...
let site_of_json = function | ` Assoc l as x -> begin try let site_name = let json = List . assoc sitename l in JsonUtil . to_string json in let site_type = let json = List . assoc sitetype l in site_type_of_json json in { User_graph . site_name ; User_graph . site_type ; } with | _ -> raise ( Yojson . Basic . Util . T...
let site_node_sites_to_json list = JsonUtil . of_array site_to_json list
let site_node_sites_of_json = JsonUtil . to_array ~ error_msg " : site node sites " site_of_json
let site_node_to_json = function | None -> ` Null | Some node -> ` Assoc [ sitenodename , JsonUtil . of_string node . User_graph . node_type ; sitenodesites , site_node_sites_to_json node . User_graph . node_sites ]
let site_node_of_json = function begin try let node_id = let json = List . assoc_opt sitenodeid l in Option_util . map ( JsonUtil . to_int ? error_msg : None ) json in let node_type = let json = List . assoc sitenodename l in JsonUtil . to_string json in let node_sites = let json = List . assoc sitenodesites l in site_...
let contact_map_to_json contact_map = ` Assoc [ contactmap , JsonUtil . of_pair ~ lab1 : accuracy_string ~ lab2 : map accuracy_to_json ( JsonUtil . of_array ( JsonUtil . of_array site_node_to_json ) ) contact_map ]
let contact_map_of_json = function | ` Assoc l as x -> begin try let json = List . assoc contactmap l in JsonUtil . to_pair ~ lab1 : accuracy_string ~ lab2 : map ~ error_msg ( : JsonUtil . build_msg " contact map " ) accuracy_of_json ( JsonUtil . to_array ~ error_msg ( : JsonUtil . build_msg " site nodes list " ) ( Jso...
type scc = ( ( string * string ) * ( string * string ) ) list list
let string_pair_to_json ( a , b ) = JsonUtil . of_pair ~ lab1 : agent ~ lab2 : sitename JsonUtil . of_string JsonUtil . of_string ( a , b )
let string_pair_of_json ( json : Yojson . Basic . t ) : string * string = JsonUtil . to_pair ~ lab1 : agent ~ lab2 : sitename ~ error_msg " : site " ( JsonUtil . to_string ~ error_msg " : agent name " ) ( JsonUtil . to_string ~ error_msg " : site_name " ) json
let string_pair_pair_to_json ( a , b ) = JsonUtil . of_pair string_pair_to_json string_pair_to_json ( a , b )
let string_pair_pair_of_json json : ( string * string ) * ( string * string ) = JsonUtil . to_pair ~ error_msg " : bond " string_pair_of_json string_pair_of_json json
let string_pair_pair_list_to_json l = JsonUtil . of_list string_pair_pair_to_json l
let string_pair_pair_list_of_json json = JsonUtil . to_list ~ error_msg " : list_of_bonds " string_pair_pair_of_json json
let string_pair_pair_list_list_to_json l = JsonUtil . of_list string_pair_pair_list_to_json l
let string_pair_pair_list_list_of_json json = JsonUtil . to_list ~ error_msg " : list_of_lists_of_bonds " string_pair_pair_list_of_json json
let scc_to_json ( cm_acc , scc_acc , scc ) = ` Assoc [ contactmapscc , JsonUtil . of_triple ~ lab1 : accuracy_cm ~ lab2 : accuracy_scc ~ lab3 : map accuracy_to_json accuracy_to_json string_pair_pair_list_list_to_json ( cm_acc , scc_acc , scc ) ]
let scc_of_json = function | ` Assoc l as x -> begin try let json = List . assoc contactmapscc l in JsonUtil . to_triple ~ lab1 : accuracy_cm ~ lab2 : accuracy_scc ~ lab3 : map ~ error_msg " : scc decomposition " accuracy_of_json accuracy_of_json string_pair_pair_list_list_of_json json with | _ -> raise ( Yojson . Basi...
type rule_direction = | Direct_rule | Reverse_rule | Both_directions | Dummy_rule_direction | Variable
type rule = { rule_id : int ; rule_label : string ; rule_ast : string ; rule_position : Locality . t ; rule_direction : rule_direction ; rule_hidden : bool ; }
let direction_to_json d = match d with | Direct_rule -> ` String " direct " | Reverse_rule -> ` String " reverse " | Both_directions -> ` String " both " | Dummy_rule_direction -> ` String " dummy " | Variable -> ` String " variable "
let json_to_direction s = match s with | ` String " direct " -> Direct_rule | ` String " reverse " -> Reverse_rule | ` String " both " -> Both_directions | ` String " dummy " -> Dummy_rule_direction | ` String " variable " -> Variable | x -> raise ( Yojson . Basic . Util . Type_error ( " rule direction " , x ) )
let rule_to_json rule = ` Assoc [ rule_id , JsonUtil . of_int rule . rule_id ; label , JsonUtil . of_string rule . rule_label ; ast , JsonUtil . of_string rule . rule_ast ; position , Locality . annot_to_yojson JsonUtil . of_unit ( ( ) , rule . rule_position ) ; direction , direction_to_json rule . rule_direction ; rul...
let json_to_rule = function | ` Assoc l as x when List . length l = 6 -> begin try { rule_id = JsonUtil . to_int ( List . assoc rule_id l ) ; rule_label = JsonUtil . to_string ( List . assoc label l ) ; rule_ast = JsonUtil . to_string ( List . assoc ast l ) ; rule_position = snd ( Locality . annot_of_yojson ( JsonUtil ...
type var = { var_id : int ; var_label : string ; var_ast : string ; var_position : Locality . t }
let var_to_json var = ` Assoc [ rule_id , JsonUtil . of_int var . var_id ; label , JsonUtil . of_string var . var_label ; ast , JsonUtil . of_string var . var_ast ; position , Locality . annot_to_yojson JsonUtil . of_unit ( ( ) , var . var_position ) ]
let json_to_var = function | ` Assoc l as x when List . length l = 4 -> begin try { var_id = JsonUtil . to_int ( List . assoc rule_id l ) ; var_label = JsonUtil . to_string ( List . assoc label l ) ; var_ast = JsonUtil . to_string ( List . assoc ast l ) ; var_position = snd ( Locality . annot_of_yojson ( JsonUtil . to_...
type ( ' rule , ' var ) influence_node = | Rule of ' rule | Var of ' var
type pos_of_rules_and_vars = ( ( int , int ) influence_node * Locality . t ) list
let influence_node_to_json rule_to_json var_to_json a = match a with | Var i -> ` Assoc [ variable , var_to_json i ] | Rule i -> ` Assoc [ rule , rule_to_json i ]
let influence_node_of_json json_to_rule json_to_var = function | ` Assoc [ s , json ] when s = variable -> Var ( json_to_var json ) | ` Assoc [ s , json ] when s = rule -> Rule ( json_to_rule json ) | x -> let error_msg = " Not a correct influence node " in raise ( Yojson . Basic . Util . Type_error ( error_msg , x ) )
let short_influence_node_to_json = influence_node_to_json JsonUtil . of_int JsonUtil . of_int
let short_influence_node_of_json = influence_node_of_json ( JsonUtil . to_int ~ error_msg ( : JsonUtil . build_msg " rule id " ) ) ( JsonUtil . to_int ~ error_msg ( : JsonUtil . build_msg " var id " ) )
let pos_of_rules_and_vars_to_json = JsonUtil . of_list ( JsonUtil . of_pair ~ lab1 : key ~ lab2 : locality short_influence_node_to_json ( fun loc -> Locality . annot_to_yojson JsonUtil . of_unit ( ( ) , loc ) ) )
let pos_of_rules_and_vars_of_json = JsonUtil . to_list ( JsonUtil . to_pair ~ lab1 : key ~ lab2 : locality short_influence_node_of_json ( fun x -> snd ( Locality . annot_of_yojson ( JsonUtil . to_unit ~ error_msg ( : JsonUtil . build_msg " locality " ) ) x ) ) )