
--- AutoHotkey v1 vocabulary tree for Lx
-- @module vocabulary

-- Not highlighted as "variable" because built into AHK
local variables = {
	"A_AhkPath",
	"A_AhkVersion",
	"A_AppData",
	"A_AppDataCommon",
	"A_AutoTrim",
	"A_BatchLines",
	"A_CaretX",
	"A_CaretY",
	"A_Computername",
	"A_ControlDelay",
	"A_Cursor",
	"A_DD",
	"A_DDD",
	"A_DDDD",
	"A_DefaultMouseSpeed",
	"A_Desktop",
	"A_Desktopcommon",
	"A_Detecthiddentext",
	"A_Detecthiddenwindows",
	"A_Endchar",
	"A_EventInfo",
	"A_ExitReason",
	"A_FileEncoding",
	"A_FormatFloat",
	"A_FormatInteger",
	"A_Gui",
	"A_GuiControl",
	"A_GuiControlEvent",
	"A_GuiEvent",
	"A_GuiHeight",
	"A_GuiWidth",
	"A_GuiX",
	"A_GuiY",
	"A_Hour",
	"A_IconFile",
	"A_IconHidden",
	"A_IconNumber",
	"A_IconTip",
	"A_Index",
	"A_IpAddress1",
	"A_IpAddress2",
	"A_IpAddress3",
	"A_IpAddress4",
	"A_Is64bitOS",
	"A_IsAdmin",
	"A_IsCompiled",
	"A_IsCritical",
	"A_IsPaused",
	"A_IsSuspended",
	"A_IsUnicode",
	"A_KeyDelay",
	"A_Language",
	"A_LastError",
	"A_LineFile",
	"A_LineNumber",
	"A_LoopField",
	"A_LoopFileAttrib",
	"A_LoopFileDir",
	"A_LoopFileExt",
	"A_LoopFileFullPath",
	"A_LoopFileLongPath",
	"A_LoopFileName",
	"A_LoopFileShortName",
	"A_LoopFileShortPath",
	"A_LoopFileSize",
	"A_LoopFileSizeKB",
	"A_LoopFileSizeMB",
	"A_LoopFileTimeAccessed",
	"A_LoopFileTimeCreated",
	"A_LoopFileTimeModified",
	"A_LoopReadLine",
	"A_LoopRegKey",
	"A_LoopRegName",
	"A_LoopRegSubKey",
	"A_LoopRegTimeModified",
	"A_LoopRegType",
	"A_MDay",
	"A_Min",
	"A_MM",
	"A_MMM",
	"A_MMMM",
	"A_Mon",
	"A_MouseDelay",
	"A_MSec",
	"A_MyDocuments",
	"A_Now",
	"A_NowUTC",
	"A_NumBatchLines",
	"A_OSType",
	"A_OSVersion",
	"A_PriorHotkey",
	"A_PriorKey",
	"A_ProgramFiles",
	"A_Programs",
	"A_ProgramsCommon",
	"A_PtrSize",
	"A_RegView",
	"A_ScreenDpi",
	"A_ScreenHeight",
	"A_ScreenWidth",
	"A_ScriptDir",
	"A_ScriptFullPath",
	"A_ScriptHwnd",
	"A_ScriptName",
	"A_Sec",
	"A_Space",
	"A_StartMenu",
	"A_StartMenuCommon",
	"A_StartUp",
	"A_StartUpCommon",
	"A_StringCaseSense",
	"A_Tab",
	"A_Temp",
	"A_ThisFunc",
	"A_ThisHotkey",
	"A_ThisLabel",
	"A_ThisMenu",
	"A_ThisMenuItem",
	"A_ThisMenuItemPos",
	"A_TickCount",
	"A_TimeIdle",
	"A_TimeIdlePhysical",
	"A_TimeSincePriorHotkey",
	"A_TimeSinceThisHotkey",
	"A_TitleMatchMode",
	"A_TitleMatchModeSpeed",
	"A_UserName",
	"A_WDay",
	"A_WinDelay",
	"A_WinDir",
	"A_WorkingDir",
	"A_YDay",
	"A_Year",
	"A_YWeek",
	"A_YYYY",
	"ClipboardAll",
	"Clipboard",
	"ComSpec",
	"ErrorLevel",
	"ProgramFiles",
}

local keywords = {
	"ByRef",
	"Case",
	"Class",
	"Else",
	"Exit",
	"ExitApp",
	"For",
	"Global",
	"If",
	"Local",
	"Loop",
	"OnExit",
	"Pause",
	"Sleep",
	"Static",
	"Suspend",
	"Switch",
	"Until",
	"While",
}

local control = {
	"Return",
	"Break",
	"Continue",
	"GoTo",
	"Gosub",
}

local exception = {
	"Try",
	"Throw",
	"Catch",
	"Finally",
}

local functions = {
	"_NewEnum",
	"Abs",
	"ACos",
	"Array",
	"Asc",
	"ASin",
	"ATan",
	"Ceil",
	"Chr",
	"ComObjActive",
	"ComObjArray",
	"ComObjConnect",
	"ComObjCreate",
	"ComObject",
	"ComObjError",
	"ComObjFlags",
	"ComObjGet",
	"ComObjQuery",
	"ComObjType",
	"ComObjValue",
	"Cos",
	"DllCall",
	"Exception",
	"Exp",
	"FileExist",
	"FileOpen",
	"Floor",
	"Format",
	"Func",
	"GetKeyName",
	"GetKeySC",
	"GetKeyState",
	"GetKeyVK",
	"IL_Add",
	"IL_Create",
	"IL_Destroy",
	"InStr",
	"IsByRef",
	"IsFunc",
	"IsLabel",
	"IsObject",
	"Ln",
	"Log",
	"LTrim",
	"LV_Add",
	"LV_Delete",
	"LV_DeleteCol",
	"LV_GetCount",
	"LV_GetNext",
	"LV_GetText",
	"LV_Insert",
	"LV_InsertCol",
	"LV_Modify",
	"LV_ModifyCol",
	"LV_SetImageList",
	"Mod",
	"NumGet",
	"NumPut",
	"ObjAddRef",
	"ObjClone",
	"Object",
	"ObjGetAddress",
	"ObjGetCapacity",
	"ObjHasKey",
	"ObjInsert",
	"ObjMaxIndex",
	"ObjMinIndex",
	"ObjNewEnum",
	"ObjRelease",
	"ObjRemove",
	"ObjSetCapacity",
	"OnMessage",
	"RegExMatch",
	"RegExReplace",
	"RegisterCallback",
	"Round",
	"RTrim",
	"SB_SetIcon",
	"SB_SetParts",
	"SB_SetText",
	"Sin",
	"Sqrt",
	"StrGet",
	"StrLen",
	"StrPut",
	"StrReplace",
	"StrSplit",
	"SubStr",
	"Tan",
	"Trim",
	"TV_Add",
	"TV_Delete",
	"TV_Get",
	"TV_GetChild",
	"TV_GetCount",
	"TV_GetNext",
	"TV_GetParent",
	"TV_GetPrev",
	"TV_GetSelection",
	"TV_GetText",
	"TV_Modify",
	"TV_SetImageList",
	"VarSetCapacity",
	"WinActive",
	"WinExist",
}

local commands = {
	-- Legacy control flow (AHK v1)
	"IfWinActive", -- Execute following line if matching window is active
	"IfWinNotActive", -- Execute if matching window is not active
	"IfWinExist", -- Execute if matching window exists
	"IfWinNotExist", -- Execute if matching window does not exist

	-- Script and execution control
	"AutoTrim", -- Control automatic trimming of whitespace
	"Critical", -- Prevent thread interruption
	"Pause", -- Pause the current script thread
	"Reload", -- Reload the script
	"Shutdown", -- Shut down, log off, or restart the system
	"Sleep", -- Delay execution for a number of milliseconds
	"Thread", -- Control thread interruptibility
	"SetBatchLines", -- Control script execution speed

	-- Input and keyboard
	"BlockInput", -- Block keyboard and mouse input
	"Hotkey", -- Create or modify hotkeys
	"KeyHistory", -- Display recent key events
	"KeyWait", -- Wait for a key or mouse button
	"Send", -- Send keystrokes
	"SendEvent", -- Send keystrokes via event mode
	"SendInput", -- Send keystrokes via input mode
	"SendPlay", -- Send keystrokes via play mode
	"SendRaw", -- Send literal text
	"SendLevel", -- Set send level for hotkeys

	-- Mouse input
	"Click", -- Simulate mouse click
	"MouseClick", -- Perform mouse click
	"MouseClickDrag", -- Click and drag mouse
	"MouseGetPos", -- Get mouse position
	"MouseMove", -- Move mouse cursor
	"SetDefaultMouseSpeed", -- Set default mouse speed
	"SetMouseDelay", -- Set mouse delay

	-- Window management
	"WinActivate", -- Activate window
	"WinActivateBottom", -- Activate bottom-most window
	"WinClose", -- Close window
	"WinExist", -- Check for window existence
	"WinGet", -- Retrieve window info
	"WinGetActiveStats", -- Get active window stats
	"WinGetActiveTitle", -- Get active window title
	"WinGetClass", -- Get window class
	"WinGetPos", -- Get window position
	"WinGetText", -- Get window text
	"WinGetTitle", -- Get window title
	"WinHide", -- Hide window
	"WinKill", -- Force-close window
	"WinMaximize", -- Maximize window
	"WinMenuSelectItem", -- Select menu item
	"WinMinimize", -- Minimize window
	"WinMinimizeAll", -- Minimize all windows
	"WinMinimizeAllUndo", -- Undo minimize all
	"WinMove", -- Move or resize window
	"WinRestore", -- Restore window
	"WinSet", -- Modify window attributes
	"WinSetTitle", -- Change window title
	"WinShow", -- Show window
	"WinWait", -- Wait for window
	"WinWaitActive", -- Wait for active window
	"WinWaitClose", -- Wait for window to close
	"WinWaitNotActive", -- Wait for window to become inactive

	-- Control and GUI interaction
	"Control", -- Send command to control
	"ControlClick", -- Click a control
	"ControlFocus", -- Focus a control
	"ControlGet", -- Get control info
	"ControlGetFocus", -- Get focused control
	"ControlGetPos", -- Get control position
	"ControlGetText", -- Get control text
	"ControlMove", -- Move control
	"ControlSend", -- Send keys to control
	"ControlSendRaw", -- Send raw keys to control
	"ControlSetText", -- Set control text
	"Gui", -- Create or modify GUI
	"GuiControl", -- Modify GUI control
	"GuiControlGet", -- Get GUI control info

	-- File and filesystem
	"FileAppend", -- Append text to file
	"FileCopy", -- Copy file
	"FileCopyDir", -- Copy directory
	"FileCreateDir", -- Create directory
	"FileCreateShortcut", -- Create shortcut
	"FileDelete", -- Delete file
	"FileEncoding", -- Set file encoding
	"FileGetAttrib", -- Get file attributes
	"FileGetShortcut", -- Get shortcut info
	"FileGetSize", -- Get file size
	"FileGetTime", -- Get file timestamp
	"FileGetVersion", -- Get file version
	"FileInstall", -- Include file in compiled script
	"FileMove", -- Move file
	"FileMoveDir", -- Move directory
	"FileRead", -- Read file
	"FileReadLine", -- Read line from file
	"FileRecycle", -- Recycle file
	"FileRecycleEmpty", -- Empty recycle bin
	"FileRemoveDir", -- Remove directory
	"FileSelectFile", -- Show file dialog
	"FileSelectFolder", -- Show folder dialog
	"FileSetAttrib", -- Set file attributes
	"FileSetTime", -- Set file timestamp
	"SplitPath", -- Split file path

	-- Environment and system
	"EnvAdd", -- Add to environment variable
	"EnvGet", -- Get environment variable
	"EnvSet", -- Set environment variable
	"EnvSub", -- Subtract from environment variable
	"EnvUpdate", -- Refresh environment variables
	"SetEnv", -- Set script variable
	"SetWorkingDir", -- Change working directory
	"Run", -- Run external program
	"RunAs", -- Run program as another user
	"RunWait", -- Run program and wait
	"Process", -- Manage processes
	"Random", -- Generate random number
	"SysGet", -- Retrieve system metrics

	-- Registry
	"RegDelete", -- Delete registry value
	"RegRead", -- Read registry value
	"RegWrite", -- Write registry value
	"SetRegView", -- Set registry view

	-- Sound
	"SoundBeep", -- Play beep
	"SoundGet", -- Get sound setting
	"SoundGetWaveVolume", -- Get wave volume
	"SoundPlay", -- Play sound file
	"SoundSet", -- Set sound setting
	"SoundSetWaveVolume", -- Set wave volume

	-- Display and tooltips
	"MsgBox", -- Show message box
	"ToolTip", -- Show tooltip
	"TrayTip", -- Show tray notification
	"StatusBarGetText", -- Get status bar text
	"StatusBarWait", -- Wait for status bar change

	-- Pixel and image
	"ImageSearch", -- Search screen for image
	"PixelGetColor", -- Get pixel color
	"PixelSearch", -- Search for pixel color

	-- Groups
	"GroupActivate", -- Activate window group
	"GroupAdd", -- Add window to group
	"GroupClose", -- Close group windows
	"GroupDeactivate", -- Deactivate group

	-- INI files
	"IniDelete", -- Delete INI entry
	"IniRead", -- Read INI entry
	"IniWrite", -- Write INI entry

	-- Menu and lists
	"Menu", -- Create or modify menu
	"ListHotkeys", -- List hotkeys
	"ListLines", -- List executed lines
	"ListVars", -- List variables

	-- Misc utilities
	"ClipWait", -- Wait for clipboard
	"CoordMode", -- Set coordinate mode
	"DetectHiddenText", -- Toggle hidden text detection
	"DetectHiddenWindows", -- Toggle hidden window detection
	"Drive", -- Perform drive operation
	"DriveGet", -- Get drive info
	"DriveSpaceFree", -- Get free space
	"Edit", -- Open file in editor
	"FormatTime", -- Format date/time
	"Input", -- Wait for user input
	"InputBox", -- Prompt for user input
	"OutputDebug", -- Send debug string
	"PostMessage", -- Post Windows message
	"SendMessage", -- Send Windows message
	"SendMode", -- Set send mode
	"SetCapsLockState", -- Set CapsLock state
	"SetControlDelay", -- Set control delay
	"SetKeyDelay", -- Set key delay
	"SetNumLockState", -- Set NumLock state
	"SetScrollLockState", -- Set ScrollLock state
	"SetStoreCapsLockMode", -- Control CapsLock storage
	"SetTimer", -- Create or modify timer
	"SetTitleMatchMode", -- Set window title matching
	"SetWinDelay", -- Set window delay
	"Sort", -- Sort variable contents
	"StringCaseSense", -- Set string case sensitivity
	"StringLower", -- Convert string to lowercase
	"StringUpper", -- Convert string to uppercase
	"Transform", -- Perform miscellaneous transformations
	"UrlDownloadToFile", -- Download file from URL

	-- Legacy string commands (AHK v1)
	"StringGetPos", -- Find position of substring
	"StringLeft", -- Extract left part of string
	"StringLen", -- Get string length
	"StringMid", -- Extract substring
	"StringReplace", -- Replace substring
	"StringRight", -- Extract right part of string
	"StringSplit", -- Split string into array
	"StringTrimLeft", -- Trim characters from left
	"StringTrimRight", -- Trim characters from right
}

local function add_ci(symbols, word, token_type)
	-- AutoHotkey v1 is case-insensitive for keywords, built-in variables, commands, and functions
	-- Add a few common case variants without exploding the table
	local lower = string.lower(word)
	local upper = string.upper(word)
	local title = string.upper(string.sub(word, 1, 1)) .. string.lower(string.sub(word, 2))

	symbols[lower] = token_type
	symbols[upper] = token_type
	symbols[title] = token_type
	symbols[word] = token_type
end

local symbols = {}

for _, v in ipairs(variables) do
	add_ci(symbols, v, "keyword2") -- not "variable" because built into AHK
end

for _, v in ipairs(keywords) do
	add_ci(symbols, v, "keyword")
end

for _, v in ipairs(control) do
	add_ci(symbols, v, "control")
end

for _, v in ipairs(exception) do
	add_ci(symbols, v, "exception")
end

for _, v in ipairs(functions) do
	add_ci(symbols, v, "function")
end

for _, v in ipairs(commands) do
	add_ci(symbols, v, "keyword2")
end

add_ci(symbols, "True", "literal")
add_ci(symbols, "False", "literal")

return symbols
