mirror of
https://github.com/comby-tools/comby.git
synced 2024-09-11 13:25:36 +03:00
rename to in_place_substitutions
This commit is contained in:
parent
489f3a8c94
commit
455fb95e29
@ -11,13 +11,13 @@ type match_context_replacement =
|
||||
|
||||
type result =
|
||||
{ rewritten_source : string
|
||||
; contextual_substitutions : match_context_replacement list
|
||||
; in_place_substitutions : match_context_replacement list
|
||||
}
|
||||
[@@deriving yojson]
|
||||
|
||||
let empty_result =
|
||||
{ rewritten_source = ""
|
||||
; contextual_substitutions = []
|
||||
; in_place_substitutions = []
|
||||
}
|
||||
[@@deriving yojson]
|
||||
|
||||
@ -40,7 +40,7 @@ let substitute_match_contexts (matches: Match.t list) source replacements =
|
||||
let rewritten_source = Rewrite_template.substitute rewrite_template environment |> fst in
|
||||
let offsets = Rewrite_template.get_offsets_for_holes rewrite_template (Environment.vars environment) in
|
||||
let offsets = Rewrite_template.get_offsets_after_substitution offsets environment in
|
||||
let contextual_substitutions =
|
||||
let in_place_substitutions =
|
||||
List.map2_exn replacements offsets ~f:(fun replacement (_uid, offset) ->
|
||||
let match_start = { Location.default with offset } in
|
||||
let offset = offset + String.length replacement.replacement_content in
|
||||
@ -49,7 +49,7 @@ let substitute_match_contexts (matches: Match.t list) source replacements =
|
||||
{ replacement with range })
|
||||
in
|
||||
{ rewritten_source
|
||||
; contextual_substitutions
|
||||
; in_place_substitutions
|
||||
}
|
||||
|
||||
(*
|
||||
@ -108,5 +108,5 @@ let all ?source ~rewrite_template matches : result option =
|
||||
|> List.map ~f:(substitute_in_rewrite_template rewrite_template)
|
||||
|> List.map ~f:(fun { replacement_content; _ } -> replacement_content)
|
||||
|> String.concat ~sep:"\n"
|
||||
|> (fun rewritten_source -> { rewritten_source; contextual_substitutions = [] })
|
||||
|> (fun rewritten_source -> { rewritten_source; in_place_substitutions = [] })
|
||||
|> Option.some
|
||||
|
@ -9,7 +9,7 @@ type match_context_replacement =
|
||||
|
||||
type result =
|
||||
{ rewritten_source : string
|
||||
; contextual_substitutions : match_context_replacement list
|
||||
; in_place_substitutions : match_context_replacement list
|
||||
}
|
||||
[@@deriving yojson]
|
||||
|
||||
|
@ -98,7 +98,7 @@ let process_single_source matcher verbose configuration source specification mat
|
||||
|> fun matches ->
|
||||
if matches = [] then
|
||||
(* If there are no matches, return the original source (for editor support). *)
|
||||
Some (Some (Rewrite.{ rewritten_source = input_text; contextual_substitutions = [] }), [])
|
||||
Some (Some (Rewrite.{ rewritten_source = input_text; in_place_substitutions = [] }), [])
|
||||
else
|
||||
Some (rewrite rewrite_template rewrite_rule input_text matches, matches)
|
||||
in
|
||||
@ -110,8 +110,8 @@ let process_single_source matcher verbose configuration source specification mat
|
||||
in
|
||||
result
|
||||
|> function
|
||||
| Some (Some { rewritten_source; contextual_substitutions }, matches) ->
|
||||
Rewritten (contextual_substitutions, rewritten_source, List.length matches)
|
||||
| Some (Some { rewritten_source; in_place_substitutions }, matches) ->
|
||||
Rewritten (in_place_substitutions, rewritten_source, List.length matches)
|
||||
| Some (None, _)
|
||||
| None -> Nothing
|
||||
with
|
||||
|
@ -55,7 +55,7 @@ let%expect_test "comments_in_string_literals_should_not_be_treated_as_comments_b
|
||||
| None -> print_string "BROKEN EXPECT");
|
||||
[%expect_exact {|{
|
||||
"rewritten_source": "123433312343331122",
|
||||
"contextual_substitutions": [
|
||||
"in_place_substitutions": [
|
||||
{
|
||||
"range": {
|
||||
"start": { "offset": 0, "line": -1, "column": -1 },
|
||||
@ -103,7 +103,7 @@ let%expect_test "comments_in_string_literals_should_not_be_treated_as_comments_b
|
||||
| None -> print_string "BROKEN EXPECT");
|
||||
[%expect_exact {|{
|
||||
"rewritten_source": "123433312343331122;123433312343331122;",
|
||||
"contextual_substitutions": [
|
||||
"in_place_substitutions": [
|
||||
{
|
||||
"range": {
|
||||
"start": { "offset": 19, "line": -1, "column": -1 },
|
||||
@ -184,7 +184,7 @@ let%expect_test "multiple_contextual_substitutions" =
|
||||
| None -> print_string "BROKEN EXPECT");
|
||||
[%expect_exact {|{
|
||||
"rewritten_source": "xxxx bar xxxx",
|
||||
"contextual_substitutions": [
|
||||
"in_place_substitutions": [
|
||||
{
|
||||
"range": {
|
||||
"start": { "offset": 9, "line": -1, "column": -1 },
|
||||
|
Loading…
Reference in New Issue
Block a user