Repository :
https://github.com/colorer/Colorer-library
On branch : cregexp_refactoring
Link :
https://github.com/colorer/Colorer-library/commit/01226fa3dc4ad3ac92fbaba069df01751c499dda
>---------------------------------------------------------------
commit 01226fa3dc4ad3ac92fbaba069df01751c499dda
Author: Aleksey Dobrunov <
cta...@ctapmex.com>
Date: Sun Aug 16 22:27:18 2026 +0500
Drop unfinished NAMED_MATCHES_IN_HASH and CHECKNAMES from CRegExp.
>---------------------------------------------------------------
01226fa3dc4ad3ac92fbaba069df01751c499dda
src/colorer/cregexp/cregexp.cpp | 131 +-------------------------------
src/colorer/cregexp/cregexp.h | 54 -------------
src/colorer/parsers/TextParserHelpers.h | 4 +-
3 files changed, 5 insertions(+), 184 deletions(-)
diff --git a/src/colorer/cregexp/cregexp.cpp b/src/colorer/cregexp/cregexp.cpp
index a6fb564..390ac2c 100644
--- a/src/colorer/cregexp/cregexp.cpp
+++ b/src/colorer/cregexp/cregexp.cpp
@@ -20,7 +20,6 @@ void SMatches::topseSanitize(int cur)
}
}
-#if !defined NAMED_MATCHES_IN_HASH
void SMatches::topnseSanitize(int cur)
{
while (topnse < cur) {
@@ -29,7 +28,6 @@ void SMatches::topnseSanitize(int cur)
ne[topnse] = -1;
}
}
-#endif
SRegInfo::SRegInfo()
@@ -48,12 +46,6 @@ SRegInfo::~SRegInfo()
case EOps::ReWord:
delete un.word;
break;
-#ifdef NAMED_MATCHES_IN_HASH
- case EOps::ReNamedBrackets:
- case EOps::ReBkBrackName:
- if (namedata)
- delete namedata;
-#endif
default:
if (op > EOps::ReBlockOps && (op < EOps::ReSymbolOps || op == EOps::ReBrackets || op == EOps::ReNamedBrackets))
delete un.param;
@@ -78,11 +70,7 @@ void CRegExp::init()
backStr = nullptr;
backTrace = nullptr;
#endif
-#ifndef NAMED_MATCHES_IN_HASH
cnMatch = 0;
-#else
- namedMatches = 0;
-#endif
count_elem = 0;
}
CRegExp::CRegExp()
@@ -98,9 +86,7 @@ CRegExp::CRegExp(const UnicodeString* text)
CRegExp::~CRegExp()
{
delete tree_root;
-#ifndef NAMED_MATCHES_IN_HASH
for (int bp = 0; bp < cnMatch; bp++) delete brnames[bp];
-#endif
}
bool CRegExp::matchChars(wchar one, wchar another) const
@@ -118,14 +104,10 @@ EError CRegExp::setRELow(const UnicodeString& expr)
delete tree_root;
tree_root = nullptr;
-#ifndef NAMED_MATCHES_IN_HASH
for (int bp = 0; bp < cnMatch; bp++) delete brnames[bp];
-#endif
cMatch = 0;
-#ifndef NAMED_MATCHES_IN_HASH
cnMatch = 0;
-#endif
endChange = startChange = false;
int start = 0;
while (start < len && Character::isWhitespace(expr[start])) start++;
@@ -437,7 +419,6 @@ EError CRegExp::setStructs(SRegInfo*& re, const UnicodeString& expr, int& retPos
next->op = EOps::ReMetaSymb;
next->un.metaSymbol = EMetaSymbols::ReEnd;
break;
-#ifndef NAMED_MATCHES_IN_HASH
case 'y':
case 'Y':
next->op = (expr[i + 1] == 'y' ? EOps::ReBkTrace : EOps::ReBkTraceN);
@@ -463,7 +444,6 @@ EError CRegExp::setStructs(SRegInfo*& re, const UnicodeString& expr, int& retPos
}
break;
#endif // COLORERMODE
-#endif // NAMED_MATCHES_IN_HASH
case 'p': // \p{name}
{
@@ -474,17 +454,9 @@ EError CRegExp::setStructs(SRegInfo*& re, const UnicodeString& expr, int& retPos
if (br_name == nullptr)
return EError::ESYNTAX;
blen = br_name->length();
-#ifndef NAMED_MATCHES_IN_HASH
next->param0 = getBracketNo(br_name.get());
if (next->param0 == -1)
return EError::ESYNTAX;
-#else
- if (br_name->length() && namedMatches && !namedMatches->getItem(br_name)) {
- return EBRACKETS;
- }
- next->param0 = 0;
- next->namedata = new UnicodeString(br_name);
-#endif
i += blen + 2;
} break;
default:
@@ -663,13 +635,6 @@ EError CRegExp::setStructs(SRegInfo*& re, const UnicodeString& expr, int& retPos
delete br_name;
}
else {
-#ifndef NAMED_MATCHES_IN_HASH
-#ifdef CHECKNAMES
- if (getBracketNo(br_name) != -1) {
- delete br_name;
- return EError::EBRACKETS;
- }
-#endif
if (cnMatch < NAMED_MATCHES_NUM) {
next->param0 = cnMatch;
brnames[cnMatch] = br_name;
@@ -680,20 +645,6 @@ EError CRegExp::setStructs(SRegInfo*& re, const UnicodeString& expr, int& retPos
delete br_name;
next->param0 = -1;
}
-#else
-#ifdef CHECKNAMES
- if (br_name->length() && namedMatches && namedMatches->getItem(br_name)) {
- delete br_name;
- return EError::EBRACKETS;
- }
-#endif
- next->param0 = 0;
- next->namedata = br_name;
- if (namedMatches) {
- SMatch mt = {-1, -1};
- namedMatches->setItem(br_name, mt);
- }
-#endif
}
i += blen + 4;
}
@@ -1047,16 +998,11 @@ bool CRegExp::lowParse(SRegInfo* re, SRegInfo* prev, int toParse)
matches->s[re->param0] = matches->e[re->param0];
}
else {
-#ifndef NAMED_MATCHES_IN_HASH
matches->topnseSanitize(re->param0);
matches->ns[re->param0] = re->s;
matches->ne[re->param0] = toParse;
if (matches->ne[re->param0] < matches->ns[re->param0])
matches->ns[re->param0] = matches->ne[re->param0];
-#else
- SMatch mt = {re->s, toParse};
- namedMatches->setItem(re->namedata, mt);
-#endif
}
break;
case EOps::ReSymb:
@@ -1156,7 +1102,6 @@ bool CRegExp::lowParse(SRegInfo* re, SRegInfo* prev, int toParse)
continue;
break;
case EOps::ReBkTraceName:
-#ifndef NAMED_MATCHES_IN_HASH
sv = re->param0;
if (!backStr || !backTrace || sv == -1) {
check_stack(false, &re, &prev, &toParse, &leftenter, &action);
@@ -1174,15 +1119,7 @@ bool CRegExp::lowParse(SRegInfo* re, SRegInfo* prev, int toParse)
if (br)
continue;
break;
-#else
- // !!!;
- {
- check_stack(false, &re, &prev, &toParse, &leftenter, &action);
- continue;
- }
-#endif // NAMED_MATCHES_IN_HASH
case EOps::ReBkTraceNName:
-#ifndef NAMED_MATCHES_IN_HASH
sv = re->param0;
if (!backStr || !backTrace || sv == -1 || backTrace->cnMatch <= sv) {
check_stack(false, &re, &prev, &toParse, &leftenter, &action);
@@ -1205,17 +1142,9 @@ bool CRegExp::lowParse(SRegInfo* re, SRegInfo* prev, int toParse)
if (br)
continue;
break;
-#else
- // !!;
- {
- check_stack(false, &re, &prev, &toParse, &leftenter, &action);
- continue;
- }
-#endif // NAMED_MATCHES_IN_HASH
#endif // COLORERMODE
case EOps::ReBkBrackName:
-#ifndef NAMED_MATCHES_IN_HASH
sv = re->param0;
if (sv == -1 || cnMatch <= sv) {
check_stack(false, &re, &prev, &toParse, &leftenter, &action);
@@ -1238,30 +1167,6 @@ bool CRegExp::lowParse(SRegInfo* re, SRegInfo* prev, int toParse)
if (br)
continue;
break;
-#else
- {
- SMatch* mt = namedMatches->getItem(re->namedata);
- if (!mt) {
- check_stack(false, &re, &prev, &toParse, &leftenter, &action);
- continue;
- }
- if (mt->s == -1 || mt->e == -1) {
- check_stack(false, &re, &prev, &toParse, &leftenter, &action);
- continue;
- }
- br = false;
- for (i = mt->s; i < mt->e; i++) {
- if (toParse >= end || pattern[toParse] != pattern[i]) {
- check_stack(false, &re, &prev, &toParse, &leftenter, &action);
- br = true;
- break;
- }
- toParse++;
- }
- if (br)
- continue;
- } break;
-#endif // NAMED_MATCHES_IN_HASH
case EOps::ReBkBrack:
sv = re->param0;
@@ -1603,16 +1508,12 @@ inline bool CRegExp::parseRE(int pos)
matches->reset();
matches->cMatch = cMatch;
-#ifndef NAMED_MATCHES_IN_HASH
matches->cnMatch = cnMatch;
-#endif
do {
// stack=null;
if (lowParse(tree_root, nullptr, toParse)) {
matches->topseSanitize(cMatch - 1);
-#ifndef NAMED_MATCHES_IN_HASH
matches->topnseSanitize(cnMatch - 1);
-#endif
return true;
}
if (!positionMoves)
@@ -1622,13 +1523,8 @@ inline bool CRegExp::parseRE(int pos)
return false;
}
-bool CRegExp::parse(const UnicodeString* str, int pos, int eol, SMatches* mtch
-#ifdef NAMED_MATCHES_IN_HASH
- ,
- PMatchHash nmtch
-#endif
- ,
- int soScheme, int posMoves)
+bool CRegExp::parse(const UnicodeString* str, int pos, int eol, SMatches* mtch, int soScheme,
+ int posMoves)
{
bool nms = positionMoves;
if (posMoves != -1)
@@ -1639,20 +1535,12 @@ bool CRegExp::parse(const UnicodeString* str, int pos, int eol, SMatches* mtch
global_pattern = str;
end = eol;
matches = mtch;
-#ifdef NAMED_MATCHES_IN_HASH
- namedMatches = nmtch;
-#endif
bool result = parseRE(pos);
positionMoves = nms;
return result;
}
-bool CRegExp::parse(const UnicodeString* str, SMatches* mtch
-#ifdef NAMED_MATCHES_IN_HASH
- ,
- PMatchHash nmtch
-#endif
-)
+bool CRegExp::parse(const UnicodeString* str, SMatches* mtch)
{
end = str->length();
global_pattern = str;
@@ -1660,9 +1548,6 @@ bool CRegExp::parse(const UnicodeString* str, SMatches* mtch
schemeStart = 0;
#endif
matches = mtch;
-#ifdef NAMED_MATCHES_IN_HASH
- namedMatches = nmtch;
-#endif
return parseRE(0);
}
@@ -1672,15 +1557,7 @@ bool CRegExp::parse(const UnicodeString* str, SMatches* mtch
bool CRegExp::setRE(const UnicodeString* re)
{
error = EError::EERROR;
-#ifdef NAMED_MATCHES_IN_HASH
- PMatchHash oldnamedMatches = namedMatches;
- SMatchHash tmpMatchHash;
- namedMatches = &tmpMatchHash;
error = setRELow(*re);
- namedMatches = oldnamedMatches;
-#else
- error = setRELow(*re);
-#endif
return error == EError::EOK;
}
bool CRegExp::isOk()
@@ -1705,7 +1582,6 @@ void CRegExp::clearRegExpStack()
CRegExp::RegExpStack = nullptr;
}
-#ifndef NAMED_MATCHES_IN_HASH
int CRegExp::getBracketNo(const UnicodeString* brname)
{
for (int brn = 0; brn < cnMatch; brn++)
@@ -1719,7 +1595,6 @@ UnicodeString* CRegExp::getBracketName(int no)
return nullptr;
return brnames[no];
}
-#endif
#ifdef COLORERMODE
bool CRegExp::setBackRE(CRegExp* bkre)
diff --git a/src/colorer/cregexp/cregexp.h b/src/colorer/cregexp/cregexp.h
index a952aef..3a58523 100644
--- a/src/colorer/cregexp/cregexp.h
+++ b/src/colorer/cregexp/cregexp.h
@@ -15,43 +15,10 @@
/// regexp compatibility mode
#define COLORERMODE
-/// use hashes for saving named brackets
-//#define NAMED_MATCHES_IN_HASH
-
-/// check duplicate brackets
-//#define CHECKNAMES
-
-#if defined COLORERMODE && defined NAMED_MATCHES_IN_HASH
-#error COLORERMODE && NAMED_MATCHES_IN_HASH not realyzed yet
-#endif
-
/// numeric matches num
#define MATCHES_NUM 0x10
-
-#if !defined NAMED_MATCHES_IN_HASH
// number of named brackets (access through SMatches.ns)
#define NAMED_MATCHES_NUM 0x10
-#endif
-
-#ifdef NAMED_MATCHES_IN_HASH
-struct SMatch
-{
- int s, e;
-};
-// you can redefine this class
-typedef class SMatchHash
-{
- public:
- SMatch* setItem(const UnicodeString* name, SMatch& smatch)
- {
- return nullptr;
- };
- SMatch* getItem(const UnicodeString* name)
- {
- return nullptr;
- };
-} * PMatchHash;
-#endif
enum class EOps {
ReBlockOps,
@@ -131,11 +98,9 @@ struct SMatches
s[0] = e[0] = -1;
cMatch = 0;
topse = 0;
-#if !defined NAMED_MATCHES_IN_HASH
ns[0] = ne[0] = -1;
cnMatch = 0;
topnse = 0;
-#endif
}
void topseSanitize(int cur); // use before accessing s[cur]/e[cur] to ensure their lazy inited to -1
@@ -144,13 +109,11 @@ struct SMatches
int topse;
int cMatch;
-#if !defined NAMED_MATCHES_IN_HASH
void topnseSanitize(int cur); // use before accessing ns[cur]/ne[cur] to ensure their lazy inited to -1
int ns[NAMED_MATCHES_NUM];
int ne[NAMED_MATCHES_NUM];
int topnse;
int cnMatch;
-#endif
};
/** Regular expressions internal tree node.
@@ -169,9 +132,6 @@ class SRegInfo
CharacterClass* charclass;
SRegInfo* param;
} un;
-#if defined NAMED_MATCHES_IN_HASH
- UnicodeString* namedata;
-#endif
SRegInfo* parent = nullptr;
SRegInfo* next = nullptr;
SRegInfo* prev = nullptr;
@@ -319,15 +279,6 @@ class CRegExp
previous structures.
*/
bool setRE(const UnicodeString* re);
-#ifdef NAMED_MATCHES_IN_HASH
- /** Runs RE parser against input string @c str
- */
- bool parse(const UnicodeString* str, SMatches* mtch, SMatchHash* nmtch = nullptr);
- /** Runs RE parser against input string @c str
- */
- bool parse(const UnicodeString* str, int pos, int eol, SMatches* mtch,
- SMatchHash* nmtch = nullptr, int soscheme = 0, int moves = -1);
-#else
/** Runs RE parser against input string @c str
*/
bool parse(const UnicodeString* str, SMatches* mtch);
@@ -335,7 +286,6 @@ class CRegExp
*/
bool parse(const UnicodeString* str, int pos, int eol, SMatches* mtch, int soscheme = 0,
int moves = -1);
-#endif
bool canStartWith(wchar ch) const;
private:
@@ -363,12 +313,8 @@ class CRegExp
SMatches* matches = nullptr;
int cMatch = 0;
-#if !defined NAMED_MATCHES_IN_HASH
UnicodeString* brnames[NAMED_MATCHES_NUM] = {};
int cnMatch = 0;
-#else
- SMatchHash* namedMatches = nullptr;
-#endif
void init();
EError setRELow(const UnicodeString& re);
diff --git a/src/colorer/parsers/TextParserHelpers.h b/src/colorer/parsers/TextParserHelpers.h
index 393560e..8424326 100644
--- a/src/colorer/parsers/TextParserHelpers.h
+++ b/src/colorer/parsers/TextParserHelpers.h
@@ -3,8 +3,8 @@
#include "colorer/parsers/HrcLibraryImpl.h"
-#if !defined COLORERMODE || defined NAMED_MATCHES_IN_HASH
-#error need (COLORERMODE & !NAMED_MATCHES_IN_HASH) in cregexp
+#if !defined COLORERMODE
+#error need COLORERMODE in cregexp
#endif
#define MATCH_NOTHING 0