LIBOBJS = \
$(LIBSRCS:.ml=.$(OBJEXT)) \
+ $(LEXERS:.ml=.$(OBJEXT)) \
lib/x11_prims.o \
lib/misc_prims.o \
lib/utf8.o
ocamlc $(OLDFLAGS) $(INCS) -o $@ $^
%.bin:
ocamlopt $(OLDFLAGS) $(INCS) -o $@ $^
-
-#.mly.ml :
-# ocamlyacc $(OYACCFLAGS) -o $@ $<
-#.mly.mli:
-# ocamlyacc $(OYACCFLAGS) -o $@ $<
lib/buf.cmi :
lib/cfg.cmo lib/cfg.cmi : lib/x11.cmi lib/cfg.ml
lib/cfg.cmx lib/cfg.o lib/cfg.cmi : lib/x11.cmi lib/x11.cmx lib/cfg.ml
-lib/colormap.cmo lib/colormap.cmi : lib/colormap.ml
-lib/colormap.cmx lib/colormap.o lib/colormap.cmi : lib/colormap.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
let normal = intvar "tide.colors.syntax.normal" 5
let comment = intvar "tide.colors.syntax.comment" 3
let constant = intvar "tide.colors.syntax.constant" 14
+ let keyword = intvar "tide.colors.syntax.keyword" 15
+ let typedef = intvar "tide.colors.syntax.typedef" 8
+
let number = intvar "tide.colors.syntax.number" 14
let boolean = intvar "tide.colors.syntax.boolean" 14
let float = intvar "tide.colors.syntax.float" 14
let string = intvar "tide.colors.syntax.string" 14
let char = intvar "tide.colors.syntax.character" 14
let preproc = intvar "tide.colors.syntax.preproc" 9
- let typedef = intvar "tide.colors.syntax.typedef" 8
- let keyword = intvar "tide.colors.syntax.keyword" 15
let statement = intvar "tide.colors.syntax.statement" 10
let procedure = intvar "tide.colors.syntax.function" 11
let variable = intvar "tide.colors.syntax.variable" 12
+open Lexing
+
exception Eof
+
type style = Normal | Comment | Constant | Keyword | Type
(*
String | Character | Number | Boolean
| Variable | Function | Keyword | Operator | PreProcessor | Type
| Statement | Special
*)
+
+module Span = struct
+ type t = { start : int; stop : int; style : style }
+ let compare a b =
+ if a.stop < b.start then -1
+ else if a.start > b.stop then 1
+ else 0
+end
+
+module SpanSet = Set.Make(Span)
+
+type t = SpanSet.t
+
+type lexer = (style -> unit) -> Lexing.lexbuf -> unit
+
+let get_color = function
+| Normal -> Cfg.Color.Syntax.normal
+| Comment -> Cfg.Color.Syntax.comment
+| Constant -> Cfg.Color.Syntax.constant
+| Keyword -> Cfg.Color.Syntax.keyword
+| Type -> Cfg.Color.Syntax.typedef
+
+let set_color mapref lexbuf c =
+ let span = Span.({
+ start = (lexeme_start lexbuf);
+ stop = (lexeme_end lexbuf);
+ style = c })
+ in
+ mapref := SpanSet.add span !mapref;
+ ()
+
+let create scanfn fetchfn =
+ 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
+ scanfn set_color lexbuf
+ done;
+ !mapref
+ with Eof -> !mapref
+
+let find pos set =
+ let range = Span.({ start = pos; stop = pos; style = Normal }) in
+ match (SpanSet.find_opt range set) with
+ | Some r -> get_color Span.(r.style)
+ | None -> get_color Normal
--- /dev/null
+open Lexing
+
+exception Eof
+
+type style = Normal | Comment | Constant | Keyword | Type
+
+type t
+
+type lexer = (style -> unit) -> Lexing.lexbuf -> unit
+
+val create : lexer -> (bytes -> int -> int) -> t
+
+(*
+val from_channel : lexer -> in_channel -> t
+val from_string : lexer -> string -> t
+val from_function : lexer -> (bytes -> int -> int) -> t
+*)
+
+val find : int -> t -> int
let tabsz = (xoff * tabwidth) in
csr.x <- (csr.startx + ((csr.x - csr.startx + tabsz) / tabsz * tabsz))
- let place_glyph csr glyph =
+ let place_glyph csr glyph clr =
let xoff = (glyph_width glyph) in
if (csr.x + xoff) > csr.width then (next_line csr);
- let _ = X11.draw_glyph Cfg.Color.palette.(5) glyph (csr.x, csr.y) in
+ let _ = X11.draw_glyph Cfg.Color.palette.(clr) glyph (csr.x, csr.y) in
csr.x <- csr.x + xoff
- let draw_glyph csr c =
+ let draw_glyph csr c clr =
match c with
| 0x0A -> next_line csr
| 0x0D -> ()
| 0x09 -> draw_tab csr
- | _ -> place_glyph csr (X11.get_glyph font c)
+ | _ -> place_glyph csr (X11.get_glyph font c) clr
let next_glyph csr c =
let glyph = (X11.get_glyph font c) in
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;
+ draw_glyph csr c Cfg.Color.Syntax.normal;
num := !num + 1;
has_next_line csr
in
val restart : t -> int -> int -> t
val next_line : t -> unit
val has_next_line : t -> bool
- val draw_glyph : t -> int -> unit
+ val draw_glyph : t -> int -> int -> unit
val next_glyph : t -> int -> bool
end
--- /dev/null
+# change indentation
+'s/^/ /g' # increase indentation
+'s/^ //g' # decrease indentation
+
+# change comment
+'s,^\/\/[ ]\?,,g' # remove C comment
+'s,^#[ ]\?,,g' # remove script comment
+
+'s,^,\/\/,g' # add C comment
+'s,^,#,g' # add script comment
+
+'s/\n\n\n+/\n\n/g' # remove redundant newlines, keep max two
+'s/[ ]+$//g' # remove trailing whitespace
+
+'s/->/./g' # pointer to struct
+'s/\./->/g' # struct to pointer
+
+s,//[^\n]*\n,,g # strip C // comments from selection
+s,/\*.*\*/\n,,g # strip C /* */ 1-line comments from selection
+t "scratch" 0 # copy selection to scratch file