From 7cb4e3d14a4ce579dc093836d9b29ee165b1553c Mon Sep 17 00:00:00 2001 From: "Jan T. Sott" Date: Wed, 13 Oct 2021 19:51:45 +0200 Subject: [PATCH] enh(nsis) adds NSIS v3.08 commands, some small improvements (#3351) - Adding some missing keywords - Splitting keywords into arrays Co-authored-by: Josh Goebel --- CHANGES.md | 3 + src/languages/nsis.js | 448 +++++++++++++++++++++++++++- test/markup/nsis/default.expect.txt | 14 +- 3 files changed, 445 insertions(+), 20 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7502834a43..86dc83bf1f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -37,6 +37,8 @@ Grammars: - enh(scala) add `using` soft keyword (#3330) [Nicolas Stucki][] - enh(fsharp) added `f#` alias (#3337) [Bahnschrift][] - enh(bash) added gnu core utilities (#3342) [katzeprior][] +- enh(nsis) add new NSIS commands (#3351) [idleberg][] +- fix(nsis) set `case_insensitive` to `true` (#3351) [idleberg][] - fix(css/less/stylus/scss) highlight single-colon psuedo-elements properly (#3240) [zsoltlengyelit][] [Austin Schick]: https://github.com/austin-schick @@ -50,6 +52,7 @@ Grammars: [katzeprior]: https://github.com/katzeprior [zsoltlengyelit]: github.com/zsoltlengyelit [Syb Wartna]:https://github.com/waarissyb +[idleberg]: https://github.com/idleberg ## Version 11.2.0 diff --git a/src/languages/nsis.js b/src/languages/nsis.js index 59956cbfaf..fa3b2e547f 100644 --- a/src/languages/nsis.js +++ b/src/languages/nsis.js @@ -5,10 +5,149 @@ Author: Jan T. Sott Website: https://nsis.sourceforge.io/Main_Page */ +import * as regex from '../lib/regex.js'; + export default function(hljs) { + const LANGUAGE_CONSTANTS = [ + "ADMINTOOLS", + "APPDATA", + "CDBURN_AREA", + "CMDLINE", + "COMMONFILES32", + "COMMONFILES64", + "COMMONFILES", + "COOKIES", + "DESKTOP", + "DOCUMENTS", + "EXEDIR", + "EXEFILE", + "EXEPATH", + "FAVORITES", + "FONTS", + "HISTORY", + "HWNDPARENT", + "INSTDIR", + "INTERNET_CACHE", + "LANGUAGE", + "LOCALAPPDATA", + "MUSIC", + "NETHOOD", + "OUTDIR", + "PICTURES", + "PLUGINSDIR", + "PRINTHOOD", + "PROFILE", + "PROGRAMFILES32", + "PROGRAMFILES64", + "PROGRAMFILES", + "QUICKLAUNCH", + "RECENT", + "RESOURCES_LOCALIZED", + "RESOURCES", + "SENDTO", + "SMPROGRAMS", + "SMSTARTUP", + "STARTMENU", + "SYSDIR", + "TEMP", + "TEMPLATES", + "VIDEOS", + "WINDIR" + ]; + + const PARAM_NAMES = [ + "ARCHIVE", + "FILE_ATTRIBUTE_ARCHIVE", + "FILE_ATTRIBUTE_NORMAL", + "FILE_ATTRIBUTE_OFFLINE", + "FILE_ATTRIBUTE_READONLY", + "FILE_ATTRIBUTE_SYSTEM", + "FILE_ATTRIBUTE_TEMPORARY", + "HKCR", + "HKCU", + "HKDD", + "HKEY_CLASSES_ROOT", + "HKEY_CURRENT_CONFIG", + "HKEY_CURRENT_USER", + "HKEY_DYN_DATA", + "HKEY_LOCAL_MACHINE", + "HKEY_PERFORMANCE_DATA", + "HKEY_USERS", + "HKLM", + "HKPD", + "HKU", + "IDABORT", + "IDCANCEL", + "IDIGNORE", + "IDNO", + "IDOK", + "IDRETRY", + "IDYES", + "MB_ABORTRETRYIGNORE", + "MB_DEFBUTTON1", + "MB_DEFBUTTON2", + "MB_DEFBUTTON3", + "MB_DEFBUTTON4", + "MB_ICONEXCLAMATION", + "MB_ICONINFORMATION", + "MB_ICONQUESTION", + "MB_ICONSTOP", + "MB_OK", + "MB_OKCANCEL", + "MB_RETRYCANCEL", + "MB_RIGHT", + "MB_RTLREADING", + "MB_SETFOREGROUND", + "MB_TOPMOST", + "MB_USERICON", + "MB_YESNO", + "NORMAL", + "OFFLINE", + "READONLY", + "SHCTX", + "SHELL_CONTEXT", + "SYSTEM|TEMPORARY", + ]; + + const COMPILER_FLAGS = [ + "addincludedir", + "addplugindir", + "appendfile", + "cd", + "define", + "delfile", + "echo", + "else", + "endif", + "error", + "execute", + "finalize", + "getdllversion", + "gettlbversion", + "if", + "ifdef", + "ifmacrodef", + "ifmacrondef", + "ifndef", + "include", + "insertmacro", + "macro", + "macroend", + "makensis", + "packhdr", + "searchparse", + "searchreplace", + "system", + "tempfile", + "undef", + "uninstfinalize", + "verbose", + "warning", + ]; + const CONSTANTS = { - className: 'variable', - begin: /\$(ADMINTOOLS|APPDATA|CDBURN_AREA|CMDLINE|COMMONFILES32|COMMONFILES64|COMMONFILES|COOKIES|DESKTOP|DOCUMENTS|EXEDIR|EXEFILE|EXEPATH|FAVORITES|FONTS|HISTORY|HWNDPARENT|INSTDIR|INTERNET_CACHE|LANGUAGE|LOCALAPPDATA|MUSIC|NETHOOD|OUTDIR|PICTURES|PLUGINSDIR|PRINTHOOD|PROFILE|PROGRAMFILES32|PROGRAMFILES64|PROGRAMFILES|QUICKLAUNCH|RECENT|RESOURCES_LOCALIZED|RESOURCES|SENDTO|SMPROGRAMS|SMSTARTUP|STARTMENU|SYSDIR|TEMP|TEMPLATES|VIDEOS|WINDIR)/ + className: 'variable.constant', + begin: regex.concat(/\$/, regex.either(...LANGUAGE_CONSTANTS)) }; const DEFINES = { @@ -33,13 +172,16 @@ export default function(hljs) { const PARAMETERS = { // command parameters className: 'params', - begin: '(ARCHIVE|FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_NORMAL|FILE_ATTRIBUTE_OFFLINE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_TEMPORARY|HKCR|HKCU|HKDD|HKEY_CLASSES_ROOT|HKEY_CURRENT_CONFIG|HKEY_CURRENT_USER|HKEY_DYN_DATA|HKEY_LOCAL_MACHINE|HKEY_PERFORMANCE_DATA|HKEY_USERS|HKLM|HKPD|HKU|IDABORT|IDCANCEL|IDIGNORE|IDNO|IDOK|IDRETRY|IDYES|MB_ABORTRETRYIGNORE|MB_DEFBUTTON1|MB_DEFBUTTON2|MB_DEFBUTTON3|MB_DEFBUTTON4|MB_ICONEXCLAMATION|MB_ICONINFORMATION|MB_ICONQUESTION|MB_ICONSTOP|MB_OK|MB_OKCANCEL|MB_RETRYCANCEL|MB_RIGHT|MB_RTLREADING|MB_SETFOREGROUND|MB_TOPMOST|MB_USERICON|MB_YESNO|NORMAL|OFFLINE|READONLY|SHCTX|SHELL_CONTEXT|SYSTEM|TEMPORARY)' + begin: regex.either(...PARAM_NAMES) }; const COMPILER = { // !compiler_flags className: 'keyword', - begin: /!(addincludedir|addplugindir|appendfile|cd|define|delfile|echo|else|endif|error|execute|finalize|getdllversion|gettlbversion|if|ifdef|ifmacrodef|ifmacrondef|ifndef|include|insertmacro|macro|macroend|makensis|packhdr|searchparse|searchreplace|system|tempfile|undef|verbose|warning)/ + begin: regex.concat( + /!/, + regex.either(...COMPILER_FLAGS) + ) }; const METACHARS = { @@ -50,7 +192,7 @@ export default function(hljs) { const PLUGINS = { // plug::ins - className: 'class', + className: 'title.function', begin: /\w+::\w+/ }; @@ -80,14 +222,295 @@ export default function(hljs) { ] }; + const KEYWORDS = [ + "Abort", + "AddBrandingImage", + "AddSize", + "AllowRootDirInstall", + "AllowSkipFiles", + "AutoCloseWindow", + "BGFont", + "BGGradient", + "BrandingText", + "BringToFront", + "Call", + "CallInstDLL", + "Caption", + "ChangeUI", + "CheckBitmap", + "ClearErrors", + "CompletedText", + "ComponentText", + "CopyFiles", + "CRCCheck", + "CreateDirectory", + "CreateFont", + "CreateShortCut", + "Delete", + "DeleteINISec", + "DeleteINIStr", + "DeleteRegKey", + "DeleteRegValue", + "DetailPrint", + "DetailsButtonText", + "DirText", + "DirVar", + "DirVerify", + "EnableWindow", + "EnumRegKey", + "EnumRegValue", + "Exch", + "Exec", + "ExecShell", + "ExecShellWait", + "ExecWait", + "ExpandEnvStrings", + "File", + "FileBufSize", + "FileClose", + "FileErrorText", + "FileOpen", + "FileRead", + "FileReadByte", + "FileReadUTF16LE", + "FileReadWord", + "FileWriteUTF16LE", + "FileSeek", + "FileWrite", + "FileWriteByte", + "FileWriteWord", + "FindClose", + "FindFirst", + "FindNext", + "FindWindow", + "FlushINI", + "GetCurInstType", + "GetCurrentAddress", + "GetDlgItem", + "GetDLLVersion", + "GetDLLVersionLocal", + "GetErrorLevel", + "GetFileTime", + "GetFileTimeLocal", + "GetFullPathName", + "GetFunctionAddress", + "GetInstDirError", + "GetKnownFolderPath", + "GetLabelAddress", + "GetTempFileName", + "GetWinVer", + "Goto", + "HideWindow", + "Icon", + "IfAbort", + "IfErrors", + "IfFileExists", + "IfRebootFlag", + "IfRtlLanguage", + "IfShellVarContextAll", + "IfSilent", + "InitPluginsDir", + "InstallButtonText", + "InstallColors", + "InstallDir", + "InstallDirRegKey", + "InstProgressFlags", + "InstType", + "InstTypeGetText", + "InstTypeSetText", + "Int64Cmp", + "Int64CmpU", + "Int64Fmt", + "IntCmp", + "IntCmpU", + "IntFmt", + "IntOp", + "IntPtrCmp", + "IntPtrCmpU", + "IntPtrOp", + "IsWindow", + "LangString", + "LicenseBkColor", + "LicenseData", + "LicenseForceSelection", + "LicenseLangString", + "LicenseText", + "LoadAndSetImage", + "LoadLanguageFile", + "LockWindow", + "LogSet", + "LogText", + "ManifestDPIAware", + "ManifestLongPathAware", + "ManifestMaxVersionTested", + "ManifestSupportedOS", + "MessageBox", + "MiscButtonText", + "Name", + "Nop", + "OutFile", + "Page", + "PageCallbacks", + "PEAddResource", + "PEDllCharacteristics", + "PERemoveResource", + "PESubsysVer", + "Pop", + "Push", + "Quit", + "ReadEnvStr", + "ReadINIStr", + "ReadRegDWORD", + "ReadRegStr", + "Reboot", + "RegDLL", + "Rename", + "RequestExecutionLevel", + "ReserveFile", + "Return", + "RMDir", + "SearchPath", + "SectionGetFlags", + "SectionGetInstTypes", + "SectionGetSize", + "SectionGetText", + "SectionIn", + "SectionSetFlags", + "SectionSetInstTypes", + "SectionSetSize", + "SectionSetText", + "SendMessage", + "SetAutoClose", + "SetBrandingImage", + "SetCompress", + "SetCompressor", + "SetCompressorDictSize", + "SetCtlColors", + "SetCurInstType", + "SetDatablockOptimize", + "SetDateSave", + "SetDetailsPrint", + "SetDetailsView", + "SetErrorLevel", + "SetErrors", + "SetFileAttributes", + "SetFont", + "SetOutPath", + "SetOverwrite", + "SetRebootFlag", + "SetRegView", + "SetShellVarContext", + "SetSilent", + "ShowInstDetails", + "ShowUninstDetails", + "ShowWindow", + "SilentInstall", + "SilentUnInstall", + "Sleep", + "SpaceTexts", + "StrCmp", + "StrCmpS", + "StrCpy", + "StrLen", + "SubCaption", + "Unicode", + "UninstallButtonText", + "UninstallCaption", + "UninstallIcon", + "UninstallSubCaption", + "UninstallText", + "UninstPage", + "UnRegDLL", + "Var", + "VIAddVersionKey", + "VIFileVersion", + "VIProductVersion", + "WindowIcon", + "WriteINIStr", + "WriteRegBin", + "WriteRegDWORD", + "WriteRegExpandStr", + "WriteRegMultiStr", + "WriteRegNone", + "WriteRegStr", + "WriteUninstaller", + "XPStyle" + ]; + + const LITERALS = [ + "admin", + "all", + "auto", + "both", + "bottom", + "bzip2", + "colored", + "components", + "current", + "custom", + "directory", + "false", + "force", + "hide", + "highest", + "ifdiff", + "ifnewer", + "instfiles", + "lastused", + "leave", + "left", + "license", + "listonly", + "lzma", + "nevershow", + "none", + "normal", + "notset", + "off", + "on", + "open", + "print", + "right", + "show", + "silent", + "silentlog", + "smooth", + "textonly", + "top", + "true", + "try", + "un.components", + "un.custom", + "un.directory", + "un.instfiles", + "un.license", + "uninstConfirm", + "user", + "Win10", + "Win7", + "Win8", + "WinVista", + "zlib" + ]; + + const FUNCTION_DEF = { + match: [ + /Function/, + /\s+/, + regex.concat(/(\.)?/, hljs.IDENT_RE) + ], + scope: { + 1: "keyword", + 3: "title.function" + } + }; + return { name: 'NSIS', - case_insensitive: false, + case_insensitive: true, keywords: { - keyword: - 'Abort AddBrandingImage AddSize AllowRootDirInstall AllowSkipFiles AutoCloseWindow BGFont BGGradient BrandingText BringToFront Call CallInstDLL Caption ChangeUI CheckBitmap ClearErrors CompletedText ComponentText CopyFiles CRCCheck CreateDirectory CreateFont CreateShortCut Delete DeleteINISec DeleteINIStr DeleteRegKey DeleteRegValue DetailPrint DetailsButtonText DirText DirVar DirVerify EnableWindow EnumRegKey EnumRegValue Exch Exec ExecShell ExecShellWait ExecWait ExpandEnvStrings File FileBufSize FileClose FileErrorText FileOpen FileRead FileReadByte FileReadUTF16LE FileReadWord FileWriteUTF16LE FileSeek FileWrite FileWriteByte FileWriteWord FindClose FindFirst FindNext FindWindow FlushINI GetCurInstType GetCurrentAddress GetDlgItem GetDLLVersion GetDLLVersionLocal GetErrorLevel GetFileTime GetFileTimeLocal GetFullPathName GetFunctionAddress GetInstDirError GetKnownFolderPath GetLabelAddress GetTempFileName Goto HideWindow Icon IfAbort IfErrors IfFileExists IfRebootFlag IfRtlLanguage IfShellVarContextAll IfSilent InitPluginsDir InstallButtonText InstallColors InstallDir InstallDirRegKey InstProgressFlags InstType InstTypeGetText InstTypeSetText Int64Cmp Int64CmpU Int64Fmt IntCmp IntCmpU IntFmt IntOp IntPtrCmp IntPtrCmpU IntPtrOp IsWindow LangString LicenseBkColor LicenseData LicenseForceSelection LicenseLangString LicenseText LoadAndSetImage LoadLanguageFile LockWindow LogSet LogText ManifestDPIAware ManifestLongPathAware ManifestMaxVersionTested ManifestSupportedOS MessageBox MiscButtonText Name Nop OutFile Page PageCallbacks PEAddResource PEDllCharacteristics PERemoveResource PESubsysVer Pop Push Quit ReadEnvStr ReadINIStr ReadRegDWORD ReadRegStr Reboot RegDLL Rename RequestExecutionLevel ReserveFile Return RMDir SearchPath SectionGetFlags SectionGetInstTypes SectionGetSize SectionGetText SectionIn SectionSetFlags SectionSetInstTypes SectionSetSize SectionSetText SendMessage SetAutoClose SetBrandingImage SetCompress SetCompressor SetCompressorDictSize SetCtlColors SetCurInstType SetDatablockOptimize SetDateSave SetDetailsPrint SetDetailsView SetErrorLevel SetErrors SetFileAttributes SetFont SetOutPath SetOverwrite SetRebootFlag SetRegView SetShellVarContext SetSilent ShowInstDetails ShowUninstDetails ShowWindow SilentInstall SilentUnInstall Sleep SpaceTexts StrCmp StrCmpS StrCpy StrLen SubCaption Unicode UninstallButtonText UninstallCaption UninstallIcon UninstallSubCaption UninstallText UninstPage UnRegDLL Var VIAddVersionKey VIFileVersion VIProductVersion WindowIcon WriteINIStr WriteRegBin WriteRegDWORD WriteRegExpandStr WriteRegMultiStr WriteRegNone WriteRegStr WriteUninstaller XPStyle', - literal: - 'admin all auto both bottom bzip2 colored components current custom directory false force hide highest ifdiff ifnewer instfiles lastused leave left license listonly lzma nevershow none normal notset off on open print right show silent silentlog smooth textonly top true try un.components un.custom un.directory un.instfiles un.license uninstConfirm user Win10 Win7 Win8 WinVista zlib' + keyword: KEYWORDS, + literal: LITERALS }, contains: [ hljs.HASH_COMMENT_MODE, @@ -99,10 +522,9 @@ export default function(hljs) { relevance: 0 } ), + FUNCTION_DEF, { - className: 'function', - beginKeywords: 'Function PageEx Section SectionGroup', - end: '$' + beginKeywords: 'Function PageEx Section SectionGroup FunctionEnd SectionEnd', }, STRING, COMPILER, diff --git a/test/markup/nsis/default.expect.txt b/test/markup/nsis/default.expect.txt index d3e453a2b0..9574047d8f 100644 --- a/test/markup/nsis/default.expect.txt +++ b/test/markup/nsis/default.expect.txt @@ -16,22 +16,22 @@ CRCCheck on !ifdef ${x64} - InstallDir "$PROGRAMFILES64\installer_name" + InstallDir "$PROGRAMFILES64\installer_name" !else - InstallDir "$PROGRAMFILES\installer_name" + InstallDir "$PROGRAMFILES\installer_name" !endif ; Pages !insertmacro MUI_PAGE_INSTFILES ; Sections -Section "section_name" section_index - nsExec::ExecToLog "calc.exe" -SectionEnd +Section "section_name" section_index + nsExec::ExecToLog "calc.exe" +SectionEnd ; Functions -Function .onInit +Function .onInit DetailPrint "The install button reads $(^InstallBtn)" DetailPrint 'Here comes a$\n$\rline-break!' DetailPrint `Escape the dollar-sign: $$` -FunctionEnd +FunctionEnd