mirror of
https://github.com/comby-tools/comby.git
synced 2024-09-11 13:25:36 +03:00
Fix strings prefixed by non-whitespace or hole or delimiter
This commit is contained in:
parent
fdcbce8aa9
commit
2a34e9ff92
@ -343,6 +343,8 @@ ocaml setup.ml -build
|
||||
ocaml setup.ml -install
|
||||
cd -
|
||||
|
||||
make
|
||||
make clean
|
||||
make build-with-coverage
|
||||
make test
|
||||
|
||||
|
@ -172,7 +172,7 @@ module Html = struct
|
||||
|
||||
let user_defined_delimiters =
|
||||
Dyck.Syntax.user_defined_delimiters @
|
||||
[ ("<", ">")
|
||||
[ "<", ">"
|
||||
]
|
||||
|
||||
let comment_parser =
|
||||
|
@ -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 =
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user