]> git.mdlowis.com Git - archive/tide-hl.git/commitdiff
moved styling from range_stop to range_start
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 10 Mar 2018 01:35:48 +0000 (20:35 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 10 Mar 2018 01:35:48 +0000 (20:35 -0500)
colormap.ml
lex_cpp.mll
lex_ocaml.mll
main.ml

index 535a706c3fdff787cfb8dc98af132851f8bff3d8..72f319b19c2b0af2c779ddf6ec54ef781490bea4 100644 (file)
@@ -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)
+
index 4ac935f2f604087c0826ca29ddafe3d35287756d..0c13ebd3e9a926f4517c42a099dc3180030f0ec6 100644 (file)
@@ -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 }
 
index 5e350738081430a51e785f2b7e52cb55454c0960..793f1ecef4f6b1d44ac7f5645c8d78818d2137fe 100644 (file)
@@ -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 52c222698232139640e77fd55479db1b9120161f..9c3711dc860c4f7caaf0b7645eb37044e1b47d74 100644 (file)
--- 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