Skip to content

Commit

Permalink
Have ..~ report pattern line errors in the same way as ....
Browse files Browse the repository at this point in the history
When `...` fails to match it (sensibly) tells you that the error was on
the of the pattern *after* the `...`, but `..~` reported the pattern
line itself. This commit makes `..~` follow `...`s behaviour.
  • Loading branch information
ltratt committed Jun 3, 2024
1 parent 2f9d8f2 commit 9794e4e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ impl<'a> FMatcher<'a> {
None => return Ok(()),
}
} else if x.trim() == GROUP_ANCHOR_WILDCARD {
ptn_lines_off += 1;
// We now have to perform (bounded) backtracking
let ptn_lines_off_orig = ptn_lines_off;
let text_lines_off_orig = text_lines_off;
ptnl = ptn_lines.next();
Expand All @@ -295,8 +297,6 @@ impl<'a> FMatcher<'a> {
if ptnl.is_none() {
return Ok(());
}
// We now have to perform (bounded) backtracking
ptn_lines_off += 1;
let mut ptn_lines_sub = ptn_lines.clone();
let mut ptnl_sub = ptnl;
let mut text_lines_sub = text_lines.clone();
Expand Down Expand Up @@ -1013,10 +1013,10 @@ mod tests {
assert_eq!(helper("...\nc\nd\n", "a\nb\nc\n0\ne"), (3, 4));
assert_eq!(helper("...\nd\n", "a\nb\nc\n0\ne"), (2, 5));

assert_eq!(helper("a\n..~\nc\nd\ne", "a\nb\nc\nd"), (2, 2));
assert_eq!(helper("a\n..~\nc\nd", "a\nb\nc\ne"), (2, 2));
assert_eq!(helper("a\n..~\nc\nd", "a\nc\ne\nc\ne"), (2, 2));
assert_eq!(helper("a\n..~\nc\nd\n...\nf", "a\ne\nf\nc\nd\ne"), (5, 6));
assert_eq!(helper("a\n..~\nc\nd\ne", "a\nb\nc\nd"), (3, 2));
assert_eq!(helper("a\n..~\nc\nd", "a\nb\nc\ne"), (3, 2));
assert_eq!(helper("a\n..~\nc\nd", "a\nc\ne\nc\ne"), (3, 2));
assert_eq!(helper("a\n..~\nc\nd\n...\nf", "a\ne\nf\nc\nd\ne"), (6, 6));
}

#[test]
Expand Down

0 comments on commit 9794e4e

Please sign in to comment.