Fix `str.replace_re` and `str.replace_re_all` (#6615)
authorAndres Noetzli <andres.noetzli@gmail.com>
Thu, 27 May 2021 22:42:10 +0000 (15:42 -0700)
committerGitHub <noreply@github.com>
Thu, 27 May 2021 22:42:10 +0000 (22:42 +0000)
commit29f0b8f378377ed836bddaaf88883d0b2eeb545d
tree5d9edb57c60ab8c8a07dab52f18b72dd441d4fdf
parent631032b15327c28c44b51490dceb434a38f3419a
Fix `str.replace_re` and `str.replace_re_all` (#6615)

Fixes #6057. The reductions of `str.replace_re` and `str.replace_re_all`
were not correctly enforcing that the operations replace the _first_
occurrence of some regular expression in a string. This commit fixes the
issue by introducing a new operator `str.indexof_re(s, r, n)`, which,
analoguously to `str.indexof`, returns the index of the first match of
the regular expression `r` in `s`. The commit adds basic rewrites for
evaluating the operator as well as its reduction. Additionally, it
converts the reductions of `str.replace_re` and `str.replace_re_all` to
use that new operator. This simplifies the reductions of the two
operators and ensures that the semantics are consistent between the two.
29 files changed:
NEWS
src/api/cpp/cvc5.cpp
src/api/cpp/cvc5_kind.h
src/parser/smt2/smt2.cpp
src/printer/smt2/smt2_printer.cpp
src/theory/strings/extf_solver.cpp
src/theory/strings/kinds
src/theory/strings/rewrites.cpp
src/theory/strings/rewrites.h
src/theory/strings/sequences_rewriter.cpp
src/theory/strings/sequences_rewriter.h
src/theory/strings/skolem_cache.cpp
src/theory/strings/skolem_cache.h
src/theory/strings/term_registry.cpp
src/theory/strings/theory_strings.cpp
src/theory/strings/theory_strings_preprocess.cpp
src/theory/strings/theory_strings_utils.cpp
test/regress/CMakeLists.txt
test/regress/regress0/strings/indexof_re.smt2 [new file with mode: 0644]
test/regress/regress1/strings/indexof_re_red.smt2 [new file with mode: 0644]
test/regress/regress1/strings/issue6057-replace-re-all-jiwonparc.smt2 [new file with mode: 0644]
test/regress/regress1/strings/issue6057-replace-re.smt2 [new file with mode: 0644]
test/regress/regress1/strings/issue6203-6-replace-re.smt2 [new file with mode: 0644]
test/regress/regress1/strings/issue6337-replace-re-all.smt2 [new file with mode: 0644]
test/regress/regress1/strings/issue6337-replace-re.smt2 [new file with mode: 0644]
test/regress/regress2/strings/issue6057-replace-re-all-simplified.smt2 [new file with mode: 0644]
test/regress/regress2/strings/issue6057-replace-re-all.smt2 [new file with mode: 0644]
test/regress/regress2/strings/replace_re.smt2
test/regress/regress3/strings/indexof_re_red.smt2 [new file with mode: 0644]