Skip to content

Commit 79892eb

Browse files
authored
Multi line comment fix (#2303)
* F# parsing, tiral to add multi-line text string support, not working yet * updates
1 parent 73defae commit 79892eb

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

Externals/crystaledit/editlib/parsers/fsharp.cpp

+43-6
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ static const tchar_t * s_apszFsKeywordList[] =
158158
_T("Char"),
159159
_T("DateTime"),
160160
_T("Decimal"),
161+
_T("Guid"),
161162
_T("Int16"),
162163
_T("Int32"),
163164
_T("Int64"),
@@ -197,17 +198,20 @@ unsigned
197198
CrystalLineParser::ParseLineFSharp (unsigned dwCookie, const tchar_t *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
198199
{
199200
if (nLength == 0)
200-
return dwCookie & COOKIE_EXT_COMMENT;
201+
return dwCookie & (COOKIE_EXT_COMMENT | COOKIE_RAWSTRING);
201202

202-
bool bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0;
203+
bool bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT & ~COOKIE_RAWSTRING) == 0;
203204
const tchar_t* pszCommentBegin = nullptr;
204205
const tchar_t* pszCommentEnd = nullptr;
206+
const tchar_t* pszTextBegin = nullptr;
207+
const tchar_t* pszTextEnd = nullptr;
205208
bool bRedefineBlock = true;
206209
bool bDecIndex = false;
207210
int nIdentBegin = -1;
208211
int nPrevI = -1;
212+
int nPrevII = -2;
209213
int I = 0;
210-
for (I = 0;; nPrevI = I, I = static_cast<int>(tc::tcharnext(pszChars + I) - pszChars))
214+
for (I = 0;; nPrevII=nPrevI, nPrevI = I, I = static_cast<int>(tc::tcharnext(pszChars + I) - pszChars))
211215
{
212216
if (I == nPrevI)
213217
{
@@ -225,7 +229,7 @@ CrystalLineParser::ParseLineFSharp (unsigned dwCookie, const tchar_t *pszChars,
225229
{
226230
DEFINE_BLOCK(nPos, COLORINDEX_COMMENT);
227231
}
228-
else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING))
232+
else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING | COOKIE_RAWSTRING))
229233
{
230234
DEFINE_BLOCK(nPos, COLORINDEX_STRING);
231235
}
@@ -305,6 +309,25 @@ CrystalLineParser::ParseLineFSharp (unsigned dwCookie, const tchar_t *pszChars,
305309
break;
306310
}
307311

312+
// Multi-line string constant """...."""
313+
if (dwCookie & COOKIE_RAWSTRING)
314+
{
315+
if ((pszTextBegin < pszChars + I) && (I > 1 && pszChars[I] == '"' && pszChars[nPrevI] == '"' && pszChars[nPrevII] == '"'))
316+
{
317+
dwCookie &= ~COOKIE_RAWSTRING;
318+
bRedefineBlock = true;
319+
pszTextEnd = pszChars + I + 2;
320+
}
321+
continue;
322+
}
323+
324+
if ((pszTextEnd < pszChars + I) && (I > 1 && pszChars[I] == '"' && pszChars[nPrevI] == '"' && pszChars[nPrevII] == '"'))
325+
{
326+
DEFINE_BLOCK(nPrevII, COLORINDEX_STRING);
327+
dwCookie |= COOKIE_RAWSTRING;
328+
break;
329+
}
330+
308331
// Preprocessor directive #....
309332
if (dwCookie & COOKIE_PREPROCESSOR)
310333
{
@@ -313,11 +336,17 @@ CrystalLineParser::ParseLineFSharp (unsigned dwCookie, const tchar_t *pszChars,
313336
DEFINE_BLOCK(nPrevI, COLORINDEX_COMMENT);
314337
dwCookie |= COOKIE_EXT_COMMENT;
315338
}
339+
if ((pszTextEnd < pszChars + I) && (I > 1 && pszChars[I] == '"' && pszChars[nPrevI] == '"' && pszChars[nPrevII] == '"'))
340+
{
341+
DEFINE_BLOCK(nPrevII, COLORINDEX_STRING);
342+
dwCookie |= COOKIE_RAWSTRING;
343+
break;
344+
}
316345
continue;
317346
}
318347

319348
// Normal text
320-
if (pszChars[I] == '"')
349+
if (pszChars[I] == '"' && (I < 2 || pszChars[nPrevI] != '"' || pszChars[nPrevII] != '"'))
321350
{
322351
DEFINE_BLOCK(I, COLORINDEX_STRING);
323352
dwCookie |= COOKIE_STRING;
@@ -340,6 +369,13 @@ CrystalLineParser::ParseLineFSharp (unsigned dwCookie, const tchar_t *pszChars,
340369
pszCommentBegin = pszChars + I + 1;
341370
continue;
342371
}
372+
if ((pszTextEnd < pszChars + I) && (I > 1 && pszChars[I] == '"' && pszChars[nPrevI] == '"' && pszChars[nPrevII] == '"'))
373+
{
374+
DEFINE_BLOCK(nPrevII, COLORINDEX_STRING);
375+
dwCookie |= COOKIE_RAWSTRING;
376+
pszTextBegin = pszChars + I + 1;
377+
continue;
378+
}
343379

344380
if (bFirstChar)
345381
{
@@ -443,6 +479,7 @@ CrystalLineParser::ParseLineFSharp (unsigned dwCookie, const tchar_t *pszChars,
443479
}
444480

445481
if (pszChars[nLength - 1] != '\\' || IsMBSTrail(pszChars, nLength - 1))
446-
dwCookie &= COOKIE_EXT_COMMENT;
482+
dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_RAWSTRING);
483+
447484
return dwCookie;
448485
}

0 commit comments

Comments
 (0)