mirror of
https://github.com/comby-tools/comby.git
synced 2024-09-11 13:25:36 +03:00
Relax balanced apostrophe for ocaml and rust
This commit is contained in:
parent
210bbcc8a3
commit
1dc3c9005e
@ -8,6 +8,7 @@ module Dyck = struct
|
||||
|
||||
let escapable_string_literals = []
|
||||
|
||||
(* This is ignored since there are no literals *)
|
||||
let escape_char =
|
||||
'\\'
|
||||
|
||||
@ -290,6 +291,12 @@ module Rust = struct
|
||||
module Syntax = struct
|
||||
include Swift.Syntax
|
||||
|
||||
(* Override ' as escapable string literal, since
|
||||
these can be used in typing *)
|
||||
let escapable_string_literals =
|
||||
[ {|"|}
|
||||
]
|
||||
|
||||
let raw_string_literals =
|
||||
[ ({|r#|}, {|#|})
|
||||
]
|
||||
@ -303,6 +310,12 @@ module OCaml = struct
|
||||
open Types
|
||||
include Generic.Syntax
|
||||
|
||||
(* Override ' as escapable string literal, since
|
||||
these can be used in typing *)
|
||||
let escapable_string_literals =
|
||||
[ {|"|}
|
||||
]
|
||||
|
||||
let raw_string_literals =
|
||||
[ ("{|", "|}")
|
||||
]
|
||||
|
@ -13,6 +13,7 @@
|
||||
test_c_style_comments
|
||||
test_c_separators
|
||||
test_string_literals
|
||||
test_special_matcher_cases
|
||||
test_generic
|
||||
test_rewrite_parts
|
||||
test_rewrite_rule
|
||||
|
32
test/test_special_matcher_cases.ml
Normal file
32
test/test_special_matcher_cases.ml
Normal file
@ -0,0 +1,32 @@
|
||||
open Core
|
||||
|
||||
open Matchers
|
||||
open Rewriter
|
||||
|
||||
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
|
||||
|> function
|
||||
| [] -> print_string "No matches."
|
||||
| results ->
|
||||
Option.value_exn (Rewrite.all ~source ~rewrite_template results)
|
||||
|> (fun { rewritten_source; _ } -> rewritten_source)
|
||||
|> print_string
|
||||
|
||||
let%expect_test "parse_rust_apostrophe_ok" =
|
||||
let source = {|pub struct GlobBuilder<'a> {}|} in
|
||||
let match_template = {|{}|} in
|
||||
let rewrite_template = {|{} // success|} in
|
||||
|
||||
run (module Matchers.Rust) source match_template rewrite_template;
|
||||
[%expect_exact {|pub struct GlobBuilder<'a> {} // success|}]
|
||||
|
||||
let%expect_test "parse_ocaml_apostrophe_ok" =
|
||||
let source = {|type 'a t = Poly of 'a | Int of int |} in
|
||||
let match_template = {|type :[v] t = :[_] Int of :[i]|} in
|
||||
let rewrite_template = {|:[v], :[i]|} in
|
||||
|
||||
run (module Matchers.OCaml) source match_template rewrite_template;
|
||||
[%expect_exact {|'a, int |}]
|
Loading…
Reference in New Issue
Block a user