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
| 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.({
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
{ 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"
| "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 }