Skip to content

Commit 4a73506

Browse files
committed
enh(nsis) Var mode, supports /GLOBAL param also
1 parent b6bfd7e commit 4a73506

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/languages/nsis.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Website: https://nsis.sourceforge.io/Main_Page
88
import * as regex from '../lib/regex.js';
99

1010
export default function(hljs) {
11+
const regex = hljs.regex;
1112
const LANGUAGE_CONSTANTS = [
1213
"ADMINTOOLS",
1314
"APPDATA",
@@ -493,7 +494,7 @@ export default function(hljs) {
493494
"zlib"
494495
];
495496

496-
const FUNCTION_DEF = {
497+
const FUNCTION_DEFINITION = {
497498
match: [
498499
/Function/,
499500
/\s+/,
@@ -505,6 +506,21 @@ export default function(hljs) {
505506
}
506507
};
507508

509+
const VARIABLE_NAME_RE = regex.concat(hljs.IDENT_RE, "(\.", hljs.IDENT_RE, ")*");
510+
const VARIABLE_DEFINITION = {
511+
match: [
512+
/Var/,
513+
/\s+/,
514+
/(?:\/GLOBAL\s+)?/,
515+
VARIABLE_NAME_RE
516+
],
517+
scope: {
518+
1: "keyword",
519+
3: "params",
520+
4: "variable"
521+
}
522+
};
523+
508524
return {
509525
name: 'NSIS',
510526
case_insensitive: true,
@@ -522,7 +538,8 @@ export default function(hljs) {
522538
relevance: 0
523539
}
524540
),
525-
FUNCTION_DEF,
541+
VARIABLE_DEFINITION,
542+
FUNCTION_DEFINITION,
526543
{
527544
beginKeywords: 'Function PageEx Section SectionGroup FunctionEnd SectionEnd',
528545
},

test/markup/nsis/default.expect.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
<span class="hljs-comment">; Functions</span>
3333
<span class="hljs-keyword">Function</span> <span class="hljs-title function_">.onInit</span>
3434
<span class="hljs-keyword">DetailPrint</span> <span class="hljs-string">&quot;The install button reads <span class="hljs-variable">$(^InstallBtn)</span>&quot;</span>
35-
<span class="hljs-keyword">DetailPrint</span> <span class="hljs-string">&#x27;Here comes a<span class="hljs-meta">$\n</span><span class="hljs-meta">$\r</span>line-break!&#x27;</span>
36-
<span class="hljs-keyword">DetailPrint</span> <span class="hljs-string">`Escape the dollar-sign: <span class="hljs-meta">$$</span>`</span>
35+
<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>
36+
<span class="hljs-keyword">DetailPrint</span> <span class="hljs-string">`Escape the dollar-sign: <span class="hljs-char escape_">$$</span>`</span>
3737
<span class="hljs-keyword">FunctionEnd</span>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<span class="hljs-keyword">Var</span> CustomVariable
1+
<span class="hljs-keyword">Var</span> <span class="hljs-variable">CustomVariable</span>
22
<span class="hljs-keyword">StrCpy</span> <span class="hljs-variable">$CustomVariable</span> <span class="hljs-string">&quot;Hello World&quot;</span>
3-
<span class="hljs-keyword">MessageBox</span> <span class="hljs-params">MB_OK</span> <span class="hljs-string">&quot;<span class="hljs-meta">$$</span>CustomVariable is: <span class="hljs-variable">$CustomVariable</span>&quot;</span>
3+
<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>
44

5-
<span class="hljs-keyword">Var</span> Variable.With.Dots
5+
<span class="hljs-keyword">Var</span> <span class="hljs-variable">Variable.With.Dots</span>
66
<span class="hljs-keyword">StrCpy</span> <span class="hljs-variable">$Variable.With.Dots</span> <span class="hljs-string">&quot;Hello World&quot;</span>
7-
<span class="hljs-keyword">MessageBox</span> <span class="hljs-params">MB_OK</span> <span class="hljs-string">&quot;<span class="hljs-meta">$$</span>Variable.With.Dots is: <span class="hljs-variable">$Variable.With.Dots</span>&quot;</span>
7+
<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>

0 commit comments

Comments
 (0)