Consecutive newline holes should match consecutive lines

This commit is contained in:
Rijnard van Tonder 2019-09-01 00:52:23 -04:00 committed by GitHub
parent c5a86ab5df
commit 45d5505c4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 9 deletions

View File

@ -496,12 +496,10 @@ module Make (Syntax : Syntax.S) = struct
| Hole Line (identifier, _dimension) ->
let allowed =
let until_char = '\n' in
let allowed = any_char |>> String.of_char in
let allowed = (not_followed_by (char until_char) "" >> allowed) in
allowed
let allowed = many1 (is_not (char '\n')) in
allowed >>= fun x -> return [(String.of_char_list x)^"\n"]
in
let hole_semantics = many1 (not_followed_by rest "" >> allowed) in
let hole_semantics = allowed << char '\n' in
record_matches identifier hole_semantics
| Hole Blank (identifier, _dimension) ->

View File

@ -42,10 +42,10 @@ derp
let rewrite_template = {|{:[x]}|} in
run source match_template rewrite_template;
[%expect_exact {|
{foo.}
{foo.bar.quux}
{derp}
|}]
{foo.
}{foo.bar.quux
}{derp
}|}]
let%expect_test "leading_indentation" =
let run = run_all in
@ -79,3 +79,36 @@ let%expect_test "alphanum_partial_match" =
let rewrite_template = {|{:[x]}|} in
run source match_template rewrite_template;
[%expect_exact {| foo. {a} derp|}]
let%expect_test "newline_matcher_should_not_be_sat_on_space" =
let run = run_all in
let source =
{|a b c d
e f g h|} in
let match_template = {|:[line\n] |} in
let rewrite_template = {|{:[line]}|} in
run source match_template rewrite_template;
[%expect_exact {|{a b c d
}e f g h|}];
let run = run_all in
let source =
{|a b c d
e f g h|} in
let match_template = {|:[line\n]:[next]|} in
let rewrite_template = {|{:[line]}|} in
run source match_template rewrite_template;
[%expect_exact {|{a b c d
}|}];
let run = run_all in
let source =
{|a b c d
e f g h
|} in
let match_template = {|:[line1\n]:[next\n]|} in
let rewrite_template = {|{:[line1]|:[next]}|} in
run source match_template rewrite_template;
[%expect_exact {|{a b c d
|e f g h
}|}]