mirror of
https://github.com/comby-tools/comby.git
synced 2024-08-16 16:50:37 +03:00
test hole.length (#286)
This commit is contained in:
parent
258a0c3a05
commit
123a01e890
@ -1015,7 +1015,7 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) = struct
|
||||
let rec aux_all ?configuration ?(nested = false) ~template ~source () =
|
||||
matches_ref := [];
|
||||
if String.is_empty template && String.is_empty source then [trivial]
|
||||
else match first_is_broken template source (Some rule) with (* FIXME always Some rule *)
|
||||
else match first_is_broken template source (Some rule) with
|
||||
| Ok _
|
||||
| Error _ ->
|
||||
let matches = List.rev !matches_ref in
|
||||
|
@ -22,12 +22,16 @@ let replacement_sentinel metasyntax =
|
||||
let left = Option.value left ~default:"" in
|
||||
let right = Option.value right ~default:"" in
|
||||
Some (left, right)
|
||||
| Hole (Alphanum, Delimited (left, right)) ->
|
||||
let left = Option.value left ~default:"" in
|
||||
let right = Option.value right ~default:"" in
|
||||
Some (left, right)
|
||||
| Regex (left, _, right) ->
|
||||
Some (left, right)
|
||||
| _ -> None)
|
||||
|> function
|
||||
| Some v -> v
|
||||
| None -> failwith "A custom metasyntax must define syntax for an Everything hole or Regex to customize rewriting"
|
||||
| None -> failwith "A custom metasyntax must define syntax for an Everything or Alphanum hole or Regex to customize rewriting"
|
||||
|
||||
(** Parse the first :[id(label)] label encountered in the template. *)
|
||||
let parse_first_label ?(metasyntax = Metasyntax.default_metasyntax) template =
|
||||
|
@ -1,6 +1,7 @@
|
||||
open Core
|
||||
|
||||
open Comby_kernel
|
||||
open Test_helpers
|
||||
|
||||
let configuration = Matchers.Configuration.create ~match_kind:Fuzzy ()
|
||||
|
||||
@ -8,12 +9,6 @@ let create (module E : Matchers.Engine.S) syntax =
|
||||
let metasyntax = Matchers.Metasyntax.{ syntax; identifier = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_" } in
|
||||
Option.value_exn (E.select_with_extension ~metasyntax ".go")
|
||||
|
||||
let run (module M : Matchers.Matcher.S) source match_template _rewrite_template =
|
||||
M.all ~configuration ~template:match_template ~source ()
|
||||
|> function
|
||||
| [] -> print_string "No matches."
|
||||
| results -> print_string (Format.asprintf "%a" Match.pp_json_lines (None, results))
|
||||
|
||||
let%expect_test "custom_metasyntax_everything" =
|
||||
let matcher =
|
||||
[ Matchers.Metasyntax.Hole (Everything, Delimited (Some "$", None))
|
||||
@ -21,28 +16,28 @@ let%expect_test "custom_metasyntax_everything" =
|
||||
in
|
||||
|
||||
let source = "simple(test)" in
|
||||
run (create (module Matchers.Alpha) matcher) source "simple($A)" "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) source "simple($A)";
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":12,"line":1,"column":13}},"environment":[{"variable":"A","value":"test","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":11,"line":1,"column":12}}}],"matched":"simple(test)"}]}
|
||||
|}];
|
||||
run (create (module Matchers.Omega) matcher) source "simple($A)" "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) source "simple($A)";
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":12,"line":1,"column":13}},"environment":[{"variable":"A","value":"test","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":11,"line":1,"column":12}}}],"matched":"simple(test)"}]}
|
||||
|}];
|
||||
|
||||
|
||||
let source = "(nested(test))" in
|
||||
run (create (module Matchers.Alpha) matcher) source "($A)" "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) source "($A)";
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":14,"line":1,"column":15}},"environment":[{"variable":"A","value":"nested(test)","range":{"start":{"offset":1,"line":1,"column":2},"end":{"offset":13,"line":1,"column":14}}}],"matched":"(nested(test))"}]}
|
||||
|}];
|
||||
run (create (module Matchers.Omega) matcher) source "($A)" "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) source "($A)";
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":14,"line":1,"column":15}},"environment":[{"variable":"A","value":"nested(test)","range":{"start":{"offset":1,"line":1,"column":2},"end":{"offset":13,"line":1,"column":14}}}],"matched":"(nested(test))"}]}
|
||||
|}];
|
||||
|
||||
|
||||
let source = "flat stuff yeah" in
|
||||
run (create (module Matchers.Alpha) matcher) source "flat $A yeah" "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) source "flat $A yeah";
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":15,"line":1,"column":16}},"environment":[{"variable":"A","value":"stuff","range":{"start":{"offset":5,"line":1,"column":6},"end":{"offset":10,"line":1,"column":11}}}],"matched":"flat stuff yeah"}]}
|
||||
|}];
|
||||
run (create (module Matchers.Omega) matcher) source "flat $A yeah" "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) source "flat $A yeah";
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":15,"line":1,"column":16}},"environment":[{"variable":"A","value":"stuff","range":{"start":{"offset":5,"line":1,"column":6},"end":{"offset":10,"line":1,"column":11}}}],"matched":"flat stuff yeah"}]}
|
||||
|}]
|
||||
|
||||
@ -55,10 +50,10 @@ let%expect_test "custom_metasyntax_regex" =
|
||||
in
|
||||
|
||||
let source = "simple(test)" in
|
||||
run (create (module Matchers.Alpha) matcher) source {|$A:\w+ |} "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) source {|$A:\w+ |};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}},"environment":[{"variable":"A","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}}],"matched":"simple"},{"range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"A","value":"test","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":11,"line":1,"column":12}}}],"matched":"test"}]}
|
||||
|}];
|
||||
run (create (module Matchers.Omega) matcher) source {|$A:\w+ |} "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) source {|$A:\w+ |};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}},"environment":[{"variable":"A","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}}],"matched":"simple"},{"range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"A","value":"test","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":11,"line":1,"column":12}}}],"matched":"test"}]}
|
||||
|}]
|
||||
|
||||
@ -70,17 +65,17 @@ let%expect_test "custom_metasyntax_multiple_holes" =
|
||||
]
|
||||
in
|
||||
|
||||
run (create (module Matchers.Alpha) matcher) "simple(bar)" {|$FOO(?BAR)|} "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) "simple(bar)" {|$FOO(?BAR)|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"BAR","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}},{"variable":"FOO","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}}],"matched":"simple(bar)"}]}
|
||||
|}];
|
||||
run (create (module Matchers.Omega) matcher) "simple(bar)" {|$FOO(?BAR)|} "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) "simple(bar)" {|$FOO(?BAR)|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"BAR","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}},{"variable":"FOO","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}}],"matched":"simple(bar)"}]}
|
||||
|}];
|
||||
|
||||
run (create (module Matchers.Alpha) matcher) "foo(bar)" {|?FOO($BAR)|} "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) "foo(bar)" {|?FOO($BAR)|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":8,"line":1,"column":9}},"environment":[{"variable":"BAR","value":"bar","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}},{"variable":"FOO","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo(bar)"}]}
|
||||
|}];
|
||||
run (create (module Matchers.Omega) matcher) "foo(bar)" {|?FOO($BAR)|} "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) "foo(bar)" {|?FOO($BAR)|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":8,"line":1,"column":9}},"environment":[{"variable":"BAR","value":"bar","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}},{"variable":"FOO","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo(bar)"}]}
|
||||
|}];
|
||||
|
||||
@ -91,10 +86,10 @@ let%expect_test "custom_metasyntax_multiple_holes" =
|
||||
]
|
||||
in
|
||||
|
||||
run (create (module Matchers.Alpha) matcher) "foo(bar.baz)" {|$$A|} "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) "foo(bar.baz)" {|$$A|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}},"environment":[{"variable":"A","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo"},{"range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}},"environment":[{"variable":"A","value":"bar","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}}],"matched":"bar"},{"range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"A","value":"baz","range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}}}],"matched":"baz"}]}
|
||||
|}];
|
||||
run (create (module Matchers.Omega) matcher) "foo(bar.baz)" {|$$A|} "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) "foo(bar.baz)" {|$$A|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}},"environment":[{"variable":"A","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo"},{"range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}},"environment":[{"variable":"A","value":"bar","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}}],"matched":"bar"},{"range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"A","value":"baz","range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}}}],"matched":"baz"}]}
|
||||
|}];
|
||||
|
||||
@ -106,10 +101,10 @@ let%expect_test "custom_metasyntax_multiple_holes" =
|
||||
]
|
||||
in
|
||||
|
||||
run (create (module Matchers.Alpha) matcher) "foo(bar.baz)" {|$M:\w+ |} "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) "foo(bar.baz)" {|$M:\w+ |};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}},"environment":[{"variable":"M","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo"},{"range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}},"environment":[{"variable":"M","value":"bar","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}}],"matched":"bar"},{"range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"M","value":"baz","range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}}}],"matched":"baz"}]}
|
||||
|}];
|
||||
run (create (module Matchers.Omega) matcher) "foo(bar.baz)" {|$M:\w+ |} "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) "foo(bar.baz)" {|$M:\w+ |};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}},"environment":[{"variable":"M","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo"},{"range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}},"environment":[{"variable":"M","value":"bar","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}}],"matched":"bar"},{"range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"M","value":"baz","range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}}}],"matched":"baz"}]}
|
||||
|}];
|
||||
|
||||
@ -122,9 +117,9 @@ let%expect_test "custom_metasyntax_multiple_holes" =
|
||||
]
|
||||
in
|
||||
|
||||
run (create (module Matchers.Alpha) matcher) "foo(bar.baz)" {|$M:\w+ |} "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) "foo(bar.baz)" {|$M:\w+ |};
|
||||
[%expect_exact {|No matches.|}];
|
||||
run (create (module Matchers.Omega) matcher) "foo(bar.baz)" {|$M:\w+ |} "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) "foo(bar.baz)" {|$M:\w+ |};
|
||||
[%expect_exact {|No matches.|}]
|
||||
|
||||
|
||||
@ -136,11 +131,11 @@ let%expect_test "custom_metasyntax_underscore" =
|
||||
]
|
||||
in
|
||||
|
||||
run (create (module Matchers.Alpha) matcher) "simple(bar)" {|$_(?_)|} "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) "simple(bar)" {|$_(?_)|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"_","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}}],"matched":"simple(bar)"}]}
|
||||
|}];
|
||||
(* different because we record _ the first time and don't subsequently for implicit_equals *)
|
||||
run (create (module Matchers.Omega) matcher) "simple(bar)" {|$_(?_)|} "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) "simple(bar)" {|$_(?_)|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"_","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}}],"matched":"simple(bar)"}]}
|
||||
|}]
|
||||
|
||||
@ -152,10 +147,10 @@ let%expect_test "custom_metasyntax_equivalence" =
|
||||
]
|
||||
in
|
||||
|
||||
run (create (module Matchers.Alpha) matcher) "foo(foo)" {|$A($A~\w+$)|} "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) "foo(foo)" {|$A($A~\w+$)|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":8,"line":1,"column":9}},"environment":[{"variable":"A","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}},{"variable":"A_equal_!@#$000000000011","value":"foo","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}}],"matched":"foo(foo)"}]}
|
||||
|}];
|
||||
run (create (module Matchers.Omega) matcher) "foo(foo)" {|$A($A~\w+$)|} "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) "foo(foo)" {|$A($A~\w+$)|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":8,"line":1,"column":9}},"environment":[{"variable":"A","value":"foo","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}},{"variable":"A_equal_!@#$000000000012","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo(foo)"}]}
|
||||
|}]
|
||||
|
||||
@ -167,9 +162,9 @@ let%expect_test "custom_metasyntax_definition_order" =
|
||||
]
|
||||
in
|
||||
|
||||
run (create (module Matchers.Alpha) matcher) "simple(bar)baz" {|$A($B)$C~\w+$|} "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) "simple(bar)baz" {|$A($B)$C~\w+$|};
|
||||
[%expect_exact {|No matches.|}];
|
||||
run (create (module Matchers.Omega) matcher) "simple(bar)baz" {|$A($B)$C~\w+$|} "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) "simple(bar)baz" {|$A($B)$C~\w+$|};
|
||||
[%expect_exact {|No matches.|}];
|
||||
|
||||
let matcher =
|
||||
@ -179,10 +174,10 @@ let%expect_test "custom_metasyntax_definition_order" =
|
||||
]
|
||||
in
|
||||
|
||||
run (create (module Matchers.Alpha) matcher) "simple(bar)baz" {|$A($B)$C~\w+$|} "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) "simple(bar)baz" {|$A($B)$C~\w+$|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":14,"line":1,"column":15}},"environment":[{"variable":"A","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}},{"variable":"B","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}},{"variable":"C","value":"baz","range":{"start":{"offset":11,"line":1,"column":12},"end":{"offset":14,"line":1,"column":15}}}],"matched":"simple(bar)baz"}]}
|
||||
|}];
|
||||
run (create (module Matchers.Omega) matcher) "simple(bar)baz" {|$A($B)$C~\w+$|} "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) "simple(bar)baz" {|$A($B)$C~\w+$|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":14,"line":1,"column":15}},"environment":[{"variable":"A","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}},{"variable":"B","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}},{"variable":"C","value":"baz","range":{"start":{"offset":11,"line":1,"column":12},"end":{"offset":14,"line":1,"column":15}}}],"matched":"simple(bar)baz"}]}
|
||||
|}]
|
||||
|
||||
@ -253,10 +248,10 @@ let%expect_test "custom_metasyntax_greek_letters" =
|
||||
]
|
||||
in
|
||||
|
||||
run (create (module Matchers.Alpha) matcher) "simple(bar)" {|α(β)|} "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) "simple(bar)" {|α(β)|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"α","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}},{"variable":"β","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}}],"matched":"simple(bar)"}]}
|
||||
|}];
|
||||
run (create (module Matchers.Omega) matcher) "simple(bar)" {|α(β)|} "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) "simple(bar)" {|α(β)|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"α","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}},{"variable":"β","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}}],"matched":"simple(bar)"}]}
|
||||
|}]
|
||||
|
||||
@ -268,9 +263,24 @@ let%expect_test "custom_metasyntax_alphanum_test" =
|
||||
]
|
||||
in
|
||||
|
||||
run (create (module Matchers.Alpha) matcher) "simple(bar)" {|[:A:](α)|} "";
|
||||
run_all_matches (create (module Matchers.Alpha) matcher) "simple(bar)" {|[:A:](α)|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"A","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}},{"variable":"α","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}}],"matched":"simple(bar)"}]}
|
||||
|}];
|
||||
run (create (module Matchers.Omega) matcher) "simple(bar)" {|[:A:](α)|} "";
|
||||
run_all_matches (create (module Matchers.Omega) matcher) "simple(bar)" {|[:A:](α)|};
|
||||
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"A","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}},{"variable":"α","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}}],"matched":"simple(bar)"}]}
|
||||
|}]
|
||||
|
||||
let%expect_test "custom_metasyntax_rewrite_length" =
|
||||
let syntax =
|
||||
Matchers.Metasyntax.
|
||||
[ Hole (Alphanum, Delimited (Some "[:", Some ":]"))
|
||||
; Hole (Alphanum, Reserved_identifiers ["α"; "β"])
|
||||
]
|
||||
in
|
||||
|
||||
let metasyntax = Matchers.Metasyntax.{ syntax; identifier = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_" } in
|
||||
|
||||
run ~metasyntax (create (module Matchers.Alpha) syntax) "simple(bar)" {|[:A:](α)|} {|[:A:].length (α.length)|};
|
||||
[%expect_exact {|6 (3)|}];
|
||||
run ~metasyntax (create (module Matchers.Omega) syntax) "simple(bar)" {|[:A:](α)|} {|[:A:].length (α.length)|};
|
||||
[%expect_exact {|6 (3)|}]
|
||||
|
@ -27,7 +27,7 @@ let print_only_match matches =
|
||||
|> Yojson.Safe.pretty_to_string
|
||||
|> print_string
|
||||
|
||||
let run ?(configuration = configuration) (module M : Matchers.Matcher.S) source match_template ?rule rewrite_template =
|
||||
let run ?(configuration = configuration) ?metasyntax (module M : Matchers.Matcher.S) source match_template ?rule rewrite_template =
|
||||
let rule =
|
||||
match rule with
|
||||
| Some rule -> Matchers.Rule.create rule |> Or_error.ok_exn
|
||||
@ -37,7 +37,7 @@ let run ?(configuration = configuration) (module M : Matchers.Matcher.S) source
|
||||
|> function
|
||||
| [] -> print_string "No matches."
|
||||
| results ->
|
||||
Option.value_exn (Rewrite.all ~source ~rewrite_template results)
|
||||
Option.value_exn (Rewrite.all ?metasyntax ~source ~rewrite_template results)
|
||||
|> (fun { rewritten_source; _ } -> rewritten_source)
|
||||
|> print_string
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user