1 ///////////////////////////////////////////////////////////////////////////
4 // Updated: 19-Jul-1998
6 // Copyright: Ferdinand Prantl, portions by Stcherbatchenko Andrei
7 // E-mail: prantl@ff.cuni.cz
9 // ASP syntax highlighing definition
11 // You are free to use or modify this code to the following restrictions:
12 // - Acknowledge me somewhere in your about box, simple "Parts of code by.."
13 // will be enough. If you can't (or don't want to), contact me personally.
14 // - LEAVE THIS HEADER INTACT
15 ////////////////////////////////////////////////////////////////////////////
18 #include "crystallineparser.h"
19 #include "../SyntaxColors.h"
20 #include "../utils/string_util.h"
26 static LPCTSTR s_apszAspKeywordList[] =
50 _T ("CreateVerifyItem"),
81 _T ("GetAttrValBool"),
82 _T ("GetAttrValEnumInt"),
83 _T ("GetAttrValEnumString"),
84 _T ("GetAttrValFloat"),
86 _T ("GetAttrValString"),
147 _T ("SetAttrValBool"),
148 _T ("SetAttrValEnumInt"),
149 _T ("SetAttrValEnumString"),
150 _T ("SetAttrValFloat"),
151 _T ("SetAttrValInt"),
152 _T ("SetAttrValString"),
163 _T ("StringFunction"),
179 _T ("VerifyCardinalities"),
190 IsAspKeyword (LPCTSTR pszChars, int nLength)
192 return ISXKEYWORDI (s_apszAspKeywordList, pszChars, nLength);
196 CrystalLineParser::ParseLineAsp (DWORD dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
199 return dwCookie & (COOKIE_EXT_COMMENT|COOKIE_EXT_USER1);
201 bool bFirstChar = (dwCookie & ~(COOKIE_EXT_COMMENT|COOKIE_EXT_USER1)) == 0;
202 bool bRedefineBlock = true;
203 bool bDecIndex = false;
204 int nIdentBegin = -1;
207 for (I = 0;; nPrevI = I, I = static_cast<int>(::CharNext(pszChars+I) - pszChars))
211 // CharNext did not advance, so we're at the end of the string
212 // and we already handled this character, so stop
221 if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
223 DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
225 else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING))
227 DEFINE_BLOCK (nPos, COLORINDEX_STRING);
229 else if (dwCookie & COOKIE_PREPROCESSOR)
231 DEFINE_BLOCK (nPos, COLORINDEX_PREPROCESSOR);
233 else if (dwCookie & COOKIE_EXT_USER1)
235 DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
239 if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.')
241 DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
245 DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR);
246 bRedefineBlock = true;
251 bRedefineBlock = false;
256 // Can be bigger than length if there is binary data
257 // See bug #1474782 Crash when comparing SQL with with binary data
258 if (I >= nLength || pszChars[I] == 0)
261 if (dwCookie & COOKIE_COMMENT)
263 DEFINE_BLOCK (I, COLORINDEX_COMMENT);
264 dwCookie |= COOKIE_COMMENT;
268 // String constant "...."
269 if (dwCookie & COOKIE_STRING)
271 if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
273 dwCookie &= ~COOKIE_STRING;
274 bRedefineBlock = true;
279 // Char constant '..'
280 if (dwCookie & COOKIE_CHAR)
282 if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
284 dwCookie &= ~COOKIE_CHAR;
285 bRedefineBlock = true;
290 // Extended comment <!--....-->
291 if (dwCookie & COOKIE_EXT_COMMENT)
293 if (!(dwCookie & COOKIE_EXT_USER1))
295 if (I > 1 && pszChars[I] == '>' && pszChars[nPrevI] == '-' && *::CharPrev(pszChars, pszChars + nPrevI) == '-')
297 dwCookie &= ~COOKIE_EXT_COMMENT;
298 bRedefineBlock = true;
304 if ((dwCookie & COOKIE_EXT_USER1) && pszChars[I] == '\'')
306 DEFINE_BLOCK (I, COLORINDEX_COMMENT);
307 dwCookie |= COOKIE_COMMENT;
311 // Extended comment <?....?>
312 if (dwCookie & COOKIE_EXT_USER1)
314 if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
316 dwCookie &= ~COOKIE_EXT_USER1;
317 bRedefineBlock = true;
323 if ((dwCookie & (COOKIE_PREPROCESSOR|COOKIE_EXT_USER1)) && pszChars[I] == '"')
325 DEFINE_BLOCK (I, COLORINDEX_STRING);
326 dwCookie |= COOKIE_STRING;
330 if ((dwCookie & (COOKIE_PREPROCESSOR|COOKIE_EXT_USER1)) && pszChars[I] == '\'')
332 // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
333 if (!I || !xisalnum (pszChars[nPrevI]))
335 DEFINE_BLOCK (I, COLORINDEX_STRING);
336 dwCookie |= COOKIE_CHAR;
341 if (!(dwCookie & COOKIE_EXT_USER1))
343 if (!(dwCookie & COOKIE_EXT_USER1) && I < nLength - 3 && pszChars[I] == '<' && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-')
345 DEFINE_BLOCK (I, COLORINDEX_COMMENT);
347 dwCookie |= COOKIE_EXT_COMMENT;
348 dwCookie &= ~COOKIE_PREPROCESSOR;
355 if (!xisspace (pszChars[I]))
360 if (I < nLength && pszChars[I] == '<' && I < nLength - 1 && (pszChars[I + 1] == '?' || pszChars[I + 1] == '%'))
362 DEFINE_BLOCK (I, COLORINDEX_NORMALTEXT);
363 dwCookie |= COOKIE_EXT_USER1;
369 continue; // We don't need to extract keywords,
370 // for faster parsing skip the rest of loop
372 if (xisalnum (pszChars[I]) || pszChars[I] == '.')
374 if (nIdentBegin == -1)
379 if (nIdentBegin >= 0)
381 if (dwCookie & COOKIE_PREPROCESSOR)
383 if (IsHtmlKeyword (pszChars + nIdentBegin, I - nIdentBegin) && (pszChars[nIdentBegin - 1] == _T ('<') || pszChars[nIdentBegin - 1] == _T ('/')))
385 DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
387 else if (IsHtmlUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
389 DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1);
391 else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
393 DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
400 else if (dwCookie & COOKIE_EXT_USER1)
402 if (IsAspKeyword (pszChars + nIdentBegin, I - nIdentBegin))
404 DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
406 else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
408 DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
412 bool bFunction = false;
414 for (int j = I; j < nLength; j++)
416 if (!xisspace (pszChars[j]))
418 if (pszChars[j] == '(')
427 DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
435 else if (dwCookie & COOKIE_USER1)
437 if (IsHtmlUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin))
439 DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2);
446 bRedefineBlock = true;
453 // Preprocessor start: < or bracket
454 if (!(dwCookie & COOKIE_EXT_USER1) && I < nLength && pszChars[I] == '<' && !(I < nLength - 3 && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-'))
456 DEFINE_BLOCK (I, COLORINDEX_OPERATOR);
457 DEFINE_BLOCK (I + 1, COLORINDEX_PREPROCESSOR);
458 dwCookie |= COOKIE_PREPROCESSOR;
464 if (dwCookie & COOKIE_EXT_USER1)
466 if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
468 dwCookie &= ~COOKIE_EXT_USER1;
470 bRedefineBlock = true;
476 // Preprocessor end: > or bracket
477 if (dwCookie & COOKIE_PREPROCESSOR)
479 if (pszChars[I] == '>')
481 dwCookie &= ~COOKIE_PREPROCESSOR;
483 bRedefineBlock = true;
489 // Preprocessor start: &
490 if (!(dwCookie & COOKIE_EXT_USER1) && pszChars[I] == '&')
492 dwCookie |= COOKIE_USER1;
497 // Preprocessor end: ;
498 if (dwCookie & COOKIE_USER1)
500 if (pszChars[I] == ';')
502 dwCookie &= ~COOKIE_USER1;
511 if (nIdentBegin >= 0 && (dwCookie & COOKIE_PREPROCESSOR))
513 if (IsHtmlKeyword (pszChars + nIdentBegin, I - nIdentBegin) && (pszChars[nIdentBegin - 1] == _T ('<') || pszChars[nIdentBegin - 1] == _T ('/')))
515 DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
517 else if (IsHtmlUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
519 DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1);
521 else if (IsHtmlUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin))
523 DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2);
525 else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
527 DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
531 bool bFunction = false;
533 for (int j = I; j < nLength; j++)
535 if (!xisspace (pszChars[j]))
537 if (pszChars[j] == '(')
546 DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
550 else if (nIdentBegin >= 0 && (dwCookie & COOKIE_EXT_USER1))
552 if (IsAspKeyword (pszChars + nIdentBegin, I - nIdentBegin))
554 DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
556 else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
558 DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
562 bool bFunction = false;
564 for (int j = I; j < nLength; j++)
566 if (!xisspace (pszChars[j]))
568 if (pszChars[j] == '(')
577 DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
582 dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_STRING | COOKIE_PREPROCESSOR | COOKIE_EXT_USER1);