# 13 "length.mll" open Lexing let header = "$Id: length.mll,v 1.15 2005-01-21 17:40:51 maranget Exp $" exception Cannot ;; let font = 10 ;; let font_float = float font ;; type t = Char of int | Pixel of int | Percent of int | No of string | Default let pretty = function | Char x -> string_of_int x^" chars" | Pixel x -> string_of_int x^" pxls" | Percent x -> string_of_int x^"%" | Default -> "default" | No s -> "*"^s^"*" let is_zero = function | Char 0|Pixel 0|Percent 0 -> true | _ -> false let pixel_to_char x = (100 * x + 50)/(100 * font) and char_to_pixel x = font * x let mk_char x = Char (truncate (0.5 +. x)) let mk_pixel x = Pixel (truncate (0.5 +. x)) and mk_percent x = Percent (truncate x) ;; let convert unit x = match unit with | "ex"|"em" -> mk_char x | "pt" -> mk_pixel x | "in" -> mk_char ((x *. 72.27) /. font_float) | "cm" -> mk_char ((x *. 28.47) /. font_float) | "mm" -> mk_char ((x *. 2.847) /. font_float) | "pc" -> mk_char ((x *. 12.0) /. font_float) | "@percent" -> mk_percent (100.0 *. x) | _ -> No unit ;; # 49 "length.ml" let __ocaml_lex_tables = { Lexing.lex_base = "\000\000\255\255\000\000\000\000\017\000\029\000\039\000\000\000\ \000\000\000\000\001\000\000\000\000\000\254\255\000\000\002\000\ \007\000"; Lexing.lex_backtrk = "\001\000\255\255\002\000\255\255\255\255\000\000\000\000\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\001\000\001\000\ \000\000"; Lexing.lex_default = "\255\255\000\000\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\000\000\015\000\015\000\ \255\255"; Lexing.lex_trans = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\016\000\016\000\255\255\255\255\016\000\000\000\255\255\ \016\000\016\000\000\000\000\000\016\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \016\000\000\000\255\255\000\000\000\000\000\000\000\000\016\000\ \000\000\000\000\000\000\000\000\000\000\001\000\004\000\000\000\ \005\000\005\000\005\000\005\000\005\000\005\000\005\000\005\000\ \005\000\005\000\000\000\000\000\000\000\000\000\000\000\000\000\ \003\000\006\000\006\000\006\000\006\000\006\000\006\000\006\000\ \006\000\006\000\006\000\004\000\000\000\005\000\005\000\005\000\ \005\000\005\000\005\000\005\000\005\000\005\000\005\000\006\000\ \006\000\006\000\006\000\006\000\006\000\006\000\006\000\006\000\ \006\000\000\000\000\000\010\000\000\000\008\000\011\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\012\000\000\000\ \007\000\000\000\009\000\000\000\013\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \255\255\000\000\255\255\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ "; Lexing.lex_check = "\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\014\000\014\000\015\000\015\000\014\000\255\255\015\000\ \016\000\016\000\255\255\255\255\016\000\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \014\000\255\255\015\000\255\255\255\255\255\255\255\255\016\000\ \255\255\255\255\255\255\255\255\255\255\000\000\002\000\255\255\ \002\000\002\000\002\000\002\000\002\000\002\000\002\000\002\000\ \002\000\002\000\255\255\255\255\255\255\255\255\255\255\255\255\ \002\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ \004\000\004\000\004\000\005\000\255\255\005\000\005\000\005\000\ \005\000\005\000\005\000\005\000\005\000\005\000\005\000\006\000\ \006\000\006\000\006\000\006\000\006\000\006\000\006\000\006\000\ \006\000\255\255\255\255\009\000\255\255\007\000\010\000\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\011\000\255\255\ \003\000\255\255\008\000\255\255\012\000\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \014\000\255\255\015\000\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ "; Lexing.lex_base_code = ""; Lexing.lex_backtrk_code = ""; Lexing.lex_default_code = ""; Lexing.lex_trans_code = ""; Lexing.lex_check_code = ""; Lexing.lex_code = ""; } let rec main_rule lexbuf = __ocaml_lex_main_rule_rec lexbuf 0 and __ocaml_lex_main_rule_rec lexbuf __ocaml_lex_state = match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with | 0 -> # 61 "length.mll" (let x,unit = positif lexbuf in convert unit (0.0 -. x)) # 162 "length.ml" | 1 -> # 62 "length.mll" (let x,unit = positif lexbuf in convert unit x) # 167 "length.ml" | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf; __ocaml_lex_main_rule_rec lexbuf __ocaml_lex_state and positif lexbuf = __ocaml_lex_positif_rec lexbuf 2 and __ocaml_lex_positif_rec lexbuf __ocaml_lex_state = match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with | 0 -> # 66 "length.mll" (let lxm = lexeme lexbuf in float_of_string lxm,unit lexbuf) # 179 "length.ml" | 1 -> # 68 "length.mll" (1.0, "@percent") # 184 "length.ml" | 2 -> # 69 "length.mll" (raise Cannot) # 189 "length.ml" | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf; __ocaml_lex_positif_rec lexbuf __ocaml_lex_state and unit lexbuf = __ocaml_lex_unit_rec lexbuf 14 and __ocaml_lex_unit_rec lexbuf __ocaml_lex_state = match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with | 0 -> # 71 "length.mll" (unit lexbuf) # 200 "length.ml" | 1 -> # 72 "length.mll" (lexeme lexbuf) # 205 "length.ml" | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf; __ocaml_lex_unit_rec lexbuf __ocaml_lex_state ;; # 74 "length.mll" open Lexing let main lexbuf = try main_rule lexbuf with | Cannot -> let sbuf = lexbuf.lex_buffer in No (String.sub sbuf 0 lexbuf.lex_buffer_len) # 222 "length.ml"