1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
(* The goal of this lexer is to remove html encoding from strings, so that
they display nicely on the command-line. The only encodings included are the
one actually used. Because this executable is mainly used for testing, this
is fine. *)
rule buffer b = parse
| "&" { Buffer.add_char b '&'; buffer b lexbuf }
| "<" { Buffer.add_char b '<'; buffer b lexbuf }
| ">" { Buffer.add_char b '>'; buffer b lexbuf }
| ">" { Buffer.add_char b '>'; buffer b lexbuf }
| ">" { Buffer.add_char b '>'; buffer b lexbuf }
| """ { Buffer.add_char b '>'; buffer b lexbuf }
| "'" { Buffer.add_char b '\''; buffer b lexbuf }
| "-" { Buffer.add_char b '-'; buffer b lexbuf }
| eof { () }
| _ { Buffer.add_string b (Lexing.lexeme lexbuf) ; buffer b lexbuf }
{
let string str =
let lexbuf = Lexing.from_string str in
let b = Buffer.create (String.length str) in
buffer b lexbuf ;
Buffer.contents b
}
|