mirror of
https://github.com/comby-tools/comby.git
synced 2024-09-11 13:25:36 +03:00
Option -matcher to force matcher and ignore file extensions
This commit is contained in:
parent
3df17927a8
commit
dc4b4b3b88
@ -1,4 +1,4 @@
|
||||
let experimental = true
|
||||
let experimental = false
|
||||
|
||||
module Text = struct
|
||||
module Syntax = struct
|
||||
|
10
src/main.ml
10
src/main.ml
@ -301,6 +301,7 @@ let base_command_parameters : (unit -> 'result) Command.Param.t =
|
||||
and directory_depth = flag "depth" (optional int) ~doc:"n Depth to recursively descend into directories"
|
||||
and specification_directories = flag "templates" (optional (Arg_type.comma_separated string)) ~doc:"path CSV of directories containing templates"
|
||||
and file_extensions = flag "extensions" ~aliases:["e"; "file-extensions"; "f"] (optional (Arg_type.comma_separated string)) ~doc:"extensions Comma-separated extensions to include, like \".go\" or \".c,.h\". It is just a file suffix, so you can use it to match whole file names like \"main.go\""
|
||||
and override_matcher = flag "matcher" ~aliases:["m"] (optional string) ~doc:"extension Use this matcher on all files regardless of their file extension"
|
||||
and zip_file = flag "zip" ~aliases:["z"] (optional string) ~doc:"zipfile A zip file containing files to rewrite"
|
||||
and json_pretty = flag "json-pretty" no_arg ~doc:"Output pretty JSON format"
|
||||
and json_lines = flag "json-lines" no_arg ~doc:"Output JSON line format"
|
||||
@ -366,9 +367,12 @@ let base_command_parameters : (unit -> 'result) Command.Param.t =
|
||||
in
|
||||
fun () ->
|
||||
let matcher =
|
||||
match file_extensions with
|
||||
| None | Some [] -> Matchers.select_with_extension ".generic"
|
||||
| Some (extension::_) -> Matchers.select_with_extension extension
|
||||
if Option.is_some override_matcher then
|
||||
Matchers.select_with_extension (Option.value_exn override_matcher)
|
||||
else
|
||||
match file_extensions with
|
||||
| None | Some [] -> Matchers.select_with_extension ".generic"
|
||||
| Some (extension::_) -> Matchers.select_with_extension extension
|
||||
in
|
||||
run matcher configuration
|
||||
]
|
||||
|
@ -840,4 +840,39 @@ let%expect_test "dir_depth_option" =
|
||||
+++ example/src/depth-1/depth-2/depth-2.c
|
||||
@@ -1,1 +1,1 @@
|
||||
-int depth_2() {}
|
||||
+int correct_depth_2() {} |}];
|
||||
+int correct_depth_2() {} |}]
|
||||
|
||||
let%expect_test "matcher_override" =
|
||||
let source = "hello world" in
|
||||
let src_dir = "example" ^/ "src" in
|
||||
let command_args = Format.sprintf "'(' '_unbalanced_match_' main.c -sequential -d %s -matcher .txt -diff" src_dir in
|
||||
let command = Format.sprintf "%s %s" binary_path command_args in
|
||||
let result =
|
||||
let rec rerun () =
|
||||
try
|
||||
read_source_from_stdin command source
|
||||
with
|
||||
| Unix.Unix_error (EINTR, _, _) -> rerun ()
|
||||
in
|
||||
rerun ()
|
||||
in
|
||||
print_string result;
|
||||
[%expect{|
|
||||
--- example/src/ignore-me/main.c
|
||||
+++ example/src/ignore-me/main.c
|
||||
@@ -1,1 +1,1 @@
|
||||
-int main() {}
|
||||
+int main_unbalanced_match_) {}
|
||||
--- example/src/main.c
|
||||
+++ example/src/main.c
|
||||
@@ -1,1 +1,1 @@
|
||||
-int main() {}
|
||||
+int main_unbalanced_match_) {} |}];
|
||||
|
||||
let source = "hello world" in
|
||||
let src_dir = "example" ^/ "src" in
|
||||
let command_args = Format.sprintf "'(' '_unbalanced_match_' main.c -sequential -d %s -diff" src_dir in
|
||||
let command = Format.sprintf "%s %s" binary_path command_args in
|
||||
read_source_from_stdin command source
|
||||
|> print_string;
|
||||
[%expect{| |}]
|
||||
|
@ -100,13 +100,12 @@ let%expect_test "ocaml_complex_blocks_with_same_end" =
|
||||
[%expect_exact {|
|
||||
-Body->match x with
|
||||
| _ ->
|
||||
let module M = struct type t end
|
||||
begin
|
||||
begin
|
||||
let module M = struct type t<-Body-
|
||||
-Body->begin
|
||||
match y with
|
||||
| _ -> ()
|
||||
| _ -> ()<-Body-
|
||||
end
|
||||
end<-Body-
|
||||
end
|
||||
|}]
|
||||
|
||||
(* FIXME(#35): "before" triggers "for" block *)
|
||||
@ -125,7 +124,14 @@ end
|
||||
let rewrite_template = {|-Block->:[1]<-Block-|} in
|
||||
|
||||
run (module Matchers.Ruby) source match_template rewrite_template;
|
||||
[%expect_exact {|No matches.|}]
|
||||
[%expect_exact {|
|
||||
-Block->ActionController::Base
|
||||
before_filter :generate_css_from_less
|
||||
|
||||
def generate_css_from_less
|
||||
Less::More.generate_all<-Block-
|
||||
end
|
||||
|}]
|
||||
|
||||
|
||||
let%expect_test "erlang_blocks" =
|
||||
@ -134,4 +140,4 @@ let%expect_test "erlang_blocks" =
|
||||
let rewrite_template = {|-Block->:[rest]<-Block-|} in
|
||||
|
||||
run (module Matchers.Erlang) source match_template rewrite_template;
|
||||
[%expect_exact {|Big = -Block->-> if X > 10 -> true; true -> false end<-Block-.|}]
|
||||
[%expect_exact {|Big = -Block->-> if X > 10 -> true; true -> false<-Block- end.|}]
|
||||
|
Loading…
Reference in New Issue
Block a user