Skip to content

Commit

Permalink
Merge ed0602d into 1dc3c90
Browse files Browse the repository at this point in the history
  • Loading branch information
rvantonder committed Jun 6, 2019
2 parents 1dc3c90 + ed0602d commit b09a601
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/matchers/languages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module Html = struct

let user_defined_delimiters =
Dyck.Syntax.user_defined_delimiters @
[ ("<", ">")
[ "<", ">"
]

let comment_parser =
Expand Down
17 changes: 13 additions & 4 deletions lib/matchers/matcher.ml
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,25 @@ module Make (Syntax : Syntax.S) = struct
return (id, including, until_char)

let reserved_delimiters =
List.concat_map Syntax.user_defined_delimiters ~f:(fun (from, until) -> [from; until])
|> List.map ~f:string
|> fun reserved ->
let reserved_delimiters =
List.concat_map Syntax.user_defined_delimiters ~f:(fun (from, until) -> [from; until])
|> List.map ~f:string
in
let reserved_escapable_strings =
List.concat_map Syntax.escapable_string_literals ~f:(fun x -> [x])
|> List.map ~f:string
in
let reserved_raw_strings =
List.concat_map Syntax.raw_string_literals ~f:(fun (from, until) -> [from; until])
|> List.map ~f:string
in
let single =
string ":[[" >> (many (alphanum <|> char '_') |>> String.of_char_list) << string "]]"
in
let greedy =
string ":[" >> (many (alphanum <|> char '_') |>> String.of_char_list) << string "]"
in
single::greedy::reserved
[single] @ [greedy] @ reserved_delimiters @ reserved_escapable_strings @ reserved_raw_strings
|> choice

let reserved =
Expand Down
8 changes: 8 additions & 0 deletions test/test_special_matcher_cases.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ let run ?(configuration = configuration) (module M : Matchers.Matcher) source ma
|> (fun { rewritten_source; _ } -> rewritten_source)
|> print_string

let%expect_test "parse_rust_apostrophe_ok" =
let source = {|width="1280"|} in
let match_template = {|width=":[1]"|} in
let rewrite_template = {|:[1]|} in

run (module Matchers.Generic) source match_template rewrite_template;
[%expect_exact {|1280|}]

let%expect_test "parse_rust_apostrophe_ok" =
let source = {|pub struct GlobBuilder<'a> {}|} in
let match_template = {|{}|} in
Expand Down

0 comments on commit b09a601

Please sign in to comment.