Skip to content

Commit

Permalink
factor out replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
rvantonder committed May 29, 2019
1 parent 0c2c43f commit fb28037
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 49 deletions.
1 change: 1 addition & 0 deletions lib/comby.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Language = Language
module Matchers = Matchers
module Match = Match
module Replacement = Replacement
module Rewriter = Rewriter
module Statistics = Statistics
1 change: 1 addition & 0 deletions lib/comby.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Language = Language
module Matchers = Matchers
module Match = Match
module Replacement = Replacement
module Rewriter = Rewriter
module Statistics = Statistics
1 change: 1 addition & 0 deletions lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
mparser
mparser.pcre
comby.matchers
comby.replacement
comby.rewriter
comby.match
comby.language
Expand Down
5 changes: 2 additions & 3 deletions lib/matchers/matchers.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include Languages

module Configuration = Configuration

module type Matcher = Types.Matcher.S

include Languages
5 changes: 2 additions & 3 deletions lib/matchers/matchers.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include module type of Languages

module Configuration = Configuration

module type Matcher = Types.Matcher.S

include module type of Languages
5 changes: 5 additions & 0 deletions lib/replacement/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(library
(name replacement)
(public_name comby.replacement)
(preprocess (pps ppx_deriving.show ppx_deriving.eq ppx_sexp_conv ppx_sexp_message ppx_deriving_yojson bisect_ppx -conditional -no-comment-parsing))
(libraries comby.parsers comby.match ppxlib core mparser mparser.pcre yojson ppx_deriving_yojson ppx_deriving_yojson.runtime))
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/rewriter/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
(name rewriter)
(public_name comby.rewriter)
(preprocess (pps ppx_deriving.show ppx_sexp_conv ppx_deriving_yojson bisect_ppx -conditional -no-comment-parsing))
(libraries comby.matchers ppxlib core core.uuid))
(libraries comby.matchers comby.replacement ppxlib core core.uuid))
14 changes: 0 additions & 14 deletions lib/rewriter/replacement_context.ml

This file was deleted.

14 changes: 0 additions & 14 deletions lib/rewriter/replacement_context.mli

This file was deleted.

1 change: 0 additions & 1 deletion lib/rewriter/rewriter.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
module Replacement = Replacement
module Rewrite = Rewrite
module Rewrite_template = Rewrite_template
1 change: 0 additions & 1 deletion lib/rewriter/rewriter.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
module Replacement = Replacement
module Rewrite = Rewrite
module Rewrite_template = Rewrite_template
8 changes: 4 additions & 4 deletions src/command_configuration.ml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module Printer = struct
}
| Replacements of
{ source_path : string option
; replacements : Rewriter.Replacement.t list
; replacements : Replacement.t list
; result : string
; source_content : string
}
Expand Down Expand Up @@ -168,7 +168,7 @@ module Printer = struct
val convert : output_options -> replacement_output


val print : replacement_output -> string option -> Rewriter.Replacement.t list -> string -> string -> unit
val print : replacement_output -> string option -> Replacement.t list -> string -> string -> unit

end = struct

Expand All @@ -181,13 +181,13 @@ module Printer = struct

(* only used in rewrite *)
let get_json_rewrites replacements result =
let value = `List (List.map ~f:Rewriter.Replacement.to_yojson replacements) in
let value = `List (List.map ~f:Replacement.to_yojson replacements) in
`Assoc [("uri", `Null); ("rewritten_source", `String result); ("in_place_substitutions", value)]

(* only used in rewrite *)
let json_rewrites replacements (path: string) (diff: string) result =
let value =
`List (List.map ~f:Rewriter.Replacement.to_yojson replacements) in
`List (List.map ~f:Replacement.to_yojson replacements) in
`Assoc
[ ("uri", `String path)
; ("rewritten_source", `String result)
Expand Down
2 changes: 1 addition & 1 deletion src/command_configuration.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Printer : sig
}
| Replacements of
{ source_path : string option
; replacements : Rewriter.Replacement.t list
; replacements : Replacement.t list
; result : string
; source_content : string
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type json_result =

type processed_source_result =
| Matches of (Match.t list * int)
| Replacement of (Rewriter.Replacement.t list * string * int)
| Replacement of (Replacement.t list * string * int)
| Nothing

let verbose_out_file = "/tmp/comby.out"
Expand Down Expand Up @@ -93,7 +93,7 @@ let process_single_source
|> fun matches ->
if matches = [] then
(* If there are no matches, return the original source (for editor support). *)
Some (Some (Rewriter.Replacement.{ rewritten_source = input_text; in_place_substitutions = [] }), [])
Some (Some (Replacement.{ rewritten_source = input_text; in_place_substitutions = [] }), [])
else
Some (rewrite rewrite_template rewrite_rule input_text matches, matches)
in
Expand Down
4 changes: 2 additions & 2 deletions src/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type json_match_result =

type json_rewrite_result =
{ rewritten_source : string
; in_place_substitutions : Rewriter.Replacement.t list
; in_place_substitutions : Replacement.t list
; id : int
}
[@@deriving yojson]
Expand Down Expand Up @@ -108,7 +108,7 @@ let perform_match request =
if debug then Format.printf "Result (400) %s@." error;
respond ~code:(`Code 400) (`String error)

let rewrite_to_json id ({ rewritten_source; in_place_substitutions } : Rewriter.Replacement.result) =
let rewrite_to_json id ({ rewritten_source; in_place_substitutions } : Replacement.result) =
Format.sprintf "%s"
(Yojson.Safe.pretty_to_string
(json_rewrite_result_to_yojson
Expand Down
6 changes: 3 additions & 3 deletions test/test_rewrite_parts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let%expect_test "comments_in_string_literals_should_not_be_treated_as_comments_b
all match_template source
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some rewrite_result -> print_string (Yojson.Safe.pretty_to_string (Rewriter.Replacement.result_to_yojson rewrite_result))
| Some rewrite_result -> print_string (Yojson.Safe.pretty_to_string (Replacement.result_to_yojson rewrite_result))
| None -> print_string "BROKEN EXPECT");
[%expect_exact {|{
"rewritten_source": "123433312343331122",
Expand Down Expand Up @@ -99,7 +99,7 @@ let%expect_test "comments_in_string_literals_should_not_be_treated_as_comments_b
all match_template source
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some rewrite_result -> print_string (Yojson.Safe.pretty_to_string (Rewriter.Replacement.result_to_yojson rewrite_result))
| Some rewrite_result -> print_string (Yojson.Safe.pretty_to_string (Replacement.result_to_yojson rewrite_result))
| None -> print_string "BROKEN EXPECT");
[%expect_exact {|{
"rewritten_source": "123433312343331122;123433312343331122;",
Expand Down Expand Up @@ -180,7 +180,7 @@ let%expect_test "multiple_contextual_substitutions" =
all match_template source
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some rewrite_result -> print_string (Yojson.Safe.pretty_to_string (Rewriter.Replacement.result_to_yojson rewrite_result))
| Some rewrite_result -> print_string (Yojson.Safe.pretty_to_string (Replacement.result_to_yojson rewrite_result))
| None -> print_string "BROKEN EXPECT");
[%expect_exact {|{
"rewritten_source": "xxxx bar xxxx",
Expand Down

0 comments on commit fb28037

Please sign in to comment.