]> git.mdlowis.com Git - archive/tide-hl.git/commitdiff
implemented driver and scanning loop
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 9 Mar 2018 03:19:40 +0000 (22:19 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 9 Mar 2018 03:19:40 +0000 (22:19 -0500)
deps.mk
main.ml

diff --git a/deps.mk b/deps.mk
index 856b14c348ab31682133741dedccad032032f8a8..3fa2278234e3727cb0370818ea0f7e734115401b 100644 (file)
--- a/deps.mk
+++ b/deps.mk
@@ -6,5 +6,5 @@ lex_ocaml.cmo lex_ocaml.cmi : colormap.cmi lex_ocaml.ml
 lex_ocaml.cmx lex_ocaml.o lex_ocaml.cmi : colormap.cmi colormap.cmx lex_ocaml.ml
 lex_ruby.cmo lex_ruby.cmi : colormap.cmi lex_ruby.ml
 lex_ruby.cmx lex_ruby.o lex_ruby.cmi : colormap.cmi colormap.cmx lex_ruby.ml
-main.cmo main.cmi : main.ml
-main.cmx main.o main.cmi : main.ml
+main.cmo main.cmi : lex_ruby.cmi lex_ocaml.cmi lex_cpp.cmi colormap.cmi main.ml
+main.cmx main.o main.cmi : lex_ruby.cmi lex_ruby.cmx lex_ocaml.cmi lex_ocaml.cmx lex_cpp.cmi lex_cpp.cmx colormap.cmi colormap.cmx main.ml
diff --git a/main.ml b/main.ml
index 3907fffcc048c86183ca3a5f243aa330771498e7..86d808e365cc61050a8cf19b533c71364a27bb16 100644 (file)
--- a/main.ml
+++ b/main.ml
@@ -1,17 +1,52 @@
 
-(*
-let make lexer =
-  let ctx = { lbuf = lexer.lexbuf; pos = 0; } in
-  (try while true do lexer.scanfn ctx lexer.lexbuf done
-   with Eof -> ());
-*)
+type filetype = {
+  syntax : Colormap.ctx -> Lexing.lexbuf -> unit;
+  names : string list;
+  exts : string list;
+}
 
-while true do
-  try
-    let chunk = really_input_string stdin (read_int ()) in
-    Printf.printf "chunk: '%s'\n" chunk;
+let filetypes = [
+  {
+    syntax = Lex_cpp.scan;
+    names  = [];
+    exts   = [".c"; ".h"; ".cpp"; ".hpp"; ".cc"; ".c++"; ".cxx"]
+  };
+  {
+    syntax = Lex_ruby.scan;
+    names  = ["Rakefile"; "rakefile"; "gpkgfile"];
+    exts   = [".rb"]
+  };
+  {
+    syntax = Lex_ocaml.scan;
+    names  = [];
+    exts   = [".ml"; ".mll"; ".mli"]
+  }
+]
+
+let pick_syntax path =
+  let name = Filename.basename path in
+  let ext = Filename.extension path in
+  let match_ftype ftype =
+    (List.exists ((=) name) ftype.names) ||
+    (List.exists ((=) ext) ftype.exts)
+  in
+  (List.find_opt match_ftype filetypes)
+
+let scan_string lexfn string =
+  let lbuf = Lexing.from_string string in
+  let ctx = Colormap.({ lbuf = lbuf; pos = 0; }) in
+  try while true do lexfn ctx lbuf done
+  with Colormap.Eof ->
+    Printf.printf "0,0,0\n";
     flush stdout
-  with
-    | Failure _ -> ()
-    | End_of_file -> exit 0
-done
+
+let rec scan_input lexfn =
+  try scan_string lexfn (really_input_string stdin (read_int ())) with
+  | Failure _ -> scan_input lexfn
+  | End_of_file -> ()
+
+let () =
+  if (Array.length Sys.argv) >= 2 then
+  match pick_syntax Sys.argv.(1) with
+  | Some ft -> scan_input ft.syntax
+  | None -> ()