installers.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. """
  2. pygments.lexers.installers
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexers for installer/packager DSLs and formats.
  5. :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. import re
  9. from pygments.lexer import RegexLexer, include, bygroups, using, this, default
  10. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  11. Punctuation, Generic, Number, Whitespace
  12. __all__ = ['NSISLexer', 'RPMSpecLexer',
  13. 'DebianSourcesLexer', 'SourcesListLexer',
  14. 'DebianControlLexer']
  15. class NSISLexer(RegexLexer):
  16. """
  17. For NSIS scripts.
  18. """
  19. name = 'NSIS'
  20. url = 'http://nsis.sourceforge.net/'
  21. aliases = ['nsis', 'nsi', 'nsh']
  22. filenames = ['*.nsi', '*.nsh']
  23. mimetypes = ['text/x-nsis']
  24. version_added = '1.6'
  25. flags = re.IGNORECASE
  26. tokens = {
  27. 'root': [
  28. (r'([;#].*)(\n)', bygroups(Comment, Whitespace)),
  29. (r"'.*?'", String.Single),
  30. (r'"', String.Double, 'str_double'),
  31. (r'`', String.Backtick, 'str_backtick'),
  32. include('macro'),
  33. include('interpol'),
  34. include('basic'),
  35. (r'\$\{[a-z_|][\w|]*\}', Keyword.Pseudo),
  36. (r'/[a-z_]\w*', Name.Attribute),
  37. (r'\s+', Whitespace),
  38. (r'[\w.]+', Text),
  39. ],
  40. 'basic': [
  41. (r'(\n)(Function)(\s+)([._a-z][.\w]*)\b',
  42. bygroups(Whitespace, Keyword, Whitespace, Name.Function)),
  43. (r'\b([_a-z]\w*)(::)([a-z][a-z0-9]*)\b',
  44. bygroups(Keyword.Namespace, Punctuation, Name.Function)),
  45. (r'\b([_a-z]\w*)(:)', bygroups(Name.Label, Punctuation)),
  46. (r'(\b[ULS]|\B)([!<>=]?=|\<\>?|\>)\B', Operator),
  47. (r'[|+-]', Operator),
  48. (r'\\', Punctuation),
  49. (r'\b(Abort|Add(?:BrandingImage|Size)|'
  50. r'Allow(?:RootDirInstall|SkipFiles)|AutoCloseWindow|'
  51. r'BG(?:Font|Gradient)|BrandingText|BringToFront|Call(?:InstDLL)?|'
  52. r'(?:Sub)?Caption|ChangeUI|CheckBitmap|ClearErrors|CompletedText|'
  53. r'ComponentText|CopyFiles|CRCCheck|'
  54. r'Create(?:Directory|Font|Shortcut)|Delete(?:INI(?:Sec|Str)|'
  55. r'Reg(?:Key|Value))?|DetailPrint|DetailsButtonText|'
  56. r'Dir(?:Show|Text|Var|Verify)|(?:Disabled|Enabled)Bitmap|'
  57. r'EnableWindow|EnumReg(?:Key|Value)|Exch|Exec(?:Shell|Wait)?|'
  58. r'ExpandEnvStrings|File(?:BufSize|Close|ErrorText|Open|'
  59. r'Read(?:Byte)?|Seek|Write(?:Byte)?)?|'
  60. r'Find(?:Close|First|Next|Window)|FlushINI|Function(?:End)?|'
  61. r'Get(?:CurInstType|CurrentAddress|DlgItem|DLLVersion(?:Local)?|'
  62. r'ErrorLevel|FileTime(?:Local)?|FullPathName|FunctionAddress|'
  63. r'InstDirError|LabelAddress|TempFileName)|'
  64. r'Goto|HideWindow|Icon|'
  65. r'If(?:Abort|Errors|FileExists|RebootFlag|Silent)|'
  66. r'InitPluginsDir|Install(?:ButtonText|Colors|Dir(?:RegKey)?)|'
  67. r'Inst(?:ProgressFlags|Type(?:[GS]etText)?)|Int(?:CmpU?|Fmt|Op)|'
  68. r'IsWindow|LangString(?:UP)?|'
  69. r'License(?:BkColor|Data|ForceSelection|LangString|Text)|'
  70. r'LoadLanguageFile|LockWindow|Log(?:Set|Text)|MessageBox|'
  71. r'MiscButtonText|Name|Nop|OutFile|(?:Uninst)?Page(?:Ex(?:End)?)?|'
  72. r'PluginDir|Pop|Push|Quit|Read(?:(?:Env|INI|Reg)Str|RegDWORD)|'
  73. r'Reboot|(?:Un)?RegDLL|Rename|RequestExecutionLevel|ReserveFile|'
  74. r'Return|RMDir|SearchPath|Section(?:Divider|End|'
  75. r'(?:(?:Get|Set)(?:Flags|InstTypes|Size|Text))|Group(?:End)?|In)?|'
  76. r'SendMessage|Set(?:AutoClose|BrandingImage|Compress(?:ionLevel|'
  77. r'or(?:DictSize)?)?|CtlColors|CurInstType|DatablockOptimize|'
  78. r'DateSave|Details(?:Print|View)|Error(?:s|Level)|FileAttributes|'
  79. r'Font|OutPath|Overwrite|PluginUnload|RebootFlag|ShellVarContext|'
  80. r'Silent|StaticBkColor)|'
  81. r'Show(?:(?:I|Uni)nstDetails|Window)|Silent(?:Un)?Install|Sleep|'
  82. r'SpaceTexts|Str(?:CmpS?|Cpy|Len)|SubSection(?:End)?|'
  83. r'Uninstall(?:ButtonText|(?:Sub)?Caption|EXEName|Icon|Text)|'
  84. r'UninstPage|Var|VI(?:AddVersionKey|ProductVersion)|WindowIcon|'
  85. r'Write(?:INIStr|Reg(:?Bin|DWORD|(?:Expand)?Str)|Uninstaller)|'
  86. r'XPStyle)\b', Keyword),
  87. (r'\b(CUR|END|(?:FILE_ATTRIBUTE_)?'
  88. r'(?:ARCHIVE|HIDDEN|NORMAL|OFFLINE|READONLY|SYSTEM|TEMPORARY)|'
  89. r'HK(CC|CR|CU|DD|LM|PD|U)|'
  90. r'HKEY_(?:CLASSES_ROOT|CURRENT_(?:CONFIG|USER)|DYN_DATA|'
  91. r'LOCAL_MACHINE|PERFORMANCE_DATA|USERS)|'
  92. r'ID(?:ABORT|CANCEL|IGNORE|NO|OK|RETRY|YES)|'
  93. r'MB_(?:ABORTRETRYIGNORE|DEFBUTTON[1-4]|'
  94. r'ICON(?:EXCLAMATION|INFORMATION|QUESTION|STOP)|'
  95. r'OK(?:CANCEL)?|RETRYCANCEL|RIGHT|SETFOREGROUND|TOPMOST|USERICON|'
  96. r'YESNO(?:CANCEL)?)|SET|SHCTX|'
  97. r'SW_(?:HIDE|SHOW(?:MAXIMIZED|MINIMIZED|NORMAL))|'
  98. r'admin|all|auto|both|bottom|bzip2|checkbox|colored|current|false|'
  99. r'force|hide|highest|if(?:diff|newer)|lastused|leave|left|'
  100. r'listonly|lzma|nevershow|none|normal|off|on|pop|push|'
  101. r'radiobuttons|right|show|silent|silentlog|smooth|textonly|top|'
  102. r'true|try|user|zlib)\b', Name.Constant),
  103. ],
  104. 'macro': [
  105. (r'\!(addincludedir(?:dir)?|addplugindir|appendfile|cd|define|'
  106. r'delfilefile|echo(?:message)?|else|endif|error|execute|'
  107. r'if(?:macro)?n?(?:def)?|include|insertmacro|macro(?:end)?|packhdr|'
  108. r'search(?:parse|replace)|system|tempfilesymbol|undef|verbose|'
  109. r'warning)\b', Comment.Preproc),
  110. ],
  111. 'interpol': [
  112. (r'\$(R?[0-9])', Name.Builtin.Pseudo), # registers
  113. (r'\$(ADMINTOOLS|APPDATA|CDBURN_AREA|COOKIES|COMMONFILES(?:32|64)|'
  114. r'DESKTOP|DOCUMENTS|EXE(?:DIR|FILE|PATH)|FAVORITES|FONTS|HISTORY|'
  115. r'HWNDPARENT|INTERNET_CACHE|LOCALAPPDATA|MUSIC|NETHOOD|PICTURES|'
  116. r'PLUGINSDIR|PRINTHOOD|PROFILE|PROGRAMFILES(?:32|64)|QUICKLAUNCH|'
  117. r'RECENT|RESOURCES(?:_LOCALIZED)?|SENDTO|SM(?:PROGRAMS|STARTUP)|'
  118. r'STARTMENU|SYSDIR|TEMP(?:LATES)?|VIDEOS|WINDIR|\{NSISDIR\})',
  119. Name.Builtin),
  120. (r'\$(CMDLINE|INSTDIR|OUTDIR|LANGUAGE)', Name.Variable.Global),
  121. (r'\$[a-z_]\w*', Name.Variable),
  122. ],
  123. 'str_double': [
  124. (r'"', String.Double, '#pop'),
  125. (r'\$(\\[nrt"]|\$)', String.Escape),
  126. include('interpol'),
  127. (r'[^"]+', String.Double),
  128. ],
  129. 'str_backtick': [
  130. (r'`', String.Double, '#pop'),
  131. (r'\$(\\[nrt"]|\$)', String.Escape),
  132. include('interpol'),
  133. (r'[^`]+', String.Double),
  134. ],
  135. }
  136. class RPMSpecLexer(RegexLexer):
  137. """
  138. For RPM ``.spec`` files.
  139. """
  140. name = 'RPMSpec'
  141. aliases = ['spec']
  142. filenames = ['*.spec']
  143. mimetypes = ['text/x-rpm-spec']
  144. url = 'https://rpm-software-management.github.io/rpm/manual/spec.html'
  145. version_added = '1.6'
  146. _directives = ('(?:package|prep|build|install|clean|check|pre[a-z]*|'
  147. 'post[a-z]*|trigger[a-z]*|files)')
  148. tokens = {
  149. 'root': [
  150. (r'#.*$', Comment),
  151. include('basic'),
  152. ],
  153. 'description': [
  154. (r'^(%' + _directives + ')(.*)$',
  155. bygroups(Name.Decorator, Text), '#pop'),
  156. (r'\s+', Whitespace),
  157. (r'.', Text),
  158. ],
  159. 'changelog': [
  160. (r'\*.*$', Generic.Subheading),
  161. (r'^(%' + _directives + ')(.*)$',
  162. bygroups(Name.Decorator, Text), '#pop'),
  163. (r'\s+', Whitespace),
  164. (r'.', Text),
  165. ],
  166. 'string': [
  167. (r'"', String.Double, '#pop'),
  168. (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
  169. include('interpol'),
  170. (r'.', String.Double),
  171. ],
  172. 'basic': [
  173. include('macro'),
  174. (r'(?i)^(Name|Version|Release|Epoch|Summary|Group|License|Packager|'
  175. r'Vendor|Icon|URL|Distribution|Prefix|Patch[0-9]*|Source[0-9]*|'
  176. r'Requires\(?[a-z]*\)?|[a-z]+Req|Obsoletes|Suggests|Provides|Conflicts|'
  177. r'Build[a-z]+|[a-z]+Arch|Auto[a-z]+)(:)(.*)$',
  178. bygroups(Generic.Heading, Punctuation, using(this))),
  179. (r'^%description', Name.Decorator, 'description'),
  180. (r'^%changelog', Name.Decorator, 'changelog'),
  181. (r'^(%' + _directives + ')(.*)$', bygroups(Name.Decorator, Text)),
  182. (r'%(attr|defattr|dir|doc(?:dir)?|setup|config(?:ure)?|'
  183. r'make(?:install)|ghost|patch[0-9]+|find_lang|exclude|verify)',
  184. Keyword),
  185. include('interpol'),
  186. (r"'.*?'", String.Single),
  187. (r'"', String.Double, 'string'),
  188. (r'\s+', Whitespace),
  189. (r'.', Text),
  190. ],
  191. 'macro': [
  192. (r'%define.*$', Comment.Preproc),
  193. (r'%\{\!\?.*%define.*\}', Comment.Preproc),
  194. (r'(%(?:if(?:n?arch)?|else(?:if)?|endif))(.*)$',
  195. bygroups(Comment.Preproc, Text)),
  196. ],
  197. 'interpol': [
  198. (r'%\{?__[a-z_]+\}?', Name.Function),
  199. (r'%\{?_([a-z_]+dir|[a-z_]+path|prefix)\}?', Keyword.Pseudo),
  200. (r'%\{\?\w+\}', Name.Variable),
  201. (r'\$\{?RPM_[A-Z0-9_]+\}?', Name.Variable.Global),
  202. (r'%\{[a-zA-Z]\w+\}', Keyword.Constant),
  203. ]
  204. }
  205. class DebianSourcesLexer(RegexLexer):
  206. """
  207. Lexer that highlights debian.sources files.
  208. """
  209. name = 'Debian Sources file'
  210. aliases = ['debian.sources']
  211. filenames = ['*.sources']
  212. version_added = '2.19'
  213. url = 'https://manpages.debian.org/bookworm/apt/sources.list.5.en.html#THE_DEB_AND_DEB-SRC_TYPES:_GENERAL_FORMAT'
  214. tokens = {
  215. 'root': [
  216. (r'^(Signed-By)(:)(\s*)', bygroups(Keyword, Punctuation, Whitespace), 'signed-by'),
  217. (r'^([a-zA-Z\-0-9\.]*?)(:)(\s*)(.*?)$',
  218. bygroups(Keyword, Punctuation, Whitespace, String)),
  219. ],
  220. 'signed-by': [
  221. (r' -----END PGP PUBLIC KEY BLOCK-----\n', Text, '#pop'),
  222. (r'.+\n', Text),
  223. ],
  224. }
  225. class SourcesListLexer(RegexLexer):
  226. """
  227. Lexer that highlights debian sources.list files.
  228. """
  229. name = 'Debian Sourcelist'
  230. aliases = ['debsources', 'sourceslist', 'sources.list']
  231. filenames = ['sources.list']
  232. version_added = '0.7'
  233. mimetype = ['application/x-debian-sourceslist']
  234. url = 'https://wiki.debian.org/SourcesList'
  235. tokens = {
  236. 'root': [
  237. (r'\s+', Whitespace),
  238. (r'#.*?$', Comment),
  239. (r'^(deb(?:-src)?)(\s+)',
  240. bygroups(Keyword, Whitespace), 'distribution')
  241. ],
  242. 'distribution': [
  243. (r'#.*?$', Comment, '#pop'),
  244. (r'\$\(ARCH\)', Name.Variable),
  245. (r'[^\s$[]+', String),
  246. (r'\[', String.Other, 'escaped-distribution'),
  247. (r'\$', String),
  248. (r'\s+', Whitespace, 'components')
  249. ],
  250. 'escaped-distribution': [
  251. (r'\]', String.Other, '#pop'),
  252. (r'\$\(ARCH\)', Name.Variable),
  253. (r'[^\]$]+', String.Other),
  254. (r'\$', String.Other)
  255. ],
  256. 'components': [
  257. (r'#.*?$', Comment, '#pop:2'),
  258. (r'$', Text, '#pop:2'),
  259. (r'\s+', Whitespace),
  260. (r'\S+', Keyword.Pseudo),
  261. ]
  262. }
  263. def analyse_text(text):
  264. for line in text.splitlines():
  265. line = line.strip()
  266. if line.startswith('deb ') or line.startswith('deb-src '):
  267. return True
  268. class DebianControlLexer(RegexLexer):
  269. """
  270. Lexer for Debian ``control`` files and ``apt-cache show <pkg>`` outputs.
  271. """
  272. name = 'Debian Control file'
  273. url = 'https://www.debian.org/doc/debian-policy/ch-controlfields.html'
  274. aliases = ['debcontrol', 'control']
  275. filenames = ['control']
  276. version_added = '0.9'
  277. tokens = {
  278. 'root': [
  279. (r'^(Description)', Keyword, 'description'),
  280. (r'^(Maintainer|Uploaders|Changed-By)(:)(\s*)',
  281. bygroups(Keyword, Punctuation, Whitespace),
  282. 'maintainer'),
  283. (r'^((?:Build-|Pre-)?Depends(?:-Indep|-Arch)?)(:)(\s*)',
  284. bygroups(Keyword, Punctuation, Whitespace), 'package_list'),
  285. (r'^(Recommends|Suggests|Enhances|Breaks|Replaces|Provides|Conflicts)(:)(\s*)',
  286. bygroups(Keyword, Punctuation, Whitespace), 'package_list'),
  287. (r'^((?:Python-)?Version)(:)(\s*)(\S+)$',
  288. bygroups(Keyword, Punctuation, Whitespace, Number)),
  289. (r'^((?:Installed-)?Size)(:)(\s*)(\S+)$',
  290. bygroups(Keyword, Punctuation, Whitespace, Number)),
  291. (r'^(MD5Sum|SHA1|SHA256)(:)(\s*)(\S+)$',
  292. bygroups(Keyword, Punctuation, Whitespace, Number)),
  293. (r'^([a-zA-Z\-0-9\.]*?)(:)(\s*)(.*?)$',
  294. bygroups(Keyword, Punctuation, Whitespace, String)),
  295. ],
  296. 'maintainer': [
  297. (r'<[^>]+>$', Generic.Strong, '#pop'),
  298. (r'<[^>]+>', Generic.Strong),
  299. (r',\n?', Whitespace),
  300. (r'[^,<]+$', Text, '#pop'),
  301. (r'[^,<]+', Text),
  302. ],
  303. 'description': [
  304. (r'(.*)(Homepage)(: )(\S+)',
  305. bygroups(Text, String, Name, Name.Class)),
  306. (r':.*\n', Generic.Strong),
  307. (r' .*\n', Text),
  308. default('#pop'),
  309. ],
  310. 'package_list': [
  311. (r'(\$)(\{)(\w+)(\s*)(:)(\s*)(\w+)(\})',
  312. bygroups(Operator, Punctuation, Name.Entity, Whitespace,
  313. Punctuation, Whitespace, Text, Punctuation)),
  314. (r'\(', Punctuation, 'package_list_vers'),
  315. (r'\|', Operator),
  316. (r'\n\s', Whitespace),
  317. (r'\n', Whitespace, '#pop'),
  318. (r'[,\s]', Text),
  319. (r'[+.a-zA-Z0-9-]+', Name.Function),
  320. (r'\[.*?\]', Name.Entity),
  321. ],
  322. 'package_list_vers': [
  323. (r'\)', Punctuation, '#pop'),
  324. (r'([><=]+)(\s*)([^)]+)', bygroups(Operator, Whitespace, Number)),
  325. ]
  326. }