Skip to content

Commit

Permalink
crystaledit/editlib/parses/*: refactor
Browse files Browse the repository at this point in the history
(cherry picked from commit e867c0d)
  • Loading branch information
sdottaka committed Sep 8, 2024
1 parent 7ce3809 commit 90e7844
Show file tree
Hide file tree
Showing 32 changed files with 1,185 additions and 1,923 deletions.
38 changes: 15 additions & 23 deletions Externals/crystaledit/editlib/parsers/abap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,19 @@ static bool IsNumber(const tchar_t* pszChars, int nLength)
return result;
}

static inline void
DefineIdentiferBlock(const tchar_t *pszChars, int nLength, CrystalLineParser::TEXTBLOCK * pBuf, int &nActualItems, int nIdentBegin, int I)
{
if (IsAbapKeyword(pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK(nIdentBegin, COLORINDEX_KEYWORD);
}
else if (IsNumber(pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK(nIdentBegin, COLORINDEX_NUMBER);
}
}

unsigned
CrystalLineParser::ParseLineAbap(unsigned dwCookie, const tchar_t* pszChars, int nLength, TEXTBLOCK* pBuf, int& nActualItems)
{
Expand Down Expand Up @@ -1210,14 +1223,7 @@ CrystalLineParser::ParseLineAbap(unsigned dwCookie, const tchar_t* pszChars, int
{
if (nIdentBegin >= 0)
{
if (IsAbapKeyword(pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK(nIdentBegin, COLORINDEX_KEYWORD);
}
else if (IsNumber(pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK(nIdentBegin, COLORINDEX_NUMBER);
}
DefineIdentiferBlock(pszChars, nLength, pBuf, nActualItems, nIdentBegin, I);

bRedefineBlock = true;
bDecIndex = true;
Expand All @@ -1227,23 +1233,9 @@ CrystalLineParser::ParseLineAbap(unsigned dwCookie, const tchar_t* pszChars, int
}

if (nIdentBegin >= 0)
{
if (IsAbapKeyword(pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK(nIdentBegin, COLORINDEX_KEYWORD);
}
else if (IsNumber(pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK(nIdentBegin, COLORINDEX_NUMBER);
}
}
DefineIdentiferBlock(pszChars, nLength, pBuf, nActualItems, nIdentBegin, I);

if (pszChars[nLength - 1] != '\\' || IsMBSTrail(pszChars, nLength - 1))
dwCookie &= COOKIE_EXT_COMMENT;
return dwCookie;
}





73 changes: 29 additions & 44 deletions Externals/crystaledit/editlib/parsers/batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,33 @@ IsUser2Keyword (const tchar_t *pszChars, int nLength)
return ISXKEYWORDI (s_apszUser2KeywordList, pszChars, nLength);
}

static inline void
DefineIdentiferBlock(const tchar_t *pszChars, int nLength, CrystalLineParser::TEXTBLOCK * pBuf, int &nActualItems, int nIdentBegin, int I, unsigned &dwCookie)
{
if (IsBatKeyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
if ((I - nIdentBegin ==4 && !tc::tcsnicmp (pszChars + nIdentBegin, _T ("GOTO"), 4)) ||
(I - nIdentBegin ==5 && !tc::tcsnicmp (pszChars + nIdentBegin, _T ("GOSUB"), 5))
)
{
dwCookie=COOKIE_PREPROCESSOR;
}
}
else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1);
}
else if (IsUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2);
}
else if (CrystalLineParser::IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
}
}

unsigned
CrystalLineParser::ParseLineBatch (unsigned dwCookie, const tchar_t *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
{
Expand Down Expand Up @@ -846,28 +873,7 @@ CrystalLineParser::ParseLineBatch (unsigned dwCookie, const tchar_t *pszChars, i
}
else
{
if (IsBatKeyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
if ((I - nIdentBegin ==4 && !tc::tcsnicmp (pszChars + nIdentBegin, _T ("GOTO"), 4)) ||
(I - nIdentBegin ==5 && !tc::tcsnicmp (pszChars + nIdentBegin, _T ("GOSUB"), 5))
)
{
dwCookie=COOKIE_PREPROCESSOR;
}
}
else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1);
}
else if (IsUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2);
}
else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
}
DefineIdentiferBlock(pszChars, nLength, pBuf, nActualItems, nIdentBegin, I, dwCookie);
}
bRedefineBlock = true;
bDecIndex = true;
Expand All @@ -878,28 +884,7 @@ CrystalLineParser::ParseLineBatch (unsigned dwCookie, const tchar_t *pszChars, i

if (nIdentBegin >= 0)
{
if (IsBatKeyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
if ((I - nIdentBegin ==4 && !tc::tcsnicmp (pszChars + nIdentBegin, _T ("GOTO"), 4)) ||
(I - nIdentBegin ==5 && !tc::tcsnicmp (pszChars + nIdentBegin, _T ("GOSUB"), 5))
)
{
dwCookie=COOKIE_PREPROCESSOR;
}
}
else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1);
}
else if (IsUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2);
}
else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
}
DefineIdentiferBlock(pszChars, nLength, pBuf, nActualItems, nIdentBegin, I, dwCookie);
}

dwCookie = 0;
Expand Down
104 changes: 40 additions & 64 deletions Externals/crystaledit/editlib/parsers/cplusplus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,44 @@ IsUser1Keyword (const tchar_t *pszChars, int nLength)
return ISXKEYWORD (s_apszUser1KeywordList, pszChars, nLength);
}

static inline void
DefineIdentiferBlock(const tchar_t *pszChars, int nLength, CrystalLineParser::TEXTBLOCK * pBuf, int &nActualItems, int nIdentBegin, int I,
bool (*IsKeyword)(const tchar_t *pszChars, int nLength),
bool (*IsUser1Keyword)(const tchar_t *pszChars, int nLength))
{
if (IsKeyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
}
else if (IsUser1Keyword && IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1);
}
else if (CrystalLineParser::IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
}
else
{
bool bFunction = false;

for (int j = I; j < nLength; j++)
{
if (!xisspace (pszChars[j]))
{
if (pszChars[j] == '(')
{
bFunction = true;
}
break;
}
}
if (bFunction)
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
}
}
}
unsigned
CrystalLineParser::ParseLineC (unsigned dwCookie, const tchar_t *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
{
Expand Down Expand Up @@ -441,38 +479,7 @@ CrystalLineParser::ParseLineCJava (unsigned dwCookie, const tchar_t *pszChars, i
{
if (nIdentBegin >= 0)
{
if (IsKeyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
}
else if (IsUser1Keyword && IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1);
}
else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
}
else
{
bool bFunction = false;

for (int j = I; j < nLength; j++)
{
if (!xisspace (pszChars[j]))
{
if (pszChars[j] == '(')
{
bFunction = true;
}
break;
}
}
if (bFunction)
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
}
}
DefineIdentiferBlock(pszChars, nLength, pBuf, nActualItems, nIdentBegin, I, IsKeyword, IsUser1Keyword);
bRedefineBlock = true;
bDecIndex = true;
nIdentBegin = -1;
Expand All @@ -482,38 +489,7 @@ CrystalLineParser::ParseLineCJava (unsigned dwCookie, const tchar_t *pszChars, i

if (nIdentBegin >= 0)
{
if (IsKeyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
}
else if (IsUser1Keyword && IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1);
}
else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
}
else
{
bool bFunction = false;

for (int j = I; j < nLength; j++)
{
if (!xisspace (pszChars[j]))
{
if (pszChars[j] == '(')
{
bFunction = true;
}
break;
}
}
if (bFunction)
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
}
}
DefineIdentiferBlock(pszChars, nLength, pBuf, nActualItems, nIdentBegin, I, IsKeyword, IsUser1Keyword);
}

if (pszChars[nLength - 1] != '\\' || IsMBSTrail(pszChars, nLength - 1))
Expand Down
Loading

0 comments on commit 90e7844

Please sign in to comment.