]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
first pass at syntax highlighting for c. most things work except block comments
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 8 Dec 2017 04:19:43 +0000 (23:19 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 8 Dec 2017 04:19:43 +0000 (23:19 -0500)
Makefile
deps.mk
lib/buf.ml
lib/colormap.ml
lib/draw.ml
lib/draw.mli
lib/lexers/lex_cpp.mll
lib/view.ml
lib/x11_prims.c

index 73f80b3a230fccb89b77cfb681f8d921f6fee44f..392a124c9f5ed3d8b0f162afa0a51a9ac6654773 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,19 +1,26 @@
 # Toolchain Configuration
 #-------------------------------------------------------------------------------
-OFLAGS     = -g
+OS         = $(shell uname)
+OFLAGS     = -g -nodynlink
 MKLIBFLAGS = -custom
 OLDFLAGS   =
 
 # Native Config
+OC     = ocamlopt
 BINEXT = bin
 OBJEXT = cmx
 LIBEXT = cmxa
 
 # Bytecode Config
+#OC     = ocamlc
 #BINEXT = byte
 #OBJEXT = cmo
 #LIBEXT = cma
 
+ifeq ($(OS),Darwin)
+       OFLAGS += -ccopt -dead_strip
+endif
+
 # Include and Lib Paths
 #-------------------------------------------------------------------------------
 INCS = -I . -I lib -I tests -I lib/lexers \
@@ -39,9 +46,9 @@ LIBSRCS = \
        lib/cfg.ml \
        lib/rope.ml \
        lib/buf.ml \
+       lib/colormap.ml \
        lib/draw.ml \
        lib/scrollmap.ml \
-       lib/colormap.ml \
        $(LEXERS) \
        lib/view.ml
 
@@ -89,14 +96,14 @@ deps deps.mk: $(wildcard *.ml* lib/*.ml* tests/*.ml*)
 #-------------------------------------------------------------------------------
 .SUFFIXES: .c .o .ml .mli .mll .cmo .cmx .cmi .cma .cmxa .byte .bin
 .c.o:
-       ocamlc $(OFLAGS) -c $^ $(INCS)
+       ocamlopt $(OFLAGS) -c $^ $(INCS)
        mv $(notdir $@) $(dir $@)
 .ml.cmo :
        ocamlc -c $(OFLAGS) $(INCS) -o $@ $<
 .ml.cmx :
        ocamlopt -c $(OFLAGS) $(INCS) -o $@ $<
 .mli.cmi :
-       ocamlc -c $(OFLAGS) $(INCS) -o $@ $<
+       $(OC) -c $(OFLAGS) $(INCS) -o $@ $<
 .mll.ml :
        ocamllex $(OLEXFLAGS) -o $@ $<
 %.cma:
diff --git a/deps.mk b/deps.mk
index a7d32787a10637efbe01aed86862b0febbb8658b..d1e54dd0d0a71038d320a367af8913c793f6683b 100644 (file)
--- a/deps.mk
+++ b/deps.mk
@@ -8,9 +8,9 @@ lib/cfg.cmx lib/cfg.o lib/cfg.cmi : lib/x11.cmi lib/x11.cmx lib/cfg.ml
 lib/colormap.cmo : lib/cfg.cmi lib/colormap.cmi lib/colormap.ml
 lib/colormap.cmx lib/colormap.o : lib/cfg.cmi lib/cfg.cmx lib/colormap.cmi lib/colormap.ml
 lib/colormap.cmi :
-lib/draw.cmo : lib/x11.cmi lib/cfg.cmi lib/buf.cmi lib/draw.cmi lib/draw.ml
-lib/draw.cmx lib/draw.o : lib/x11.cmi lib/x11.cmx lib/cfg.cmi lib/cfg.cmx lib/buf.cmi lib/buf.cmx lib/draw.cmi lib/draw.ml
-lib/draw.cmi : lib/x11.cmi lib/buf.cmi
+lib/draw.cmo : lib/x11.cmi lib/colormap.cmi lib/cfg.cmi lib/buf.cmi lib/draw.cmi lib/draw.ml
+lib/draw.cmx lib/draw.o : lib/x11.cmi lib/x11.cmx lib/colormap.cmi lib/colormap.cmx lib/cfg.cmi lib/cfg.cmx lib/buf.cmi lib/buf.cmx lib/draw.cmi lib/draw.ml
+lib/draw.cmi : lib/x11.cmi lib/colormap.cmi lib/buf.cmi
 lib/misc.cmo lib/misc.cmi : lib/misc.ml
 lib/misc.cmx lib/misc.o lib/misc.cmi : lib/misc.ml
 lib/rope.cmo : lib/rope.cmi lib/rope.ml
index 58fb5d84e22a4dea8dcd0061fa24d8b75b10d37d..d40bcfc859078db5d45ba4fb9ef1f1a3aa3840fb 100644 (file)
@@ -38,7 +38,6 @@ let make_lexfn buf =
       (!count >= n)
     ) buf !pos;
     pos := !pos + !count;
-    Printf.printf "count %d\n" !count;
     !count)
 
 module Cursor = struct
index 6740036b44be9d71d1beab852b45eb046263d982..0169632776972ccd8661719ff6417221daea98e6 100644 (file)
@@ -33,7 +33,7 @@ let get_color = function
 let set_color mapref lexbuf c =
   let span = Span.({
     start = (lexeme_start lexbuf);
-    stop  = (lexeme_end lexbuf);
+    stop  = (lexeme_end lexbuf) - 1;
     style = c })
   in
   mapref := SpanSet.add span !mapref;
@@ -46,11 +46,16 @@ let make scanfn fetchfn =
     let lexbuf = Lexing.from_function fetchfn in
     let set_color = set_color mapref lexbuf in
     while true do
-      print_endline "scanning";
       scanfn set_color lexbuf
     done;
     !mapref
-  with Eof -> !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
 
 let empty = SpanSet.empty
 
index 23f66ac46adf271ec5034ac2d4038329d3ffce56..c140ef4e06d23e26be9717af41a059ac47871c12 100644 (file)
@@ -98,11 +98,11 @@ let vrule height csr =
   rule_bkg 1 (height - csr.y) csr;
   csr.x <- csr.x + 1
 
-let buffer csr buf off =
+let buffer csr buf clr off =
   dark_bkg (csr.width - csr.x) (csr.height - csr.y) csr;
   let num = ref 0 and csr = (restart csr 2 0) in
   let draw_rune c =
-    draw_glyph csr c Cfg.Color.Syntax.normal;
+    draw_glyph csr c (Colormap.find (off + !num) clr);
     num := !num + 1;
     has_next_line csr
   in
@@ -131,6 +131,6 @@ let scroll csr params =
   csr.x <- csr.x + 14;
   vrule csr.height csr
 
-let edit csr buf =
+let edit csr buf clr =
   dark_bkg (csr.width - csr.x) (csr.height - csr.y) csr;
-  buffer csr buf
+  buffer csr buf clr
index e1847c2113e5a7ecb30dc9004f484a8876471e27..517ee3471510cd480f38fd559487f15c4213b73d 100644 (file)
@@ -18,7 +18,7 @@ val dark_bkg : int -> int -> Cursor.t -> unit
 val light_bkg : int -> int -> Cursor.t -> unit
 val rule_bkg : int -> int -> Cursor.t -> unit
 
-val buffer : Cursor.t -> Buf.t -> int -> int
+val buffer : Cursor.t -> Buf.t -> Colormap.t -> int -> int
 
 val string : string -> Cursor.t -> unit
 val hrule : int -> Cursor.t -> unit
@@ -27,4 +27,4 @@ val vrule : int -> Cursor.t -> unit
 val status : Cursor.t -> string -> unit
 val tags : Cursor.t -> Buf.t -> unit
 val scroll : Cursor.t -> (float * float) -> unit
-val edit : Cursor.t -> Buf.t -> int -> int
+val edit : Cursor.t -> Buf.t -> Colormap.t -> int -> int
index ae08c8629ddc056246e3c95ff784d9e4f433ee7f..158851e2f4b9a9f2aabb7f4ae30e626dc3e2ce22 100644 (file)
@@ -3,6 +3,9 @@
 (* Line and Block Comments *)
 let ln_cmt = "//" [^ '\r' '\n']*
 let blk_cmt = "/*" _* "*/"
+let character = "'" ([^'\\' '\''] | '\\' _) "'"
+let string = '"' ([^'\\' '"'] | '\\' _)* ['"' '\n']
+let identifier = ['a'-'z' 'A'-'Z' '_'] ['a'-'z' 'A'-'Z' '0'-'9' '_']*
 
 let const = "true" | "false" | "NULL"
 
@@ -13,12 +16,18 @@ let typedef = "bool" | "short" | "int" | "long" | "unsigned" | "signed" | "char"
     | "size_t" | "void" | "extern" | "static" | "inline" | "struct" | "enum"
     | "typedef" | "union" | "volatile" | "auto" | "const" | "int8_t" | "int16_t"
     | "int32_t" | "int64_t" | "uint8_t" | "uint16_t" | "uint32_t" | "uint64_t"
+    | "float" | "double"
 
 rule scan color = parse
+  | ln_cmt { color Comment }
+(*  | blk_cmt { color Comment } *)
+  | character { color Constant }
+  | string { color Constant }
+
   | const { color Constant }
   | keyword { color Keyword }
   | typedef { color Type }
-  | ln_cmt { color Comment }
-  | blk_cmt { color Comment }
-  | _
+
+  | identifier { (* skip *) }
+  | _ { (* skip *) }
   | eof { raise Eof }
index 9c6cfe1850bf9a5d1537ed8f06e9935d2d341513..835f587dbe40762f0ad5789a402447ba5719e33f 100644 (file)
@@ -24,7 +24,7 @@ let resize view width =
 
 let draw view csr =
   let view = (resize view (Draw.Cursor.max_width csr)) in
-  let num = Draw.buffer csr view.buf (Scrollmap.first view.map) in
+  let num = Draw.buffer csr view.buf view.clr (Scrollmap.first view.map) in
   { view with num = num }
 
 let scroll_up view =
index 2e03ef0952e7aa8bc3264ef0226e2eb3920d0b21..316824af19ba9b446d8f9b3ac59813f49c6d6c6e 100644 (file)
@@ -108,6 +108,7 @@ CAMLprim value x11_draw_rect(value rect) {
 #define _XOPEN_SOURCE 700
 #include <time.h>
 #include <sys/time.h>
+#define printf(...) ((void)0)
 
 uint64_t getmillis(void) {
     struct timespec time;