Repository :
https://github.com/colorer/Colorer-library
On branch : cregexp_refactoring
Link :
https://github.com/colorer/Colorer-library/commit/e5107f108e80e5136add4ed4cfadd409b490ae3f
>---------------------------------------------------------------
commit e5107f108e80e5136add4ed4cfadd409b490ae3f
Author: Aleksey Dobrunov <
cta...@ctapmex.com>
Date: Sun Aug 16 21:14:43 2026 +0500
Preserve CRegExp compile errors instead of overwriting them with EBRACKETS.
>---------------------------------------------------------------
e5107f108e80e5136add4ed4cfadd409b490ae3f
src/colorer/cregexp/cregexp.cpp | 5 ++---
tests/unit/test_cregexp.cpp | 19 ++++++++++++-------
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/colorer/cregexp/cregexp.cpp b/src/colorer/cregexp/cregexp.cpp
index 5495533..8569929 100644
--- a/src/colorer/cregexp/cregexp.cpp
+++ b/src/colorer/cregexp/cregexp.cpp
@@ -163,11 +163,10 @@ EError CRegExp::setRELow(const UnicodeString& expr)
int endPos;
EError err = setStructs(tree_root->un.param, UnicodeString(expr, start, len), endPos);
- if (endPos != len)
- err = EError::EBRACKETS;
-
if (err != EError::EOK)
return err;
+ if (endPos != len)
+ return EError::EBRACKETS;
optimize();
return EError::EOK;
}
diff --git a/tests/unit/test_cregexp.cpp b/tests/unit/test_cregexp.cpp
index 0349a7e..955aca5 100644
--- a/tests/unit/test_cregexp.cpp
+++ b/tests/unit/test_cregexp.cpp
@@ -103,17 +103,22 @@ TEST_CASE("CRegExp compilation errors", "[cregexp]")
REQUIRE(re.getError() == error);
}
- SECTION("malformed pattern does not compile")
+ SECTION("malformed pattern")
{
- // Unclosed constructs and dangling quantifiers currently collapse to EBRACKETS
- // in setRELow when the compiler returns before filling endPos.
- const auto pattern = GENERATE(as<const char16_t*>{}, u"/(abc/", u"/abc)/", u"/[abc/", u"/a{/",
- u"/+/", u"/{2}/", u"/*/");
+ const auto [pattern, error] = GENERATE(table<const char16_t*, EError>({
+ {u"/(abc/", EError::EBRACKETS},
+ {u"/abc)/", EError::EBRACKETS},
+ {u"/[abc/", EError::EENUM},
+ {u"/a{/", EError::EBRACKETS},
+ {u"/+/", EError::EOP},
+ {u"/{2}/", EError::EOP},
+ {u"/*/", EError::EOP},
+ }));
const auto pre = ustr(pattern);
CRegExp re(&pre);
INFO("pattern: " << UStr::to_stdstr(&pre));
REQUIRE_FALSE(re.isOk());
- REQUIRE(re.getError() != EError::EOK);
+ REQUIRE(re.getError() == error);
}
}
@@ -470,7 +475,7 @@ TEST_CASE("CRegExp Colorer backtrace \\y", "[cregexp]")
const auto end_re = ustr(u"/\\y{n}/");
CRegExp end;
REQUIRE_FALSE(end.setRE(&end_re));
- REQUIRE(end.getError() != EError::EOK);
+ REQUIRE(end.getError() == EError::EERROR);
}
}