ThirdParty/Pygments/pygments/lexers/installers.py

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

eric ide

mercurial