Skip to content

Commit

Permalink
F# parsing, tiral to add multi-line text string support, not working yet
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorium committed Apr 29, 2024
1 parent 131a7e2 commit 1cf5458
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions Externals/crystaledit/editlib/parsers/fsharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,18 @@ unsigned
CrystalLineParser::ParseLineFSharp (unsigned dwCookie, const tchar_t *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
{
if (nLength == 0)
return dwCookie & COOKIE_EXT_COMMENT;
return dwCookie & (COOKIE_EXT_COMMENT | COOKIE_RAWSTRING);

bool bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0;
bool bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT & ~COOKIE_RAWSTRING) == 0;
const tchar_t* pszCommentBegin = nullptr;
const tchar_t* pszCommentEnd = nullptr;
const tchar_t* pszTextBegin = nullptr;
const tchar_t* pszTextEnd = nullptr;
bool bRedefineBlock = true;
bool bDecIndex = false;
int nIdentBegin = -1;
int nPrevI = -1;
int nPrevII = -2;
int I = 0;
for (I = 0;; nPrevI = I, I = static_cast<int>(tc::tcharnext(pszChars + I) - pszChars))
{
Expand All @@ -225,7 +228,7 @@ CrystalLineParser::ParseLineFSharp (unsigned dwCookie, const tchar_t *pszChars,
{
DEFINE_BLOCK(nPos, COLORINDEX_COMMENT);
}
else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING))
else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING | COOKIE_RAWSTRING))
{
DEFINE_BLOCK(nPos, COLORINDEX_STRING);
}
Expand Down Expand Up @@ -305,6 +308,25 @@ CrystalLineParser::ParseLineFSharp (unsigned dwCookie, const tchar_t *pszChars,
break;
}

// Multi-line string constant """...."""
if (dwCookie & COOKIE_RAWSTRING)
{
if ((pszTextBegin < pszChars + I) && (I > 1 && pszChars[I] == '"' && pszChars[nPrevI] == '"' && pszChars[nPrevII] == '"'))
{
dwCookie &= ~COOKIE_RAWSTRING;
bRedefineBlock = true;
pszTextEnd = pszChars + I + 2;
}
continue;
}

if ((pszTextEnd < pszChars + I) && (I > 1 && pszChars[I] == '"' && pszChars[nPrevI] == '"' && pszChars[nPrevII] == '"'))
{
DEFINE_BLOCK(nPrevII, COLORINDEX_STRING);
dwCookie |= COOKIE_RAWSTRING;
break;
}

// Preprocessor directive #....
if (dwCookie & COOKIE_PREPROCESSOR)
{
Expand All @@ -313,6 +335,12 @@ CrystalLineParser::ParseLineFSharp (unsigned dwCookie, const tchar_t *pszChars,
DEFINE_BLOCK(nPrevI, COLORINDEX_COMMENT);
dwCookie |= COOKIE_EXT_COMMENT;
}
if ((pszTextEnd < pszChars + I) && (I > 1 && pszChars[I] == '"' && pszChars[nPrevI] == '"' && pszChars[nPrevII] == '"'))
{
DEFINE_BLOCK(nPrevII, COLORINDEX_STRING);
dwCookie |= COOKIE_RAWSTRING;
break;
}
continue;
}

Expand Down Expand Up @@ -340,6 +368,13 @@ CrystalLineParser::ParseLineFSharp (unsigned dwCookie, const tchar_t *pszChars,
pszCommentBegin = pszChars + I + 1;
continue;
}
if ((pszTextEnd < pszChars + I) && (I > 1 && pszChars[I] == '"' && pszChars[nPrevI] == '"' && pszChars[nPrevII] == '"'))
{
DEFINE_BLOCK(nPrevII, COLORINDEX_STRING);
dwCookie |= COOKIE_RAWSTRING;
pszTextBegin = pszChars + I + 1;
continue;
}

if (bFirstChar)
{
Expand Down Expand Up @@ -443,6 +478,7 @@ CrystalLineParser::ParseLineFSharp (unsigned dwCookie, const tchar_t *pszChars,
}

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

return dwCookie;
}

0 comments on commit 1cf5458

Please sign in to comment.