add nested matching (#236)

This commit is contained in:
Rijnard van Tonder 2021-02-06 22:04:45 -07:00 committed by GitHub
parent 4c7d6364aa
commit 8d9e75fe36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 486 additions and 150 deletions

View File

@ -14,6 +14,10 @@ type t = Ast.t
type result = bool * environment option
type options = Options.t
let options = Options.of_rule
let sat = fst
let result_env = snd
@ -53,6 +57,7 @@ let rec apply
function
| True -> true, Some env
| False -> false, Some env
| Option _ -> true, Some env
| Equal (Variable var, String value)
| Equal (String value, Variable var) ->
equal_in_environment var value env
@ -76,7 +81,7 @@ let rec apply
| String template ->
begin
let configuration = match_configuration_of_syntax template in
Matcher.all ~configuration ~template ~source |> function
Matcher.all ~configuration ~template ~source () |> function
| [] -> None
| matches ->
(* merge environments. overwrite behavior is undefined *)
@ -128,7 +133,7 @@ let rec apply
let result =
Environment.lookup env variable >>= fun source ->
let configuration = Configuration.create ~match_kind:Fuzzy () in
let matches = Matcher.all ~configuration ~template ~source in
let matches = Matcher.all ~configuration ~template ~source () in
let source = if substitute_in_place then Some source else None in
let result = Rewrite.all ?source ~rewrite_template matches in
match result with
@ -181,6 +186,7 @@ let create rule =
in
let true' = spaces >> string Syntax.true' << spaces |>> fun _ -> True in
let false' = spaces >> string Syntax.false' << spaces |>> fun _ -> False in
let option_parser = spaces >> string Syntax.option_nested << spaces |>> fun _ -> Option "nested" in
let rec expression_parser s =
choice
[ match_pattern_parser
@ -189,6 +195,7 @@ let create rule =
; attempt operator_parser
; true'
; false'
; option_parser
]
s
and match_pattern_parser s =
@ -231,4 +238,4 @@ let create rule =
in
match parse_string rule_parser rule () with
| Success rule -> Ok rule
| Failed (msg, _) -> Or_error.error_string msg
| Failed (error, _) -> Or_error.error_string error

View File

@ -11,6 +11,7 @@ type antecedent = atom
type expression =
| True
| False
| Option of string
| Equal of atom * atom
| Not_equal of atom * atom
| Match of atom * (antecedent * consequent) list

View File

@ -13,6 +13,10 @@ type t = Ast.t
type result = bool * environment option
type options = Options.t
let options = Options.of_rule
let (|>>) p f =
p >>= fun x -> return (f x)
@ -55,6 +59,7 @@ let rec apply
function
| True -> true, Some env
| False -> false, Some env
| Option _ -> true, Some env
| Equal (Variable var, String value)
| Equal (String value, Variable var) ->
equal_in_environment var value env
@ -78,7 +83,7 @@ let rec apply
| String template ->
begin
let configuration = match_configuration_of_syntax template in
Matcher.all ~configuration ~template ~source |> function
Matcher.all ~configuration ~template ~source () |> function
| [] -> None
| matches ->
(* merge environments. overwrite behavior is undefined *)
@ -130,7 +135,7 @@ let rec apply
let result =
Environment.lookup env variable >>= fun source ->
let configuration = Configuration.create ~match_kind:Fuzzy () in
let matches = Matcher.all ~configuration ~template ~source in
let matches = Matcher.all ~configuration ~template ~source () in
let source = if substitute_in_place then Some source else None in
let result = Rewrite.all ?source ~rewrite_template matches in
match result with
@ -196,6 +201,7 @@ let create rule =
in
let true' = spaces *> string Syntax.true' <* spaces |>> fun _ -> True in
let false' = spaces *> string Syntax.false' <* spaces |>> fun _ -> False in
let option_parser = spaces *> string Syntax.option_nested <* spaces |>> fun _ -> Option "nested" in
let expression_parser =
fix (fun expression_parser ->
let match_pattern_parser =
@ -229,6 +235,7 @@ let create rule =
; operator_parser
; true'
; false'
; option_parser
])
in
let rule_parser =
@ -239,5 +246,5 @@ let create rule =
<* end_of_input
in
match parse_string rule_parser rule with
| Ok rule -> Or_error.return rule
| Ok rule -> Ok rule
| Error error -> Or_error.error_string error

10
lib/language/options.ml Normal file
View File

@ -0,0 +1,10 @@
open Core
type t =
{ nested : bool
}
let of_rule (rule : Ast.t) : t =
List.fold rule ~init:{ nested = false } ~f:(fun acc -> function
| Option name when String.(name = Syntax.option_nested) -> { nested = true }
| _ -> acc)

5
lib/language/options.mli Normal file
View File

@ -0,0 +1,5 @@
type t =
{ nested : bool
}
val of_rule : Ast.t -> t

View File

@ -7,5 +7,6 @@ let variable_left_delimiter = ":["
let variable_right_delimiter = "]"
let true' = "true"
let false' = "false"
let option_nested = "nested"
let pipe_operator = "|"
let arrow = "->"

View File

@ -9,7 +9,11 @@ type t = Ast.t
type result = bool * environment option
type options = Options.t
module type Engine = sig
val options : t -> Options.t
val sat : result -> bool
val result_env : result -> environment option

View File

@ -1056,46 +1056,110 @@ module Make (Syntax : Syntax.S) (Info : Info.S) = struct
in
first' shift p source
let all ?configuration ~template ~source:original_source : Match.t list =
let open Or_error in
depth := (-1);
configuration_ref := Option.value configuration ~default:!configuration_ref;
let make_result = function
| Ok ok -> ok
| Error _ -> []
in
make_result @@ begin
to_template template >>= fun p ->
let p =
if String.is_empty template then
MParser.(eof >> return Unit)
else
p
let all ?configuration ?(nested = false) ~template ~source:original_source () : Match.t list =
let rec aux_all ?configuration ?(nested = false) ~template ~source:original_source () =
let open Or_error in
depth := (-1);
configuration_ref := Option.value configuration ~default:!configuration_ref;
let make_result = function
| Ok ok -> ok
| Error _ -> []
in
let rec aux acc shift =
match first' shift p original_source with
| Ok ({range = { match_start; match_end; _ }; _} as result) ->
let shift = match_end.offset in
let shift, matched =
if match_start.offset = match_end.offset then
match_start.offset + 1, "" (* advance one if the matched content is the empty string *)
else
shift, extract_matched_text original_source match_start match_end
in
if debug then Format.printf "Extracted matched: %s" matched;
let result = { result with matched } in
if shift >= String.length original_source then
result :: acc
make_result @@ begin
to_template template >>= fun p ->
let p =
if String.is_empty template then
MParser.(eof >> return Unit)
else
aux (result :: acc) shift
| Error _ -> acc
p
in
let rec aux acc shift =
match first' shift p original_source with
| Ok ({range = { match_start; match_end; _ }; _} as result) ->
let shift = match_end.offset in
let shift, matched =
if match_start.offset = match_end.offset then
match_start.offset + 1, "" (* advance one if the matched content is the empty string *)
else
shift, extract_matched_text original_source match_start match_end
in
if debug then Format.printf "Extracted matched: %s" matched;
let result = { result with matched } in
if shift >= String.length original_source then
result :: acc
else
aux (result :: acc) shift
| Error _ ->
acc
in
let matches = aux [] 0 |> List.rev in
if nested then
return ((compute_nested_matches ?configuration ~nested template matches) @ matches)
else
return matches
end
and compute_nested_matches ?configuration ?nested template matches =
let rec aux acc matches =
match (matches : Match.t list) with
| [] -> acc
| { environment; _ }::rest ->
List.fold ~init:acc (Environment.vars environment) ~f:(fun acc v ->
let source_opt = Environment.lookup environment v in
match source_opt with
| Some source ->
let nested_matches =
match first ?configuration template source with
| Ok { matched; _ } when String.(matched <> source) ->
if String.(matched = "") && String.length source > 1 then
let matches = aux_all ?configuration ?nested ~template ~source () in
let { match_start = ms; _ } = Option.value_exn (Environment.lookup_range environment v) in
List.map matches ~f:(fun m ->
(*Format.eprintf "Doing %S. Parent matched is %S. Start is %d@." m.matched matched ms.offset;*)
let environment =
List.fold (Environment.vars m.environment) ~init:m.environment ~f:(fun env var ->
let open Option in
let updated : environment option =
Environment.lookup_range env var
>>| fun r ->
let range = {
match_start =
{ r.match_start with offset = ms.offset + r.match_start.offset - 1 } ;
match_end =
{ r.match_end with offset = ms.offset + r.match_end.offset - 1 }
}
in
Environment.update_range env var range
in
match updated with
| None -> env
| Some env -> env)
in
let range = {
match_start =
{ m.range.match_start with offset = ms.offset + m.range.match_start.offset - 1 } ;
match_end =
{ m.range.match_end with offset = ms.offset + m.range.match_end.offset - 1 }
}
in
{ m with range; environment })
else
[]
| _ ->
[]
in
acc @ nested_matches
| _ -> acc)
@ aux acc rest
in
let matches = aux [] 0 |> List.rev in
(* TODO(RVT): reintroduce nested matches *)
let compute_nested_matches matches = matches in
let matches = compute_nested_matches matches in
return matches
end
aux [] matches
in
if nested then
(* Use sort on offset for a top-down ordering. *)
aux_all ?configuration ~nested ~template ~source:original_source ()
|> List.sort ~compare:(fun left right -> left.range.match_start.offset - right.range.match_start.offset)
else
(* Don't change list order for non-nested matches--it's backwards and matters for rewriting. *)
aux_all ?configuration ~nested ~template ~source:original_source ()
let set_rewrite_template _ = () (* Unused in alpha matcher *)
end

View File

@ -822,18 +822,82 @@ module Make (Syntax : Syntax.S) (Info : Info.S) = struct
in
Match.create ~range ()
let all ?configuration ~template ~source : Match.t list =
configuration_ref := Option.value configuration ~default:!configuration_ref;
matches_ref := [];
if String.is_empty template && String.is_empty source then [trivial]
else match first_is_broken template source with
| Ok _
| Error _ -> List.rev !matches_ref
let all ?configuration ?(nested = false) ~template ~source:original_source () : Match.t list =
let rec aux_all ?configuration ?(nested = false) ~template ~source () =
configuration_ref := Option.value configuration ~default:!configuration_ref;
matches_ref := [];
if String.is_empty template && String.is_empty source then [trivial]
else match first_is_broken template source with
| Ok _
| Error _ ->
let matches = List.rev !matches_ref in
if nested then
(compute_nested_matches ?configuration ~nested template matches) @ matches
else
matches
and compute_nested_matches ?configuration ?nested template matches =
let open Match in
let open Range in
let rec aux acc matches =
match (matches : Match.t list) with
| [] -> acc
| { environment; _ }::rest ->
List.fold ~init:acc (Environment.vars environment) ~f:(fun acc v ->
let source_opt = Environment.lookup environment v in
match source_opt with
| Some source ->
let nested_matches =
let matches = aux_all ?configuration ?nested ~template ~source () in
let { match_start = ms; _ } = Option.value_exn (Environment.lookup_range environment v) in
List.map matches ~f:(fun m ->
let environment =
List.fold (Environment.vars m.environment) ~init:m.environment ~f:(fun env var ->
let open Option in
let updated : environment option =
Environment.lookup_range env var
>>| fun r ->
let range = {
match_start =
{ r.match_start with offset = ms.offset + r.match_start.offset - 1 } ;
match_end =
{ r.match_end with offset = ms.offset + r.match_end.offset - 1 }
}
in
Environment.update_range env var range
in
match updated with
| None -> env
| Some env -> env)
in
let range = {
match_start =
{ m.range.match_start with offset = ms.offset + m.range.match_start.offset - 1 } ;
match_end =
{ m.range.match_end with offset = ms.offset + m.range.match_end.offset - 1 }
}
in
{ m with range; environment })
in
acc @ nested_matches
| _ -> acc)
@ aux acc rest
in
aux [] matches
in
if nested then
let open Match in
(* Use sort on offset for a top-down ordering. *)
aux_all ?configuration ~nested ~template ~source:original_source ()
|> List.sort ~compare:(fun left right -> left.range.match_start.offset - right.range.match_start.offset)
else
(* Don't reverse the list for non-nested matches--it matters for rewriting. *)
aux_all ?configuration ~nested ~template ~source:original_source ()
let first ?configuration ?shift:_ template source : Match.t Or_error.t =
configuration_ref := Option.value configuration ~default:!configuration_ref;
matches_ref := [];
match all ?configuration ~template ~source with
match all ?configuration ~template ~source () with
| [] -> Or_error.error_string "No result"
| (hd::_) -> Ok hd (* FIXME be efficient *)
end

View File

@ -123,8 +123,10 @@ module Matcher = struct
val all
: ?configuration:Configuration.t
-> ?nested: bool
-> template:string
-> source:string
-> unit
-> Match.t list
end
end

View File

@ -56,8 +56,9 @@ let timed_run
(match rewrite_template with
| Some template -> Matcher.set_rewrite_template template;
| None -> ());
let matches = Matcher.all ~configuration ~template ~source in
let rule = Option.value rule ~default:[Ast.True] in
let options = if omega then Rule.Omega.options rule else Rule.Alpha.options rule in
let matches = Matcher.all ~nested:options.nested ~configuration ~template ~source () in
let matches = apply_rule ?substitute_in_place (module Matcher) omega rule matches in
List.map matches ~f:(Match.convert_offset ~fast:fast_offset_conversion ~source)

View File

@ -8,7 +8,7 @@ open Matchers.Alpha
let configuration = Configuration.create ~match_kind:Fuzzy ()
let run ?(configuration = configuration) source match_template rewrite_template =
Generic.all ~configuration ~template:match_template ~source
Generic.all ~configuration ~template:match_template ~source ()
|> function
| [] -> print_string "No matches."
| results ->

View File

@ -14,7 +14,7 @@ let run ?(configuration = configuration) (module M : Matchers.Matcher) source ma
| Some rule -> Rule.Alpha.create rule |> Or_error.ok_exn
| None -> Rule.Alpha.create "where true" |> Or_error.ok_exn
in
M.all ~configuration ~template:match_template ~source
M.all ~configuration ~template:match_template ~source ()
|> List.filter ~f:(fun { Match.environment; _ } -> Rule.Alpha.(sat @@ apply rule environment))
|> function
| [] -> print_string "No matches."

View File

@ -8,7 +8,7 @@ open Matchers.Alpha
let configuration = Configuration.create ~match_kind:Fuzzy ()
let run ?(configuration = configuration) (module M : Matchers.Matcher) source match_template rewrite_template =
M.all ~configuration ~template:match_template ~source
M.all ~configuration ~template:match_template ~source ()
|> function
| [] -> print_string "No matches."
| results ->

View File

@ -29,7 +29,7 @@ let run ?(configuration = configuration) source match_template rewrite_template
print_string ""
let run_all ?(configuration = configuration) source match_template rewrite_template =
Generic.all ~configuration ~template:match_template ~source
Generic.all ~configuration ~template:match_template ~source ()
|> function
| [] -> print_string "No matches."
| results ->
@ -424,7 +424,7 @@ let%expect_test "trivial_empty_case" =
let source = "" in
let match_template = "" in
begin
Generic.all ~configuration ~template:match_template ~source
Generic.all ~configuration ~template:match_template ~source ()
|> function
| [] -> print_string "No matches."
| hd :: _ ->

View File

@ -56,7 +56,11 @@
test_rewrite_parts_omega
test_user_defined_language_alpha
test_user_defined_language_omega)
test_user_defined_language_omega
test_nested_matches_alpha
test_nested_matches_omega
)
(inline_tests)
(preprocess (pps ppx_expect ppx_sexp_message ppx_deriving_yojson ppx_deriving_yojson.runtime))
(libraries

View File

@ -7,7 +7,7 @@ open Test_helpers
include Test_alpha
let all ?(configuration = configuration) template source =
C.all ~configuration ~template ~source
C.all ~configuration ~template ~source ()
let%expect_test "rewrite_comments_1" =
let template = "replace this :[1] end" in

View File

@ -7,7 +7,7 @@ open Test_helpers
include Test_omega
let all ?(configuration = configuration) template source =
C.all ~configuration ~template ~source
C.all ~configuration ~template ~source ()
let%expect_test "rewrite_comments_1" =
let template = "replace this :[1] end" in

View File

@ -21,7 +21,7 @@ let run ?(configuration = configuration) source match_template rewrite_template
let run_all ?(m = (module Generic : Matchers.Matcher)) ?(configuration = configuration) source match_template rewrite_template =
let (module M) = m in
M.all ~configuration ~template:match_template ~source
M.all ~configuration ~template:match_template ~source ()
|> function
| [] -> print_string "No matches."
| results ->
@ -416,7 +416,7 @@ let%expect_test "trivial_empty_case" =
let source = "" in
let match_template = "" in
begin
Generic.all ~configuration ~template:match_template ~source
Generic.all ~configuration ~template:match_template ~source ()
|> function
| [] -> print_string "No matches."
| hd :: _ ->

View File

@ -20,7 +20,7 @@ let run ?(configuration = configuration) source match_template rewrite_template
print_string ""
let run_all ?(configuration = configuration) source match_template rewrite_template =
Generic.all ~configuration ~template:match_template ~source
Generic.all ~configuration ~template:match_template ~source ()
|> function
| [] -> print_string "No matches."
| results ->
@ -415,7 +415,7 @@ let%expect_test "trivial_empty_case" =
let source = "" in
let match_template = "" in
begin
Generic.all ~configuration ~template:match_template ~source
Generic.all ~configuration ~template:match_template ~source ()
|> function
| [] -> print_string "No matches."
| hd :: _ ->
@ -427,7 +427,7 @@ let%expect_test "trivial_empty_case" =
let source = "" in
let match_template = "" in
begin
Generic.all ~configuration ~template:match_template ~source
Generic.all ~configuration ~template:match_template ~source ()
|> function
| [] -> print_string "No matches."
| hd :: _ ->

View File

@ -7,7 +7,7 @@ open Test_helpers
include Test_alpha
let run_all ?(configuration = configuration) source match_template rewrite_template =
Generic.all ~configuration ~template:match_template ~source
Generic.all ~configuration ~template:match_template ~source ()
|> function
| [] -> print_string "No matches."
| results ->

View File

@ -7,7 +7,7 @@ open Test_helpers
include Test_omega
let run_all ?(configuration = configuration) source match_template rewrite_template =
Generic.all ~configuration ~template:match_template ~source
Generic.all ~configuration ~template:match_template ~source ()
|> function
| [] -> print_string "No matches."
| results ->

View File

@ -7,7 +7,7 @@ open Test_helpers
include Test_alpha
let all ?(configuration = configuration) template source =
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
let print_matches matches =
List.map matches ~f:Match.to_yojson

View File

@ -7,7 +7,7 @@ open Test_helpers
include Test_omega
let all ?(configuration = configuration) template source =
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
let print_matches matches =
List.map matches ~f:Match.to_yojson

View File

@ -33,6 +33,13 @@ let%expect_test "parse_basic" =
[%expect_exact {|(rule ((Equal (String a) (String a))))
|}]
let%expect_test "parse_option_nested" =
Rule.create {|where nested, "a" == "a" |}
|> Or_error.ok_exn
|> fun rule -> print_s [%message (rule : Ast.expression list)];
[%expect_exact {|(rule ((Option nested) (Equal (String a) (String a))))
|}]
let%expect_test "parse_match_one_case" =
Rule.create {|where match "match_me" { | "case_one" -> true }|}
|> Or_error.ok_exn
@ -143,7 +150,7 @@ let%expect_test "where_true" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -192,7 +199,7 @@ let%expect_test "match_sat" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -208,7 +215,7 @@ let%expect_test "match_sat" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -251,7 +258,7 @@ let%expect_test "match_sat" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -287,7 +294,7 @@ let%expect_test "match_sat" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -322,7 +329,7 @@ let%expect_test "match_sat" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -341,7 +348,7 @@ let%expect_test "match_s_suffix" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -377,7 +384,7 @@ let%expect_test "match_s_suffix" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -415,7 +422,7 @@ let%expect_test "configuration_choice_based_on_case" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -434,7 +441,7 @@ let%expect_test "configuration_choice_based_on_case" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -471,7 +478,7 @@ let%expect_test "configuration_choice_based_on_case" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -492,7 +499,7 @@ let%expect_test "match_using_environment_merge" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -527,7 +534,7 @@ let%expect_test "match_using_environment_merge" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -552,7 +559,7 @@ let%expect_test "nested_matches" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -593,7 +600,7 @@ let%expect_test "nested_matches" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -614,7 +621,7 @@ let%expect_test "match_on_template" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -651,7 +658,7 @@ let%expect_test "match_on_template" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -688,7 +695,7 @@ let%expect_test "match_on_template" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|

View File

@ -33,6 +33,13 @@ let%expect_test "parse_basic" =
[%expect_exact {|(rule ((Equal (String a) (String a))))
|}]
let%expect_test "parse_option_nested" =
Rule.create {|where nested, "a" == "a" |}
|> Or_error.ok_exn
|> fun rule -> print_s [%message (rule : Ast.expression list)];
[%expect_exact {|(rule ((Option nested) (Equal (String a) (String a))))
|}]
let%expect_test "parse_match_one_case" =
Rule.create {|where match "match_me" { | "case_one" -> true }|}
|> Or_error.ok_exn
@ -143,7 +150,7 @@ let%expect_test "where_true" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -192,7 +199,7 @@ let%expect_test "match_sat" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -208,7 +215,7 @@ let%expect_test "match_sat" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -251,7 +258,7 @@ let%expect_test "match_sat" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -287,7 +294,7 @@ let%expect_test "match_sat" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -322,7 +329,7 @@ let%expect_test "match_sat" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -341,7 +348,7 @@ let%expect_test "match_s_suffix" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -377,7 +384,7 @@ let%expect_test "match_s_suffix" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -415,7 +422,7 @@ let%expect_test "configuration_choice_based_on_case" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -434,7 +441,7 @@ let%expect_test "configuration_choice_based_on_case" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -471,7 +478,7 @@ let%expect_test "configuration_choice_based_on_case" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -492,7 +499,7 @@ let%expect_test "match_using_environment_merge" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -527,7 +534,7 @@ let%expect_test "match_using_environment_merge" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -552,7 +559,7 @@ let%expect_test "nested_matches" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -593,7 +600,7 @@ let%expect_test "nested_matches" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -614,7 +621,7 @@ let%expect_test "match_on_template" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -651,7 +658,7 @@ let%expect_test "match_on_template" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|
@ -688,7 +695,7 @@ let%expect_test "match_on_template" =
|> Or_error.ok_exn
in
Generic.all ~configuration ~template ~source
Generic.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } -> Rule.(sat @@ apply rule environment))
|> print_matches;
[%expect {|

View File

@ -9,11 +9,11 @@ let%expect_test "nested_multiline_ocaml" =
let source = {|int nest = /*/*/ 0 */**/ 1;|} in
let template = {|0 * 1|} in
(* 0 is not commented out *)
let matches_no_nesting = C.all ~configuration ~template ~source in
let matches_no_nesting = C.all ~configuration ~template ~source () in
print_only_match matches_no_nesting;
[%expect_exact {|[ "0 */**/ 1" ]|}];
let matches_no_nesting = C_nested_comments.all ~configuration ~template ~source in
let matches_no_nesting = C_nested_comments.all ~configuration ~template ~source () in
(* 0 is commented out *)
print_only_match matches_no_nesting;
[%expect_exact {|[]|}];

View File

@ -9,11 +9,11 @@ let%expect_test "nested_multiline_ocaml" =
let source = {|int nest = /*/*/ 0 */**/ 1;|} in
let template = {|0 * 1|} in
(* 0 is not commented out *)
let matches_no_nesting = C.all ~configuration ~template ~source in
let matches_no_nesting = C.all ~configuration ~template ~source () in
print_only_match matches_no_nesting;
[%expect_exact {|[ "0 */**/ 1" ]|}];
let matches_no_nesting = C_nested_comments.all ~configuration ~template ~source in
let matches_no_nesting = C_nested_comments.all ~configuration ~template ~source () in
(* 0 is commented out *)
print_only_match matches_no_nesting;
[%expect_exact {|[]|}];

View File

@ -0,0 +1,76 @@
open Core
open Test_helpers
include Test_alpha
let run
?(m = (module Generic : Matchers.Matcher))
?(configuration = configuration)
?rule
source
match_template
() =
let (module M) = m in
let nested =
match rule with
| None -> true
| Some rule ->
let options = Rule.create rule |> Or_error.ok_exn |> Rule.options in
options.nested
in
M.all ~configuration ~nested ~template:match_template ~source ()
|> function
| [] -> print_string "No matches."
| matches ->
let matches = List.map matches ~f:(Match.convert_offset ~fast:true ~source) in
Format.asprintf "%a" Match.pp (None, matches)
|> print_string
let%expect_test "nested_matches" =
let source = {|
a{
b{
c{
d{e}
}
}
}
q{
b{
f{}
}
}
|} in
let match_template = {|:[[f]]{:[x]}|} in
run source match_template ();
[%expect_exact {|2:a{\n b{\n c{\n d{e}\n }\n }\n }
3:b{\n c{\n d{e}\n }\n }
4:c{\n d{e}\n }
5:d{e}
10:q{\n b{\n f{}\n }\n}
11:b{\n f{}\n }
12:f{}
|}]
let%expect_test "nested_matches" =
let source = {|a(b(c(d(e))))|} in
let match_template = {|:[[f]](:[x])|} in
run source match_template ();
[%expect_exact {|1:a(b(c(d(e))))
1:b(c(d(e)))
1:c(d(e))
1:d(e)
|}]
let%expect_test "nested_matches_from_rule" =
let source = {|a(b(c(d(e))))|} in
let match_template = {|:[[f]](:[x])|} in
let rule = {|where nested|} in
run ~rule source match_template ();
[%expect_exact {|1:a(b(c(d(e))))
1:b(c(d(e)))
1:c(d(e))
1:d(e)
|}]

View File

@ -0,0 +1,76 @@
open Core
open Test_helpers
include Test_omega
let run
?(m = (module Generic : Matchers.Matcher))
?(configuration = configuration)
?rule
source
match_template
() =
let (module M) = m in
let nested =
match rule with
| None -> true
| Some rule ->
let options = Rule.create rule |> Or_error.ok_exn |> Rule.options in
options.nested
in
M.all ~configuration ~nested ~template:match_template ~source ()
|> function
| [] -> print_string "No matches."
| matches ->
let matches = List.map matches ~f:(Match.convert_offset ~fast:true ~source) in
Format.asprintf "%a" Match.pp (None, matches)
|> print_string
let%expect_test "nested_matches" =
let source = {|
a{
b{
c{
d{e}
}
}
}
q{
b{
f{}
}
}
|} in
let match_template = {|:[[f]]{:[x]}|} in
run source match_template ();
[%expect_exact {|2:a{\n b{\n c{\n d{e}\n }\n }\n }
3:b{\n c{\n d{e}\n }\n }
4:c{\n d{e}\n }
5:d{e}
10:q{\n b{\n f{}\n }\n}
11:b{\n f{}\n }
12:f{}
|}]
let%expect_test "nested_matches" =
let source = {|a(b(c(d(e))))|} in
let match_template = {|:[[f]](:[x])|} in
run source match_template ();
[%expect_exact {|1:a(b(c(d(e))))
1:b(c(d(e)))
1:c(d(e))
1:d(e)
|}]
let%expect_test "nested_matches_from_rule" =
let source = {|a(b(c(d(e))))|} in
let match_template = {|:[[f]](:[x])|} in
let rule = {|where nested|} in
run ~rule source match_template ();
[%expect_exact {|1:a(b(c(d(e))))
1:b(c(d(e)))
1:c(d(e))
1:d(e)
|}]

View File

@ -7,35 +7,35 @@ include Test_alpha
let%expect_test "matched_contains_raw_literal_quotes" =
let source = {|"""blah"""|} in
let template = {|""":[[1]]"""|} in
let matches = Python.all ~configuration ~template ~source in
let matches = Python.all ~configuration ~template ~source () in
print_only_match matches;
[%expect_exact {|[ "\"\"\"blah\"\"\"" ]|}]
let%expect_test "interpreted_string_does_not_match_raw_literal" =
let source = {|"""blah""" "blah"|} in
let template = {|":[[1]]"|} in
let matches = Python.all ~configuration ~template ~source in
let matches = Python.all ~configuration ~template ~source () in
print_only_match matches;
[%expect_exact {|[ "\"blah\"" ]|}]
let%expect_test "interpreted_string_does_not_match_raw_literal_containing_quote" =
let source = {|"""blah""" """bl"ah""" "blah"|} in
let template = {|":[[1]]"|} in
let matches = Python.all ~configuration ~template ~source in
let matches = Python.all ~configuration ~template ~source () in
print_only_match matches;
[%expect_exact {|[ "\"blah\"" ]|}]
let%expect_test "raw_string_matches_string_containing_quote" =
let source = {|"""bl"ah"""|} in
let template = {|""":[1]"""|} in
let matches = Python.all ~configuration ~template ~source in
let matches = Python.all ~configuration ~template ~source () in
print_only_match matches;
[%expect_exact {|[ "\"\"\"bl\"ah\"\"\"" ]|}]
let%expect_test "invalid_raw_string_in_python_but_matches_because_ignores_after" =
let source = {|"""""""|} in
let template = {|""":[1]"""|} in
let matches = Python.all ~configuration ~template ~source in
let matches = Python.all ~configuration ~template ~source () in
print_only_match matches;
[%expect_exact {|[ "\"\"\"\"\"\"" ]|}]

View File

@ -7,35 +7,35 @@ include Test_omega
let%expect_test "matched_contains_raw_literal_quotes" =
let source = {|"""blah"""|} in
let template = {|""":[[1]]"""|} in
let matches = Python.all ~configuration ~template ~source in
let matches = Python.all ~configuration ~template ~source () in
print_only_match matches;
[%expect_exact {|[ "\"\"\"blah\"\"\"" ]|}]
let%expect_test "interpreted_string_does_not_match_raw_literal" =
let source = {|"""blah""" "blah"|} in
let template = {|":[[1]]"|} in
let matches = Python.all ~configuration ~template ~source in
let matches = Python.all ~configuration ~template ~source () in
print_only_match matches;
[%expect_exact {|[ "\"blah\"" ]|}]
let%expect_test "interpreted_string_does_not_match_raw_literal_containing_quote" =
let source = {|"""blah""" """bl"ah""" "blah"|} in
let template = {|":[[1]]"|} in
let matches = Python.all ~configuration ~template ~source in
let matches = Python.all ~configuration ~template ~source () in
print_only_match matches;
[%expect_exact {|[ "\"blah\"" ]|}]
let%expect_test "raw_string_matches_string_containing_quote" =
let source = {|"""bl"ah"""|} in
let template = {|""":[1]"""|} in
let matches = Python.all ~configuration ~template ~source in
let matches = Python.all ~configuration ~template ~source () in
print_only_match matches;
[%expect_exact {|[ "\"\"\"bl\"ah\"\"\"" ]|}]
let%expect_test "invalid_raw_string_in_python_but_matches_because_ignores_after" =
let source = {|"""""""|} in
let template = {|""":[1]"""|} in
let matches = Python.all ~configuration ~template ~source in
let matches = Python.all ~configuration ~template ~source () in
print_only_match matches;
[%expect_exact {|[ "\"\"\"\"\"\"" ]|}]

View File

@ -8,7 +8,7 @@ open Test_helpers
include Test_alpha
let all ?(configuration = configuration) template source =
C.all ~configuration ~template ~source
C.all ~configuration ~template ~source ()
let%expect_test "get_offsets_for_holes" =
let rewrite_template = {|1234:[1]1234:[2]|} in

View File

@ -8,7 +8,7 @@ open Test_helpers
include Test_omega
let all ?(configuration = configuration) template source =
C.all ~configuration ~template ~source
C.all ~configuration ~template ~source ()
let%expect_test "get_offsets_for_holes" =
let rewrite_template = {|1234:[1]1234:[2]|} in

View File

@ -31,7 +31,7 @@ let %expect_test "statistics" =
|> Rule.create
|> Or_error.ok_exn
in
Go.all ~configuration ~template ~source
Go.all ~configuration ~template ~source ()
|> List.filter ~f:(fun { environment; _ } ->
Rule.(sat @@ apply rule environment))
|> fun matches ->

View File

@ -7,7 +7,7 @@ open Test_helpers
include Test_alpha
let all ?(configuration = configuration) template source =
C.all ~configuration ~template ~source
C.all ~configuration ~template ~source ()
let%expect_test "comments_in_string_literals_should_not_be_treated_as_comments_by_fuzzy" =
let source = {|"/*"(x)|} in
@ -24,7 +24,7 @@ let%expect_test "comments_in_string_literals_should_not_be_treated_as_comments_b
let source = {|`//`(x)|} in
let template = {|(:[1])|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~template ~source
Go.all ~configuration ~template ~source ()
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some { rewritten_source; _ } -> print_string rewritten_source
@ -293,7 +293,7 @@ let%expect_test "go_raw_string_literals" =
let match_template = {|`:[1]`|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~source ~template:match_template
Go.all ~configuration ~source ~template:match_template ()
|> (fun matches -> Option.value_exn (Rewrite.all ~source ~rewrite_template matches))
|> (fun { rewritten_source; _ } -> rewritten_source)
|> print_string;
@ -310,7 +310,7 @@ let%expect_test "go_raw_string_literals" =
let match_template = {|:[1]|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~source ~template:match_template
Go.all ~configuration ~source ~template:match_template ()
|> (fun matches -> Option.value_exn (Rewrite.all ~source ~rewrite_template matches))
|> (fun { rewritten_source; _ } -> rewritten_source)
|> print_string;
@ -320,7 +320,7 @@ let%expect_test "match_string_literals" =
let source = {|`(` match `(``(` this `(` |} in
let match_template = {|match :[1] this|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~template:match_template ~source
Go.all ~configuration ~template:match_template ~source ()
|> (fun matches -> Option.value_exn (Rewrite.all ~source ~rewrite_template matches))
|> (fun { rewritten_source; _ } -> rewritten_source)
|> print_string;
@ -340,7 +340,7 @@ let%expect_test "go_raw_string_literals" =
let match_template = {|`:[1]`|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~source ~template:match_template
Go.all ~configuration ~source ~template:match_template ()
|> (fun matches -> Option.value_exn (Rewrite.all ~source ~rewrite_template matches))
|> (fun { rewritten_source; _ } -> rewritten_source)
|> print_string;
@ -356,7 +356,7 @@ let%expect_test "regression_matching_kubernetes" =
let source = {|"\n" y = 5|} in
let template = {|y = :[1]|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~template ~source
Go.all ~configuration ~template ~source ()
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some { rewritten_source; _ } -> print_string rewritten_source
@ -368,7 +368,7 @@ let%expect_test "match_escaped_any_char" =
let source = {|printf("hello world\n");|} in
let template = {|printf(":[1]");|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~template ~source
Go.all ~configuration ~template ~source ()
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some { rewritten_source; _ } -> print_string rewritten_source
@ -379,7 +379,7 @@ let%expect_test "match_escaped_escaped" =
let source = {|printf("hello world\n\\");|} in
let template = {|printf(":[1]");|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~template ~source
Go.all ~configuration ~template ~source ()
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some { rewritten_source; _ } -> print_string rewritten_source
@ -390,7 +390,7 @@ let%expect_test "match_escaped_escaped" =
let source = {|printf("hello world\n\");|} in
let template = {|printf(":[1]");|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~template ~source
Go.all ~configuration ~template ~source ()
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some { rewritten_source; _ } -> print_string rewritten_source
@ -417,7 +417,7 @@ let%expect_test "holes_in_raw_literals" =
|} in
let template = {|`:[1]`|} in
begin
Typescript.all ~configuration ~template ~source
Typescript.all ~configuration ~template ~source ()
|> function
| [] -> print_string "No matches."
| hd :: _ ->
@ -451,7 +451,7 @@ let%expect_test "holes_in_raw_literals_partial" =
|} in
let template = {|` query ResolveRepo(:[1]) {:[2]} `|} in
begin
Typescript.all ~configuration ~template ~source
Typescript.all ~configuration ~template ~source ()
|> function
| [] -> print_string "No matches."
| hd :: _ ->
@ -469,7 +469,7 @@ let%expect_test "dont_detect_comments_in_strings_with_hole_matcher" =
let source = {|"// not a comment"|} in
let template = {|":[1]"|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~template ~source
Go.all ~configuration ~template ~source ()
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some { rewritten_source; _ } -> print_string rewritten_source
@ -480,7 +480,7 @@ let%expect_test "match_regex_delimiters" =
let source = {|/f\/oo/ "/bar/"|} in
let template = {|/:[1]/|} in
let rewrite_template = {|:[1]|} in
Typescript.all ~configuration ~template ~source
Typescript.all ~configuration ~template ~source ()
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some { rewritten_source; _ } -> print_string rewritten_source

View File

@ -7,7 +7,7 @@ open Test_helpers
include Test_omega
let all ?(configuration = configuration) template source =
C.all ~configuration ~template ~source
C.all ~configuration ~template ~source ()
let%expect_test "comments_in_string_literals_should_not_be_treated_as_comments_by_fuzzy" =
let source = {|"/*"(x)|} in
@ -24,7 +24,7 @@ let%expect_test "comments_in_string_literals_should_not_be_treated_as_comments_b
let source = {|`//`(x)|} in
let template = {|(:[1])|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~template ~source
Go.all ~configuration ~template ~source ()
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some { rewritten_source; _ } -> print_string rewritten_source
@ -293,7 +293,7 @@ let%expect_test "go_raw_string_literals" =
let match_template = {|`:[1]`|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~source ~template:match_template
Go.all ~configuration ~source ~template:match_template ()
|> (fun matches -> Option.value_exn (Rewrite.all ~source ~rewrite_template matches))
|> (fun { rewritten_source; _ } -> rewritten_source)
|> print_string;
@ -310,7 +310,7 @@ let%expect_test "go_raw_string_literals" =
let match_template = {|:[1]|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~source ~template:match_template
Go.all ~configuration ~source ~template:match_template ()
|> (fun matches -> Option.value_exn (Rewrite.all ~source ~rewrite_template matches))
|> (fun { rewritten_source; _ } -> rewritten_source)
|> print_string;
@ -320,7 +320,7 @@ let%expect_test "match_string_literals" =
let source = {|`(` match `(``(` this `(` |} in
let match_template = {|match :[1] this|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~template:match_template ~source
Go.all ~configuration ~template:match_template ~source ()
|> (fun matches -> Option.value_exn (Rewrite.all ~source ~rewrite_template matches))
|> (fun { rewritten_source; _ } -> rewritten_source)
|> print_string;
@ -340,7 +340,7 @@ let%expect_test "go_raw_string_literals" =
let match_template = {|`:[1]`|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~source ~template:match_template
Go.all ~configuration ~source ~template:match_template ()
|> (fun matches -> Option.value_exn (Rewrite.all ~source ~rewrite_template matches))
|> (fun { rewritten_source; _ } -> rewritten_source)
|> print_string;
@ -356,7 +356,7 @@ let%expect_test "regression_matching_kubernetes" =
let source = {|"\n" y = 5|} in
let template = {|y = :[1]|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~template ~source
Go.all ~configuration ~template ~source ()
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some { rewritten_source; _ } -> print_string rewritten_source
@ -368,7 +368,7 @@ let%expect_test "match_escaped_any_char" =
let source = {|printf("hello world\n");|} in
let template = {|printf(":[1]");|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~template ~source
Go.all ~configuration ~template ~source ()
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some { rewritten_source; _ } -> print_string rewritten_source
@ -379,7 +379,7 @@ let%expect_test "match_escaped_escaped" =
let source = {|printf("hello world\n\\");|} in
let template = {|printf(":[1]");|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~template ~source
Go.all ~configuration ~template ~source ()
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some { rewritten_source; _ } -> print_string rewritten_source
@ -390,7 +390,7 @@ let%expect_test "match_escaped_escaped" =
let source = {|printf("hello world\n\");|} in
let template = {|printf(":[1]");|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~template ~source
Go.all ~configuration ~template ~source ()
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some { rewritten_source; _ } -> print_string rewritten_source
@ -417,7 +417,7 @@ let%expect_test "holes_in_raw_literals" =
|} in
let template = {|`:[1]`|} in
begin
Typescript.all ~configuration ~template ~source
Typescript.all ~configuration ~template ~source ()
|> function
| [] -> print_string "No matches."
| hd :: _ ->
@ -451,7 +451,7 @@ let%expect_test "holes_in_raw_literals_partial" =
|} in
let template = {|` query ResolveRepo(:[1]) {:[2]} `|} in
begin
Typescript.all ~configuration ~template ~source
Typescript.all ~configuration ~template ~source ()
|> function
| [] -> print_string "No matches."
| hd :: _ ->
@ -469,7 +469,7 @@ let%expect_test "dont_detect_comments_in_strings_with_hole_matcher" =
let source = {|"// not a comment"|} in
let template = {|":[1]"|} in
let rewrite_template = {|:[1]|} in
Go.all ~configuration ~template ~source
Go.all ~configuration ~template ~source ()
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some { rewritten_source; _ } -> print_string rewritten_source
@ -480,7 +480,7 @@ let%expect_test "match_regex_delimiters" =
let source = {|/f\/oo/ "/bar/"|} in
let template = {|/:[1]/|} in
let rewrite_template = {|:[1]|} in
Typescript.all ~configuration ~template ~source
Typescript.all ~configuration ~template ~source ()
|> Rewrite.all ~source ~rewrite_template
|> (function
| Some { rewritten_source; _ } -> print_string rewritten_source