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

enh(nsis) Update variables pattern #3416

Merged
merged 4 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Grammars:
- enh(clojure) Add `regex` mode to regex literal
- fix(clojure) Remove inconsistent/broken highlighting for metadata
- enh(clojure) Add `punctuation` mode for commas.
- enh(nsis) Update variables pattern (#3416) [idleberg][]

Developer Tools:

Expand Down
31 changes: 25 additions & 6 deletions src/languages/nsis.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Website: https://nsis.sourceforge.io/Main_Page
import * as regex from '../lib/regex.js';

export default function(hljs) {
const regex = hljs.regex;
const LANGUAGE_CONSTANTS = [
"ADMINTOOLS",
"APPDATA",
Expand Down Expand Up @@ -159,7 +160,7 @@ export default function(hljs) {
const VARIABLES = {
// $variables
className: 'variable',
begin: /\$+\w+/,
begin: /\$+\w[\w\.]*/,
illegal: /\(\)\{\}/
};

Expand All @@ -184,9 +185,9 @@ export default function(hljs) {
)
};

const METACHARS = {
const ESCAPE_CHARS = {
// $\n, $\r, $\t, $$
className: 'meta',
className: 'char.escape',
begin: /\$(\\[nrt]|\$)/
};

Expand Down Expand Up @@ -214,7 +215,7 @@ export default function(hljs) {
],
illegal: /\n/,
contains: [
METACHARS,
ESCAPE_CHARS,
CONSTANTS,
DEFINES,
VARIABLES,
Expand Down Expand Up @@ -493,7 +494,7 @@ export default function(hljs) {
"zlib"
];

const FUNCTION_DEF = {
const FUNCTION_DEFINITION = {
match: [
/Function/,
/\s+/,
Expand All @@ -505,6 +506,23 @@ export default function(hljs) {
}
};

// Var Custom.Variable.Name.Item
// Var /GLOBAL Custom.Variable.Name.Item
const VARIABLE_NAME_RE = /[A-Za-z][\w.]*/;
const VARIABLE_DEFINITION = {
match: [
/Var/,
/\s+/,
/(?:\/GLOBAL\s+)?/,
VARIABLE_NAME_RE
],
scope: {
1: "keyword",
3: "params",
4: "variable"
}
};

return {
name: 'NSIS',
case_insensitive: true,
Expand All @@ -522,7 +540,8 @@ export default function(hljs) {
relevance: 0
}
),
FUNCTION_DEF,
VARIABLE_DEFINITION,
FUNCTION_DEFINITION,
{
beginKeywords: 'Function PageEx Section SectionGroup FunctionEnd SectionEnd',
},
Expand Down
4 changes: 2 additions & 2 deletions test/markup/nsis/default.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
<span class="hljs-comment">; Functions</span>
<span class="hljs-keyword">Function</span> <span class="hljs-title function_">.onInit</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-meta">$\n</span><span class="hljs-meta">$\r</span>line-break!&#x27;</span>
<span class="hljs-keyword">DetailPrint</span> <span class="hljs-string">`Escape the dollar-sign: <span class="hljs-meta">$$</span>`</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>
<span class="hljs-keyword">FunctionEnd</span>
7 changes: 7 additions & 0 deletions test/markup/nsis/variables.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<span class="hljs-keyword">Var</span> <span class="hljs-variable">CustomVariable</span>
<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-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>
7 changes: 7 additions & 0 deletions test/markup/nsis/variables.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Var CustomVariable
StrCpy $CustomVariable "Hello World"
MessageBox MB_OK "$$CustomVariable is: $CustomVariable"

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