From ced00872652186a8fc535406bbf5ddb1a1f0e731 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 9 Mar 2018 20:35:48 -0500 Subject: [PATCH] moved styling from range_stop to range_start --- colormap.ml | 9 ++++++--- lex_cpp.mll | 4 ++-- lex_ocaml.mll | 4 ++-- main.ml | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/colormap.ml b/colormap.ml index 535a706..72f319b 100644 --- a/colormap.ml +++ b/colormap.ml @@ -9,6 +9,7 @@ type style = type ctx = { lbuf : lexbuf; + mutable clr : style; mutable pos : int; } @@ -39,10 +40,12 @@ let set_color ctx clr = 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) + diff --git a/lex_cpp.mll b/lex_cpp.mll index 4ac935f..0c13ebd 100644 --- a/lex_cpp.mll +++ b/lex_cpp.mll @@ -38,7 +38,7 @@ let typedef = "bool" | "short" | "int" | "long" | "unsigned" | "signed" | "char" | "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 } @@ -52,7 +52,7 @@ rule scan ctx = parse | eof { raise Eof } and comment ctx = parse - | "*/" { range_stop ctx Comment } + | "*/" { range_stop ctx } | _ { comment ctx lexbuf } | eof { raise Eof } diff --git a/lex_ocaml.mll b/lex_ocaml.mll index 5e35073..793f1ec 100644 --- a/lex_ocaml.mll +++ b/lex_ocaml.mll @@ -23,7 +23,7 @@ let keyword = "and" | "as" | "assert" | "begin" | "class" | "constraint" | "do" | "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 } @@ -35,6 +35,6 @@ rule scan ctx = parse | eof { raise Eof } and comment ctx = parse - | "*)" { range_stop ctx Comment } + | "*)" { range_stop ctx } | _ { comment ctx lexbuf } | eof { raise Eof } diff --git a/main.ml b/main.ml index 52c2226..9c3711d 100644 --- a/main.ml +++ b/main.ml @@ -33,10 +33,10 @@ let pick_syntax path = 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 -- 2.55.0