]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
fleshed out highlighter rules for C
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 8 Dec 2017 20:10:33 +0000 (15:10 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 8 Dec 2017 20:10:33 +0000 (15:10 -0500)
lib/cfg.ml
lib/colormap.ml
lib/colormap.mli
lib/lexers/lex_cpp.mll

index 9a200d6660c3d04d63062d3216a4097975dd4e9e..a107b570e1894280a8322d3ff4250d2e7c7e3ccc 100644 (file)
@@ -27,8 +27,7 @@ let cmd_tags = strvar "tide.ui.font"
     "Quit Undo Redo Cut Copy Paste | Send Find "
 
 (* font settings *)
-let font = strvar "tide.ui.tags.edit"
-    "Liberation Sans:size=11:antialias=true:autohint=true"
+let font = strvar "tide.ui.tags.edit" "Verdana:size=11"
 let line_spacing = intvar "tide.ui.line_spacing" 1
 
 (* user interface related options *)
index 0169632776972ccd8661719ff6417221daea98e6..4fc7f2b31b7730e0684ac9100180bdcc164ecffe 100644 (file)
@@ -2,7 +2,7 @@ open Lexing
 
 exception Eof
 
-type style = Normal | Comment | Constant | Keyword | Type
+type style = Normal | Comment | Constant | Keyword | Type | PreProcessor
 (*
     String | Character | Number | Boolean
   | Variable | Function | Keyword | Operator | PreProcessor | Type
@@ -29,6 +29,7 @@ let get_color = function
 | Constant -> Cfg.Color.Syntax.constant
 | Keyword  -> Cfg.Color.Syntax.keyword
 | Type     -> Cfg.Color.Syntax.typedef
+| PreProcessor -> Cfg.Color.Syntax.preproc
 
 let set_color mapref lexbuf c =
   let span = Span.({
@@ -49,13 +50,7 @@ let make scanfn fetchfn =
       scanfn set_color lexbuf
     done;
     !mapref
-  with Eof ->
-    Printf.printf "%b\n" @@ SpanSet.is_empty !mapref;
-    SpanSet.iter
-      (fun x -> Printf.printf "%d-%d\n" x.start x.stop)
-      !mapref;
-    print_endline "";
-    !mapref
+  with Eof -> !mapref
 
 let empty = SpanSet.empty
 
index d69128205e87897b75feb8fb14eacb3ffebff7c4..696dce2398a8549ce077eafaae1eb1c21c78b21c 100644 (file)
@@ -2,7 +2,7 @@ open Lexing
 
 exception Eof
 
-type style = Normal | Comment | Constant | Keyword | Type
+type style = Normal | Comment | Constant | Keyword | Type | PreProcessor
 
 type t
 
index 158851e2f4b9a9f2aabb7f4ae30e626dc3e2ce22..3029efe5aefeaa9aa7cb32e643917e47360e77fc 100644 (file)
@@ -1,11 +1,32 @@
 { open Colormap }
 
-(* Line and Block Comments *)
-let ln_cmt = "//" [^ '\r' '\n']*
-let blk_cmt = "/*" _* "*/"
+let oct = ['0'-'9']
+let dec = ['0'-'9']
+let hex = ['0'-'9' 'a'-'f' 'A'-'F']
+let exp = ['e''E'] ['+''-']? (dec)+
+
+let alpha = ['a'-'z' 'A'-'Z']
+let alpha_ = (alpha | '_')
+let alnum = (alpha | dec)
+let alnum_ = (alpha_ | dec)
+
+let fstyle = ['f' 'F' 'l' 'L']
+let istyle = ['u' 'U' 'l' 'L']
+
+let ln_cmt = "//" [^ '\n']*
 let character = "'" ([^'\\' '\''] | '\\' _) "'"
 let string = '"' ([^'\\' '"'] | '\\' _)* ['"' '\n']
 let identifier = ['a'-'z' 'A'-'Z' '_'] ['a'-'z' 'A'-'Z' '0'-'9' '_']*
+let preprocess = "#" [' ' '\t']* ['a'-'z' 'A'-'Z' '_']+
+let sys_incl = (' '|'\t')* '<' [^ '\n' '>']* '>'
+
+let number = (
+    (dec)+ (istyle)*
+  | '0' ['x''X'] (hex)+ (istyle)*
+  | (dec)+ (exp)? (fstyle)?
+  | (dec)* '.' (dec)+ (exp)? (fstyle)?
+  | (dec)+ '.' (dec)* (exp)? (fstyle)?
+)
 
 let const = "true" | "false" | "NULL"
 
@@ -19,15 +40,25 @@ let typedef = "bool" | "short" | "int" | "long" | "unsigned" | "signed" | "char"
     | "float" | "double"
 
 rule scan color = parse
-  | ln_cmt { color Comment }
-(*  | blk_cmt { color Comment } *)
-  | character { color Constant }
-  | string { color Constant }
+  | "/*"       { color Comment; comment color lexbuf }
+  | ln_cmt     { color Comment }
+  | number     { color Constant }
+  | character  { color Constant }
+  | string     { color Constant }
+  | const      { color Constant }
+  | keyword    { color Keyword }
+  | typedef    { color Type }
+  | preprocess { color PreProcessor; preproc color lexbuf }
+  | identifier { (* skip *) }
+  | _          { scan color lexbuf }
+  | eof        { raise Eof }
 
-  | const { color Constant }
-  | keyword { color Keyword }
-  | typedef { color Type }
+and comment color = parse
+  | "*/" { color Comment }
+  | _ { comment color lexbuf }
+  | eof { raise Eof }
 
-  | identifier { (* skip *) }
+and preproc color = parse
+  | sys_incl { color Constant }
   | _ { (* skip *) }
   | eof { raise Eof }