Repository :
https://github.com/colorer/Colorer-library
On branch : cregexp_refactoring
Link :
https://github.com/colorer/Colorer-library/commit/eb6c5c87f6af93e5660e8d4895a8a272f5bda4fa
>---------------------------------------------------------------
commit eb6c5c87f6af93e5660e8d4895a8a272f5bda4fa
Author: Aleksey Dobrunov <
cta...@ctapmex.com>
Date: Sun Aug 16 23:02:17 2026 +0500
Keep CRegExp parse-stack actions as ReAction instead of mixing them with bool.
>---------------------------------------------------------------
eb6c5c87f6af93e5660e8d4895a8a272f5bda4fa
src/colorer/cregexp/cregexp.cpp | 30 ++++++++++++++++--------------
src/colorer/cregexp/cregexp.h | 37 ++++++++++++++++++-------------------
2 files changed, 34 insertions(+), 33 deletions(-)
diff --git a/src/colorer/cregexp/cregexp.cpp b/src/colorer/cregexp/cregexp.cpp
index 8e79313..4d44823 100644
--- a/src/colorer/cregexp/cregexp.cpp
+++ b/src/colorer/cregexp/cregexp.cpp
@@ -896,10 +896,10 @@ bool CRegExp::checkMetaSymbol(EMetaSymbols symb, int& toParse)
}
}
-void CRegExp::check_stack(bool res, SRegInfo** re, SRegInfo** prev, int* toParse, bool* leftenter, int* action)
+void CRegExp::check_stack(bool res, SRegInfo** re, SRegInfo** prev, int* toParse, bool* leftenter, ReAction* action)
{
if (count_elem == 0) {
- *action = res;
+ *action = res ? rea_True : rea_False;
return;
}
@@ -916,8 +916,8 @@ void CRegExp::check_stack(bool res, SRegInfo** re, SRegInfo** prev, int* toParse
*leftenter = ne.leftenter;
}
-void CRegExp::insert_stack(SRegInfo** re, SRegInfo** prev, int* toParse, bool* leftenter, int ifTrueReturn,
- int ifFalseReturn, SRegInfo** re2, SRegInfo** prev2, int toParse2)
+void CRegExp::insert_stack(SRegInfo** re, SRegInfo** prev, int* toParse, bool* leftenter, ReAction ifTrueReturn,
+ ReAction ifFalseReturn, SRegInfo** re2, SRegInfo** prev2, int toParse2)
{
if (RegExpStack_Size == 0) {
CRegExp::RegExpStack = new StackElem[INIT_MEM_SIZE];
@@ -958,15 +958,15 @@ bool CRegExp::lowParse(SRegInfo* re, SRegInfo* prev, int toParse)
bool leftenter = true;
bool br = false;
const UnicodeString& pattern = *global_pattern;
- int action = -1;
+ ReAction action = rea_None;
if (!re) {
re = prev->parent;
leftenter = false;
}
while (true) {
- while (re || action != -1) {
- if (re && action == -1)
+ while (re || action != rea_None) {
+ if (re && action == rea_None)
switch (re->op) {
case EOps::ReEmpty:
break;
@@ -1320,6 +1320,8 @@ bool CRegExp::lowParse(SRegInfo* re, SRegInfo* prev, int toParse)
}
switch (action) {
+ case rea_None:
+ break;
case rea_False:
if (count_elem) {
check_stack(false, &re, &prev, &toParse, &leftenter, &action);
@@ -1337,26 +1339,26 @@ bool CRegExp::lowParse(SRegInfo* re, SRegInfo* prev, int toParse)
return true;
break;
case rea_Break:
- action = -1;
+ action = rea_None;
break;
case rea_RangeN_step2:
- action = -1;
+ action = rea_None;
insert_stack(&re, &prev, &toParse, &leftenter, rea_True, rea_False, &re->next, &re, toParse);
continue;
break;
case rea_RangeNM_step2:
- action = -1;
+ action = rea_None;
insert_stack(&re, &prev, &toParse, &leftenter, rea_True, rea_RangeNM_step3, &re->next, &re, toParse);
continue;
break;
case rea_RangeNM_step3:
- action = -1; //-V1037
+ action = rea_None;
re->param1++;
check_stack(false, &re, &prev, &toParse, &leftenter, &action);
continue;
break;
case rea_NGRangeN_step2:
- action = -1;
+ action = rea_None;
if (re->param0)
re->param0--;
re = re->un.param;
@@ -1364,13 +1366,13 @@ bool CRegExp::lowParse(SRegInfo* re, SRegInfo* prev, int toParse)
continue;
break;
case rea_NGRangeNM_step2:
- action = -1;
+ action = rea_None;
insert_stack(&re, &prev, &toParse, &leftenter, rea_True, rea_NGRangeNM_step3, &re->un.param, nullptr,
toParse);
continue;
break;
case rea_NGRangeNM_step3:
- action = -1;
+ action = rea_None;
re->param1++;
check_stack(false, &re, &prev, &toParse, &leftenter, &action);
continue;
diff --git a/src/colorer/cregexp/cregexp.h b/src/colorer/cregexp/cregexp.h
index 63e2f5b..785b493 100644
--- a/src/colorer/cregexp/cregexp.h
+++ b/src/colorer/cregexp/cregexp.h
@@ -141,23 +141,8 @@ class SRegInfo
EOps op = EOps::ReEmpty;
};
-struct StackElem
-{
- // local variable
- SRegInfo* re;
- SRegInfo* prev;
- int toParse;
- bool leftenter;
- // step if function return true
- int ifTrueReturn;
- // step if function return false
- int ifFalseReturn;
-};
-
-#define INIT_MEM_SIZE 512
-#define MEM_INC 128
-
enum ReAction {
+ rea_None = -1,
rea_False = 0,
rea_True = 1,
rea_Break,
@@ -168,6 +153,20 @@ enum ReAction {
rea_NGRangeNM_step2,
rea_NGRangeNM_step3
};
+
+struct StackElem
+{
+ // local variable
+ SRegInfo* re;
+ SRegInfo* prev;
+ int toParse;
+ bool leftenter;
+ ReAction ifTrueReturn;
+ ReAction ifFalseReturn;
+};
+
+#define INIT_MEM_SIZE 512
+#define MEM_INC 128
/** Regular Expression compiler and matcher.
Colorer regular expressions library cregexp.
@@ -339,9 +338,9 @@ class CRegExp
int count_elem;
void check_stack(bool res, SRegInfo** re, SRegInfo** prev, int* toParse, bool* leftenter,
- int* action);
- void insert_stack(SRegInfo** re, SRegInfo** prev, int* toParse, bool* leftenter, int ifTrueReturn,
- int ifFalseReturn, SRegInfo** re2, SRegInfo** prev2, int toParse2);
+ ReAction* action);
+ void insert_stack(SRegInfo** re, SRegInfo** prev, int* toParse, bool* leftenter, ReAction ifTrueReturn,
+ ReAction ifFalseReturn, SRegInfo** re2, SRegInfo** prev2, int toParse2);
static StackElem* RegExpStack;
static int RegExpStack_Size;