From 6bb3bf15be13fc7604bb9adb42733c1cbab43e89 Mon Sep 17 00:00:00 2001 From: "Jan T. Sott" Date: Thu, 10 Dec 2015 01:33:16 +0100 Subject: [PATCH 1/4] add NSIS language --- demos/nsis.html | 54 ++++++++++++++++++++++++++++ js/language/nsis.js | 88 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 demos/nsis.html create mode 100644 js/language/nsis.js diff --git a/demos/nsis.html b/demos/nsis.html new file mode 100644 index 00000000..6fcc01cd --- /dev/null +++ b/demos/nsis.html @@ -0,0 +1,54 @@ + + +Syntax Highlighting + + + +
+/*
+ * Multi-line comment, baby
+ */
+
+; Includes ---------------------------------
+!include MUI2.nsh
+!include LogicLib.nsh
+
+; Settings ---------------------------------
+Name "installer_name"
+OutFile "installer_name.exe"
+RequestExecutionLevel user
+InstallDir "$PROGRAMFILES\installer_name"
+
+; Pages ------------------------------------
+!insertmacro MUI_PAGE_COMPONENTS 
+!insertmacro MUI_PAGE_DIRECTORY
+!insertmacro MUI_PAGE_INSTFILES
+
+; Languages --------------------------------
+!insertmacro MUI_LANGUAGE "English"
+
+; Sections ---------------------------------
+Section "section" SECTION_INDEX
+
+    ${If} 0 == 1
+      nsExec::Exec "calc.exe" 
+    ${Else}
+      DetailPrint "Zero will never be one"
+    ${EndIf}
+
+SectionEnd
+
+; Descriptions -----------------------------
+LangString DESC_SECTION_INDEX ${LANG_ENGLISH} "section_description"
+
+!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
+    !insertmacro MUI_DESCRIPTION_TEXT ${SECTION_INDEX} $(DESC_SECTION_INDEX)
+!insertmacro MUI_FUNCTION_DESCRIPTION_END
+
+ + + + + + diff --git a/js/language/nsis.js b/js/language/nsis.js new file mode 100644 index 00000000..d7d43612 --- /dev/null +++ b/js/language/nsis.js @@ -0,0 +1,88 @@ +/** + * NSIS patterns + * + * @author Jan T. Sott + * @version 1.0.0 + */ +Rainbow.extend('nsis', [ + + { + 'name': 'keyword.operator', + 'pattern': /<|>|&/g + }, + { + 'name': 'comment.line', + 'pattern': /(\#|;)[\s\S]*?$/gm + }, + { + 'name': 'comment.block', + 'pattern': /\/\*[\s\S]*?\*\/|(\/\/|\#)[\s\S]*?$/gm + }, + { + 'name': 'constant.numeric', + 'pattern': /\b(\d+(\.\d+)?(e(\+|\-)?\d+)?(f|d)?|0x[\da-f]+)\b/gi + }, + { + 'name': 'constant.language', + 'pattern': /\b((un\.)?components|(un\.)?custom|(un\.)?directory|(un\.)?instfiles|(un\.)?license|uninstConfirm|admin|all|auto|both|bottom|bzip2|current|false|force|hide|highest|ifdiff|ifnewer|lastused|leave|left|listonly|lzma|nevershow|none|normal|notset|off|on|right|show|silent|silentlog|textonly|top|true|try|user|Win10|Win7|Win8|WinVista|zlib)(?=\(|\b)/g + }, + + { + 'name': 'constant.option', + 'pattern': /\b(ARCHIVE|FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_NORMAL|FILE_ATTRIBUTE_OFFLINE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_TEMPORARY|HIDDEN|HKCC|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|IDD_DIR|IDD_INST|IDD_INSTFILES|IDD_LICENSE|IDD_SELCOM|IDD_UNINST|IDD_VERIFY|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|MB_YESNOCANCEL|NORMAL|OFFLINE|READONLY|SHCTX|SHELL_CONTEXT|SW_HIDE|SW_SHOWDEFAULT|SW_SHOWMAXIMIZED|SW_SHOWMINIMIZED|SW_SHOWNORMAL|SYSTEM|TEMPORARY)(?=\(|\b)/g + }, + { + 'matches': { + 1: 'variable.dollar-sign', + 2: 'variable' + }, + 'pattern': /(\$)(\w+)\b/g + }, + { + 'name': 'variable.definition', + 'pattern': /\${[\w]+}/g + }, + { + 'name': 'variable.language', + 'pattern': /\$\([\w]+\)/g + }, + { + 'name': 'support.compiler', + 'pattern': /\s(\!)(include|addincludedir|addplugindir|appendfile|cd|delfile|echo|error|execute|packhdr|finalize|getdllversion|system|tempfile|warning|verbose|define|undef|insertmacro|macro|macroend|makensis|searchparse|searchreplace)(?=\(|\b)/g + }, + { + 'name': 'entity.compiler.block', + 'pattern': /\s(\!)(ifdef|ifndef|if|ifmacrodef|ifmacrondef|else|endif)(?=\(|\b)/g + }, + { + 'name': 'keyword.command', + 'pattern': /\b(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|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|GetLabelAddress|GetTempFileName|Goto|HideWindow|Icon|IfAbort|IfErrors|IfFileExists|IfRebootFlag|IfSilent|InitPluginsDir|InstallButtonText|InstallColors|InstallDir|InstallDirRegKey|InstProgressFlags|InstType|InstTypeGetText|InstTypeSetText|IntCmp|IntCmpU|IntFmt|IntOp|IsWindow|LangString|LicenseBkColor|LicenseData|LicenseForceSelection|LicenseLangString|LicenseText|LoadLanguageFile|LockWindow|LogSet|LogText|ManifestDPIAware|ManifestSupportedOS|MessageBox|MiscButtonText|Name|Nop|OutFile|Page|PageCallbacks|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|SetPluginUnload|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|WriteRegStr|WriteUninstaller|XPStyle)(?=\(|\b)/g + }, + { + 'name': 'keyword.plugin', + 'pattern': /\b(\w+\:\:\w+)(?=\(|\b)/g + }, + { + 'name': 'entity.command.block', + 'pattern': /\b(Function|FunctionEnd|Section|SectionEnd|SectionGroup|SectionGroupEnd|SubSection|SubSectionEnd|PageEx|PageExEnd)(?=\(|\b)/g + }, + { + 'name': 'string', + 'matches': { + 1: 'string.open', + 2: [{ + 'name': 'string.interpolation', + 'matches': { + 1: 'string.open', + 2: { + 'language': 'nsis' + }, + 3: 'string.close' + }, + 'pattern': /(\#\{)(.*?)(\})/g + }], + 3: 'string.close' + }, + 'pattern': /("|`|')(.*?[^\\\1])?(\1)/g + } +], true); From 52a8ca3922bac5b096a8e7c46e18864fe35400b2 Mon Sep 17 00:00:00 2001 From: "Jan T. Sott" Date: Thu, 10 Dec 2015 02:27:22 +0100 Subject: [PATCH 2/4] update patterns --- js/language/nsis.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/js/language/nsis.js b/js/language/nsis.js index d7d43612..f841fd40 100644 --- a/js/language/nsis.js +++ b/js/language/nsis.js @@ -5,11 +5,7 @@ * @version 1.0.0 */ Rainbow.extend('nsis', [ - - { - 'name': 'keyword.operator', - 'pattern': /<|>|&/g - }, + { 'name': 'comment.line', 'pattern': /(\#|;)[\s\S]*?$/gm @@ -48,11 +44,11 @@ Rainbow.extend('nsis', [ }, { 'name': 'support.compiler', - 'pattern': /\s(\!)(include|addincludedir|addplugindir|appendfile|cd|delfile|echo|error|execute|packhdr|finalize|getdllversion|system|tempfile|warning|verbose|define|undef|insertmacro|macro|macroend|makensis|searchparse|searchreplace)(?=\(|\b)/g + 'pattern': /\!(include|addincludedir|addplugindir|appendfile|cd|delfile|echo|error|execute|packhdr|finalize|getdllversion|system|tempfile|warning|verbose|define|undef|insertmacro|macro|macroend|makensis|searchparse|searchreplace)(?=\(|\b)/g }, { 'name': 'entity.compiler.block', - 'pattern': /\s(\!)(ifdef|ifndef|if|ifmacrodef|ifmacrondef|else|endif)(?=\(|\b)/g + 'pattern': /(\!)(ifdef|ifndef|if|ifmacrodef|ifmacrondef|else|endif)(?=\(|\b)/g }, { 'name': 'keyword.command', From 0263a07e31b3f5875788b39d87dbd2c2ed098fa6 Mon Sep 17 00:00:00 2001 From: "Jan T. Sott" Date: Thu, 10 Dec 2015 02:27:37 +0100 Subject: [PATCH 3/4] add NSIS tests --- tests/language/test.nsis.js | 128 ++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 tests/language/test.nsis.js diff --git a/tests/language/test.nsis.js b/tests/language/test.nsis.js new file mode 100644 index 00000000..fbc0444b --- /dev/null +++ b/tests/language/test.nsis.js @@ -0,0 +1,128 @@ +/* global describe, run */ +var language = 'nsis'; + +describe(language, function() { + run( + language, + + 'comment line 1', + + '; this is a comment', + + '; this is a comment' + ); + run( + language, + + 'comment line 2', + + '# this is a comment', + + '# this is a comment' + ); + + run( + language, + + 'comment block', + + '/*\n' + + 'NSIS v3.0a\n' + + 'Released under the zlib/png license\n' + + '*/', + + '/*\n' + + 'NSIS v3.0a\n' + + 'Released under the zlib/png license\n' + + '*/' + ); + + run( + language, + + 'include', + + '!include LogicLib.nsh', + + '!include LogicLib.nsh' + ); + + run( + language, + + 'string', + + '"this is a string"', + + '"this is a string"' + ); + + run( + language, + + 'language constant', + + 'LangString DESC_SECTION_INDEX ${LANG_ENGLISH} "this is a string"', + + 'LangString DESC_SECTION_INDEX ${LANG_ENGLISH} "this is a string"' + ); + + run( + language, + + 'variable assignment', + + 'StrCpy $0 "this is a string"', + + 'StrCpy $0 "this is a string"' + ); + + run( + language, + + 'operator math', + + 'IntOp $0 1 + 1', + + 'IntOp $0 1 + 1' + ); + + run( + language, + + 'function', + + 'Function .onInit\n'+ + ' Nop\n'+ + 'FunctionEnd', + + 'Function .onInit\n'+ + ' Nop\n'+ + 'FunctionEnd' + ); + + run( + language, + + 'conditional', + + '!if 0 < 1\n'+ + ' MessageBox MB_OK "Always true"\n'+ + '!endif', + + '!if 0 < 1\n'+ + ' MessageBox MB_OK "Always true"\n'+ + '!endif' + ); + + run( + language, + + 'plugin', + + 'nsExec::Exec "calc.exe"', + + 'nsExec::Exec "calc.exe"' + ); + +}); From 6e6a7dc7b38aa353b712e51cbfff11ada04120de Mon Sep 17 00:00:00 2001 From: "Jan T. Sott" Date: Thu, 10 Dec 2015 02:29:53 +0100 Subject: [PATCH 4/4] add NSIS tests --- tests/rainbow.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/rainbow.html b/tests/rainbow.html index 2ac44d7d..afa17abb 100644 --- a/tests/rainbow.html +++ b/tests/rainbow.html @@ -23,6 +23,7 @@ + @@ -53,6 +54,7 @@ +