Commits

Georg Brandl committed 2fc596f

Enhancements to the Squid conf lexer (#664).

Comments (0)

Files changed (3)

   * Nemerle
   * F#
 
+- Enhancements to the Squid conf lexer (#664).
+
 - Fix Lua "class" highlighting: it does not have classes (#665).
 
 - Fix degenerate regex in Scala lexer (#671).

pygments/lexers/text.py

     mimetypes = ['text/x-squidconf']
     flags = re.IGNORECASE
 
-    keywords = [ "acl", "always_direct", "announce_host",
+    keywords = [ "access_log", "acl", "always_direct", "announce_host",
                  "announce_period", "announce_port", "announce_to",
                  "anonymize_headers", "append_domain", "as_whois_server",
                  "auth_param_basic", "authenticate_children",
                  "ftpget_options", "ftpget_program", "ftp_list_width",
                  "ftp_passive", "ftp_user", "half_closed_clients",
                  "header_access", "header_replace", "hierarchy_stoplist",
-                 "high_response_time_warning", "high_page_fault_warning",
+                 "high_response_time_warning", "high_page_fault_warning", "hosts_file",
                  "htcp_port", "http_access", "http_anonymizer", "httpd_accel",
                  "httpd_accel_host", "httpd_accel_port",
                  "httpd_accel_uses_host_header", "httpd_accel_with_proxy",
              "snmp_community",
              ]
 
-    ip_re = r'\b(?:\d{1,3}\.){3}\d{1,3}\b'
+    ip_re = r'(?:(?:(?:[3-9]\d?|2(?:5[0-5]|[0-4]?\d)?|1\d{0,2}|0x0*[0-9a-f]{1,2}|0+[1-3]?[0-7]{0,2})(?:\.(?:[3-9]\d?|2(?:5[0-5]|[0-4]?\d)?|1\d{0,2}|0x0*[0-9a-f]{1,2}|0+[1-3]?[0-7]{0,2})){3})|(?!.*::.*::)(?:(?!:)|:(?=:))(?:[0-9a-f]{0,4}(?:(?<=::)|(?<!::):)){6}(?:[0-9a-f]{0,4}(?:(?<=::)|(?<!::):)[0-9a-f]{0,4}(?:(?<=::)|(?<!:)|(?<=:)(?<!::):)|(?:25[0-4]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-4]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))'
 
     def makelistre(list):
-        return r'\b(?:'+'|'.join(list)+r')\b'
+        return r'\b(?:' + '|'.join(list) + r')\b'
 
     tokens = {
         'root': [
-            (r'\s+', Text),
+            (r'\s+', Whitespace),
             (r'#', Comment, 'comment'),
             (makelistre(keywords), Keyword),
             (makelistre(opts), Name.Constant),
             (r'stats/'+makelistre(actions), String),
             (r'log/'+makelistre(actions)+r'=', String),
             (makelistre(acls), Keyword),
-            (ip_re+r'(?:/(?:'+ip_re+r')|\d+)?', Number),
-            (r'\b\d+\b', Number),
+            (ip_re + r'(?:/(?:' + ip_re + r'|\b\d+\b))?', Number.Float),
+            (r'(?:\b\d+\b(?:-\b\d+|%)?)', Number),
             (r'\S+', Text),
         ],
         'comment': [

tests/examplefiles/squid.conf

-# First, a comment block for the deafult conf:
+# Some multiline comments
 
-#  TAG: buffered_logs   on|off
-#       cache.log log file is written with stdio functions, and as such
-#       it can be buffered or unbuffered. By default it will be unbuffered.
-#       Buffering it can speed up the writing slightly (though you are
-#       unlikely to need to worry unless you run with tons of debugging
-#       enabled in which case performance will suffer badly anyway..).
-#
-#Default:
-# buffered_logs off
-
-# Now, a slightly useful (but in no way complete) set of options:
-
-cache_peer upstream1.example.com parent 8080 0 no-query proxy-only round-robin
-cache_peer upstream2.example.com parent 3128 0 no-query proxy-only round-robin
-never_direct allow all
-never_direct allow CONNECT
-
-acl myclients src 127.0.0.1
-http_access allow myclients
-
-acl mynet src 192.168.0.0/255.255.0.0
-no_cache deny mynet
-
-acl mynetlocal dst 192.168.0.0/255.255.0.0
-always_direct allow mynetlocal
+acl manager proto cache_object
+acl localhost src 127.0.0.1/32 ::1
+acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
+acl SSL_ports port 443
+acl Safe_ports port 80		# http
+acl Safe_ports port 21		# ftp
+acl Safe_ports port 443		# https
+acl Safe_ports port 70		# gopher
+acl Safe_ports port 210		# wais
+acl Safe_ports port 1025-65535	# unregistered ports
+acl Safe_ports port 280		# http-mgmt
+acl Safe_ports port 488		# gss-http
+acl Safe_ports port 591		# filemaker
+acl Safe_ports port 777		# multiling http
+acl CONNECT method CONNECT
+http_access allow manager localhost
+http_access deny manager
+http_access deny !Safe_ports
+http_access deny CONNECT !SSL_ports
+http_access allow localhost
+http_access deny all
+http_port 3128
+hierarchy_stoplist cgi-bin ?
+coredump_dir /var/spool/squid3
+refresh_pattern ^ftp:		1440	20%	10080
+refresh_pattern ^gopher:	1440	0%	1440
+refresh_pattern -i (/cgi-bin/|\?) 0	0%	0
+refresh_pattern .		0	20%	4320