Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add NSIS support #188

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions demos/nsis.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Syntax Highlighting</title>
<link href="../themes/blackboard.css" rel="stylesheet" type="text/css" media="screen">
<body>
<style type="text/css">
</style>
<pre>
<code data-language="nsis">/*
* 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</code>
</pre>

<script src="../js/rainbow.js"></script>
<script src="../js/language/generic.js"></script>
<script src="../js/language/nsis.js"></script>

</body>
84 changes: 84 additions & 0 deletions js/language/nsis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* NSIS patterns
*
* @author Jan T. Sott
* @version 1.0.0
*/
Rainbow.extend('nsis', [

{
'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': /\!(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': /(\!)(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);
128 changes: 128 additions & 0 deletions tests/language/test.nsis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/* global describe, run */
var language = 'nsis';

describe(language, function() {
run(
language,

'comment line 1',

'; this is a comment',

'<span class="comment line">; this is a comment</span>'
);
run(
language,

'comment line 2',

'# this is a comment',

'<span class="comment line"># this is a comment</span>'
);

run(
language,

'comment block',

'/*\n' +
'NSIS v3.0a\n' +
'Released under the zlib/png license\n' +
'*/',

'<span class="comment block">/*\n' +
'NSIS v3.0a\n' +
'Released under the zlib/png license\n' +
'*/</span>'
);

run(
language,

'include',

'!include LogicLib.nsh',

'<span class="support compiler">!include</span> LogicLib.nsh'
);

run(
language,

'string',

'"this is a string"',

'<span class="string"><span class="string open">"</span>this is a string<span class="string close">"</span></span>'
);

run(
language,

'language constant',

'LangString DESC_SECTION_INDEX ${LANG_ENGLISH} "this is a string"',

'<span class="keyword command">LangString</span> DESC_SECTION_INDEX <span class="variable definition">${LANG_ENGLISH}</span> <span class="string"><span class="string open">"</span>this is a string<span class="string close">"</span></span>'
);

run(
language,

'variable assignment',

'StrCpy $0 "this is a string"',

'<span class="keyword command">StrCpy</span> <span class="variable dollar-sign">$</span><span class="variable">0</span> <span class="string"><span class="string open">"</span>this is a string<span class="string close">"</span></span>'
);

run(
language,

'operator math',

'IntOp $0 1 + 1',

'<span class="keyword command">IntOp</span> <span class="variable dollar-sign">$</span><span class="variable">0</span> <span class="constant numeric">1</span> + <span class="constant numeric">1</span>'
);

run(
language,

'function',

'Function .onInit\n'+
' Nop\n'+
'FunctionEnd',

'<span class="entity command block">Function</span> .onInit\n'+
' <span class="keyword command">Nop</span>\n'+
'<span class="entity command block">FunctionEnd</span>'
);

run(
language,

'conditional',

'!if 0 < 1\n'+
' MessageBox MB_OK "Always true"\n'+
'!endif',

'<span class="entity compiler block">!if</span> <span class="constant numeric">0</span> <span class="keyword operator">&lt;</span> <span class="constant numeric">1</span>\n'+
' <span class="keyword command">MessageBox</span> <span class="constant option">MB_OK</span> <span class="string"><span class="string open">"</span>Always true<span class="string close">"</span></span>\n'+
'<span class="entity compiler block">!endif</span>'
);

run(
language,

'plugin',

'nsExec::Exec "calc.exe"',

'<span class="keyword plugin">nsExec::Exec</span> <span class="string"><span class="string open">"</span>calc.exe<span class="string close">"</span></span>'
);

});
2 changes: 2 additions & 0 deletions tests/rainbow.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<script src="../js/language/html.js"></script>
<script src="../js/language/java.js"></script>
<script src="../js/language/javascript.js"></script>
<script src="../js/language/nsis.js"></script>
<script src="../js/language/php.js"></script>
<script src="../js/language/python.js"></script>
<script src="../js/language/r.js"></script>
Expand Down Expand Up @@ -53,6 +54,7 @@
<script src="language/test.html.js"></script>
<script src="language/test.java.js"></script>
<script src="language/test.javascript.js"></script>
<script src="language/test.nsis.js"></script>
<script src="language/test.php.js"></script>
<script src="language/test.python.js"></script>
<script src="language/test.r.js"></script>
Expand Down