Skip to content
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Core Grammars:
- enh(nix) support markdown comments [h7x4][]
- enh(nix) support basic function params [h7x4][]
- enh(nix) better parsing of attrsets [h7x4][]
- enh(nsis) add missing language features [idleberg][]
- enh(nsis) add test cases [idleberg][]
- fix(nsis) prevent overlapping keywords to conflict [idleberg][]
- fix(c) - Fixed hex numbers with decimals [Dxuian]
- fix(typescript) - Fixedoptional property not highlighted correctly [Dxuian]
- fix(ruby) - fix `|=` operator false positives (as block arguments) [Aboobacker MK]
Expand Down
55 changes: 44 additions & 11 deletions src/languages/nsis.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Website: https://nsis.sourceforge.io/Main_Page
Category: scripting
*/

import * as regex from '../lib/regex.js';

export default function(hljs) {
const regex = hljs.regex;
const LANGUAGE_CONSTANTS = [
Expand Down Expand Up @@ -65,8 +63,13 @@ export default function(hljs) {
"FILE_ATTRIBUTE_READONLY",
"FILE_ATTRIBUTE_SYSTEM",
"FILE_ATTRIBUTE_TEMPORARY",
"HKCC",
"HKCR",
"HKCR32",
"HKCR64",
"HKCU",
"HKCU32",
"HKCU64",
"HKDD",
"HKEY_CLASSES_ROOT",
"HKEY_CURRENT_CONFIG",
Expand All @@ -76,6 +79,8 @@ export default function(hljs) {
"HKEY_PERFORMANCE_DATA",
"HKEY_USERS",
"HKLM",
"HKLM32",
"HKLM64",
"HKPD",
"HKU",
"IDABORT",
Expand Down Expand Up @@ -103,41 +108,53 @@ export default function(hljs) {
"MB_TOPMOST",
"MB_USERICON",
"MB_YESNO",
"NORMAL",
"MB_YESNOCANCEL",
"OFFLINE",
"READONLY",
"SHCTX",
"SHELL_CONTEXT",
"SYSTEM|TEMPORARY",
"SW_HIDE",
"SW_SHOW",
"SW_SHOWMAXIMIZED",
"SW_SHOWMINIMIZED",
"SW_SHOWNORMAL",
];

const COMPILER_FLAGS = [
"addincludedir",
"addplugindir",
"appendfile",
"appendmemfile",
"assert",
"cd",
"define",
"delfile",
"echo",
"elseifmacrodef",
"elseifmacrondef",
"elseifdef",
"elseifndef",
"elseif",
"else",
"endif",
"error",
"execute",
"finalize",
"getdllversion",
"gettlbversion",
"if",
"ifdef",
"ifmacrodef",
"ifmacrondef",
"ifdef",
"ifndef",
"if",
"include",
"insertmacro",
"macro",
"macroend",
"macroundef",
"macro",
"makensis",
"packhdr",
"pragma",
"searchparse",
"searchreplace",
"system",
Expand Down Expand Up @@ -175,15 +192,19 @@ export default function(hljs) {
const PARAMETERS = {
// command parameters
className: 'params',
begin: regex.either(...PARAM_NAMES)
begin: regex.concat(
regex.either(...PARAM_NAMES),
/\b/
)
};

const COMPILER = {
// !compiler_flags
className: 'keyword',
begin: regex.concat(
/!/,
regex.either(...COMPILER_FLAGS)
regex.either(...COMPILER_FLAGS),
/\b/
)
};

Expand Down Expand Up @@ -245,6 +266,7 @@ export default function(hljs) {
"CompletedText",
"ComponentText",
"CopyFiles",
"CPU",
"CRCCheck",
"CreateDirectory",
"CreateFont",
Expand Down Expand Up @@ -300,12 +322,15 @@ export default function(hljs) {
"GetInstDirError",
"GetKnownFolderPath",
"GetLabelAddress",
"GetRegView",
"GetShellVarContext",
"GetTempFileName",
"GetWinVer",
"Goto",
"HideWindow",
"Icon",
"IfAbort",
"IfAltRegView",
"IfErrors",
"IfFileExists",
"IfRebootFlag",
Expand Down Expand Up @@ -343,7 +368,11 @@ export default function(hljs) {
"LockWindow",
"LogSet",
"LogText",
"ManifestAppendCustomString",
"ManifestDisableWindowFiltering",
"ManifestDPIAware",
"ManifestDPIAwareness",
"ManifestGdiScaling",
"ManifestLongPathAware",
"ManifestMaxVersionTested",
"ManifestSupportedOS",
Expand All @@ -363,6 +392,7 @@ export default function(hljs) {
"Quit",
"ReadEnvStr",
"ReadINIStr",
"ReadMemory",
"ReadRegDWORD",
"ReadRegStr",
"Reboot",
Expand All @@ -388,6 +418,7 @@ export default function(hljs) {
"SetCompress",
"SetCompressor",
"SetCompressorDictSize",
"SetCompressionLevel",
"SetCtlColors",
"SetCurInstType",
"SetDatablockOptimize",
Expand Down Expand Up @@ -416,7 +447,9 @@ export default function(hljs) {
"StrCpy",
"StrLen",
"SubCaption",
"Target",
"Unicode",
"UnsafeStrCpy",
"UninstallButtonText",
"UninstallCaption",
"UninstallIcon",
Expand Down Expand Up @@ -542,15 +575,15 @@ export default function(hljs) {
),
VARIABLE_DEFINITION,
FUNCTION_DEFINITION,
{ beginKeywords: 'Function PageEx Section SectionGroup FunctionEnd SectionEnd', },
{ beginKeywords: 'Function PageEx Section SectionGroup FunctionEnd PageExEnd SectionEnd SectionGroupEnd', },
STRING,
COMPILER,
DEFINES,
VARIABLES,
LANGUAGES,
PARAMETERS,
PLUGINS,
hljs.NUMBER_MODE
hljs.C_NUMBER_MODE
]
};
}
41 changes: 32 additions & 9 deletions test/markup/nsis/default.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,59 @@
for highlight.js
*/</span>

<span class="hljs-comment">; Semicolon comment</span>
<span class="hljs-comment"># Hash comment</span>

<span class="hljs-keyword">!assert</span> <span class="hljs-variable">${NSIS_CHAR_SIZE}</span> = <span class="hljs-number">2</span> <span class="hljs-string">&quot;Unicode required&quot;</span>

<span class="hljs-comment">; Includes</span>
<span class="hljs-keyword">!include</span> MUI2.nsh

<span class="hljs-comment">; Defines</span>
<span class="hljs-keyword">!define</span> x64 <span class="hljs-string">&quot;true&quot;</span>

<span class="hljs-comment">; Settings</span>
<span class="hljs-keyword">Name</span> <span class="hljs-string">&quot;installer_name&quot;</span>
<span class="hljs-keyword">OutFile</span> <span class="hljs-string">&quot;installer_name.exe&quot;</span>
<span class="hljs-keyword">RequestExecutionLevel</span> <span class="hljs-literal">user</span>
<span class="hljs-keyword">CRCCheck</span> <span class="hljs-literal">on</span>

<span class="hljs-keyword">!if</span>def <span class="hljs-variable">${x64}</span>
<span class="hljs-keyword">!ifdef</span> <span class="hljs-variable">${x64}</span>
<span class="hljs-keyword">InstallDir</span> <span class="hljs-string">&quot;<span class="hljs-variable constant_">$PROGRAMFILES64</span>\installer_name&quot;</span>
<span class="hljs-keyword">!else</span>
<span class="hljs-keyword">InstallDir</span> <span class="hljs-string">&quot;<span class="hljs-variable constant_">$PROGRAMFILES</span>\installer_name&quot;</span>
<span class="hljs-keyword">!endif</span>

<span class="hljs-comment">; Pages</span>
<span class="hljs-keyword">!insertmacro</span> MUI_PAGE_INSTFILES
<span class="hljs-comment">; Prefix collisions: !if/!ifdef, !else/!elseif/!elseifdef</span>
<span class="hljs-keyword">!if</span> <span class="hljs-number">1</span> &lt; <span class="hljs-number">2</span>
<span class="hljs-keyword">!elseif</span> <span class="hljs-number">1</span> == <span class="hljs-number">1</span>
<span class="hljs-keyword">!elseifdef</span> MISSING
<span class="hljs-keyword">!endif</span>

<span class="hljs-comment">; Prefix collisions: !macro/!macroend/!macroundef</span>
<span class="hljs-keyword">!macro</span> MyMacro param1
<span class="hljs-keyword">DetailPrint</span> <span class="hljs-string">&quot;<span class="hljs-variable">${param1}</span>&quot;</span>
<span class="hljs-keyword">!macroend</span>
<span class="hljs-keyword">!insertmacro</span> MyMacro <span class="hljs-string">&quot;hello&quot;</span>

<span class="hljs-comment">; Prefix collisions: HKLM/HKLM64, HKCR/HKCR32</span>
<span class="hljs-keyword">WriteRegStr</span> <span class="hljs-params">HKLM</span> <span class="hljs-string">&quot;Software\Test&quot;</span> <span class="hljs-string">&quot;Key&quot;</span> <span class="hljs-string">&quot;Value&quot;</span>
<span class="hljs-keyword">ReadRegStr</span> <span class="hljs-variable">$0</span> <span class="hljs-params">HKLM64</span> <span class="hljs-string">&quot;Software\Test&quot;</span> <span class="hljs-string">&quot;Key&quot;</span>
<span class="hljs-keyword">DeleteRegKey</span> <span class="hljs-params">HKCR32</span> <span class="hljs-string">&quot;Software\Test&quot;</span>

<span class="hljs-comment">; Sections</span>
<span class="hljs-comment">; Prefix collisions: Section/SectionIn, File/FileOpen/FileClose, Exec/ExecWait</span>
<span class="hljs-keyword">Section</span> <span class="hljs-string">&quot;section_name&quot;</span> section_index
<span class="hljs-keyword">SectionIn</span> <span class="hljs-number">1</span> <span class="hljs-number">2</span>
<span class="hljs-keyword">File</span> /r <span class="hljs-string">&quot;data\*.*&quot;</span>
<span class="hljs-keyword">FileOpen</span> <span class="hljs-variable">$0</span> <span class="hljs-string">&quot;<span class="hljs-variable constant_">$INSTDIR</span>\file.txt&quot;</span> w
<span class="hljs-keyword">FileClose</span> <span class="hljs-variable">$0</span>
<span class="hljs-keyword">ExecWait</span> <span class="hljs-string">&#x27;&quot;setup.exe&quot;&#x27;</span> <span class="hljs-variable">$0</span>
<span class="hljs-title function_">nsExec::ExecToLog</span> <span class="hljs-string">&quot;calc.exe&quot;</span>
<span class="hljs-keyword">IntOp</span> <span class="hljs-variable">$0</span> <span class="hljs-number">255</span> + <span class="hljs-number">0xFF</span>
<span class="hljs-keyword">SectionEnd</span>

<span class="hljs-comment">; Functions</span>
<span class="hljs-comment">; Prefix collisions: MB_OK/MB_OKCANCEL, MB_YESNO/MB_YESNOCANCEL, SW_SHOW/SW_SHOWNORMAL</span>
<span class="hljs-keyword">Function</span> <span class="hljs-title function_">.onInit</span>
<span class="hljs-keyword">MessageBox</span> <span class="hljs-params">MB_OKCANCEL</span> <span class="hljs-string">&quot;Confirm?&quot;</span>
<span class="hljs-keyword">MessageBox</span> <span class="hljs-params">MB_YESNO</span>|<span class="hljs-params">MB_ICONQUESTION</span> <span class="hljs-string">&quot;Question?&quot;</span> <span class="hljs-params">IDYES</span> +<span class="hljs-number">1</span> <span class="hljs-params">IDNO</span> +<span class="hljs-number">2</span>
<span class="hljs-keyword">MessageBox</span> <span class="hljs-params">MB_YESNOCANCEL</span>|<span class="hljs-params">MB_ICONINFORMATION</span> <span class="hljs-string">&quot;Info&quot;</span>
<span class="hljs-keyword">CreateShortCut</span> <span class="hljs-string">&quot;<span class="hljs-variable constant_">$DESKTOP</span>\test.lnk&quot;</span> <span class="hljs-string">&quot;<span class="hljs-variable constant_">$INSTDIR</span>\test.exe&quot;</span> <span class="hljs-string">&quot;&quot;</span> <span class="hljs-string">&quot;&quot;</span> <span class="hljs-number">0</span> <span class="hljs-params">SW_SHOWNORMAL</span>
<span class="hljs-keyword">DetailPrint</span> <span class="hljs-string">&quot;The install button reads <span class="hljs-variable">$(^InstallBtn)</span>&quot;</span>
<span class="hljs-keyword">DetailPrint</span> <span class="hljs-string">&#x27;Here comes a<span class="hljs-char escape_">$\n</span><span class="hljs-char escape_">$\r</span>line-break!&#x27;</span>
<span class="hljs-keyword">DetailPrint</span> <span class="hljs-string">`Escape the dollar-sign: <span class="hljs-char escape_">$$</span>`</span>
Expand Down
39 changes: 31 additions & 8 deletions test/markup/nsis/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
for highlight.js
*/

; Semicolon comment
# Hash comment

!assert ${NSIS_CHAR_SIZE} = 2 "Unicode required"

; Includes
!include MUI2.nsh

; Defines
!define x64 "true"

; Settings
Name "installer_name"
OutFile "installer_name.exe"
RequestExecutionLevel user
Expand All @@ -23,16 +22,40 @@ CRCCheck on
InstallDir "$PROGRAMFILES\installer_name"
!endif

; Pages
!insertmacro MUI_PAGE_INSTFILES
; Prefix collisions: !if/!ifdef, !else/!elseif/!elseifdef
!if 1 < 2
!elseif 1 == 1
!elseifdef MISSING
!endif

; Prefix collisions: !macro/!macroend/!macroundef
!macro MyMacro param1
DetailPrint "${param1}"
!macroend
!insertmacro MyMacro "hello"

; Prefix collisions: HKLM/HKLM64, HKCR/HKCR32
WriteRegStr HKLM "Software\Test" "Key" "Value"
ReadRegStr $0 HKLM64 "Software\Test" "Key"
DeleteRegKey HKCR32 "Software\Test"

; Sections
; Prefix collisions: Section/SectionIn, File/FileOpen/FileClose, Exec/ExecWait
Section "section_name" section_index
SectionIn 1 2
File /r "data\*.*"
FileOpen $0 "$INSTDIR\file.txt" w
FileClose $0
ExecWait '"setup.exe"' $0
nsExec::ExecToLog "calc.exe"
IntOp $0 255 + 0xFF
SectionEnd

; Functions
; Prefix collisions: MB_OK/MB_OKCANCEL, MB_YESNO/MB_YESNOCANCEL, SW_SHOW/SW_SHOWNORMAL
Function .onInit
MessageBox MB_OKCANCEL "Confirm?"
MessageBox MB_YESNO|MB_ICONQUESTION "Question?" IDYES +1 IDNO +2
MessageBox MB_YESNOCANCEL|MB_ICONINFORMATION "Info"
CreateShortCut "$DESKTOP\test.lnk" "$INSTDIR\test.exe" "" "" 0 SW_SHOWNORMAL
DetailPrint "The install button reads $(^InstallBtn)"
DetailPrint 'Here comes a$\n$\rline-break!'
DetailPrint `Escape the dollar-sign: $$`
Expand Down
3 changes: 3 additions & 0 deletions test/markup/nsis/variables.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<span class="hljs-keyword">StrCpy</span> <span class="hljs-variable">$CustomVariable</span> <span class="hljs-string">&quot;Hello World&quot;</span>
<span class="hljs-keyword">MessageBox</span> <span class="hljs-params">MB_OK</span> <span class="hljs-string">&quot;<span class="hljs-char escape_">$$</span>CustomVariable is: <span class="hljs-variable">$CustomVariable</span>&quot;</span>

<span class="hljs-keyword">Var</span> <span class="hljs-params">/GLOBAL </span><span class="hljs-variable">GlobalVar</span>
<span class="hljs-keyword">StrCpy</span> <span class="hljs-variable">$GlobalVar</span> <span class="hljs-string">&quot;Hello World&quot;</span>

<span class="hljs-keyword">Var</span> <span class="hljs-variable">Variable.With.Dots</span>
<span class="hljs-keyword">StrCpy</span> <span class="hljs-variable">$Variable.With.Dots</span> <span class="hljs-string">&quot;Hello World&quot;</span>
<span class="hljs-keyword">MessageBox</span> <span class="hljs-params">MB_OK</span> <span class="hljs-string">&quot;<span class="hljs-char escape_">$$</span>Variable.With.Dots is: <span class="hljs-variable">$Variable.With.Dots</span>&quot;</span>
3 changes: 3 additions & 0 deletions test/markup/nsis/variables.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ Var CustomVariable
StrCpy $CustomVariable "Hello World"
MessageBox MB_OK "$$CustomVariable is: $CustomVariable"

Var /GLOBAL GlobalVar
StrCpy $GlobalVar "Hello World"

Var Variable.With.Dots
StrCpy $Variable.With.Dots "Hello World"
MessageBox MB_OK "$$Variable.With.Dots is: $Variable.With.Dots"
Loading