From: Michael D. Lowis Date: Fri, 8 Dec 2017 04:19:43 +0000 (-0500) Subject: first pass at syntax highlighting for c. most things work except block comments X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=ab9c1fc39d5d5a8f4a7208f01723e84d681919e6;p=archive%2Ftide-ocaml.git first pass at syntax highlighting for c. most things work except block comments --- diff --git a/Makefile b/Makefile index 73f80b3..392a124 100644 --- 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 a7d3278..d1e54dd 100644 --- 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 diff --git a/lib/buf.ml b/lib/buf.ml index 58fb5d8..d40bcfc 100644 --- a/lib/buf.ml +++ b/lib/buf.ml @@ -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 diff --git a/lib/colormap.ml b/lib/colormap.ml index 6740036..0169632 100644 --- a/lib/colormap.ml +++ b/lib/colormap.ml @@ -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 diff --git a/lib/draw.ml b/lib/draw.ml index 23f66ac..c140ef4 100644 --- a/lib/draw.ml +++ b/lib/draw.ml @@ -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 diff --git a/lib/draw.mli b/lib/draw.mli index e1847c2..517ee34 100644 --- a/lib/draw.mli +++ b/lib/draw.mli @@ -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 diff --git a/lib/lexers/lex_cpp.mll b/lib/lexers/lex_cpp.mll index ae08c86..158851e 100644 --- a/lib/lexers/lex_cpp.mll +++ b/lib/lexers/lex_cpp.mll @@ -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 } diff --git a/lib/view.ml b/lib/view.ml index 9c6cfe1..835f587 100644 --- a/lib/view.ml +++ b/lib/view.ml @@ -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 = diff --git a/lib/x11_prims.c b/lib/x11_prims.c index 2e03ef0..316824a 100644 --- a/lib/x11_prims.c +++ b/lib/x11_prims.c @@ -108,6 +108,7 @@ CAMLprim value x11_draw_rect(value rect) { #define _XOPEN_SOURCE 700 #include #include +#define printf(...) ((void)0) uint64_t getmillis(void) { struct timespec time;