Update file extensions for new matchers.

This commit is contained in:
Rijnard van Tonder 2019-04-23 19:27:29 -04:00 committed by GitHub
parent d86ef120c2
commit c120778228
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 30 deletions

View File

@ -98,6 +98,8 @@ module Ruby = struct
; Until_newline "#"
]
end
include Matcher.Make(Syntax)
end
module Elixir = struct
@ -223,6 +225,8 @@ module Php = struct
[ Until_newline "#"
]
end
include Matcher.Make(Syntax)
end
module Lisp = struct
@ -236,6 +240,8 @@ module Lisp = struct
; Nested_multiline ("#|", "|#")
]
end
include Matcher.Make(Syntax)
end
module Go = struct

View File

@ -409,22 +409,38 @@ let base_command_parameters : (unit -> 'result) Command.Param.t =
| false, _ -> Paths (parse_source_directories ?file_extensions target_directory)
in
let matcher =
let default = (module Matchers.Generic : Matchers.Matcher) in
let (module M : Matchers.Matcher) =
match file_extensions with
| None | Some [] -> default
| None | Some [] -> (module Matchers.Generic)
| Some (hd::_) ->
match hd with
| ".c" | ".h" | ".cc" | ".cpp" | ".hpp" -> (module Matchers.C : Matchers.Matcher)
| ".py" -> (module Matchers.Python : Matchers.Matcher)
| ".go" -> (module Matchers.Go : Matchers.Matcher)
| ".sh" -> (module Matchers.Bash : Matchers.Matcher)
| ".html" -> (module Matchers.Html : Matchers.Matcher)
| ".tex" -> (module Matchers.Latex : Matchers.Matcher)
| _ -> default
| ".c" | ".h" | ".cc" | ".cpp" | ".hpp" -> (module Matchers.C)
| ".clj" -> (module Matchers.Clojure)
| ".css" -> (module Matchers.CSS)
| ".dart" -> (module Matchers.Dart)
| ".elm" -> (module Matchers.Elm)
| ".erl" -> (module Matchers.Erlang)
| ".ex" -> (module Matchers.Elixir)
| ".html" | ".xml" -> (module Matchers.Html)
| ".hs" -> (module Matchers.Haskell)
| ".go" -> (module Matchers.Go)
| ".java" -> (module Matchers.Java)
| ".js" | ".ts" -> (module Matchers.Javascript)
| ".ml" | ".mli" -> (module Matchers.OCaml)
| ".php" -> (module Matchers.Php)
| ".py" -> (module Matchers.Python)
| ".rb" -> (module Matchers.Ruby)
| ".rs" -> (module Matchers.Rust)
| ".s" | ".asm" -> (module Matchers.Assembly)
| ".scala" -> (module Matchers.Scala)
| ".sql" -> (module Matchers.SQL)
| ".sh" -> (module Matchers.Bash)
| ".swift" -> (module Matchers.Swift)
| ".tex" | ".bib" -> (module Matchers.Latex)
| _ -> (module Matchers.Generic)
in
let in_place = if is_some zip_file then false else in_place in
run matcher sources specifications sequential number_of_workers stdin json_pretty json_lines verbose match_timeout in_place
run (module M) sources specifications sequential number_of_workers stdin json_pretty json_lines verbose match_timeout in_place
]
let default_command =
@ -433,4 +449,5 @@ let default_command =
let () =
Scheduler.Daemon.check_entry_point ();
default_command
|> Command.run

View File

@ -44,25 +44,35 @@ type json_rewrite_result =
}
[@@deriving yojson]
let matcher_of_file_extension =
function
| ".c" | ".h" | ".cc" | ".cpp" | ".hpp" -> (module Matchers.C : Matchers.Matcher)
| ".py" -> (module Matchers.Python : Matchers.Matcher)
| ".go" -> (module Matchers.Go : Matchers.Matcher)
| ".sh" -> (module Matchers.Bash : Matchers.Matcher)
| ".html" -> (module Matchers.Html : Matchers.Matcher)
| ".tex" -> (module Matchers.Html : Matchers.Matcher)
| _ -> (module Matchers.Generic : Matchers.Matcher)
let matcher_of_language =
function
| "c" | "c++" -> (module Matchers.C : Matchers.Matcher)
| "pyhon" -> (module Matchers.Python : Matchers.Matcher)
| "go" -> (module Matchers.Go : Matchers.Matcher)
| "bash" -> (module Matchers.Bash : Matchers.Matcher)
| "html" -> (module Matchers.Html : Matchers.Matcher)
| "latex" -> (module Matchers.Latex : Matchers.Matcher)
| _ -> (module Matchers.Generic : Matchers.Matcher)
let matcher_of_file_extension extension =
let (module M : Matchers.Matcher) =
match extension with
| ".c" | ".h" | ".cc" | ".cpp" | ".hpp" -> (module Matchers.C)
| ".clj" -> (module Matchers.Clojure)
| ".css" -> (module Matchers.CSS)
| ".dart" -> (module Matchers.Dart)
| ".elm" -> (module Matchers.Elm)
| ".erl" -> (module Matchers.Erlang)
| ".ex" -> (module Matchers.Elixir)
| ".html" | ".xml" -> (module Matchers.Html)
| ".hs" -> (module Matchers.Haskell)
| ".go" -> (module Matchers.Go)
| ".java" -> (module Matchers.Java)
| ".js" | ".ts" -> (module Matchers.Javascript)
| ".ml" | ".mli" -> (module Matchers.OCaml)
| ".php" -> (module Matchers.Php)
| ".py" -> (module Matchers.Python)
| ".rb" -> (module Matchers.Ruby)
| ".rs" -> (module Matchers.Rust)
| ".s" | ".asm" -> (module Matchers.Assembly)
| ".scala" -> (module Matchers.Scala)
| ".sql" -> (module Matchers.SQL)
| ".sh" -> (module Matchers.Bash)
| ".swift" -> (module Matchers.Swift)
| ".tex" | ".bib" -> (module Matchers.Latex)
| _ -> (module Matchers.Generic)
in
(module M : Matchers.Matcher)
let get_matches (module Matcher : Matchers.Matcher) source match_template =
let configuration = Configuration.create ~match_kind:Fuzzy () in