ui: make primary cursor blink even if no lua theme has been loaded
[vis.git] / lexers / autoit.lua
blob1a3bc5520c07a5606d2dc9c0d01101fcef848b1f
1 -- Copyright 2006-2016 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- AutoIt LPeg lexer.
3 -- Contributed by Jeff Stone.
5 local l = require('lexer')
6 local token, word_match = l.token, l.word_match
7 local P, R, S = lpeg.P, lpeg.R, lpeg.S
9 local M = {_NAME = 'autoit'}
11 -- Whitespace.
12 local ws = token(l.WHITESPACE, l.space^1)
14 -- Comments.
15 local line_comment = ';' * l.nonnewline_esc^0
16 local block_comment1 = '#comments-start' * (l.any - '#comments-end')^0 *
17 P('#comments-end')^-1
18 local block_comment2 = '#cs' * (l.any - '#ce')^0 * P('#ce')^-1
19 local comment = token(l.COMMENT, line_comment + block_comment1 + block_comment2)
21 -- Keywords.
22 local kw = token(l.KEYWORD, word_match({
23 'False', 'True', 'And', 'Or', 'Not', 'ContinueCase', 'ContinueLoop',
24 'Default', 'Dim', 'Global', 'Local', 'Const', 'Do', 'Until', 'Enum', 'Exit',
25 'ExitLoop', 'For', 'To', 'Step', 'Next', 'In', 'Func', 'Return', 'EndFunc',
26 'If', 'Then', 'ElseIf', 'Else', 'EndIf', 'Null', 'ReDim', 'Select', 'Case',
27 'EndSelect', 'Static', 'Switch', 'EndSwitch', 'Volatile', 'While', 'WEnd',
28 'With', 'EndWith'
29 }, nil, true))
31 -- Functions.
32 local func = token(l.FUNCTION, word_match({
33 'Abs', 'ACos', 'AdlibRegister', 'AdlibUnRegister', 'Asc', 'AscW', 'ASin',
34 'Assign', 'ATan', 'AutoItSetOption', 'AutoItWinGetTitle', 'AutoItWinSetTitle',
35 'Beep', 'Binary', 'BinaryLen', 'BinaryMid', 'BinaryToString', 'BitAND',
36 'BitNOT', 'BitOR', 'BitRotate', 'BitShift', 'BitXOR', 'BlockInput', 'Break',
37 'Call', 'CDTray', 'Ceiling', 'Chr', 'ChrW', 'ClipGet', 'ClipPut',
38 'ConsoleRead', 'ConsoleWrite', 'ConsoleWriteError', 'ControlClick',
39 'ControlCommand', 'ControlDisable', 'ControlEnable', 'ControlFocus',
40 'ControlGetFocus', 'ControlGetHandle', 'ControlGetPos', 'ControlGetText',
41 'ControlHide', 'ControlListView', 'ControlMove', 'ControlSend',
42 'ControlSetText', 'ControlShow', 'ControlTreeView', 'Cos', 'Dec', 'DirCopy',
43 'DirCreate', 'DirGetSize', 'DirMove', 'DirRemove', 'DllCall',
44 'DllCallAddress', 'DllCallbackFree', 'DllCallbackGetPtr',
45 'DllCallbackRegister', 'DllClose', 'DllOpen', 'DllStructCreate',
46 'DllStructGetData', 'DllStructGetPtr', 'DllStructGetSize', 'DllStructSetData',
47 'DriveGetDrive', 'DriveGetFileSystem', 'DriveGetLabel', 'DriveGetSerial',
48 'DriveGetType', 'DriveMapAdd', 'DriveMapDel', 'DriveMapGet', 'DriveSetLabel',
49 'DriveSpaceFree', 'DriveSpaceTotal', 'DriveStatus', 'EnvGet', 'EnvSet',
50 'EnvUpdate', 'Eval', 'Execute', 'Exp', 'FileChangeDir', 'FileClose',
51 'FileCopy', 'FileCreateNTFSLink', 'FileCreateShortcut', 'FileDelete',
52 'FileExists', 'FileFindFirstFile', 'FileFindNextFile', 'FileFlush',
53 'FileGetAttrib', 'FileGetEncoding', 'FileGetLongName', 'FileGetPos',
54 'FileGetShortcut', 'FileGetShortName', 'FileGetSize', 'FileGetTime',
55 'FileGetVersion', 'FileInstall', 'FileMove', 'FileOpen', 'FileOpenDialog',
56 'FileRead', 'FileReadLine', 'FileReadToArray', 'FileRecycle',
57 'FileRecycleEmpty', 'FileSaveDialog', 'FileSelectFolder', 'FileSetAttrib',
58 'FileSetEnd', 'FileSetPos', 'FileSetTime', 'FileWrite', 'FileWriteLine',
59 'Floor', 'FtpSetProxy', 'FuncName', 'GUICreate', 'GUICtrlCreateAvi',
60 'GUICtrlCreateButton', 'GUICtrlCreateCheckbox', 'GUICtrlCreateCombo',
61 'GUICtrlCreateContextMenu', 'GUICtrlCreateDate', 'GUICtrlCreateDummy',
62 'GUICtrlCreateEdit', 'GUICtrlCreateGraphic', 'GUICtrlCreateGroup',
63 'GUICtrlCreateIcon', 'GUICtrlCreateInput', 'GUICtrlCreateLabel',
64 'GUICtrlCreateList', 'GUICtrlCreateListView', 'GUICtrlCreateListViewItem',
65 'GUICtrlCreateMenu', 'GUICtrlCreateMenuItem', 'GUICtrlCreateMonthCal',
66 'GUICtrlCreateObj', 'GUICtrlCreatePic', 'GUICtrlCreateProgress',
67 'GUICtrlCreateRadio', 'GUICtrlCreateSlider', 'GUICtrlCreateTab',
68 'GUICtrlCreateTabItem', 'GUICtrlCreateTreeView', 'GUICtrlCreateTreeViewItem',
69 'GUICtrlCreateUpdown', 'GUICtrlDelete', 'GUICtrlGetHandle', 'GUICtrlGetState',
70 'GUICtrlRead', 'GUICtrlRecvMsg', 'GUICtrlRegisterListViewSort',
71 'GUICtrlSendMsg', 'GUICtrlSendToDummy', 'GUICtrlSetBkColor',
72 'GUICtrlSetColor', 'GUICtrlSetCursor', 'GUICtrlSetData',
73 'GUICtrlSetDefBkColor', 'GUICtrlSetDefColor', 'GUICtrlSetFont',
74 'GUICtrlSetGraphic', 'GUICtrlSetImage', 'GUICtrlSetLimit',
75 'GUICtrlSetOnEvent', 'GUICtrlSetPos', 'GUICtrlSetResizing', 'GUICtrlSetState',
76 'GUICtrlSetStyle', 'GUICtrlSetTip', 'GUIDelete', 'GUIGetCursorInfo',
77 'GUIGetMsg', 'GUIGetStyle', 'GUIRegisterMsg', 'GUISetAccelerators',
78 'GUISetBkColor', 'GUISetCoord', 'GUISetCursor', 'GUISetFont', 'GUISetHelp',
79 'GUISetIcon', 'GUISetOnEvent', 'GUISetState', 'GUISetStyle', 'GUIStartGroup',
80 'GUISwitch', 'Hex', 'HotKeySet', 'HttpSetProxy', 'HttpSetUserAgent', 'HWnd',
81 'InetClose', 'InetGet', 'InetGetInfo', 'InetGetSize', 'InetRead', 'IniDelete',
82 'IniRead', 'IniReadSection', 'IniReadSectionNames', 'IniRenameSection',
83 'IniWrite', 'IniWriteSection', 'InputBox', 'Int', 'IsAdmin', 'IsArray',
84 'IsBinary', 'IsBool', 'IsDeclared', 'IsDllStruct', 'IsFloat', 'IsFunc',
85 'IsHWnd', 'IsInt', 'IsKeyword', 'IsNumber', 'IsObj', 'IsPtr', 'IsString',
86 'Log', 'MemGetStats', 'Mod', 'MouseClick', 'MouseClickDrag', 'MouseDown',
87 'MouseGetCursor', 'MouseGetPos', 'MouseMove', 'MouseUp', 'MouseWheel',
88 'MsgBox', 'Number', 'ObjCreate', 'ObjCreateInterface', 'ObjEvent', 'ObjGet',
89 'ObjName', 'OnAutoItExitRegister', 'OnAutoItExitUnRegister', 'Ping',
90 'PixelChecksum', 'PixelGetColor', 'PixelSearch', 'ProcessClose',
91 'ProcessExists', 'ProcessGetStats', 'ProcessList', 'ProcessSetPriority',
92 'ProcessWait', 'ProcessWaitClose', 'ProgressOff', 'ProgressOn', 'ProgressSet',
93 'Ptr', 'Random', 'RegDelete', 'RegEnumKey', 'RegEnumVal', 'RegRead',
94 'RegWrite', 'Round', 'Run', 'RunAs', 'RunAsWait', 'RunWait', 'Send',
95 'SendKeepActive', 'SetError', 'SetExtended', 'ShellExecute',
96 'ShellExecuteWait', 'Shutdown', 'Sin', 'Sleep', 'SoundPlay',
97 'SoundSetWaveVolume', 'SplashImageOn', 'SplashOff', 'SplashTextOn', 'Sqrt',
98 'SRandom', 'StatusbarGetText', 'StderrRead', 'StdinWrite', 'StdioClose',
99 'StdoutRead', 'String', 'StringAddCR', 'StringCompare', 'StringFormat',
100 'StringFromASCIIArray', 'StringInStr', 'StringIsAlNum', 'StringIsAlpha',
101 'StringIsASCII', 'StringIsDigit', 'StringIsFloat', 'StringIsInt',
102 'StringIsLower', 'StringIsSpace', 'StringIsUpper', 'StringIsXDigit',
103 'StringLeft', 'StringLen', 'StringLower', 'StringMid', 'StringRegExp',
104 'StringRegExpReplace', 'StringReplace', 'StringReverse', 'StringRight',
105 'StringSplit', 'StringStripCR', 'StringStripWS', 'StringToASCIIArray',
106 'StringToBinary', 'StringTrimLeft', 'StringTrimRight', 'StringUpper', 'Tan',
107 'TCPAccept', 'TCPCloseSocket', 'TCPConnect', 'TCPListen', 'TCPNameToIP',
108 'TCPRecv', 'TCPSend', 'TCPShutdown, UDPShutdown', 'TCPStartup, UDPStartup',
109 'TimerDiff', 'TimerInit', 'ToolTip', 'TrayCreateItem', 'TrayCreateMenu',
110 'TrayGetMsg', 'TrayItemDelete', 'TrayItemGetHandle', 'TrayItemGetState',
111 'TrayItemGetText', 'TrayItemSetOnEvent', 'TrayItemSetState',
112 'TrayItemSetText', 'TraySetClick', 'TraySetIcon', 'TraySetOnEvent',
113 'TraySetPauseIcon', 'TraySetState', 'TraySetToolTip', 'TrayTip', 'UBound',
114 'UDPBind', 'UDPCloseSocket', 'UDPOpen', 'UDPRecv', 'UDPSend', 'VarGetType',
115 'WinActivate', 'WinActive', 'WinClose', 'WinExists', 'WinFlash',
116 'WinGetCaretPos', 'WinGetClassList', 'WinGetClientSize', 'WinGetHandle',
117 'WinGetPos', 'WinGetProcess', 'WinGetState', 'WinGetText', 'WinGetTitle',
118 'WinKill', 'WinList', 'WinMenuSelectItem', 'WinMinimizeAll',
119 'WinMinimizeAllUndo', 'WinMove', 'WinSetOnTop', 'WinSetState', 'WinSetTitle',
120 'WinSetTrans', 'WinWait', 'WinWaitActive', 'WinWaitClose', 'WinWaitNotActive'
121 }, nil, true))
123 -- Preprocessor.
124 local preproc = token(l.PREPROCESSOR, '#' * word_match({
125 'include-once', 'include', 'pragma', 'forceref', 'RequireAdmin', 'NoTrayIcon',
126 'OnAutoItStartRegister'
127 }, '-', true))
129 -- Strings.
130 local dq_str = l.delimited_range('"', true, true)
131 local sq_str = l.delimited_range("'", true, true)
132 local inc = l.delimited_range('<>', true, true, true)
133 local str = token(l.STRING, dq_str + sq_str + inc)
135 -- Macros.
136 local macro = token('macro', '@' * (l.alnum + '_')^1)
138 -- Variables.
139 local var = token(l.VARIABLE, '$' * (l.alnum + '_')^1)
141 -- Identifiers.
142 local ident = token(l.IDENTIFIER, (l.alnum + '_')^1)
144 -- Numbers.
145 local nbr = token(l.NUMBER, l.float + l.integer)
147 -- Operators.
148 local oper = token(l.OPERATOR, S('+-^*/&<>=?:()[]'))
150 M._rules = {
151 {'whitespace', ws},
152 {'comment', comment},
153 {'keyword', kw},
154 {'function', func},
155 {'preproc', preproc},
156 {'string', str},
157 {'macro', macro},
158 {'variable', var},
159 {'number', nbr},
160 {'identifier', ident},
161 {'operator', oper}
164 M._tokenstyles = {
165 macro = l.STYLE_PREPROCESSOR
168 return M