nsis.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. /*
  2. Language: NSIS
  3. Description: Nullsoft Scriptable Install System
  4. Author: Jan T. Sott <jan.sott@gmail.com>
  5. Website: https://nsis.sourceforge.io/Main_Page
  6. Category: scripting
  7. */
  8. function nsis(hljs) {
  9. const regex = hljs.regex;
  10. const LANGUAGE_CONSTANTS = [
  11. "ADMINTOOLS",
  12. "APPDATA",
  13. "CDBURN_AREA",
  14. "CMDLINE",
  15. "COMMONFILES32",
  16. "COMMONFILES64",
  17. "COMMONFILES",
  18. "COOKIES",
  19. "DESKTOP",
  20. "DOCUMENTS",
  21. "EXEDIR",
  22. "EXEFILE",
  23. "EXEPATH",
  24. "FAVORITES",
  25. "FONTS",
  26. "HISTORY",
  27. "HWNDPARENT",
  28. "INSTDIR",
  29. "INTERNET_CACHE",
  30. "LANGUAGE",
  31. "LOCALAPPDATA",
  32. "MUSIC",
  33. "NETHOOD",
  34. "OUTDIR",
  35. "PICTURES",
  36. "PLUGINSDIR",
  37. "PRINTHOOD",
  38. "PROFILE",
  39. "PROGRAMFILES32",
  40. "PROGRAMFILES64",
  41. "PROGRAMFILES",
  42. "QUICKLAUNCH",
  43. "RECENT",
  44. "RESOURCES_LOCALIZED",
  45. "RESOURCES",
  46. "SENDTO",
  47. "SMPROGRAMS",
  48. "SMSTARTUP",
  49. "STARTMENU",
  50. "SYSDIR",
  51. "TEMP",
  52. "TEMPLATES",
  53. "VIDEOS",
  54. "WINDIR"
  55. ];
  56. const PARAM_NAMES = [
  57. "ARCHIVE",
  58. "FILE_ATTRIBUTE_ARCHIVE",
  59. "FILE_ATTRIBUTE_NORMAL",
  60. "FILE_ATTRIBUTE_OFFLINE",
  61. "FILE_ATTRIBUTE_READONLY",
  62. "FILE_ATTRIBUTE_SYSTEM",
  63. "FILE_ATTRIBUTE_TEMPORARY",
  64. "HKCR",
  65. "HKCU",
  66. "HKDD",
  67. "HKEY_CLASSES_ROOT",
  68. "HKEY_CURRENT_CONFIG",
  69. "HKEY_CURRENT_USER",
  70. "HKEY_DYN_DATA",
  71. "HKEY_LOCAL_MACHINE",
  72. "HKEY_PERFORMANCE_DATA",
  73. "HKEY_USERS",
  74. "HKLM",
  75. "HKPD",
  76. "HKU",
  77. "IDABORT",
  78. "IDCANCEL",
  79. "IDIGNORE",
  80. "IDNO",
  81. "IDOK",
  82. "IDRETRY",
  83. "IDYES",
  84. "MB_ABORTRETRYIGNORE",
  85. "MB_DEFBUTTON1",
  86. "MB_DEFBUTTON2",
  87. "MB_DEFBUTTON3",
  88. "MB_DEFBUTTON4",
  89. "MB_ICONEXCLAMATION",
  90. "MB_ICONINFORMATION",
  91. "MB_ICONQUESTION",
  92. "MB_ICONSTOP",
  93. "MB_OK",
  94. "MB_OKCANCEL",
  95. "MB_RETRYCANCEL",
  96. "MB_RIGHT",
  97. "MB_RTLREADING",
  98. "MB_SETFOREGROUND",
  99. "MB_TOPMOST",
  100. "MB_USERICON",
  101. "MB_YESNO",
  102. "NORMAL",
  103. "OFFLINE",
  104. "READONLY",
  105. "SHCTX",
  106. "SHELL_CONTEXT",
  107. "SYSTEM|TEMPORARY",
  108. ];
  109. const COMPILER_FLAGS = [
  110. "addincludedir",
  111. "addplugindir",
  112. "appendfile",
  113. "assert",
  114. "cd",
  115. "define",
  116. "delfile",
  117. "echo",
  118. "else",
  119. "endif",
  120. "error",
  121. "execute",
  122. "finalize",
  123. "getdllversion",
  124. "gettlbversion",
  125. "if",
  126. "ifdef",
  127. "ifmacrodef",
  128. "ifmacrondef",
  129. "ifndef",
  130. "include",
  131. "insertmacro",
  132. "macro",
  133. "macroend",
  134. "makensis",
  135. "packhdr",
  136. "searchparse",
  137. "searchreplace",
  138. "system",
  139. "tempfile",
  140. "undef",
  141. "uninstfinalize",
  142. "verbose",
  143. "warning",
  144. ];
  145. const CONSTANTS = {
  146. className: 'variable.constant',
  147. begin: regex.concat(/\$/, regex.either(...LANGUAGE_CONSTANTS))
  148. };
  149. const DEFINES = {
  150. // ${defines}
  151. className: 'variable',
  152. begin: /\$+\{[\!\w.:-]+\}/
  153. };
  154. const VARIABLES = {
  155. // $variables
  156. className: 'variable',
  157. begin: /\$+\w[\w\.]*/,
  158. illegal: /\(\)\{\}/
  159. };
  160. const LANGUAGES = {
  161. // $(language_strings)
  162. className: 'variable',
  163. begin: /\$+\([\w^.:!-]+\)/
  164. };
  165. const PARAMETERS = {
  166. // command parameters
  167. className: 'params',
  168. begin: regex.either(...PARAM_NAMES)
  169. };
  170. const COMPILER = {
  171. // !compiler_flags
  172. className: 'keyword',
  173. begin: regex.concat(
  174. /!/,
  175. regex.either(...COMPILER_FLAGS)
  176. )
  177. };
  178. const ESCAPE_CHARS = {
  179. // $\n, $\r, $\t, $$
  180. className: 'char.escape',
  181. begin: /\$(\\[nrt]|\$)/
  182. };
  183. const PLUGINS = {
  184. // plug::ins
  185. className: 'title.function',
  186. begin: /\w+::\w+/
  187. };
  188. const STRING = {
  189. className: 'string',
  190. variants: [
  191. {
  192. begin: '"',
  193. end: '"'
  194. },
  195. {
  196. begin: '\'',
  197. end: '\''
  198. },
  199. {
  200. begin: '`',
  201. end: '`'
  202. }
  203. ],
  204. illegal: /\n/,
  205. contains: [
  206. ESCAPE_CHARS,
  207. CONSTANTS,
  208. DEFINES,
  209. VARIABLES,
  210. LANGUAGES
  211. ]
  212. };
  213. const KEYWORDS = [
  214. "Abort",
  215. "AddBrandingImage",
  216. "AddSize",
  217. "AllowRootDirInstall",
  218. "AllowSkipFiles",
  219. "AutoCloseWindow",
  220. "BGFont",
  221. "BGGradient",
  222. "BrandingText",
  223. "BringToFront",
  224. "Call",
  225. "CallInstDLL",
  226. "Caption",
  227. "ChangeUI",
  228. "CheckBitmap",
  229. "ClearErrors",
  230. "CompletedText",
  231. "ComponentText",
  232. "CopyFiles",
  233. "CRCCheck",
  234. "CreateDirectory",
  235. "CreateFont",
  236. "CreateShortCut",
  237. "Delete",
  238. "DeleteINISec",
  239. "DeleteINIStr",
  240. "DeleteRegKey",
  241. "DeleteRegValue",
  242. "DetailPrint",
  243. "DetailsButtonText",
  244. "DirText",
  245. "DirVar",
  246. "DirVerify",
  247. "EnableWindow",
  248. "EnumRegKey",
  249. "EnumRegValue",
  250. "Exch",
  251. "Exec",
  252. "ExecShell",
  253. "ExecShellWait",
  254. "ExecWait",
  255. "ExpandEnvStrings",
  256. "File",
  257. "FileBufSize",
  258. "FileClose",
  259. "FileErrorText",
  260. "FileOpen",
  261. "FileRead",
  262. "FileReadByte",
  263. "FileReadUTF16LE",
  264. "FileReadWord",
  265. "FileWriteUTF16LE",
  266. "FileSeek",
  267. "FileWrite",
  268. "FileWriteByte",
  269. "FileWriteWord",
  270. "FindClose",
  271. "FindFirst",
  272. "FindNext",
  273. "FindWindow",
  274. "FlushINI",
  275. "GetCurInstType",
  276. "GetCurrentAddress",
  277. "GetDlgItem",
  278. "GetDLLVersion",
  279. "GetDLLVersionLocal",
  280. "GetErrorLevel",
  281. "GetFileTime",
  282. "GetFileTimeLocal",
  283. "GetFullPathName",
  284. "GetFunctionAddress",
  285. "GetInstDirError",
  286. "GetKnownFolderPath",
  287. "GetLabelAddress",
  288. "GetTempFileName",
  289. "GetWinVer",
  290. "Goto",
  291. "HideWindow",
  292. "Icon",
  293. "IfAbort",
  294. "IfErrors",
  295. "IfFileExists",
  296. "IfRebootFlag",
  297. "IfRtlLanguage",
  298. "IfShellVarContextAll",
  299. "IfSilent",
  300. "InitPluginsDir",
  301. "InstallButtonText",
  302. "InstallColors",
  303. "InstallDir",
  304. "InstallDirRegKey",
  305. "InstProgressFlags",
  306. "InstType",
  307. "InstTypeGetText",
  308. "InstTypeSetText",
  309. "Int64Cmp",
  310. "Int64CmpU",
  311. "Int64Fmt",
  312. "IntCmp",
  313. "IntCmpU",
  314. "IntFmt",
  315. "IntOp",
  316. "IntPtrCmp",
  317. "IntPtrCmpU",
  318. "IntPtrOp",
  319. "IsWindow",
  320. "LangString",
  321. "LicenseBkColor",
  322. "LicenseData",
  323. "LicenseForceSelection",
  324. "LicenseLangString",
  325. "LicenseText",
  326. "LoadAndSetImage",
  327. "LoadLanguageFile",
  328. "LockWindow",
  329. "LogSet",
  330. "LogText",
  331. "ManifestDPIAware",
  332. "ManifestLongPathAware",
  333. "ManifestMaxVersionTested",
  334. "ManifestSupportedOS",
  335. "MessageBox",
  336. "MiscButtonText",
  337. "Name|0",
  338. "Nop",
  339. "OutFile",
  340. "Page",
  341. "PageCallbacks",
  342. "PEAddResource",
  343. "PEDllCharacteristics",
  344. "PERemoveResource",
  345. "PESubsysVer",
  346. "Pop",
  347. "Push",
  348. "Quit",
  349. "ReadEnvStr",
  350. "ReadINIStr",
  351. "ReadRegDWORD",
  352. "ReadRegStr",
  353. "Reboot",
  354. "RegDLL",
  355. "Rename",
  356. "RequestExecutionLevel",
  357. "ReserveFile",
  358. "Return",
  359. "RMDir",
  360. "SearchPath",
  361. "SectionGetFlags",
  362. "SectionGetInstTypes",
  363. "SectionGetSize",
  364. "SectionGetText",
  365. "SectionIn",
  366. "SectionSetFlags",
  367. "SectionSetInstTypes",
  368. "SectionSetSize",
  369. "SectionSetText",
  370. "SendMessage",
  371. "SetAutoClose",
  372. "SetBrandingImage",
  373. "SetCompress",
  374. "SetCompressor",
  375. "SetCompressorDictSize",
  376. "SetCtlColors",
  377. "SetCurInstType",
  378. "SetDatablockOptimize",
  379. "SetDateSave",
  380. "SetDetailsPrint",
  381. "SetDetailsView",
  382. "SetErrorLevel",
  383. "SetErrors",
  384. "SetFileAttributes",
  385. "SetFont",
  386. "SetOutPath",
  387. "SetOverwrite",
  388. "SetRebootFlag",
  389. "SetRegView",
  390. "SetShellVarContext",
  391. "SetSilent",
  392. "ShowInstDetails",
  393. "ShowUninstDetails",
  394. "ShowWindow",
  395. "SilentInstall",
  396. "SilentUnInstall",
  397. "Sleep",
  398. "SpaceTexts",
  399. "StrCmp",
  400. "StrCmpS",
  401. "StrCpy",
  402. "StrLen",
  403. "SubCaption",
  404. "Unicode",
  405. "UninstallButtonText",
  406. "UninstallCaption",
  407. "UninstallIcon",
  408. "UninstallSubCaption",
  409. "UninstallText",
  410. "UninstPage",
  411. "UnRegDLL",
  412. "Var",
  413. "VIAddVersionKey",
  414. "VIFileVersion",
  415. "VIProductVersion",
  416. "WindowIcon",
  417. "WriteINIStr",
  418. "WriteRegBin",
  419. "WriteRegDWORD",
  420. "WriteRegExpandStr",
  421. "WriteRegMultiStr",
  422. "WriteRegNone",
  423. "WriteRegStr",
  424. "WriteUninstaller",
  425. "XPStyle"
  426. ];
  427. const LITERALS = [
  428. "admin",
  429. "all",
  430. "auto",
  431. "both",
  432. "bottom",
  433. "bzip2",
  434. "colored",
  435. "components",
  436. "current",
  437. "custom",
  438. "directory",
  439. "false",
  440. "force",
  441. "hide",
  442. "highest",
  443. "ifdiff",
  444. "ifnewer",
  445. "instfiles",
  446. "lastused",
  447. "leave",
  448. "left",
  449. "license",
  450. "listonly",
  451. "lzma",
  452. "nevershow",
  453. "none",
  454. "normal",
  455. "notset",
  456. "off",
  457. "on",
  458. "open",
  459. "print",
  460. "right",
  461. "show",
  462. "silent",
  463. "silentlog",
  464. "smooth",
  465. "textonly",
  466. "top",
  467. "true",
  468. "try",
  469. "un.components",
  470. "un.custom",
  471. "un.directory",
  472. "un.instfiles",
  473. "un.license",
  474. "uninstConfirm",
  475. "user",
  476. "Win10",
  477. "Win7",
  478. "Win8",
  479. "WinVista",
  480. "zlib"
  481. ];
  482. const FUNCTION_DEFINITION = {
  483. match: [
  484. /Function/,
  485. /\s+/,
  486. regex.concat(/(\.)?/, hljs.IDENT_RE)
  487. ],
  488. scope: {
  489. 1: "keyword",
  490. 3: "title.function"
  491. }
  492. };
  493. // Var Custom.Variable.Name.Item
  494. // Var /GLOBAL Custom.Variable.Name.Item
  495. const VARIABLE_NAME_RE = /[A-Za-z][\w.]*/;
  496. const VARIABLE_DEFINITION = {
  497. match: [
  498. /Var/,
  499. /\s+/,
  500. /(?:\/GLOBAL\s+)?/,
  501. VARIABLE_NAME_RE
  502. ],
  503. scope: {
  504. 1: "keyword",
  505. 3: "params",
  506. 4: "variable"
  507. }
  508. };
  509. return {
  510. name: 'NSIS',
  511. case_insensitive: true,
  512. keywords: {
  513. keyword: KEYWORDS,
  514. literal: LITERALS
  515. },
  516. contains: [
  517. hljs.HASH_COMMENT_MODE,
  518. hljs.C_BLOCK_COMMENT_MODE,
  519. hljs.COMMENT(
  520. ';',
  521. '$',
  522. { relevance: 0 }
  523. ),
  524. VARIABLE_DEFINITION,
  525. FUNCTION_DEFINITION,
  526. { beginKeywords: 'Function PageEx Section SectionGroup FunctionEnd SectionEnd', },
  527. STRING,
  528. COMPILER,
  529. DEFINES,
  530. VARIABLES,
  531. LANGUAGES,
  532. PARAMETERS,
  533. PLUGINS,
  534. hljs.NUMBER_MODE
  535. ]
  536. };
  537. }
  538. export { nsis as default };