nsis.js 9.8 KB

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