1 ///////////////////////////////////////////////////////////////////////////
4 // Updated: 23-Apr-2021
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[] =
32 _T ("AdlibUnRegister"),
39 _T ("AutoItSetOption"),
40 _T ("AutoItWinGetTitle"),
41 _T ("AutoItWinSetTitle"),
46 _T ("BinaryToString"),
66 _T ("ConsoleWriteError"),
71 _T ("ControlCommand"),
72 _T ("ControlDisable"),
75 _T ("ControlGetFocus"),
76 _T ("ControlGetHandle"),
78 _T ("ControlGetText"),
80 _T ("ControlListView"),
83 _T ("ControlSetText"),
85 _T ("ControlTreeView"),
96 _T ("DllCallAddress"),
97 _T ("DllCallbackFree"),
98 _T ("DllCallbackGetPtr"),
99 _T ("DllCallbackRegister"),
102 _T ("DllStructCreate"),
103 _T ("DllStructGetData"),
104 _T ("DllStructGetPtr"),
105 _T ("DllStructGetSize"),
106 _T ("DllStructGetString"),
107 _T ("DllStructSetData"),
109 _T ("DriveGetDrive"),
110 _T ("DriveGetFileSystem"),
111 _T ("DriveGetLabel"),
112 _T ("DriveGetSerial"),
117 _T ("DriveSetLabel"),
118 _T ("DriveSpaceFree"),
119 _T ("DriveSpaceTotal"),
138 _T ("FileChangeDir"),
141 _T ("FileCreateNTFSLink"),
142 _T ("FileCreateShortcut"),
145 _T ("FileFindFirstFile"),
146 _T ("FileFindNextFile"),
148 _T ("FileGetAttrib"),
149 _T ("FileGetEncoding"),
150 _T ("FileGetLongName"),
152 _T ("FileGetShortcut"),
153 _T ("FileGetShortName"),
156 _T ("FileGetVersion"),
160 _T ("FileOpenDialog"),
163 _T ("FileReadToArray"),
165 _T ("FileRecycleEmpty"),
166 _T ("FileSaveDialog"),
167 _T ("FileSelectFolder"),
168 _T ("FileSetAttrib"),
173 _T ("FileWriteLine"),
182 _T ("GUICtrlCreateAvi"),
183 _T ("GUICtrlCreateButton"),
184 _T ("GUICtrlCreateCheckbox"),
185 _T ("GUICtrlCreateCombo"),
186 _T ("GUICtrlCreateContextMenu"),
187 _T ("GUICtrlCreateDate"),
188 _T ("GUICtrlCreateDummy"),
189 _T ("GUICtrlCreateEdit"),
190 _T ("GUICtrlCreateGraphic"),
191 _T ("GUICtrlCreateGroup"),
192 _T ("GUICtrlCreateIcon"),
193 _T ("GUICtrlCreateInput"),
194 _T ("GUICtrlCreateLabel"),
195 _T ("GUICtrlCreateList"),
196 _T ("GUICtrlCreateListView"),
197 _T ("GUICtrlCreateListViewItem"),
198 _T ("GUICtrlCreateMenu"),
199 _T ("GUICtrlCreateMenuItem"),
200 _T ("GUICtrlCreateMonthCal"),
201 _T ("GUICtrlCreateObj"),
202 _T ("GUICtrlCreatePic"),
203 _T ("GUICtrlCreateProgress"),
204 _T ("GUICtrlCreateRadio"),
205 _T ("GUICtrlCreateSlider"),
206 _T ("GUICtrlCreateTab"),
207 _T ("GUICtrlCreateTabItem"),
208 _T ("GUICtrlCreateTreeView"),
209 _T ("GUICtrlCreateTreeViewItem"),
210 _T ("GUICtrlCreateUpdown"),
211 _T ("GUICtrlDelete"),
212 _T ("GUICtrlGetHandle"),
213 _T ("GUICtrlGetState"),
215 _T ("GUICtrlRecvMsg"),
216 _T ("GUICtrlRegisterListViewSort"),
217 _T ("GUICtrlSendMsg"),
218 _T ("GUICtrlSendToDummy"),
219 _T ("GUICtrlSetBkColor"),
220 _T ("GUICtrlSetColor"),
221 _T ("GUICtrlSetCursor"),
222 _T ("GUICtrlSetData"),
223 _T ("GUICtrlSetDefBkColor"),
224 _T ("GUICtrlSetDefColor"),
225 _T ("GUICtrlSetFont"),
226 _T ("GUICtrlSetGraphic"),
227 _T ("GUICtrlSetImage"),
228 _T ("GUICtrlSetLimit"),
229 _T ("GUICtrlSetOnEvent"),
230 _T ("GUICtrlSetPos"),
231 _T ("GUICtrlSetResizing"),
232 _T ("GUICtrlSetState"),
233 _T ("GUICtrlSetStyle"),
234 _T ("GUICtrlSetTip"),
236 _T ("GUIGetCursorInfo"),
239 _T ("GUIRegisterMsg"),
240 _T ("GUISetAccelerators"),
241 _T ("GUISetBkColor"),
247 _T ("GUISetOnEvent"),
250 _T ("GUIStartGroup"),
255 _T ("HttpSetUserAgent"),
266 _T ("IniReadSection"),
267 _T ("IniReadSectionNames"),
268 _T ("IniRenameSection"),
270 _T ("IniWriteSection"),
298 _T ("MouseClickDrag"),
300 _T ("MouseGetCursor"),
311 _T ("ObjCreateInterface"),
316 _T ("OnAutoItExitRegister"),
317 _T ("OnAutoItExitUnRegister"),
321 _T ("PixelChecksum"),
322 _T ("PixelGetColor"),
325 _T ("ProcessExists"),
326 _T ("ProcessGetStats"),
328 _T ("ProcessSetPriority"),
330 _T ("ProcessWaitClose"),
350 _T ("SendKeepActive"),
354 _T ("ShellExecuteWait"),
359 _T ("SoundSetWaveVolume"),
360 _T ("SplashImageOn"),
366 _T ("StatusbarGetText"),
374 _T ("StringCompare"),
376 _T ("StringFromASCIIArray"),
378 _T ("StringIsAlNum"),
379 _T ("StringIsAlpha"),
380 _T ("StringIsASCII"),
381 _T ("StringIsDigit"),
382 _T ("StringIsFloat"),
384 _T ("StringIsLower"),
385 _T ("StringIsSpace"),
386 _T ("StringIsUpper"),
387 _T ("StringIsXDigit"),
393 _T ("StringRegExpReplace"),
394 _T ("StringReplace"),
395 _T ("StringReverse"),
398 _T ("StringStripCR"),
399 _T ("StringStripWS"),
400 _T ("StringToASCIIArray"),
401 _T ("StringToBinary"),
402 _T ("StringTrimLeft"),
403 _T ("StringTrimRight"),
408 _T ("TCPCloseSocket"),
415 _T ("TCPShutdownSocket"),
422 _T ("TrayCreateItem"),
423 _T ("TrayCreateMenu"),
425 _T ("TrayItemDelete"),
426 _T ("TrayItemGetHandle"),
427 _T ("TrayItemGetState"),
428 _T ("TrayItemGetText"),
429 _T ("TrayItemSetOnEvent"),
430 _T ("TrayItemSetState"),
431 _T ("TrayItemSetText"),
434 _T ("TraySetOnEvent"),
435 _T ("TraySetPauseIcon"),
437 _T ("TraySetToolTip"),
442 _T ("UDPCloseSocket"),
443 _T ("UDPJoinMulticastGroup"),
459 _T ("WinGetCaretPos"),
460 _T ("WinGetClassList"),
461 _T ("WinGetClientSize"),
464 _T ("WinGetProcess"),
470 _T ("WinMenuSelectItem"),
471 _T ("WinMinimizeAll"),
472 _T ("WinMinimizeAllUndo"),
479 _T ("WinWaitActive"),
481 _T ("WinWaitNotActive"),
486 IsAutoItKeyword (const TCHAR *pszChars, int nLength)
488 return ISXKEYWORDI (s_apszAutoItKeywordList, pszChars, nLength);
492 DefineIdentiferBlock(const TCHAR *pszChars, int nLength, CrystalLineParser::TEXTBLOCK * pBuf, int &nActualItems, int nIdentBegin, int I)
494 if (IsAutoItKeyword (pszChars + nIdentBegin, I - nIdentBegin))
496 DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
498 else if (CrystalLineParser::IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
500 DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
504 bool bFunction = false;
506 for (int j = I; j < nLength; j++)
508 if (!xisspace (pszChars[j]))
510 if (pszChars[j] == '(')
519 DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
525 CrystalLineParser::ParseLineAutoIt (unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
528 return dwCookie & COOKIE_EXT_COMMENT;
530 bool bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0;
531 bool bRedefineBlock = true;
532 bool bDecIndex = false;
533 int nIdentBegin = -1;
536 for (I = 0;; nPrevI = I, I = static_cast<int>(::CharNext(pszChars+I) - pszChars))
540 // CharNext did not advance, so we're at the end of the string
541 // and we already handled this character, so stop
550 if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
552 DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
554 else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING))
556 DEFINE_BLOCK(nPos, COLORINDEX_STRING);
558 else if (dwCookie & (COOKIE_USER1 ))
560 DEFINE_BLOCK(nPos, COLORINDEX_USER1);
562 else if (dwCookie & (COOKIE_VARIABLE))
564 DEFINE_BLOCK(nPos, COLORINDEX_USER2);
566 else if (dwCookie & COOKIE_PREPROCESSOR)
568 DEFINE_BLOCK (nPos, COLORINDEX_PREPROCESSOR);
572 if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
574 DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
578 DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR);
579 bRedefineBlock = true;
584 bRedefineBlock = false;
589 // Can be bigger than length if there is binary data
590 // See bug #1474782 Crash when comparing SQL with with binary data
591 if (I >= nLength || pszChars[I] == 0)
594 if (dwCookie & COOKIE_COMMENT)
596 DEFINE_BLOCK (I, COLORINDEX_COMMENT);
597 dwCookie |= COOKIE_COMMENT;
601 // String constant '....'
602 if (dwCookie & COOKIE_CHAR)
604 if (pszChars[I] == '\'')
606 dwCookie &= ~COOKIE_CHAR;
607 bRedefineBlock = true;
612 // String constant "...."
613 if (dwCookie & COOKIE_STRING)
615 if (pszChars[I] == '"')
617 dwCookie &= ~COOKIE_STRING;
618 bRedefineBlock = true;
623 // Extended comment #cs .... #ce
624 if (dwCookie & COOKIE_EXT_COMMENT)
626 if (bFirstChar && pszChars[I] == '#' &&
627 ((I + 3 <= nLength && memcmp(&pszChars[I], _T("#ce"), 3 * sizeof(TCHAR)) == 0) ||
628 (I + 13 <= nLength && memcmp(&pszChars[I], _T("#comments-end"), 13 * sizeof(TCHAR)) == 0)))
630 dwCookie &= ~COOKIE_EXT_COMMENT;
631 bRedefineBlock = true;
633 I += pszChars[I + 2] == 'e' ? 2 : 12;
635 if (!xisspace (pszChars[I]))
640 if (pszChars[I] == ';')
642 DEFINE_BLOCK (I, COLORINDEX_COMMENT);
643 dwCookie |= COOKIE_COMMENT;
647 // Preprocessor directive #....
648 if (dwCookie & COOKIE_PREPROCESSOR)
655 if (pszChars[I] == '@')
657 DEFINE_BLOCK(I, COLORINDEX_USER1);
658 dwCookie |= COOKIE_USER1;
663 if (dwCookie & COOKIE_USER1)
665 if (!xisalnum(pszChars[I]))
667 dwCookie &= ~COOKIE_USER1;
668 bRedefineBlock = true;
674 if (pszChars[I] == '$')
676 DEFINE_BLOCK(I, COLORINDEX_USER2);
677 dwCookie |= COOKIE_VARIABLE;
682 if (dwCookie & COOKIE_VARIABLE)
684 if (!xisalnum(pszChars[I]))
686 dwCookie &= ~COOKIE_VARIABLE;
687 bRedefineBlock = true;
694 if (pszChars[I] == '"')
696 DEFINE_BLOCK (I, COLORINDEX_STRING);
697 dwCookie |= COOKIE_STRING;
702 if (pszChars[I] == '\'')
704 DEFINE_BLOCK (I, COLORINDEX_STRING);
705 dwCookie |= COOKIE_CHAR;
711 if (pszChars[I] == '#')
713 if ((I + 3 <= nLength && memcmp(&pszChars[I], _T("#cs"), 3 * sizeof(TCHAR)) == 0) ||
714 (I + 15 <= nLength && memcmp(&pszChars[I], _T("#comments-start"), 15 * sizeof(TCHAR)) == 0))
716 DEFINE_BLOCK (I, COLORINDEX_COMMENT);
717 dwCookie |= COOKIE_EXT_COMMENT;
721 DEFINE_BLOCK(I, COLORINDEX_PREPROCESSOR);
722 dwCookie |= COOKIE_PREPROCESSOR;
727 if (!xisspace (pszChars[I]))
732 continue; // We don't need to extract keywords,
733 // for faster parsing skip the rest of loop
735 if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
737 if (nIdentBegin == -1)
742 if (nIdentBegin >= 0)
744 DefineIdentiferBlock(pszChars, nLength, pBuf, nActualItems, nIdentBegin, I);
745 bRedefineBlock = true;
752 if (nIdentBegin >= 0)
753 DefineIdentiferBlock(pszChars, nLength, pBuf, nActualItems, nIdentBegin, I);
755 dwCookie &= COOKIE_EXT_COMMENT;