Relax balanced apostrophe for ocaml and rust

This commit is contained in:
Rijnard van Tonder 2019-06-05 23:06:34 -04:00 committed by GitHub
parent 210bbcc8a3
commit 1dc3c9005e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 0 deletions

View File

@ -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 =
[ ("{|", "|}")
]

View File

@ -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

View 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 |}]