text
stringlengths 0
601k
|
---|
let linux_lvm2_pvgroup_logical_volumes proxy = OBus_property . make ~ monitor : UDisks_monitor . monitor p_LinuxLvm2PVGroupLogicalVolumes proxy |
let linux_lvm2_lvname proxy = OBus_property . make ~ monitor : UDisks_monitor . monitor p_LinuxLvm2LVName proxy |
let linux_lvm2_lvuuid proxy = OBus_property . make ~ monitor : UDisks_monitor . monitor p_LinuxLvm2LVUuid proxy |
let linux_lvm2_lvgroup_name proxy = OBus_property . make ~ monitor : UDisks_monitor . monitor p_LinuxLvm2LVGroupName proxy |
let linux_lvm2_lvgroup_uuid proxy = OBus_property . make ~ monitor : UDisks_monitor . monitor p_LinuxLvm2LVGroupUuid proxy |
let linux_dmmp_component_holder proxy = OBus_property . map_r_with_context ( fun context x -> OBus_proxy . make ( OBus_context . sender context ) x ) ( OBus_property . make ~ monitor : UDisks_monitor . monitor p_LinuxDmmpComponentHolder proxy ) |
let linux_dmmp_name proxy = OBus_property . make ~ monitor : UDisks_monitor . monitor p_LinuxDmmpName proxy |
let linux_dmmp_slaves proxy = OBus_property . map_r_with_context ( fun context x -> List . map ( fun path -> OBus_proxy . make ( OBus_context . sender context ) path ) x ) ( OBus_property . make ~ monitor : UDisks_monitor . monitor p_LinuxDmmpSlaves proxy ) |
let linux_dmmp_parameters proxy = OBus_property . make ~ monitor : UDisks_monitor . monitor p_LinuxDmmpParameters proxy |
let linux_loop_filename proxy = OBus_property . make ~ monitor : UDisks_monitor . monitor p_LinuxLoopFilename proxy |
let properties proxy = OBus_property . group ~ monitor : UDisks_monitor . monitor proxy interface |
module type S = sig module M : Monads . State_sig type key = int val add : key -> unit M . t val find : key -> key M . t val union : key -> key -> key M . t val show : string M . t end |
module UF : S = struct type node = T of { rank : int } | Ptr of key and key = int module S = Stores . Map ( Int_map ) ( struct type key = int type value = node let key_to_string = string_of_int let value_to_string ( x : value ) = match x with | T { rank } -> Printf . sprintf " [ % d ] " rank | Ptr k -> Printf . sprintf " ptr ( % d ) " k end ) module M = Monads . Make_state_monad ( S ) let add ( k : key ) = let open M in set k ( T { rank = 1 } ) let rec get_root ( k : key ) ( acc : key list ) = let open M in get k >>= function | None -> let msg = Printf . sprintf " UF . get_root : invalid key % d " k in Stdlib . failwith msg | Some ( T { rank } ) -> let ptr_to_root = Ptr k in iter_list ( fun key -> set key ptr_to_root ) acc >>= fun ( ) -> return ( k , rank ) | Some ( Ptr k ' ) -> get_root k ' ( k :: acc ) let find ( k : key ) = let open M in get_root k [ ] >>= fun ( res , _ ) -> return res let union k1 k2 = let open M in get_root k1 [ ] >>= fun ( k1 , rank1 ) -> get_root k2 [ ] >>= fun ( k2 , rank2 ) -> if k1 = k2 then return k1 else if rank1 < rank2 then set k1 ( Ptr k2 ) >>= fun ( ) -> return k2 else if rank1 > rank2 then set k2 ( Ptr k1 ) >>= fun ( ) -> return k1 else let new_root = T { rank = rank1 + 1 } in set k2 ( Ptr k1 ) >>= fun ( ) -> set k1 new_root >>= fun ( ) -> return k1 let show s = ( S . to_string s , s ) end |
module type Str_conv_sig = sig module type UintSig = sig type t val name : string val fmt : string val zero : t val max_int : t val bits : int val of_int : int -> t val to_int : t -> int val add : t -> t -> t val mul : t -> t -> t val divmod : t -> t -> t * t end module type S = sig type t val of_string : string -> t val to_string : t -> string val to_string_bin : t -> string val to_string_oct : t -> string val to_string_hex : t -> string val printer : Format . formatter -> t -> unit val printer_bin : Format . formatter -> t -> unit val printer_oct : Format . formatter -> t -> unit val printer_hex : Format . formatter -> t -> unit end module Make ( U : UintSig ) : S with type t = U . t end |
module Str_conv : Str_conv_sig = struct module type UintSig = sig type t val name : string val fmt : string val zero : t val max_int : t val bits : int val of_int : int -> t val to_int : t -> int val add : t -> t -> t val mul : t -> t -> t val divmod : t -> t -> t * t end module type S = sig type t val of_string : string -> t val to_string : t -> string val to_string_bin : t -> string val to_string_oct : t -> string val to_string_hex : t -> string val printer : Format . formatter -> t -> unit val printer_bin : Format . formatter -> t -> unit val printer_oct : Format . formatter -> t -> unit val printer_hex : Format . formatter -> t -> unit end module Make ( U : UintSig ) : S with type t = U . t = struct type t = U . t let digit_of_char c = let disp = if c >= ' 0 ' && c <= ' 9 ' then 48 else if c >= ' A ' && c <= ' F ' then 55 else if c >= ' a ' && c <= ' f ' then 87 else failwith ( U . name ^ " . of_string " ) in int_of_char c - disp let of_string ' s base = let base = U . of_int base in let res = ref U . zero in let thresh = fst ( U . divmod U . max_int base ) in for i = 0 to String . length s - 1 do let c = s . [ i ] in if ! res > thresh then failwith ( U . name ^ " . of_string " ) ; if c <> ' _ ' then begin let d = U . of_int ( digit_of_char c ) in res := U . add ( U . mul ! res base ) d ; if ! res < d then failwith ( U . name ^ " . of_string " ) ; end done ; ! res let of_string s = let fail = U . name ^ " . of_string " in let len = String . length s in match len with | 0 -> invalid_arg fail | 1 | 2 -> of_string ' s 10 | _ -> if s . [ 0 ] = ' 0 ' && ( s . [ 1 ] < ' 0 ' || s . [ 1 ] > ' 9 ' ) then let base = match s . [ 1 ] with | ' b ' | ' B ' -> 2 | ' o ' | ' O ' -> 8 | ' x ' | ' X ' -> 16 | _ -> invalid_arg fail in of_string ' ( String . sub s 2 ( len - 2 ) ) base else of_string ' s 10 let to_string_base base prefix x = let y = ref x in if ! y = U . zero then " 0 " else begin let buffer = Bytes . create U . bits in let conv = " 0123456789abcdef " in let base = U . of_int base in let i = ref ( Bytes . length buffer ) in while ! y <> U . zero do let x ' , digit = U . divmod ! y base in y := x ' ; decr i ; Bytes . set buffer ! i conv . [ U . to_int digit ] done ; prefix ^ Bytes . sub_string buffer ! i ( Bytes . length buffer - ! i ) end let to_string = to_string_base 10 " " let to_string_bin = to_string_base 2 " 0b " let to_string_oct = to_string_base 8 " 0o " let to_string_hex = to_string_base 16 " 0x " let print_with f fmt x = Format . fprintf fmt " [ @% s ] " @ ( f x ^ U . fmt ) let printer = print_with to_string let printer_bin = print_with to_string_bin let printer_oct = print_with to_string_oct let printer_hex = print_with to_string_hex end end |
module Conv = Uint . Str_conv . Make ( struct type t = uint16 let fmt = " Ul " let name = " Uint16 " let zero = zero let max_int = max_int let bits = 16 let of_int = of_int let to_int = to_int let add = add let mul = mul let divmod = ( fun x y -> div x y , rem x y ) end ) |
module Conv = Uint . Str_conv . Make ( struct type t = uint32 let fmt = " Ul " let name = " Uint32 " let zero = zero let max_int = max_int let bits = 32 let of_int = of_int let to_int = to_int let add = add let mul = mul let divmod = ( fun x y -> div x y , rem x y ) end ) |
module Conv = Uint . Str_conv . Make ( struct type t = uint64 let name = " Uint64 " let fmt = " UL " let zero = zero let max_int = max_int let bits = 64 let of_int = of_int let to_int = to_int let add = add let mul = mul let divmod = ( fun x y -> div x y , rem x y ) end ) |
let to_signed c = let c = Char . code c in if ( c > 127 ) then ( ( - lnot c + 1 ) land 255 ) else c |
let zero = Char . unsafe_chr 0 |
let one = Char . unsafe_chr 1 |
let add x y = ( code x + code y ) land max_int |> chr |
let sub x y = ( code x - code y ) land max_int |> chr |
let mul x y = ( code x * code y ) land max_int |> chr |
let div x y = code x / code y |> chr |
let rem x y = code x mod code y |> chr |
let pred x = sub x one |
let succ x = add x one |
module Infix = struct let ( * ) = mul let ( + ) = add let ( - ) = sub let ( / ) = div let ( mod ) = rem end |
let ( lsl ) x y = ( code x lsl code y ) land max_int |> chr |
let ( lsr ) x y = code x lsr code y |> chr |
let ( land ) x y = code x land code y |> chr |
let ( lor ) x y = code x lor code y |> chr |
let ( lxor ) x y = code x lxor code y |> chr |
let lnot x = x lxor ( Char . chr max_int ) |
let swap_nibbles x = ( ( x land ( chr 0x0f ) ) lsl chr 4 ) lor ( ( x land ( Char . chr 0xF0 ) ) lsr ( chr 4 ) ) |
let is_bit_set x bit = x land ( one lsl ( Char . unsafe_chr bit ) ) != zero |
let is_bit_set ' bit x = is_bit_set x bit |
let set_bit x bit = x lor ( one lsl ( Char . unsafe_chr bit ) ) |
let set_bit ' bit x = x lor ( one lsl ( Char . unsafe_chr bit ) ) |
let unset_bit x bit = x land ( lnot ( one lsl ( Char . unsafe_chr bit ) ) ) |
let unset_bit ' bit x = x land ( lnot ( one lsl ( Char . unsafe_chr bit ) ) ) |
let toggle_bit x bit = x lxor ( one lsl ( Char . unsafe_chr bit ) ) |
let show_hex x = Printf . sprintf " 0x % 02X " ( code x ) |
let show_hex ' x = Printf . sprintf " % 02X " ( code x ) |
let show_bin d = if d = zero then " 0 " else let rec aux acc d = if d = zero then acc else aux ( string_of_int ( code ( d land one ) ) :: acc ) ( d lsr one ) in String . concat " " ( aux [ ] d ) |
let get_n_bits x n = ( x lsl n ) lsr n |
module MakeInfix ( B : Uints_intf . Basics ) : Uints_intf . Infix with type t := B . t = struct open B let ( + ) = add let ( - ) = sub let ( * ) = mul let ( / ) = div let ( = ) = equal let ( <> ) = ( fun a b -> not ( equal a b ) ) let ( <= ) = le let ( mod ) = rem let ( land ) = logand let ( lor ) = logor let ( lxor ) = logxor let ( lsl ) = shift_left let ( lsr ) = shift_right end |
module Uint8 = struct module B = struct type t = int let max_int = 0xFF let zero = 0 let one = 1 let compare = Int . compare let equal x y = compare x y = 0 let le x y = ( x <= y ) let add x y = ( x + y ) land max_int let sub x y = ( x - y ) land max_int let mul x y = ( x * y ) land max_int let div x y = ( x / y ) land max_int let rem x y = ( x mod y ) land max_int let succ x = add x one let pred x = sub x one let logand x y = ( x land y ) let logor x y = ( x lor y ) let logxor = ( lxor ) let shift_left x y = ( x lsl y ) land max_int let shift_right = ( lsr ) let of_int x = x land max_int let of_char c = Char . code c let to_char t = Char . unsafe_chr t external to_int : t -> int = " % identity " let show = Printf . sprintf " $% 02X " end include B module Infix = MakeInfix ( B ) include Infix end |
module Uint16 = struct module B = struct type t = int let max_int = 0xFFFF let zero = 0 let one = 1 let compare = Int . compare let equal x y = compare x y = 0 let le x y = ( x <= y ) let add x y = ( x + y ) land max_int let sub x y = ( x - y ) land max_int let mul x y = ( x * y ) land max_int let div x y = ( x / y ) land max_int let rem x y = ( x mod y ) land max_int let succ x = add x one let pred x = sub x one let logand x y = ( x land y ) let logor x y = ( x lor y ) let logxor = ( lxor ) let shift_left x y = ( x lsl y ) land max_int let shift_right = ( lsr ) let of_int x = x land max_int external to_int : t -> int = " % identity " let show = Printf . sprintf " $% 04X " end include B module Infix = MakeInfix ( B ) include Infix let of_uint8 x = x |> Uint8 . to_int |> of_int let to_uint8 x = x |> to_int |> Uint8 . of_int end |
module Int8 = struct type t = int let of_byte b = b let of_int x = if x < 0 then ( x land 0xFF ) lor 0b10000000 else ( x land 0xFF ) let is_neg t = t land ( 1 lsl 7 ) <> 0 let abs t = if is_neg t then ( t - 1 ) lxor 0b11111111 else t let to_int t = if is_neg t then ( - abs t ) else t let show t = if t land ( 1 lsl 7 ) <> 0 then Printf . sprintf " -% d " ( Int . abs @@ t - 0x100 ) else Printf . sprintf " % d " t end |
module type Basics = sig type t val show : t -> string val max_int : t val zero : t val one : t val compare : t -> t -> int val equal : t -> t -> bool val le : t -> t -> bool val add : t -> t -> t val sub : t -> t -> t val mul : t -> t -> t val div : t -> t -> t val rem : t -> t -> t val succ : t -> t val pred : t -> t val logand : t -> t -> t val logor : t -> t -> t val logxor : t -> t -> t val shift_left : t -> int -> t val shift_right : t -> int -> t val of_int : int -> t val to_int : t -> int end |
module type Infix = sig type t val ( + ) : t -> t -> t val ( - ) : t -> t -> t val ( * ) : t -> t -> t val ( / ) : t -> t -> t val ( = ) : t -> t -> bool val ( <> ) : t -> t -> bool val ( <= ) : t -> t -> bool val ( mod ) : t -> t -> t val ( land ) : t -> t -> t val ( lor ) : t -> t -> t val ( lxor ) : t -> t -> t val ( lsl ) : t -> int -> t val ( lsr ) : t -> int -> t end |
module type S = sig type t include Basics with type t := t module Infix : Infix with type t := t include Infix with type t := t end |
let toggle_element ( projection : Api_types_j . simulation_info option -> bool ) ( content : [ < Html_types . div_content_fun ] Html . elt Html . list_wrap ) = Html . div ~ a [ : Tyxml_js . R . Html . a_class ( React . S . bind State_simulation . model ( fun model -> React . S . const ( if projection ( State_simulation . t_simulation_info model ) then [ " show " ] else [ " hidden " ] ) ) ) ] content |
let option_label label = if String . length label > 10 then ( String . sub label 0 7 ) " . . . " ^ else label |
let export_controls ( ~ export_select_id : string ) ( ~ export_filename_id : string ) ( ~ export_button_id : string ) ( ~ export_data_label : string ) = let export_formats : string list = [ export_data_label ] in let export_filename = Html . input ~ a [ : Html . a_id export_filename_id ; Html . a_input_type ` Text ; Html . a_class [ " form - control " ] ; Html . a_placeholder " file name " ] ( ) in let export_button = Html . button ~ a [ : Html . a_id export_button_id ; Html . Unsafe . string_attrib " role " " button " ; Html . a_class [ " btn " ; " btn - default " ; " pull - right " ] ] [ Html . cdata " export " ] in let export_formats_select = List . map ( fun format -> [ % html { |< option value " } =| format { " } ( |>| Html . cdata format ) { |</ option } ] ) >| export_formats in [ % html { |< div class " = row " > < div class " = col - sm - 12 " > < div class " = form - inline " > < div class " = form - group " > < select class " = form - control " id " } =| export_select_id { " |>< option value " = png " > png </ option >< option value " = svg " > svg </ option } >| export_formats_select { |</ select > </ div > < div class " = form - group " > < label class " = checkbox - inline " > } [ | export_filename ] { | </ label > </ div > < div class " = form - group " > < label class " = checkbox - inline " > } [ | export_button ] { | </ label > </ div > </ div > </ div > </ div } ] >| |
let label_news tab_is_active counter = let count = React . S . map ( fun model -> let simulation_info = State_simulation . t_simulation_info model in counter simulation_info ) State_simulation . model in let bip = ref React . E . never in let labels , set_labels = ReactiveData . RList . create [ ] in let _ = React . S . map ( fun tab_active -> let ( ) = React . E . stop ! bip in if tab_active then ReactiveData . RList . set set_labels [ ] else bip := React . E . map ( fun v -> ReactiveData . RList . set set_labels ( if v > 0 then [ Html . txt " " ; Html . span ~ a [ : Html . a_class [ " label " ; " label - default " ] ] [ Html . txt " New " ; ] ] else [ ] ) ) ( React . S . changes count ) ) tab_is_active in labels |
let badge ( counter : Api_types_j . simulation_info option -> int ) = let badge , badge_handle = ReactiveData . RList . create [ ] in let _ = React . S . map ( fun model -> let simulation_info = State_simulation . t_simulation_info model in let count = counter simulation_info in if count > 0 then ReactiveData . RList . set badge_handle [ Html . txt " " ; Html . span ~ a [ : Html . a_class [ " badge " ] ; ] [ Html . txt ( string_of_int count ) ; ] ; ] else ReactiveData . RList . set badge_handle [ ] ) State_simulation . model in badge |
let arguments ( key : string ) : string list = List . map snd ( List . filter ( fun ( k , _ ) -> key = k ) Url . Current . arguments ) |
let version ( ? test ' : a option = None ) ( ~ prod ' : a ) ( ~ dev ' : a ) ' : a = let version : string list = arguments " version " in match ( test , version ) with | ( Some test , [ " test " ] ) -> test | ( _ , [ " dev " ] ) -> dev | _ -> prod |
let navli label force_class decorations = let default_attributes = [ Html . a_id ( " nav " ^ label ) ; Html . a_role [ " presentation " ] ] in let attributes = match force_class with | None -> default_attributes | Some l -> ( Tyxml_js . R . Html5 . a_class l ) :: default_attributes in let text = ReactiveData . RList . concat ( ReactiveData . RList . singleton ( Html . cdata label ) ) decorations in Html . li ~ a : attributes [ Tyxml_js . R . Html . a ~ a [ : Html . Unsafe . string_attrib " data - toggle " " tab " ; Html . a_role [ " tab " ] ; Html . Unsafe . string_attrib " aria - controls " label ; Html . a_href ( " " #^ label ) ] text ] |
let navtabs nav_tab_id = function | [ ] | ( _ , Some _ , _ ) :: _ -> Common . toss " ui_common . navtabs : missing tabs " | ( ti , None , l ) :: t -> Html . ul ~ a [ : Html . a_id nav_tab_id ; Html . a_class [ " nav " ; " nav - tabs " ] ; Html . Unsafe . string_attrib " role " " tablist " ] ( navli ti ( Some ( React . S . const [ " active " ] ) ) l :: List . map ( fun ( t , a_class , li ) -> navli t a_class li ) t ) |
let onenavcontent label active classes content = Html . div ~ a [ : Html . a_id label ; Html . a_class ( if active then " flex - content " :: " tab - pane " :: " active " :: classes else " flex - content " :: " tab - pane " :: classes ) ; Html . Unsafe . string_attrib " role " " tabpanel " ] content |
let navcontent ? id classes = function | [ ] -> Common . toss " ui_common . navcontent : missing content " | ( t , cl , c ) :: l -> let id : [ > ` Id ] Html . attrib list = match id with | None -> [ ] | Some id -> [ Html . a_id id ] in Html . div ~ a ( [ : Html . a_class ( [ " panel - content " ; " tab - content " ; " flex - content " ] @ classes ) ; ] @ id ) ( onenavcontent t true cl c :: List . map ( fun ( t , cl , c ) -> onenavcontent t false cl c ) l ) |
let level ? debug ? info ? notice ? warning ? error ? fatal ( ) : ' a list = let level : string list = arguments " level " in let extract key value = match value with | None -> [ ] | Some value -> if List . mem key level then [ value ] else [ ] in ( extract " debug " debug ) @ ( extract " info " info ) @ ( extract " notice " notice ) @ ( extract " warning " warning ) @ ( extract " error " error ) @ ( extract " fatal " fatal ) @ [ ] |
let features ( ? default [ ] ) = ( options ( : string * ' a ) list ) : ' a list = let features : string list = arguments " feature " in let matches : ' a list = List . map snd ( List . filter ( fun ( feature , _ ) -> List . mem feature features ) options ) in match matches with | [ ] -> default | _ :: _ -> matches |
let input_change input_dom signal_handler = input_dom . ## onchange := Dom_html . handler ( fun _ -> let ( ) = signal_handler ( Js . to_string ( input_dom . ## value ) ) in Js . _true ) |
module type Menu = sig val content : unit -> [ > ` Button | ` Div | ` Ul | ` A of [ > ` PCDATA | ` Span ] ] Tyxml_js . Html5 . elt list val onload : unit -> unit end ; ; |
module type Div = sig val id : string val content : unit -> Html_types . div_content_fun Tyxml_js . Html . elt list val onload : unit -> unit end ; ; |
module type Tab = sig val navli : unit -> Html_types . flow5_without_interactive Tyxml_js . Html5 . elt ReactiveData . RList . t val content : unit -> Html_types . div_content_fun Tyxml_js . Html5 . elt list val onload : unit -> unit val onresize : unit -> unit end ; ; |
module type SubTab = sig include Tab val parent_hide : unit -> unit val parent_shown : unit -> unit end |
module type Panel = sig val content : unit -> Html_types . div Tyxml_js . Html5 . elt val onload : unit -> unit val onresize : unit -> unit end ; ; |
let id_dom ( id : string ) : ' a Js . t = Js . Unsafe . coerce ( ( Js . Opt . get ( document ## getElementById ( Js . string id ) ) ( fun ( ) -> Common . toss ( Format . sprintf " ui_common . id_dom : could not find id % s " id ) ) ) : Dom_html . element Js . t ) |
let create_modal ( ~ id : string ) ( ~ title_label : string ) ( ~ body : [ < Html_types . div_content_fun ] Html . elt Html . list_wrap ) ( ~ submit_label : string ) ( ~ submit : ( ' self Js . t , _ Js . t ) Dom . event_listener ) : [ > Html_types . div ] Html . elt = let button = Html . button ~ a [ : Html . a_button_type ` Submit ; Html . a_class [ " btn " ; " btn - primary " ; ] ] [ Html . txt submit_label ] in let form = Html . form ~ a [ : Html . a_class [ " modal - content " ] ] [ Html . div ~ a [ : Html . a_class [ " modal - header " ] ] [ Html . button ~ a [ : Html . Unsafe . string_attrib " type " " button " ; Html . a_class [ " close " ] ; Html . Unsafe . string_attrib " data - dismiss " " modal " ; Html . Unsafe . string_attrib " aria - label " " Close " ; ] [ Html . span ~ a [ : Html . Unsafe . string_attrib " aria - hidden " " true " ] [ Html . entity " times " ] ] ; Html . h4 [ Html . cdata title_label ] ] ; Html . div ~ a [ : Html . a_class [ " modal - body " ] ] body ; Html . div ~ a [ : Html . a_class [ " modal - footer " ] ] ( [ Html . button ~ a [ : Html . Unsafe . string_attrib " type " " button " ; Html . a_class [ " btn " ; " btn - default " ] ; Html . Unsafe . string_attrib " data - dismiss " " modal " ; ] [ Html . cdata " Cancel " ] ; ] [ @ button ] ) ] in let ( ) = ( Tyxml_js . To_dom . of_form form ) . ## onsubmit := submit in Html . div ~ a [ : Html . a_class [ " modal " ; " fade " ] ; Html . a_id id ; Html . Unsafe . string_attrib " tabindex " " - 1 " ; Html . Unsafe . string_attrib " role " " dialog " ; ] [ Html . div ~ a [ : Html . a_class [ " modal - dialog " ] ; Html . Unsafe . string_attrib " role " " document " ; ] [ form ] ] |
type token = | DEF | EXTERN | PLUS | MINUS | MUL | DIV | LPAREN | RPAREN | SEMI | COMMA | EOF | NUMBER of float | KWD of char | IDENT of string |
let regexp newline = ( ' \ 010 ' | ' \ 013 ' | " \ 013 \ 010 ) " |
let regexp blank = [ ' ' ' \ 009 ' ' \ 012 ' ] 012 ' |
let regexp blanks = blank + |
let regexp lowercase = [ ' a ' - ' z ' ' \ 223 ' - ' \ 246 ' ' \ 248 ' - ' \ 255 ' ' _ ' ] ' _ ' |
let regexp uppercase = [ ' A ' - ' Z ' ' \ 192 ' - ' \ 214 ' ' \ 216 ' - ' \ 222 ' ] 222 ' |
let regexp whitespace = ( blank | newline ) newline |
let regexp underscore = " _ " |
let regexp tilde = " " ~ |
let regexp identchar = [ ' A ' - ' Z ' ' a ' - ' z ' ' _ ' ' \ 192 ' - ' \ 214 ' ' \ 216 ' - ' \ 246 ' ' \ 248 ' - ' \ 255 ' ' \ ' ' ' 0 ' - ' 9 ' ] ' 9 ' |
let regexp symbolchar = [ ' ! ' ' $ ' ' % ' ' & ' ' * ' ' + ' ' - ' ' . ' ' / ' ' : ' ' < ' ' = ' ' > ' ' ? ' ' @ ' ' ^ ' ' | ' ' ~ ' ] ' |
let regexp lident = lowercase identchar * |
let regexp uidnet = uppercase identchar * |
let regexp decimal_literal = [ ' 0 ' - ' 9 ' ] ' 9 ' [ ' 0 ' - ' 9 ' ' _ ' ] ' _ ' * |
let regexp hex_literal = ' 0 ' [ ' x ' ' X ' ] ' X ' [ ' 0 ' - ' 9 ' ' A ' - ' F ' ' a ' - ' f ' ] ' f ' [ ' f ' ' 0 ' - ' 9 ' ' A ' - ' F ' ' a ' - ' f ' ' _ ' ] ' _ ' * |
let regexp oct_literal = ' 0 ' [ ' o ' ' O ' ] ' O ' [ ' 0 ' - ' 7 ' ] ' 7 ' [ ' 0 ' - ' 7 ' ' _ ' ] ' _ ' * |
let regexp bin_literal = ' 0 ' [ ' b ' ' B ' ] ' B ' [ ' 0 ' - ' 1 ' ] ' 1 ' [ ' 0 ' - ' 1 ' ' _ ' ] ' _ ' * |
let regexp int_literal = decimal_literal | hex_literal | oct_literal | bin_literal |
let regexp float_literal = [ ' 0 ' - ' 9 ' ] ' 9 ' [ ' 0 ' - ' 9 ' ' _ ' ] ' _ ' * ( ' . ' [ ' 0 ' - ' 9 ' ' _ ' ] ' _ ' * ) ? ( [ ' e ' ' E ' ] ' E ' [ ' + ' ' - ' ] ' ? [ ' 0 ' - ' 9 ' ] ' 9 ' [ ' 0 ' - ' 9 ' ' _ ' ] ' _ ' * ) ? |
let first = ref true |
let rec alex pos = lexer | " ; " -> SEMI | ( " " -> LPAREN | ) " " -> RPAREN | " " + -> PLUS | " " - -> MINUS | " " * -> MUL | " " / -> DIV | " extern " -> EXTERN | " def " -> DEF | " , " -> COMMA | " \ n " -> new_line lexbuf pos ; alex pos lexbuf | float_literal -> ( NUMBER ( ( u8l |- float_of_string ) float_of_string lexbuf ) lexbuf ) lexbuf | lident -> IDENT ( u8l lexbuf ) lexbuf | blank + -> alex pos lexbuf | eof -> if ! first then ( first := false ; EOF ) EOF else raise Ulexing . Error | " " # -> comment pos lexbuf | _ -> raise Ulexing . Error | ' \ n ' -> new_line lexbuf pos ; alex pos lexbuf | _ -> comment pos lexbuf |
let test filename = Legacy ( . let revised_parser = menhir_with_ulex alex main in let chan = open_in filename in let lexbuf = Ulexing . from_utf8_channel chan in handle_ulexing_error revised_parser lexbuf ; close_in chan ) |
let test_lexer filename = Legacy ( . let chan = open_in filename in let lexbuf = Ulexing . from_utf8_channel chan in let tokens = tokens_of_buf alex lexbuf in Stream . iter ( dump |- print_string |- print_newline ) print_newline tokens ) |
let _ = test " sample . py " |
type separator = [ ` CR | ` LF | ` CRLF | ` NEL | ` LS | ` PS ] let sp = match op with ` CR -> [ UChar . chr_of_uint 0x000d ] 0x000d | ` LF -> [ UChar . chr_of_uint 0x000a ] 0x000a | ` CRLF -> [ UChar . chr_of_uint 0x000d ; UChar . chr_of_uint 0x000a ] 0x000a | ` NEL -> [ UChar . chr_of_uint 0x0085 ] 0x0085 | ` LS -> [ UChar . chr_of_uint 0x2028 ] 0x2028 | ` PS -> [ UChar . chr_of_uint 0x2029 ] 0x2029 in let sp_hd = List . hd sp in let sp_tl = List . tl sp in object ( self ) self val mutable wait = false val mutable out_buf = [ ] method get ( get ) get = match out_buf with u :: rest -> out_buf <- rest ; u | [ ] -> let u = inchan # get ( get ) get in if wait then begin wait <- false ; match UChar . uint_code u with 0x000a -> out_buf <- sp_tl ; sp_hd | 0x000d -> wait <- true ; out_buf <- sp_tl ; sp_hd | 0x0085 -> out_buf <- sp_tl @ sp ; sp_hd | _ -> out_buf <- sp_tl @ [ u ] u ; sp_hd end else match UChar . uint_code u with 0x000d -> wait <- true ; self # get ( get ) get | 0x000a | 0x0085 -> out_buf <- sp_tl ; sp_hd | _ -> u method close_in ( ) = out_buf <- [ ] ; inchan # close_in ( ) end let sp = match op with ` CR -> [ UChar . chr_of_uint 0x000d ] 0x000d | ` LF -> [ UChar . chr_of_uint 0x000a ] 0x000a | ` CRLF -> [ UChar . chr_of_uint 0x000d ; UChar . chr_of_uint 0x000a ] 0x000a | ` NEL -> [ UChar . chr_of_uint 0x0085 ] 0x0085 | ` LS -> [ UChar . chr_of_uint 0x2028 ] 0x2028 | ` PS -> [ UChar . chr_of_uint 0x2029 ] 0x2029 in object ( self ) self val mutable wait = false method private output_newline = List . iter outchan # put sp method put u = if wait then begin wait <- false ; match UChar . uint_code u with 0x000a -> ( ) | _ -> self # put u end else match UChar . uint_code u with 0x000d -> self # output_newline ; wait <- true | 0x000a | 0x0085 | 0x2028 | 0x2029 -> self # output_newline | _ -> outchan # put u method close_out ( ) = wait <- false ; outchan # close_out ( ) method flush : unit -> unit = outchan # flush end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.