|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.configs |
|
4 ~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexers for configuration file 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, default, words, bygroups, include, using |
|
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
|
16 Number, Punctuation, Whitespace |
|
17 from pygments.lexers.shell import BashLexer |
|
18 |
|
19 __all__ = ['IniLexer', 'RegeditLexer', 'PropertiesLexer', 'KconfigLexer', |
|
20 'Cfengine3Lexer', 'ApacheConfLexer', 'SquidConfLexer', |
|
21 'NginxConfLexer', 'LighttpdConfLexer', 'DockerLexer'] |
|
22 |
|
23 |
|
24 class IniLexer(RegexLexer): |
|
25 """ |
|
26 Lexer for configuration files in INI style. |
|
27 """ |
|
28 |
|
29 name = 'INI' |
|
30 aliases = ['ini', 'cfg', 'dosini'] |
|
31 filenames = ['*.ini', '*.cfg'] |
|
32 mimetypes = ['text/x-ini'] |
|
33 |
|
34 tokens = { |
|
35 'root': [ |
|
36 (r'\s+', Text), |
|
37 (r'[;#].*', Comment.Single), |
|
38 (r'\[.*?\]$', Keyword), |
|
39 (r'(.*?)([ \t]*)(=)([ \t]*)(.*(?:\n[ \t].+)*)', |
|
40 bygroups(Name.Attribute, Text, Operator, Text, String)) |
|
41 ] |
|
42 } |
|
43 |
|
44 def analyse_text(text): |
|
45 npos = text.find('\n') |
|
46 if npos < 3: |
|
47 return False |
|
48 return text[0] == '[' and text[npos-1] == ']' |
|
49 |
|
50 |
|
51 class RegeditLexer(RegexLexer): |
|
52 """ |
|
53 Lexer for `Windows Registry |
|
54 <http://en.wikipedia.org/wiki/Windows_Registry#.REG_files>`_ files produced |
|
55 by regedit. |
|
56 |
|
57 .. versionadded:: 1.6 |
|
58 """ |
|
59 |
|
60 name = 'reg' |
|
61 aliases = ['registry'] |
|
62 filenames = ['*.reg'] |
|
63 mimetypes = ['text/x-windows-registry'] |
|
64 |
|
65 tokens = { |
|
66 'root': [ |
|
67 (r'Windows Registry Editor.*', Text), |
|
68 (r'\s+', Text), |
|
69 (r'[;#].*', Comment.Single), |
|
70 (r'(\[)(-?)(HKEY_[A-Z_]+)(.*?\])$', |
|
71 bygroups(Keyword, Operator, Name.Builtin, Keyword)), |
|
72 # String keys, which obey somewhat normal escaping |
|
73 (r'("(?:\\"|\\\\|[^"])+")([ \t]*)(=)([ \t]*)', |
|
74 bygroups(Name.Attribute, Text, Operator, Text), |
|
75 'value'), |
|
76 # Bare keys (includes @) |
|
77 (r'(.*?)([ \t]*)(=)([ \t]*)', |
|
78 bygroups(Name.Attribute, Text, Operator, Text), |
|
79 'value'), |
|
80 ], |
|
81 'value': [ |
|
82 (r'-', Operator, '#pop'), # delete value |
|
83 (r'(dword|hex(?:\([0-9a-fA-F]\))?)(:)([0-9a-fA-F,]+)', |
|
84 bygroups(Name.Variable, Punctuation, Number), '#pop'), |
|
85 # As far as I know, .reg files do not support line continuation. |
|
86 (r'.+', String, '#pop'), |
|
87 default('#pop'), |
|
88 ] |
|
89 } |
|
90 |
|
91 def analyse_text(text): |
|
92 return text.startswith('Windows Registry Editor') |
|
93 |
|
94 |
|
95 class PropertiesLexer(RegexLexer): |
|
96 """ |
|
97 Lexer for configuration files in Java's properties format. |
|
98 |
|
99 .. versionadded:: 1.4 |
|
100 """ |
|
101 |
|
102 name = 'Properties' |
|
103 aliases = ['properties', 'jproperties'] |
|
104 filenames = ['*.properties'] |
|
105 mimetypes = ['text/x-java-properties'] |
|
106 |
|
107 tokens = { |
|
108 'root': [ |
|
109 (r'\s+', Text), |
|
110 (r'(?:[;#]|//).*$', Comment), |
|
111 (r'(.*?)([ \t]*)([=:])([ \t]*)(.*(?:(?<=\\)\n.*)*)', |
|
112 bygroups(Name.Attribute, Text, Operator, Text, String)), |
|
113 ], |
|
114 } |
|
115 |
|
116 |
|
117 def _rx_indent(level): |
|
118 # Kconfig *always* interprets a tab as 8 spaces, so this is the default. |
|
119 # Edit this if you are in an environment where KconfigLexer gets expanded |
|
120 # input (tabs expanded to spaces) and the expansion tab width is != 8, |
|
121 # e.g. in connection with Trac (trac.ini, [mimeviewer], tab_width). |
|
122 # Value range here is 2 <= {tab_width} <= 8. |
|
123 tab_width = 8 |
|
124 # Regex matching a given indentation {level}, assuming that indentation is |
|
125 # a multiple of {tab_width}. In other cases there might be problems. |
|
126 if tab_width == 2: |
|
127 space_repeat = '+' |
|
128 else: |
|
129 space_repeat = '{1,%d}' % (tab_width - 1) |
|
130 if level == 1: |
|
131 level_repeat = '' |
|
132 else: |
|
133 level_repeat = '{%s}' % level |
|
134 return r'(?:\t| %s\t| {%s})%s.*\n' % (space_repeat, tab_width, level_repeat) |
|
135 |
|
136 |
|
137 class KconfigLexer(RegexLexer): |
|
138 """ |
|
139 For Linux-style Kconfig files. |
|
140 |
|
141 .. versionadded:: 1.6 |
|
142 """ |
|
143 |
|
144 name = 'Kconfig' |
|
145 aliases = ['kconfig', 'menuconfig', 'linux-config', 'kernel-config'] |
|
146 # Adjust this if new kconfig file names appear in your environment |
|
147 filenames = ['Kconfig', '*Config.in*', 'external.in*', |
|
148 'standard-modules.in'] |
|
149 mimetypes = ['text/x-kconfig'] |
|
150 # No re.MULTILINE, indentation-aware help text needs line-by-line handling |
|
151 flags = 0 |
|
152 |
|
153 def call_indent(level): |
|
154 # If indentation >= {level} is detected, enter state 'indent{level}' |
|
155 return (_rx_indent(level), String.Doc, 'indent%s' % level) |
|
156 |
|
157 def do_indent(level): |
|
158 # Print paragraphs of indentation level >= {level} as String.Doc, |
|
159 # ignoring blank lines. Then return to 'root' state. |
|
160 return [ |
|
161 (_rx_indent(level), String.Doc), |
|
162 (r'\s*\n', Text), |
|
163 default('#pop:2') |
|
164 ] |
|
165 |
|
166 tokens = { |
|
167 'root': [ |
|
168 (r'\s+', Text), |
|
169 (r'#.*?\n', Comment.Single), |
|
170 (words(( |
|
171 'mainmenu', 'config', 'menuconfig', 'choice', 'endchoice', |
|
172 'comment', 'menu', 'endmenu', 'visible if', 'if', 'endif', |
|
173 'source', 'prompt', 'select', 'depends on', 'default', |
|
174 'range', 'option'), suffix=r'\b'), |
|
175 Keyword), |
|
176 (r'(---help---|help)[\t ]*\n', Keyword, 'help'), |
|
177 (r'(bool|tristate|string|hex|int|defconfig_list|modules|env)\b', |
|
178 Name.Builtin), |
|
179 (r'[!=&|]', Operator), |
|
180 (r'[()]', Punctuation), |
|
181 (r'[0-9]+', Number.Integer), |
|
182 (r"'(''|[^'])*'", String.Single), |
|
183 (r'"(""|[^"])*"', String.Double), |
|
184 (r'\S+', Text), |
|
185 ], |
|
186 # Help text is indented, multi-line and ends when a lower indentation |
|
187 # level is detected. |
|
188 'help': [ |
|
189 # Skip blank lines after help token, if any |
|
190 (r'\s*\n', Text), |
|
191 # Determine the first help line's indentation level heuristically(!). |
|
192 # Attention: this is not perfect, but works for 99% of "normal" |
|
193 # indentation schemes up to a max. indentation level of 7. |
|
194 call_indent(7), |
|
195 call_indent(6), |
|
196 call_indent(5), |
|
197 call_indent(4), |
|
198 call_indent(3), |
|
199 call_indent(2), |
|
200 call_indent(1), |
|
201 default('#pop'), # for incomplete help sections without text |
|
202 ], |
|
203 # Handle text for indentation levels 7 to 1 |
|
204 'indent7': do_indent(7), |
|
205 'indent6': do_indent(6), |
|
206 'indent5': do_indent(5), |
|
207 'indent4': do_indent(4), |
|
208 'indent3': do_indent(3), |
|
209 'indent2': do_indent(2), |
|
210 'indent1': do_indent(1), |
|
211 } |
|
212 |
|
213 |
|
214 class Cfengine3Lexer(RegexLexer): |
|
215 """ |
|
216 Lexer for `CFEngine3 <http://cfengine.org>`_ policy files. |
|
217 |
|
218 .. versionadded:: 1.5 |
|
219 """ |
|
220 |
|
221 name = 'CFEngine3' |
|
222 aliases = ['cfengine3', 'cf3'] |
|
223 filenames = ['*.cf'] |
|
224 mimetypes = [] |
|
225 |
|
226 tokens = { |
|
227 'root': [ |
|
228 (r'#.*?\n', Comment), |
|
229 (r'(body)(\s+)(\S+)(\s+)(control)', |
|
230 bygroups(Keyword, Text, Keyword, Text, Keyword)), |
|
231 (r'(body|bundle)(\s+)(\S+)(\s+)(\w+)(\()', |
|
232 bygroups(Keyword, Text, Keyword, Text, Name.Function, Punctuation), |
|
233 'arglist'), |
|
234 (r'(body|bundle)(\s+)(\S+)(\s+)(\w+)', |
|
235 bygroups(Keyword, Text, Keyword, Text, Name.Function)), |
|
236 (r'(")([^"]+)(")(\s+)(string|slist|int|real)(\s*)(=>)(\s*)', |
|
237 bygroups(Punctuation, Name.Variable, Punctuation, |
|
238 Text, Keyword.Type, Text, Operator, Text)), |
|
239 (r'(\S+)(\s*)(=>)(\s*)', |
|
240 bygroups(Keyword.Reserved, Text, Operator, Text)), |
|
241 (r'"', String, 'string'), |
|
242 (r'(\w+)(\()', bygroups(Name.Function, Punctuation)), |
|
243 (r'([\w.!&|()]+)(::)', bygroups(Name.Class, Punctuation)), |
|
244 (r'(\w+)(:)', bygroups(Keyword.Declaration, Punctuation)), |
|
245 (r'@[{(][^)}]+[})]', Name.Variable), |
|
246 (r'[(){},;]', Punctuation), |
|
247 (r'=>', Operator), |
|
248 (r'->', Operator), |
|
249 (r'\d+\.\d+', Number.Float), |
|
250 (r'\d+', Number.Integer), |
|
251 (r'\w+', Name.Function), |
|
252 (r'\s+', Text), |
|
253 ], |
|
254 'string': [ |
|
255 (r'\$[{(]', String.Interpol, 'interpol'), |
|
256 (r'\\.', String.Escape), |
|
257 (r'"', String, '#pop'), |
|
258 (r'\n', String), |
|
259 (r'.', String), |
|
260 ], |
|
261 'interpol': [ |
|
262 (r'\$[{(]', String.Interpol, '#push'), |
|
263 (r'[})]', String.Interpol, '#pop'), |
|
264 (r'[^${()}]+', String.Interpol), |
|
265 ], |
|
266 'arglist': [ |
|
267 (r'\)', Punctuation, '#pop'), |
|
268 (r',', Punctuation), |
|
269 (r'\w+', Name.Variable), |
|
270 (r'\s+', Text), |
|
271 ], |
|
272 } |
|
273 |
|
274 |
|
275 class ApacheConfLexer(RegexLexer): |
|
276 """ |
|
277 Lexer for configuration files following the Apache config file |
|
278 format. |
|
279 |
|
280 .. versionadded:: 0.6 |
|
281 """ |
|
282 |
|
283 name = 'ApacheConf' |
|
284 aliases = ['apacheconf', 'aconf', 'apache'] |
|
285 filenames = ['.htaccess', 'apache.conf', 'apache2.conf'] |
|
286 mimetypes = ['text/x-apacheconf'] |
|
287 flags = re.MULTILINE | re.IGNORECASE |
|
288 |
|
289 tokens = { |
|
290 'root': [ |
|
291 (r'\s+', Text), |
|
292 (r'(#.*?)$', Comment), |
|
293 (r'(<[^\s>]+)(?:(\s+)(.*?))?(>)', |
|
294 bygroups(Name.Tag, Text, String, Name.Tag)), |
|
295 (r'([a-z]\w*)(\s+)', |
|
296 bygroups(Name.Builtin, Text), 'value'), |
|
297 (r'\.+', Text), |
|
298 ], |
|
299 'value': [ |
|
300 (r'\\\n', Text), |
|
301 (r'$', Text, '#pop'), |
|
302 (r'\\', Text), |
|
303 (r'[^\S\n]+', Text), |
|
304 (r'\d+\.\d+\.\d+\.\d+(?:/\d+)?', Number), |
|
305 (r'\d+', Number), |
|
306 (r'/([a-z0-9][\w./-]+)', String.Other), |
|
307 (r'(on|off|none|any|all|double|email|dns|min|minimal|' |
|
308 r'os|productonly|full|emerg|alert|crit|error|warn|' |
|
309 r'notice|info|debug|registry|script|inetd|standalone|' |
|
310 r'user|group)\b', Keyword), |
|
311 (r'"([^"\\]*(?:\\.[^"\\]*)*)"', String.Double), |
|
312 (r'[^\s"\\]+', Text) |
|
313 ], |
|
314 } |
|
315 |
|
316 |
|
317 class SquidConfLexer(RegexLexer): |
|
318 """ |
|
319 Lexer for `squid <http://www.squid-cache.org/>`_ configuration files. |
|
320 |
|
321 .. versionadded:: 0.9 |
|
322 """ |
|
323 |
|
324 name = 'SquidConf' |
|
325 aliases = ['squidconf', 'squid.conf', 'squid'] |
|
326 filenames = ['squid.conf'] |
|
327 mimetypes = ['text/x-squidconf'] |
|
328 flags = re.IGNORECASE |
|
329 |
|
330 keywords = ( |
|
331 "access_log", "acl", "always_direct", "announce_host", |
|
332 "announce_period", "announce_port", "announce_to", "anonymize_headers", |
|
333 "append_domain", "as_whois_server", "auth_param_basic", |
|
334 "authenticate_children", "authenticate_program", "authenticate_ttl", |
|
335 "broken_posts", "buffered_logs", "cache_access_log", "cache_announce", |
|
336 "cache_dir", "cache_dns_program", "cache_effective_group", |
|
337 "cache_effective_user", "cache_host", "cache_host_acl", |
|
338 "cache_host_domain", "cache_log", "cache_mem", "cache_mem_high", |
|
339 "cache_mem_low", "cache_mgr", "cachemgr_passwd", "cache_peer", |
|
340 "cache_peer_access", "cahce_replacement_policy", "cache_stoplist", |
|
341 "cache_stoplist_pattern", "cache_store_log", "cache_swap", |
|
342 "cache_swap_high", "cache_swap_log", "cache_swap_low", "client_db", |
|
343 "client_lifetime", "client_netmask", "connect_timeout", "coredump_dir", |
|
344 "dead_peer_timeout", "debug_options", "delay_access", "delay_class", |
|
345 "delay_initial_bucket_level", "delay_parameters", "delay_pools", |
|
346 "deny_info", "dns_children", "dns_defnames", "dns_nameservers", |
|
347 "dns_testnames", "emulate_httpd_log", "err_html_text", |
|
348 "fake_user_agent", "firewall_ip", "forwarded_for", "forward_snmpd_port", |
|
349 "fqdncache_size", "ftpget_options", "ftpget_program", "ftp_list_width", |
|
350 "ftp_passive", "ftp_user", "half_closed_clients", "header_access", |
|
351 "header_replace", "hierarchy_stoplist", "high_response_time_warning", |
|
352 "high_page_fault_warning", "hosts_file", "htcp_port", "http_access", |
|
353 "http_anonymizer", "httpd_accel", "httpd_accel_host", |
|
354 "httpd_accel_port", "httpd_accel_uses_host_header", |
|
355 "httpd_accel_with_proxy", "http_port", "http_reply_access", |
|
356 "icp_access", "icp_hit_stale", "icp_port", "icp_query_timeout", |
|
357 "ident_lookup", "ident_lookup_access", "ident_timeout", |
|
358 "incoming_http_average", "incoming_icp_average", "inside_firewall", |
|
359 "ipcache_high", "ipcache_low", "ipcache_size", "local_domain", |
|
360 "local_ip", "logfile_rotate", "log_fqdn", "log_icp_queries", |
|
361 "log_mime_hdrs", "maximum_object_size", "maximum_single_addr_tries", |
|
362 "mcast_groups", "mcast_icp_query_timeout", "mcast_miss_addr", |
|
363 "mcast_miss_encode_key", "mcast_miss_port", "memory_pools", |
|
364 "memory_pools_limit", "memory_replacement_policy", "mime_table", |
|
365 "min_http_poll_cnt", "min_icp_poll_cnt", "minimum_direct_hops", |
|
366 "minimum_object_size", "minimum_retry_timeout", "miss_access", |
|
367 "negative_dns_ttl", "negative_ttl", "neighbor_timeout", |
|
368 "neighbor_type_domain", "netdb_high", "netdb_low", "netdb_ping_period", |
|
369 "netdb_ping_rate", "never_direct", "no_cache", "passthrough_proxy", |
|
370 "pconn_timeout", "pid_filename", "pinger_program", "positive_dns_ttl", |
|
371 "prefer_direct", "proxy_auth", "proxy_auth_realm", "query_icmp", |
|
372 "quick_abort", "quick_abort_max", "quick_abort_min", |
|
373 "quick_abort_pct", "range_offset_limit", "read_timeout", |
|
374 "redirect_children", "redirect_program", |
|
375 "redirect_rewrites_host_header", "reference_age", |
|
376 "refresh_pattern", "reload_into_ims", "request_body_max_size", |
|
377 "request_size", "request_timeout", "shutdown_lifetime", |
|
378 "single_parent_bypass", "siteselect_timeout", "snmp_access", |
|
379 "snmp_incoming_address", "snmp_port", "source_ping", "ssl_proxy", |
|
380 "store_avg_object_size", "store_objects_per_bucket", |
|
381 "strip_query_terms", "swap_level1_dirs", "swap_level2_dirs", |
|
382 "tcp_incoming_address", "tcp_outgoing_address", "tcp_recv_bufsize", |
|
383 "test_reachability", "udp_hit_obj", "udp_hit_obj_size", |
|
384 "udp_incoming_address", "udp_outgoing_address", "unique_hostname", |
|
385 "unlinkd_program", "uri_whitespace", "useragent_log", |
|
386 "visible_hostname", "wais_relay", "wais_relay_host", "wais_relay_port", |
|
387 ) |
|
388 |
|
389 opts = ( |
|
390 "proxy-only", "weight", "ttl", "no-query", "default", "round-robin", |
|
391 "multicast-responder", "on", "off", "all", "deny", "allow", "via", |
|
392 "parent", "no-digest", "heap", "lru", "realm", "children", "q1", "q2", |
|
393 "credentialsttl", "none", "disable", "offline_toggle", "diskd", |
|
394 ) |
|
395 |
|
396 actions = ( |
|
397 "shutdown", "info", "parameter", "server_list", "client_list", |
|
398 r'squid.conf', |
|
399 ) |
|
400 |
|
401 actions_stats = ( |
|
402 "objects", "vm_objects", "utilization", "ipcache", "fqdncache", "dns", |
|
403 "redirector", "io", "reply_headers", "filedescriptors", "netdb", |
|
404 ) |
|
405 |
|
406 actions_log = ("status", "enable", "disable", "clear") |
|
407 |
|
408 acls = ( |
|
409 "url_regex", "urlpath_regex", "referer_regex", "port", "proto", |
|
410 "req_mime_type", "rep_mime_type", "method", "browser", "user", "src", |
|
411 "dst", "time", "dstdomain", "ident", "snmp_community", |
|
412 ) |
|
413 |
|
414 ip_re = ( |
|
415 r'(?:(?:(?:[3-9]\d?|2(?:5[0-5]|[0-4]?\d)?|1\d{0,2}|0x0*[0-9a-f]{1,2}|' |
|
416 r'0+[1-3]?[0-7]{0,2})(?:\.(?:[3-9]\d?|2(?:5[0-5]|[0-4]?\d)?|1\d{0,2}|' |
|
417 r'0x0*[0-9a-f]{1,2}|0+[1-3]?[0-7]{0,2})){3})|(?!.*::.*::)(?:(?!:)|' |
|
418 r':(?=:))(?:[0-9a-f]{0,4}(?:(?<=::)|(?<!::):)){6}(?:[0-9a-f]{0,4}' |
|
419 r'(?:(?<=::)|(?<!::):)[0-9a-f]{0,4}(?:(?<=::)|(?<!:)|(?<=:)(?<!::):)|' |
|
420 r'(?:25[0-4]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-4]|2[0-4]\d|1\d\d|' |
|
421 r'[1-9]?\d)){3}))' |
|
422 ) |
|
423 |
|
424 tokens = { |
|
425 'root': [ |
|
426 (r'\s+', Whitespace), |
|
427 (r'#', Comment, 'comment'), |
|
428 (words(keywords, prefix=r'\b', suffix=r'\b'), Keyword), |
|
429 (words(opts, prefix=r'\b', suffix=r'\b'), Name.Constant), |
|
430 # Actions |
|
431 (words(actions, prefix=r'\b', suffix=r'\b'), String), |
|
432 (words(actions_stats, prefix=r'stats/', suffix=r'\b'), String), |
|
433 (words(actions_log, prefix=r'log/', suffix=r'='), String), |
|
434 (words(acls, prefix=r'\b', suffix=r'\b'), Keyword), |
|
435 (ip_re + r'(?:/(?:' + ip_re + r'|\b\d+\b))?', Number.Float), |
|
436 (r'(?:\b\d+\b(?:-\b\d+|%)?)', Number), |
|
437 (r'\S+', Text), |
|
438 ], |
|
439 'comment': [ |
|
440 (r'\s*TAG:.*', String.Escape, '#pop'), |
|
441 (r'.+', Comment, '#pop'), |
|
442 default('#pop'), |
|
443 ], |
|
444 } |
|
445 |
|
446 |
|
447 class NginxConfLexer(RegexLexer): |
|
448 """ |
|
449 Lexer for `Nginx <http://nginx.net/>`_ configuration files. |
|
450 |
|
451 .. versionadded:: 0.11 |
|
452 """ |
|
453 name = 'Nginx configuration file' |
|
454 aliases = ['nginx'] |
|
455 filenames = [] |
|
456 mimetypes = ['text/x-nginx-conf'] |
|
457 |
|
458 tokens = { |
|
459 'root': [ |
|
460 (r'(include)(\s+)([^\s;]+)', bygroups(Keyword, Text, Name)), |
|
461 (r'[^\s;#]+', Keyword, 'stmt'), |
|
462 include('base'), |
|
463 ], |
|
464 'block': [ |
|
465 (r'\}', Punctuation, '#pop:2'), |
|
466 (r'[^\s;#]+', Keyword.Namespace, 'stmt'), |
|
467 include('base'), |
|
468 ], |
|
469 'stmt': [ |
|
470 (r'\{', Punctuation, 'block'), |
|
471 (r';', Punctuation, '#pop'), |
|
472 include('base'), |
|
473 ], |
|
474 'base': [ |
|
475 (r'#.*\n', Comment.Single), |
|
476 (r'on|off', Name.Constant), |
|
477 (r'\$[^\s;#()]+', Name.Variable), |
|
478 (r'([a-z0-9.-]+)(:)([0-9]+)', |
|
479 bygroups(Name, Punctuation, Number.Integer)), |
|
480 (r'[a-z-]+/[a-z-+]+', String), # mimetype |
|
481 # (r'[a-zA-Z._-]+', Keyword), |
|
482 (r'[0-9]+[km]?\b', Number.Integer), |
|
483 (r'(~)(\s*)([^\s{]+)', bygroups(Punctuation, Text, String.Regex)), |
|
484 (r'[:=~]', Punctuation), |
|
485 (r'[^\s;#{}$]+', String), # catch all |
|
486 (r'/[^\s;#]*', Name), # pathname |
|
487 (r'\s+', Text), |
|
488 (r'[$;]', Text), # leftover characters |
|
489 ], |
|
490 } |
|
491 |
|
492 |
|
493 class LighttpdConfLexer(RegexLexer): |
|
494 """ |
|
495 Lexer for `Lighttpd <http://lighttpd.net/>`_ configuration files. |
|
496 |
|
497 .. versionadded:: 0.11 |
|
498 """ |
|
499 name = 'Lighttpd configuration file' |
|
500 aliases = ['lighty', 'lighttpd'] |
|
501 filenames = [] |
|
502 mimetypes = ['text/x-lighttpd-conf'] |
|
503 |
|
504 tokens = { |
|
505 'root': [ |
|
506 (r'#.*\n', Comment.Single), |
|
507 (r'/\S*', Name), # pathname |
|
508 (r'[a-zA-Z._-]+', Keyword), |
|
509 (r'\d+\.\d+\.\d+\.\d+(?:/\d+)?', Number), |
|
510 (r'[0-9]+', Number), |
|
511 (r'=>|=~|\+=|==|=|\+', Operator), |
|
512 (r'\$[A-Z]+', Name.Builtin), |
|
513 (r'[(){}\[\],]', Punctuation), |
|
514 (r'"([^"\\]*(?:\\.[^"\\]*)*)"', String.Double), |
|
515 (r'\s+', Text), |
|
516 ], |
|
517 |
|
518 } |
|
519 |
|
520 |
|
521 class DockerLexer(RegexLexer): |
|
522 """ |
|
523 Lexer for `Docker <http://docker.io>`_ configuration files. |
|
524 |
|
525 .. versionadded:: 2.0 |
|
526 """ |
|
527 name = 'Docker' |
|
528 aliases = ['docker', 'dockerfile'] |
|
529 filenames = ['Dockerfile', '*.docker'] |
|
530 mimetypes = ['text/x-dockerfile-config'] |
|
531 |
|
532 _keywords = (r'(?:FROM|MAINTAINER|CMD|EXPOSE|ENV|ADD|ENTRYPOINT|' |
|
533 r'VOLUME|WORKDIR)') |
|
534 |
|
535 flags = re.IGNORECASE | re.MULTILINE |
|
536 |
|
537 tokens = { |
|
538 'root': [ |
|
539 (r'^(ONBUILD)(\s+)(%s)\b' % (_keywords,), |
|
540 bygroups(Name.Keyword, Whitespace, Keyword)), |
|
541 (r'^(%s)\b(.*)' % (_keywords,), bygroups(Keyword, String)), |
|
542 (r'#.*', Comment), |
|
543 (r'RUN', Keyword), # Rest of line falls through |
|
544 (r'(.*\\\n)*.+', using(BashLexer)), |
|
545 ], |
|
546 } |