Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs and make replace(all) operations SMT-LIB compliant #75

Merged
merged 8 commits into from
Jul 25, 2023

Conversation

matthewhague
Copy link
Collaborator

  • Add a bunch of tests for ReplacePreOp that should have been there long ago
  • Fix old bugs with string replacement (I still wasn't building the right transducer from the string..)
    • Original fix 69c2ae8 wasn't quite right, and should have been done for ReplacePreOp too.
  • Add ReplaceAllShortestPreOp, rename existing pre-op to ReplaceAllLongestPreOp
    • For regex, longest and shortest both only look for non-empty matches, which is ok by SMT-LIB
  • Add ReplaceShortestPreOp, rename existing pre-op to ReplaceLongestPreOp
    • Implement correct prepend semantics for shortest if regex accepts the empty word
  • When replace_all s t t' when t is empty, then return s unchanged (via a new NOPPreOp)
  • When replace s t t' when t is empty, return t's as per SMT-LIB

The bug found was the same bug as fixed in 69c2ae8, except in the
analogous ReplacePreOp (rather than ReplaceAllPreOp) code. It occurred in
the case where a failed word match has a suffix that could have been the
start of another match attempt.
When matching e.g. abc, if an a is read instead of a b, then that a
could be the start of the new match. This was the old bug that was
fixed.

I didn't account for the fact that a could alternatively be the last
character read, and so there should be an accepting transition for that
case (you can't accept part way through a match, so existing transitions
didn't work).
That is, in replace(x, "", y), y is prepended to x.
If the string to replace is empty, then the defined SMT-LIB semantics
for shortest match is to return the string unchanged. Support this with
a new NOPPreOp object.
That is, allow an empty match in the regex, but expect the result not to
use it. (SMT-LIB semantics)
@pruemmer pruemmer merged commit f713f04 into master Jul 25, 2023
1 check passed
@pruemmer pruemmer deleted the replace-shortest branch March 25, 2024 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants