Skip to content

Commit

Permalink
relax balanced apostrophe for ocaml and rust
Browse files Browse the repository at this point in the history
  • Loading branch information
rvantonder committed Jun 6, 2019
1 parent a2a2181 commit 7b3bcdb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/matchers/languages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Dyck = struct

let escapable_string_literals = []

(* This is ignored since there are no literals *)
let escape_char =
'\\'

Expand Down Expand Up @@ -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#|}, {|#|})
]
Expand All @@ -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 =
[ ("{|", "|}")
]
Expand Down
1 change: 1 addition & 0 deletions test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions test/test_special_matcher_cases.ml
Original file line number Diff line number Diff line change
@@ -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 |}]

0 comments on commit 7b3bcdb

Please sign in to comment.