From: Michael D. Lowis Date: Thu, 7 Dec 2017 02:17:42 +0000 (-0500) Subject: started integrating lexers X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=17de34a853f30c7e23671aebf178270a27575b23;p=archive%2Ftide-ocaml.git started integrating lexers --- diff --git a/Makefile b/Makefile index 143b170..73f80b3 100644 --- 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 dab969b..a7d3278 100644 --- 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 diff --git a/lib/buf.ml b/lib/buf.ml index f139e9e..58fb5d8 100644 --- a/lib/buf.ml +++ b/lib/buf.ml @@ -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; diff --git a/lib/buf.mli b/lib/buf.mli index 9b8831b..52bb17b 100644 --- a/lib/buf.mli +++ b/lib/buf.mli @@ -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) + diff --git a/lib/colormap.ml b/lib/colormap.ml index eba9720..6740036 100644 --- a/lib/colormap.ml +++ b/lib/colormap.ml @@ -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 diff --git a/lib/colormap.mli b/lib/colormap.mli index 24703b4..d691282 100644 --- a/lib/colormap.mli +++ b/lib/colormap.mli @@ -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 diff --git a/lib/lexers/lex_cpp.mll b/lib/lexers/lex_cpp.mll index 2b19d1d..ae08c86 100644 --- a/lib/lexers/lex_cpp.mll +++ b/lib/lexers/lex_cpp.mll @@ -20,5 +20,5 @@ rule scan color = parse | typedef { color Type } | ln_cmt { color Comment } | blk_cmt { color Comment } - | _ { None } + | _ | eof { raise Eof } diff --git a/lib/view.ml b/lib/view.ml index fab1ed6..9c6cfe1 100644 --- a/lib/view.ml +++ b/lib/view.ml @@ -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