Skip to content

Commit

Permalink
Fix #2415: Wrong syntax highlighting for TeX files
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Sep 8, 2024
1 parent 4e08e3c commit 2d40a98
Showing 1 changed file with 42 additions and 64 deletions.
106 changes: 42 additions & 64 deletions Externals/crystaledit/editlib/parsers/tex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,44 @@ IsUser1Keyword (const tchar_t *pszChars, int nLength)
return ISXKEYWORDI (s_apszUser1KeywordList, pszChars, nLength);
}

static inline void
DefineIdentiferBlock(const tchar_t *pszChars, int nLength, CrystalLineParser::TEXTBLOCK * pBuf, int &nActualItems, int nIdentBegin, int I)
{
if (IsTexKeyword (pszChars + nIdentBegin, I - nIdentBegin) &&
(nIdentBegin > 0 && pszChars[nIdentBegin - 1] == '\\' && (nIdentBegin == 1 || pszChars[nIdentBegin - 2] != '\\')))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
}
else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin) &&
(nIdentBegin > 0 && pszChars[nIdentBegin - 1] == '\\' && (nIdentBegin == 1 || pszChars[nIdentBegin - 2] != '\\')))
{
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 >= 0; j--)
{
if (!xisspace (pszChars[j]))
{
if (pszChars[j] == '$')
{
bFunction = true;
}
break;
}
}
if (bFunction)
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
}
}
}

unsigned
CrystalLineParser::ParseLineTex (unsigned dwCookie, const tchar_t *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
{
Expand Down Expand Up @@ -944,6 +982,8 @@ CrystalLineParser::ParseLineTex (unsigned dwCookie, const tchar_t *pszChars, int

if (pszChars[I] == '%')
{
if (nIdentBegin >= 0)
DefineIdentiferBlock(pszChars, nLength, pBuf, nActualItems, nIdentBegin, I);
DEFINE_BLOCK (I, COLORINDEX_COMMENT);
dwCookie |= COOKIE_COMMENT;
break;
Expand Down Expand Up @@ -980,37 +1020,7 @@ CrystalLineParser::ParseLineTex (unsigned dwCookie, const tchar_t *pszChars, int
{
if (nIdentBegin >= 0)
{
if (IsTexKeyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
}
else if (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 >= 0; 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);
bRedefineBlock = true;
bDecIndex = true;
nIdentBegin = -1;
Expand All @@ -1019,39 +1029,7 @@ CrystalLineParser::ParseLineTex (unsigned dwCookie, const tchar_t *pszChars, int
}

if (nIdentBegin >= 0)
{
if (IsTexKeyword (pszChars + nIdentBegin, I - nIdentBegin))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
}
else if (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 >= 0; 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);

dwCookie &= COOKIE_EXT_COMMENT;
return dwCookie;
Expand Down

0 comments on commit 2d40a98

Please sign in to comment.