Fix strings prefixed by non-whitespace or hole or delimiter

This commit is contained in:
Rijnard van Tonder 2019-06-06 12:13:11 -04:00 committed by GitHub
parent fdcbce8aa9
commit 2a34e9ff92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 5 deletions

View File

@ -343,6 +343,8 @@ ocaml setup.ml -build
ocaml setup.ml -install
cd -
make
make clean
make build-with-coverage
make test

View File

@ -172,7 +172,7 @@ module Html = struct
let user_defined_delimiters =
Dyck.Syntax.user_defined_delimiters @
[ ("<", ">")
[ "<", ">"
]
let comment_parser =

View File

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

View File

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