aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/autoit.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/lexers/autoit.lua')
-rw-r--r--lua/lexers/autoit.lua92
1 files changed, 50 insertions, 42 deletions
diff --git a/lua/lexers/autoit.lua b/lua/lexers/autoit.lua
index 42b4bdf..6fd9f1b 100644
--- a/lua/lexers/autoit.lua
+++ b/lua/lexers/autoit.lua
@@ -1,27 +1,61 @@
--- Copyright 2006-2022 Mitchell. See LICENSE.
+-- Copyright 2006-2024 Mitchell. See LICENSE.
-- AutoIt LPeg lexer.
-- Contributed by Jeff Stone.
-local lexer = require('lexer')
-local token, word_match = lexer.token, lexer.word_match
-local P, S = lpeg.P, lpeg.S
+local lexer = lexer
+local P, S, B = lpeg.P, lpeg.S, lpeg.B
-local lex = lexer.new('autoit')
-
--- Whitespace.
-lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
+local lex = lexer.new(...)
-- Keywords.
-lex:add_rule('keyword', token(lexer.KEYWORD, word_match({
+lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD, true)))
+
+-- Functions.
+local builtin_func = -B('.') *
+ lex:tag(lexer.FUNCTION_BUILTIN, lex:word_match(lexer.FUNCTION_BUILTIN, true))
+local func = lex:tag(lexer.FUNCTION, lexer.word)
+local method = B('.') * lex:tag(lexer.FUNCTION_METHOD, lexer.word)
+lex:add_rule('function', (builtin_func + method + func) * #(lexer.space^0 * '('))
+
+-- Identifiers.
+lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word))
+
+-- Comments.
+local line_comment = lexer.to_eol(';')
+local block_comment = lexer.range('#comments-start', '#comments-end') + lexer.range('#cs', '#ce')
+lex:add_rule('comment', lex:tag(lexer.COMMENT, line_comment + block_comment))
+
+-- Preprocessor.
+lex:add_rule('preprocessor',
+ lex:tag(lexer.PREPROCESSOR, '#' * lex:word_match(lexer.PREPROCESSOR, true)))
+
+-- Strings.
+local dq_str = lexer.range('"', true, false)
+local sq_str = lexer.range("'", true, false)
+local inc = lexer.range('<', '>', true, false, true)
+lex:add_rule('string', lex:tag(lexer.STRING, dq_str + sq_str + inc))
+
+-- Macros.
+lex:add_rule('macro', lex:tag(lexer.CONSTANT_BUILTIN, '@' * (lexer.alnum + '_')^1))
+
+-- Variables.
+lex:add_rule('variable', lex:tag(lexer.VARIABLE, '$' * (lexer.alnum + '_')^1))
+
+-- Numbers.
+lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number))
+
+-- Operators.
+lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('+-^*/&<>=?:()[]')))
+
+lex:set_word_list(lexer.KEYWORD, {
'False', 'True', 'And', 'Or', 'Not', 'ContinueCase', 'ContinueLoop', 'Default', 'Dim', 'Global',
'Local', 'Const', 'Do', 'Until', 'Enum', 'Exit', 'ExitLoop', 'For', 'To', 'Step', 'Next', 'In',
'Func', 'Return', 'EndFunc', 'If', 'Then', 'ElseIf', 'Else', 'EndIf', 'Null', 'ReDim', 'Select',
'Case', 'EndSelect', 'Static', 'Switch', 'EndSwitch', 'Volatile', 'While', 'WEnd', 'With',
'EndWith'
-}, true)))
+})
--- Functions.
-lex:add_rule('function', token(lexer.FUNCTION, word_match({
+lex:set_word_list(lexer.FUNCTION_BUILTIN, {
'Abs', 'ACos', 'AdlibRegister', 'AdlibUnRegister', 'Asc', 'AscW', 'ASin', 'Assign', 'ATan',
'AutoItSetOption', 'AutoItWinGetTitle', 'AutoItWinSetTitle', 'Beep', 'Binary', 'BinaryLen',
'BinaryMid', 'BinaryToString', 'BitAND', 'BitNOT', 'BitOR', 'BitRotate', 'BitShift', 'BitXOR',
@@ -91,39 +125,13 @@ lex:add_rule('function', token(lexer.FUNCTION, word_match({
'WinGetState', 'WinGetText', 'WinGetTitle', 'WinKill', 'WinList', 'WinMenuSelectItem',
'WinMinimizeAll', 'WinMinimizeAllUndo', 'WinMove', 'WinSetOnTop', 'WinSetState', 'WinSetTitle',
'WinSetTrans', 'WinWait', 'WinWaitActive', 'WinWaitClose', 'WinWaitNotActive'
-}, true)))
+})
--- Identifiers.
-lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
-
--- Comments.
-local line_comment = lexer.to_eol(';')
-local block_comment = lexer.range('#comments-start', '#comments-end') + lexer.range('#cs', '#ce')
-lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
-
--- Preprocessor.
-lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, '#' * word_match({
+lex:set_word_list(lexer.PREPROCESSOR, {
'include-once', 'include', 'pragma', 'forceref', 'RequireAdmin', 'NoTrayIcon',
'OnAutoItStartRegister'
-}, true)))
-
--- Strings.
-local dq_str = lexer.range('"', true, false)
-local sq_str = lexer.range("'", true, false)
-local inc = lexer.range('<', '>', true, false, true)
-lex:add_rule('string', token(lexer.STRING, dq_str + sq_str + inc))
-
--- Macros.
-lex:add_rule('macro', token('macro', '@' * (lexer.alnum + '_')^1))
-lex:add_style('macro', lexer.styles.preprocessor)
+})
--- Variables.
-lex:add_rule('variable', token(lexer.VARIABLE, '$' * (lexer.alnum + '_')^1))
-
--- Numbers.
-lex:add_rule('number', token(lexer.NUMBER, lexer.number))
-
--- Operators.
-lex:add_rule('operator', token(lexer.OPERATOR, S('+-^*/&<>=?:()[]')))
+lexer.property['scintillua.comment'] = ';'
return lex