type ctx = {
lbuf : lexbuf;
+ mutable clr : style;
mutable pos : int;
}
Printf.printf "%d,%d,%d\n"
(lexeme_start ctx.lbuf) (lexeme_end ctx.lbuf) (get_color clr)
-let range_start ctx =
+let range_start ctx clr =
+ ctx.clr <- clr;
ctx.pos <- (lexeme_start ctx.lbuf)
-let range_stop ctx clr =
+let range_stop ctx =
Printf.printf "%d,%d,%d\n"
- ctx.pos (lexeme_end ctx.lbuf) (get_color clr);
+ ctx.pos (lexeme_end ctx.lbuf) (get_color ctx.clr);
ctx.pos <- (-1)
+
| "float" | "double"
rule scan ctx = parse
- | "/*" { range_start ctx; comment ctx lexbuf }
+ | "/*" { range_start ctx Comment; comment ctx lexbuf }
| ln_cmt { set_color ctx Comment }
| number { set_color ctx Number }
| character { set_color ctx Char }
| eof { raise Eof }
and comment ctx = parse
- | "*/" { range_stop ctx Comment }
+ | "*/" { range_stop ctx }
| _ { comment ctx lexbuf }
| eof { raise Eof }
| "while" | "with"
rule scan ctx = parse
- | "(*" { range_start ctx; comment ctx lexbuf }
+ | "(*" { range_start ctx Comment; comment ctx lexbuf }
| number { set_color ctx Number }
| character { set_color ctx Char }
| string { set_color ctx String }
| eof { raise Eof }
and comment ctx = parse
- | "*)" { range_stop ctx Comment }
+ | "*)" { range_stop ctx }
| _ { comment ctx lexbuf }
| eof { raise Eof }
let rec scan_string lexfn string =
let lbuf = Lexing.from_string string in
- let ctx = Colormap.({ lbuf = lbuf; pos = 0; }) in
+ let ctx = Colormap.({ lbuf = lbuf; clr = Normal; pos = 0; }) in
try while true do lexfn ctx lbuf done
with Colormap.Eof ->
- if ctx.pos >= 0 then Colormap.range_stop ctx Comment;
+ if ctx.pos >= 0 then Colormap.range_stop ctx;
Printf.printf "0,0,0\n";
flush stdout;
scan_input lexfn