]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
started integrating lexers
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 7 Dec 2017 02:17:42 +0000 (21:17 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 7 Dec 2017 02:17:42 +0000 (21:17 -0500)
Makefile
deps.mk
lib/buf.ml
lib/buf.mli
lib/colormap.ml
lib/colormap.mli
lib/lexers/lex_cpp.mll
lib/view.ml

index 143b17046f5a9749130127dec180bd65536a7efc..73f80b3a230fccb89b77cfb681f8d921f6fee44f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,7 @@ LIBEXT = cmxa
 
 # Include and Lib Paths
 #-------------------------------------------------------------------------------
-INCS = -I . -I lib -I tests \
+INCS = -I . -I lib -I tests -I lib/lexers \
     -I /usr/X11R6/include \
     -I /usr/include/freetype2 -I /usr/X11R6/include/freetype2
 
@@ -30,6 +30,9 @@ BINSRCS = \
        edit.ml \
        unittests.ml
 
+LEXERS = \
+       lib/lexers/lex_cpp.ml
+
 LIBSRCS = \
        lib/misc.ml \
        lib/x11.ml \
@@ -39,6 +42,7 @@ LIBSRCS = \
        lib/draw.ml \
        lib/scrollmap.ml \
        lib/colormap.ml \
+       $(LEXERS) \
        lib/view.ml
 
 TESTSRCS = \
@@ -49,12 +53,8 @@ TESTSRCS = \
        tests/view_tests.ml \
        tests/scrollmap_tests.ml
 
-LEXERS = \
-       lib/lexers/lex_cpp.ml
-
 LIBOBJS = \
        $(LIBSRCS:.ml=.$(OBJEXT)) \
-       $(LEXERS:.ml=.$(OBJEXT)) \
     lib/x11_prims.o \
     lib/misc_prims.o \
     lib/utf8.o
diff --git a/deps.mk b/deps.mk
index dab969b0eb3dbfc631c1de16dd56ece3c8ac1ab8..a7d32787a10637efbe01aed86862b0febbb8658b 100644 (file)
--- a/deps.mk
+++ b/deps.mk
@@ -19,8 +19,8 @@ lib/rope.cmi :
 lib/scrollmap.cmo : lib/draw.cmi lib/buf.cmi lib/scrollmap.cmi lib/scrollmap.ml
 lib/scrollmap.cmx lib/scrollmap.o : lib/draw.cmi lib/draw.cmx lib/buf.cmi lib/buf.cmx lib/scrollmap.cmi lib/scrollmap.ml
 lib/scrollmap.cmi : lib/buf.cmi
-lib/view.cmo lib/view.cmi : lib/scrollmap.cmi lib/draw.cmi lib/buf.cmi lib/view.ml
-lib/view.cmx lib/view.o lib/view.cmi : lib/scrollmap.cmi lib/scrollmap.cmx lib/draw.cmi lib/draw.cmx lib/buf.cmi lib/buf.cmx lib/view.ml
+lib/view.cmo lib/view.cmi : lib/scrollmap.cmi lib/draw.cmi lib/colormap.cmi lib/buf.cmi lib/view.ml
+lib/view.cmx lib/view.o lib/view.cmi : lib/scrollmap.cmi lib/scrollmap.cmx lib/draw.cmi lib/draw.cmx lib/colormap.cmi lib/colormap.cmx lib/buf.cmi lib/buf.cmx lib/view.ml
 lib/x11.cmo lib/x11.cmi : lib/x11.ml
 lib/x11.cmx lib/x11.o lib/x11.cmi : lib/x11.ml
 tests/buf_tests.cmo tests/buf_tests.cmi : tests/buf_tests.ml
index f139e9e072cfe34787faa52b31003e7bf917a687..58fb5d84e22a4dea8dcd0061fa24d8b75b10d37d 100644 (file)
@@ -28,6 +28,19 @@ let iteri fn buf i =
 let iter fn buf i =
   iteri (fun i c -> (fn c)) buf i
 
+let make_lexfn buf =
+  let pos = ref 0 in
+  (fun bytebuf n ->
+    let count = ref 0 in
+    iteri (fun i c ->
+      Bytes.set bytebuf !count (Char.chr c);
+      incr count;
+      (!count >= n)
+    ) buf !pos;
+    pos := !pos + !count;
+    Printf.printf "count %d\n" !count;
+    !count)
+
 module Cursor = struct
   type csr = {
     mutable start : int;
index 9b8831b8347bceafb39c7ea47588e33cbe166242..52bb17ba9932874065a545516d01c413b9f44953 100644 (file)
@@ -52,3 +52,6 @@ val eol : t -> int -> int
 val is_at : dest -> t -> int -> bool
 val is_bol : t -> int -> bool
 val is_eol : t -> int -> bool
+
+val make_lexfn : t -> (bytes -> int -> int)
+
index eba97205e4eb9538a2fecf4619d97157f391630a..6740036b44be9d71d1beab852b45eb046263d982 100644 (file)
@@ -39,17 +39,21 @@ let set_color mapref lexbuf c =
   mapref := SpanSet.add span !mapref;
   ()
 
-let create scanfn fetchfn =
+let make scanfn fetchfn =
+  print_endline "generating colormap";
   let mapref = ref SpanSet.empty in
   try
     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
 
+let empty = SpanSet.empty
+
 let find pos set =
   let range = Span.({ start = pos; stop = pos; style = Normal }) in
   match (SpanSet.find_opt range set) with
index 24703b4310c4f6b1223dbe045280920836e142e5..d69128205e87897b75feb8fb14eacb3ffebff7c4 100644 (file)
@@ -8,7 +8,8 @@ type t
 
 type lexer = (style -> unit) -> Lexing.lexbuf -> unit
 
-val create : lexer -> (bytes -> int -> int) -> t
+val empty : t
+val make : lexer -> (bytes -> int -> int) -> t
 
 (*
 val from_channel : lexer -> in_channel -> t
index 2b19d1dd90117ecc4ef363910dddbdae7b40ed67..ae08c8629ddc056246e3c95ff784d9e4f433ee7f 100644 (file)
@@ -20,5 +20,5 @@ rule scan color = parse
   | typedef { color Type }
   | ln_cmt { color Comment }
   | blk_cmt { color Comment }
-  | _ { None }
+  | _
   | eof { raise Eof }
index fab1ed65f8f3f8a0fa9b8a9031e76b8a05e29a72..9c6cfe1850bf9a5d1537ed8f06e9935d2d341513 100644 (file)
@@ -1,11 +1,14 @@
 type t = {
   num : int;
   buf : Buf.t;
-  map : Scrollmap.t
+  map : Scrollmap.t;
+  clr : Colormap.t
 }
 
 let from_buffer buf width height =
-  { num = 0; buf = buf; map = Scrollmap.make buf width 0 }
+  { num = 0; buf = buf;
+    map = Scrollmap.make buf width 0;
+    clr = Colormap.make Lex_cpp.scan (Buf.make_lexfn buf) }
 
 let empty width height =
   from_buffer (Buf.empty) width height