1 ///////////////////////////////////////////////////////////////////////////
4 // Updated: 19-Jul-1998
6 // Copyright: Ferdinand Prantl, portions by Stcherbatchenko Andrei
7 // E-mail: prantl@ff.cuni.cz
9 // AutoIt 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 // (Visual) AutoIt keywords
27 static const TCHAR * s_apszAutoItKeywordList[] =
77 _T ("CreateVerifyItem"),
119 _T ("ExternalSource"),
132 _T ("GetAttrValBool"),
133 _T ("GetAttrValEnumInt"),
134 _T ("GetAttrValEnumString"),
135 _T ("GetAttrValFloat"),
136 _T ("GetAttrValInt"),
137 _T ("GetAttrValString"),
201 _T ("NotInheritable"),
202 _T ("NotOverridable"),
231 _T ("RemoveHandler"),
244 _T ("SetAttrValBool"),
245 _T ("SetAttrValEnumInt"),
246 _T ("SetAttrValEnumString"),
247 _T ("SetAttrValFloat"),
248 _T ("SetAttrValInt"),
249 _T ("SetAttrValString"),
266 _T ("StringFunction"),
296 _T ("VerifyCardinalities"),
311 IsAutoItKeyword (const TCHAR *pszChars, int nLength)
313 return ISXKEYWORDI (s_apszAutoItKeywordList, pszChars, nLength);
317 DefineIdentiferBlock(const TCHAR *pszChars, int nLength, CrystalLineParser::TEXTBLOCK * pBuf, int &nActualItems, int nIdentBegin, int I)
319 if (IsAutoItKeyword (pszChars + nIdentBegin, I - nIdentBegin))
321 DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
323 else if (CrystalLineParser::IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
325 DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
329 bool bFunction = false;
331 for (int j = I; j < nLength; j++)
333 if (!xisspace (pszChars[j]))
335 if (pszChars[j] == '(')
344 DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
350 CrystalLineParser::ParseLineAutoIt (unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
353 return dwCookie & COOKIE_EXT_COMMENT;
355 bool bRedefineBlock = true;
356 bool bDecIndex = false;
357 int nIdentBegin = -1;
360 for (I = 0;; nPrevI = I, I = static_cast<int>(::CharNext(pszChars+I) - pszChars))
364 // CharNext did not advance, so we're at the end of the string
365 // and we already handled this character, so stop
374 if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
376 DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
378 else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING))
380 DEFINE_BLOCK (nPos, COLORINDEX_STRING);
384 if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
386 DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
390 DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR);
391 bRedefineBlock = true;
396 bRedefineBlock = false;
401 // Can be bigger than length if there is binary data
402 // See bug #1474782 Crash when comparing SQL with with binary data
403 if (I >= nLength || pszChars[I] == 0)
406 if (dwCookie & COOKIE_COMMENT)
408 DEFINE_BLOCK (I, COLORINDEX_COMMENT);
409 dwCookie |= COOKIE_COMMENT;
413 // String constant "...."
414 if (dwCookie & COOKIE_STRING)
416 if (pszChars[I] == '"')
418 dwCookie &= ~COOKIE_STRING;
419 bRedefineBlock = true;
424 if (pszChars[I] == '\'')
426 if (nIdentBegin >= 0)
427 DefineIdentiferBlock(pszChars, nLength, pBuf, nActualItems, nIdentBegin, I);
428 DEFINE_BLOCK (I, COLORINDEX_COMMENT);
429 dwCookie |= COOKIE_COMMENT;
434 if (pszChars[I] == '"')
436 DEFINE_BLOCK (I, COLORINDEX_STRING);
437 dwCookie |= COOKIE_STRING;
442 continue; // We don't need to extract keywords,
443 // for faster parsing skip the rest of loop
445 if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
447 if (nIdentBegin == -1)
452 if (nIdentBegin >= 0)
454 DefineIdentiferBlock(pszChars, nLength, pBuf, nActualItems, nIdentBegin, I);
455 bRedefineBlock = true;
462 if (nIdentBegin >= 0)
463 DefineIdentiferBlock(pszChars, nLength, pBuf, nActualItems, nIdentBegin, I);
465 dwCookie &= COOKIE_EXT_COMMENT;