ThirdParty/Pygments/pygments/lexers/text.py

changeset 1705
b0fbc9300f2b
parent 808
8f85926125ef
child 2426
da76c71624de
equal deleted inserted replaced
1704:02ae6c55b35b 1705:b0fbc9300f2b
3 pygments.lexers.text 3 pygments.lexers.text
4 ~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for non-source code file types. 6 Lexers for non-source code file types.
7 7
8 :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 import re 12 import re
13 from bisect import bisect 13 from bisect import bisect
14 14
15 from pygments.lexer import Lexer, LexerContext, RegexLexer, ExtendedRegexLexer, \ 15 from pygments.lexer import Lexer, LexerContext, RegexLexer, ExtendedRegexLexer, \
16 bygroups, include, using, this, do_insertions 16 bygroups, include, using, this, do_insertions
17 from pygments.token import Punctuation, Text, Comment, Keyword, Name, String, \ 17 from pygments.token import Punctuation, Text, Comment, Keyword, Name, String, \
18 Generic, Operator, Number, Whitespace, Literal 18 Generic, Operator, Number, Whitespace, Literal
19 from pygments.util import get_bool_opt 19 from pygments.util import get_bool_opt, ClassNotFound
20 from pygments.lexers.other import BashLexer 20 from pygments.lexers.other import BashLexer
21 21
22 __all__ = ['IniLexer', 'PropertiesLexer', 'SourcesListLexer', 'BaseMakefileLexer', 22 __all__ = ['IniLexer', 'PropertiesLexer', 'SourcesListLexer', 'BaseMakefileLexer',
23 'MakefileLexer', 'DiffLexer', 'IrcLogsLexer', 'TexLexer', 23 'MakefileLexer', 'DiffLexer', 'IrcLogsLexer', 'TexLexer',
24 'GroffLexer', 'ApacheConfLexer', 'BBCodeLexer', 'MoinWikiLexer', 24 'GroffLexer', 'ApacheConfLexer', 'BBCodeLexer', 'MoinWikiLexer',
25 'RstLexer', 'VimLexer', 'GettextLexer', 'SquidConfLexer', 25 'RstLexer', 'VimLexer', 'GettextLexer', 'SquidConfLexer',
26 'DebianControlLexer', 'DarcsPatchLexer', 'YamlLexer', 26 'DebianControlLexer', 'DarcsPatchLexer', 'YamlLexer',
27 'LighttpdConfLexer', 'NginxConfLexer', 'CMakeLexer'] 27 'LighttpdConfLexer', 'NginxConfLexer', 'CMakeLexer', 'HttpLexer',
28 'PyPyLogLexer']
28 29
29 30
30 class IniLexer(RegexLexer): 31 class IniLexer(RegexLexer):
31 """ 32 """
32 Lexer for configuration files in INI style. 33 Lexer for configuration files in INI style.
169 Lexer for simple Makefiles (no preprocessing). 170 Lexer for simple Makefiles (no preprocessing).
170 171
171 *New in Pygments 0.10.* 172 *New in Pygments 0.10.*
172 """ 173 """
173 174
174 name = 'Makefile' 175 name = 'Base Makefile'
175 aliases = ['basemake'] 176 aliases = ['basemake']
176 filenames = [] 177 filenames = []
177 mimetypes = [] 178 mimetypes = []
178 179
179 tokens = { 180 tokens = {
289 (r'\[_[^_]*_]', Operator), 290 (r'\[_[^_]*_]', Operator),
290 ], 291 ],
291 'insert': [ 292 'insert': [
292 include('specialText'), 293 include('specialText'),
293 (r'\[', Generic.Inserted), 294 (r'\[', Generic.Inserted),
294 (r'[^\n\[]*', Generic.Inserted), 295 (r'[^\n\[]+', Generic.Inserted),
295 ], 296 ],
296 'delete': [ 297 'delete': [
297 include('specialText'), 298 include('specialText'),
298 (r'\[', Generic.Deleted), 299 (r'\[', Generic.Deleted),
299 (r'[^\n\[]*', Generic.Deleted), 300 (r'[^\n\[]+', Generic.Deleted),
300 ], 301 ],
301 } 302 }
302 303
303 304
304 class IrcLogsLexer(RegexLexer): 305 class IrcLogsLexer(RegexLexer):
343 (\s*<.*?>\s*) # Nick """, 344 (\s*<.*?>\s*) # Nick """,
344 bygroups(Comment.Preproc, Name.Tag), 'msg'), 345 bygroups(Comment.Preproc, Name.Tag), 'msg'),
345 # /me msgs 346 # /me msgs
346 ("^" + timestamp + r""" 347 ("^" + timestamp + r"""
347 (\s*[*]\s+) # Star 348 (\s*[*]\s+) # Star
348 ([^\s]+\s+.*?\n) # Nick + rest of message """, 349 (\S+\s+.*?\n) # Nick + rest of message """,
349 bygroups(Comment.Preproc, Keyword, Generic.Inserted)), 350 bygroups(Comment.Preproc, Keyword, Generic.Inserted)),
350 # join/part msgs 351 # join/part msgs
351 ("^" + timestamp + r""" 352 ("^" + timestamp + r"""
352 (\s*(?:\*{3}|<?-[!@=P]?->?)\s*) # Star(s) or symbols 353 (\s*(?:\*{3}|<?-[!@=P]?->?)\s*) # Star(s) or symbols
353 ([^\s]+\s+) # Nick + Space 354 (\S+\s+) # Nick + Space
354 (.*?\n) # Rest of message """, 355 (.*?\n) # Rest of message """,
355 bygroups(Comment.Preproc, Keyword, String, Comment)), 356 bygroups(Comment.Preproc, Keyword, String, Comment)),
356 (r"^.*?\n", Text), 357 (r"^.*?\n", Text),
357 ], 358 ],
358 'msg': [ 359 'msg': [
359 (r"[^\s]+:(?!//)", Name.Attribute), # Prefix 360 (r"\S+:(?!//)", Name.Attribute), # Prefix
360 (r".*\n", Text, '#pop'), 361 (r".*\n", Text, '#pop'),
361 ], 362 ],
362 } 363 }
363 364
364 365
465 filenames = ['*.[1234567]', '*.man'] 466 filenames = ['*.[1234567]', '*.man']
466 mimetypes = ['application/x-troff', 'text/troff'] 467 mimetypes = ['application/x-troff', 'text/troff']
467 468
468 tokens = { 469 tokens = {
469 'root': [ 470 'root': [
470 (r'(?i)(\.)(\w+)', bygroups(Text, Keyword), 'request'), 471 (r'(\.)(\w+)', bygroups(Text, Keyword), 'request'),
471 (r'\.', Punctuation, 'request'), 472 (r'\.', Punctuation, 'request'),
472 # Regular characters, slurp till we find a backslash or newline 473 # Regular characters, slurp till we find a backslash or newline
473 (r'[^\\\n]*', Text, 'textline'), 474 (r'[^\\\n]*', Text, 'textline'),
474 ], 475 ],
475 'textline': [ 476 'textline': [
479 ], 480 ],
480 'escapes': [ 481 'escapes': [
481 # groff has many ways to write escapes. 482 # groff has many ways to write escapes.
482 (r'\\"[^\n]*', Comment), 483 (r'\\"[^\n]*', Comment),
483 (r'\\[fn]\w', String.Escape), 484 (r'\\[fn]\w', String.Escape),
484 (r'\\\(..', String.Escape), 485 (r'\\\(.{2}', String.Escape),
485 (r'\\.\[.*\]', String.Escape), 486 (r'\\.\[.*\]', String.Escape),
486 (r'\\.', String.Escape), 487 (r'\\.', String.Escape),
487 (r'\\\n', Text, 'request'), 488 (r'\\\n', Text, 'request'),
488 ], 489 ],
489 'request': [ 490 'request': [
611 mimetypes = ["text/x-rst", "text/prs.fallenstein.rst"] 612 mimetypes = ["text/x-rst", "text/prs.fallenstein.rst"]
612 flags = re.MULTILINE 613 flags = re.MULTILINE
613 614
614 def _handle_sourcecode(self, match): 615 def _handle_sourcecode(self, match):
615 from pygments.lexers import get_lexer_by_name 616 from pygments.lexers import get_lexer_by_name
616 from pygments.util import ClassNotFound
617 617
618 # section header 618 # section header
619 yield match.start(1), Punctuation, match.group(1) 619 yield match.start(1), Punctuation, match.group(1)
620 yield match.start(2), Text, match.group(2) 620 yield match.start(2), Text, match.group(2)
621 yield match.start(3), Operator.Word, match.group(3) 621 yield match.start(3), Operator.Word, match.group(3)
650 code += line[indention_size:] 650 code += line[indention_size:]
651 else: 651 else:
652 code += line 652 code += line
653 for item in do_insertions(ins, lexer.get_tokens_unprocessed(code)): 653 for item in do_insertions(ins, lexer.get_tokens_unprocessed(code)):
654 yield item 654 yield item
655
656 # from docutils.parsers.rst.states
657 closers = '\'")]}>\u2019\u201d\xbb!?'
658 unicode_delimiters = '\u2010\u2011\u2012\u2013\u2014\u00a0'
659 end_string_suffix = (r'((?=$)|(?=[-/:.,; \n\x00%s%s]))'
660 % (re.escape(unicode_delimiters),
661 re.escape(closers)))
655 662
656 tokens = { 663 tokens = {
657 'root': [ 664 'root': [
658 # Heading with overline 665 # Heading with overline
659 (r'^(=+|-+|`+|:+|\.+|\'+|"+|~+|\^+|_+|\*+|\++|#+)([ \t]*\n)' 666 (r'^(=+|-+|`+|:+|\.+|\'+|"+|~+|\^+|_+|\*+|\++|#+)([ \t]*\n)'
687 # A directive 694 # A directive
688 (r'^( *\.\.)(\s*)([\w:-]+?)(::)(?:([ \t]*)(.*))', 695 (r'^( *\.\.)(\s*)([\w:-]+?)(::)(?:([ \t]*)(.*))',
689 bygroups(Punctuation, Text, Operator.Word, Punctuation, Text, 696 bygroups(Punctuation, Text, Operator.Word, Punctuation, Text,
690 using(this, state='inline'))), 697 using(this, state='inline'))),
691 # A reference target 698 # A reference target
692 (r'^( *\.\.)(\s*)([\w\t ]+:)(.*?)$', 699 (r'^( *\.\.)(\s*)(_(?:[^:\\]|\\.)+:)(.*?)$',
693 bygroups(Punctuation, Text, Name.Tag, using(this, state='inline'))), 700 bygroups(Punctuation, Text, Name.Tag, using(this, state='inline'))),
694 # A footnote target 701 # A footnote/citation target
695 (r'^( *\.\.)(\s*)(\[.+\])(.*?)$', 702 (r'^( *\.\.)(\s*)(\[.+\])(.*?)$',
696 bygroups(Punctuation, Text, Name.Tag, using(this, state='inline'))), 703 bygroups(Punctuation, Text, Name.Tag, using(this, state='inline'))),
697 # A substitution def 704 # A substitution def
698 (r'^( *\.\.)(\s*)(\|.+\|)(\s*)([\w:-]+?)(::)(?:([ \t]*)(.*))', 705 (r'^( *\.\.)(\s*)(\|.+\|)(\s*)([\w:-]+?)(::)(?:([ \t]*)(.*))',
699 bygroups(Punctuation, Text, Name.Tag, Text, Operator.Word, 706 bygroups(Punctuation, Text, Name.Tag, Text, Operator.Word,
728 (r'<.+?>', Name.Tag), # Hyperlink 735 (r'<.+?>', Name.Tag), # Hyperlink
729 (r'[^\\\n\[*`:]+', Text), 736 (r'[^\\\n\[*`:]+', Text),
730 (r'.', Text), 737 (r'.', Text),
731 ], 738 ],
732 'literal': [ 739 'literal': [
733 (r'[^`\\]+', String), 740 (r'[^`]+', String),
734 (r'\\.', String), 741 (r'``' + end_string_suffix, String, '#pop'),
735 (r'``', String, '#pop'), 742 (r'`', String),
736 (r'[`\\]', String),
737 ] 743 ]
738 } 744 }
739 745
740 def __init__(self, **options): 746 def __init__(self, **options):
741 self.handlecodeblocks = get_bool_opt(options, 'handlecodeblocks', True) 747 self.handlecodeblocks = get_bool_opt(options, 'handlecodeblocks', True)
759 765
760 *New in Pygments 0.8.* 766 *New in Pygments 0.8.*
761 """ 767 """
762 name = 'VimL' 768 name = 'VimL'
763 aliases = ['vim'] 769 aliases = ['vim']
764 filenames = ['*.vim', '.vimrc'] 770 filenames = ['*.vim', '.vimrc', '.exrc', '.gvimrc',
771 '_vimrc', '_exrc', '_gvimrc', 'vimrc', 'gvimrc']
765 mimetypes = ['text/x-vim'] 772 mimetypes = ['text/x-vim']
766 flags = re.MULTILINE 773 flags = re.MULTILINE
767 774
768 tokens = { 775 tokens = {
769 'root': [ 776 'root': [
770 # Who decided that doublequote was a good comment character??
771 (r'^\s*".*', Comment), 777 (r'^\s*".*', Comment),
772 (r'(?<=\s)"[^\-:.%#=*].*', Comment),
773 778
774 (r'[ \t]+', Text), 779 (r'[ \t]+', Text),
775 # TODO: regexes can have other delims 780 # TODO: regexes can have other delims
776 (r'/(\\\\|\\/|[^\n/])*/', String.Regex), 781 (r'/(\\\\|\\/|[^\n/])*/', String.Regex),
777 (r'"(\\\\|\\"|[^\n"])*"', String.Double), 782 (r'"(\\\\|\\"|[^\n"])*"', String.Double),
778 (r"'(\\\\|\\'|[^\n'])*'", String.Single), 783 (r"'(\\\\|\\'|[^\n'])*'", String.Single),
784
785 # Who decided that doublequote was a good comment character??
786 (r'(?<=\s)"[^\-:.%#=*].*', Comment),
779 (r'-?\d+', Number), 787 (r'-?\d+', Number),
780 (r'#[0-9a-f]{6}', Number.Hex), 788 (r'#[0-9a-f]{6}', Number.Hex),
781 (r'^:', Punctuation), 789 (r'^:', Punctuation),
782 (r'[()<>+=!|,~-]', Punctuation), # Inexact list. Looks decent. 790 (r'[()<>+=!|,~-]', Punctuation), # Inexact list. Looks decent.
783 (r'\b(let|if|else|endif|elseif|fun|function|endfunction)\b', 791 (r'\b(let|if|else|endif|elseif|fun|function|endfunction)\b',
874 aliases = ['squidconf', 'squid.conf', 'squid'] 882 aliases = ['squidconf', 'squid.conf', 'squid']
875 filenames = ['squid.conf'] 883 filenames = ['squid.conf']
876 mimetypes = ['text/x-squidconf'] 884 mimetypes = ['text/x-squidconf']
877 flags = re.IGNORECASE 885 flags = re.IGNORECASE
878 886
879 keywords = [ "acl", "always_direct", "announce_host", 887 keywords = [
880 "announce_period", "announce_port", "announce_to", 888 "access_log", "acl", "always_direct", "announce_host",
881 "anonymize_headers", "append_domain", "as_whois_server", 889 "announce_period", "announce_port", "announce_to", "anonymize_headers",
882 "auth_param_basic", "authenticate_children", 890 "append_domain", "as_whois_server", "auth_param_basic",
883 "authenticate_program", "authenticate_ttl", "broken_posts", 891 "authenticate_children", "authenticate_program", "authenticate_ttl",
884 "buffered_logs", "cache_access_log", "cache_announce", 892 "broken_posts", "buffered_logs", "cache_access_log", "cache_announce",
885 "cache_dir", "cache_dns_program", "cache_effective_group", 893 "cache_dir", "cache_dns_program", "cache_effective_group",
886 "cache_effective_user", "cache_host", "cache_host_acl", 894 "cache_effective_user", "cache_host", "cache_host_acl",
887 "cache_host_domain", "cache_log", "cache_mem", 895 "cache_host_domain", "cache_log", "cache_mem", "cache_mem_high",
888 "cache_mem_high", "cache_mem_low", "cache_mgr", 896 "cache_mem_low", "cache_mgr", "cachemgr_passwd", "cache_peer",
889 "cachemgr_passwd", "cache_peer", "cache_peer_access", 897 "cache_peer_access", "cahce_replacement_policy", "cache_stoplist",
890 "cahce_replacement_policy", "cache_stoplist", 898 "cache_stoplist_pattern", "cache_store_log", "cache_swap",
891 "cache_stoplist_pattern", "cache_store_log", "cache_swap", 899 "cache_swap_high", "cache_swap_log", "cache_swap_low", "client_db",
892 "cache_swap_high", "cache_swap_log", "cache_swap_low", 900 "client_lifetime", "client_netmask", "connect_timeout", "coredump_dir",
893 "client_db", "client_lifetime", "client_netmask", 901 "dead_peer_timeout", "debug_options", "delay_access", "delay_class",
894 "connect_timeout", "coredump_dir", "dead_peer_timeout", 902 "delay_initial_bucket_level", "delay_parameters", "delay_pools",
895 "debug_options", "delay_access", "delay_class", 903 "deny_info", "dns_children", "dns_defnames", "dns_nameservers",
896 "delay_initial_bucket_level", "delay_parameters", 904 "dns_testnames", "emulate_httpd_log", "err_html_text",
897 "delay_pools", "deny_info", "dns_children", "dns_defnames", 905 "fake_user_agent", "firewall_ip", "forwarded_for", "forward_snmpd_port",
898 "dns_nameservers", "dns_testnames", "emulate_httpd_log", 906 "fqdncache_size", "ftpget_options", "ftpget_program", "ftp_list_width",
899 "err_html_text", "fake_user_agent", "firewall_ip", 907 "ftp_passive", "ftp_user", "half_closed_clients", "header_access",
900 "forwarded_for", "forward_snmpd_port", "fqdncache_size", 908 "header_replace", "hierarchy_stoplist", "high_response_time_warning",
901 "ftpget_options", "ftpget_program", "ftp_list_width", 909 "high_page_fault_warning", "hosts_file", "htcp_port", "http_access",
902 "ftp_passive", "ftp_user", "half_closed_clients", 910 "http_anonymizer", "httpd_accel", "httpd_accel_host",
903 "header_access", "header_replace", "hierarchy_stoplist", 911 "httpd_accel_port", "httpd_accel_uses_host_header",
904 "high_response_time_warning", "high_page_fault_warning", 912 "httpd_accel_with_proxy", "http_port", "http_reply_access",
905 "htcp_port", "http_access", "http_anonymizer", "httpd_accel", 913 "icp_access", "icp_hit_stale", "icp_port", "icp_query_timeout",
906 "httpd_accel_host", "httpd_accel_port", 914 "ident_lookup", "ident_lookup_access", "ident_timeout",
907 "httpd_accel_uses_host_header", "httpd_accel_with_proxy", 915 "incoming_http_average", "incoming_icp_average", "inside_firewall",
908 "http_port", "http_reply_access", "icp_access", 916 "ipcache_high", "ipcache_low", "ipcache_size", "local_domain",
909 "icp_hit_stale", "icp_port", "icp_query_timeout", 917 "local_ip", "logfile_rotate", "log_fqdn", "log_icp_queries",
910 "ident_lookup", "ident_lookup_access", "ident_timeout", 918 "log_mime_hdrs", "maximum_object_size", "maximum_single_addr_tries",
911 "incoming_http_average", "incoming_icp_average", 919 "mcast_groups", "mcast_icp_query_timeout", "mcast_miss_addr",
912 "inside_firewall", "ipcache_high", "ipcache_low", 920 "mcast_miss_encode_key", "mcast_miss_port", "memory_pools",
913 "ipcache_size", "local_domain", "local_ip", "logfile_rotate", 921 "memory_pools_limit", "memory_replacement_policy", "mime_table",
914 "log_fqdn", "log_icp_queries", "log_mime_hdrs", 922 "min_http_poll_cnt", "min_icp_poll_cnt", "minimum_direct_hops",
915 "maximum_object_size", "maximum_single_addr_tries", 923 "minimum_object_size", "minimum_retry_timeout", "miss_access",
916 "mcast_groups", "mcast_icp_query_timeout", "mcast_miss_addr", 924 "negative_dns_ttl", "negative_ttl", "neighbor_timeout",
917 "mcast_miss_encode_key", "mcast_miss_port", "memory_pools", 925 "neighbor_type_domain", "netdb_high", "netdb_low", "netdb_ping_period",
918 "memory_pools_limit", "memory_replacement_policy", 926 "netdb_ping_rate", "never_direct", "no_cache", "passthrough_proxy",
919 "mime_table", "min_http_poll_cnt", "min_icp_poll_cnt", 927 "pconn_timeout", "pid_filename", "pinger_program", "positive_dns_ttl",
920 "minimum_direct_hops", "minimum_object_size", 928 "prefer_direct", "proxy_auth", "proxy_auth_realm", "query_icmp",
921 "minimum_retry_timeout", "miss_access", "negative_dns_ttl", 929 "quick_abort", "quick_abort", "quick_abort_max", "quick_abort_min",
922 "negative_ttl", "neighbor_timeout", "neighbor_type_domain", 930 "quick_abort_pct", "range_offset_limit", "read_timeout",
923 "netdb_high", "netdb_low", "netdb_ping_period", 931 "redirect_children", "redirect_program",
924 "netdb_ping_rate", "never_direct", "no_cache", 932 "redirect_rewrites_host_header", "reference_age", "reference_age",
925 "passthrough_proxy", "pconn_timeout", "pid_filename", 933 "refresh_pattern", "reload_into_ims", "request_body_max_size",
926 "pinger_program", "positive_dns_ttl", "prefer_direct", 934 "request_size", "request_timeout", "shutdown_lifetime",
927 "proxy_auth", "proxy_auth_realm", "query_icmp", "quick_abort", 935 "single_parent_bypass", "siteselect_timeout", "snmp_access",
928 "quick_abort", "quick_abort_max", "quick_abort_min", 936 "snmp_incoming_address", "snmp_port", "source_ping", "ssl_proxy",
929 "quick_abort_pct", "range_offset_limit", "read_timeout", 937 "store_avg_object_size", "store_objects_per_bucket",
930 "redirect_children", "redirect_program", 938 "strip_query_terms", "swap_level1_dirs", "swap_level2_dirs",
931 "redirect_rewrites_host_header", "reference_age", 939 "tcp_incoming_address", "tcp_outgoing_address", "tcp_recv_bufsize",
932 "reference_age", "refresh_pattern", "reload_into_ims", 940 "test_reachability", "udp_hit_obj", "udp_hit_obj_size",
933 "request_body_max_size", "request_size", "request_timeout", 941 "udp_incoming_address", "udp_outgoing_address", "unique_hostname",
934 "shutdown_lifetime", "single_parent_bypass", 942 "unlinkd_program", "uri_whitespace", "useragent_log",
935 "siteselect_timeout", "snmp_access", "snmp_incoming_address", 943 "visible_hostname", "wais_relay", "wais_relay_host", "wais_relay_port",
936 "snmp_port", "source_ping", "ssl_proxy", 944 ]
937 "store_avg_object_size", "store_objects_per_bucket", 945
938 "strip_query_terms", "swap_level1_dirs", "swap_level2_dirs", 946 opts = [
939 "tcp_incoming_address", "tcp_outgoing_address", 947 "proxy-only", "weight", "ttl", "no-query", "default", "round-robin",
940 "tcp_recv_bufsize", "test_reachability", "udp_hit_obj", 948 "multicast-responder", "on", "off", "all", "deny", "allow", "via",
941 "udp_hit_obj_size", "udp_incoming_address", 949 "parent", "no-digest", "heap", "lru", "realm", "children", "q1", "q2",
942 "udp_outgoing_address", "unique_hostname", "unlinkd_program", 950 "credentialsttl", "none", "disable", "offline_toggle", "diskd",
943 "uri_whitespace", "useragent_log", "visible_hostname", 951 ]
944 "wais_relay", "wais_relay_host", "wais_relay_port", 952
945 ] 953 actions = [
946 954 "shutdown", "info", "parameter", "server_list", "client_list",
947 opts = [ "proxy-only", "weight", "ttl", "no-query", "default", 955 r'squid\.conf',
948 "round-robin", "multicast-responder", "on", "off", "all", 956 ]
949 "deny", "allow", "via", "parent", "no-digest", "heap", "lru", 957
950 "realm", "children", "credentialsttl", "none", "disable", 958 actions_stats = [
951 "offline_toggle", "diskd", "q1", "q2", 959 "objects", "vm_objects", "utilization", "ipcache", "fqdncache", "dns",
952 ] 960 "redirector", "io", "reply_headers", "filedescriptors", "netdb",
953 961 ]
954 actions = [ "shutdown", "info", "parameter", "server_list", 962
955 "client_list", r'squid\.conf', 963 actions_log = ["status", "enable", "disable", "clear"]
956 ] 964
957 965 acls = [
958 actions_stats = [ "objects", "vm_objects", "utilization", 966 "url_regex", "urlpath_regex", "referer_regex", "port", "proto",
959 "ipcache", "fqdncache", "dns", "redirector", "io", 967 "req_mime_type", "rep_mime_type", "method", "browser", "user", "src",
960 "reply_headers", "filedescriptors", "netdb", 968 "dst", "time", "dstdomain", "ident", "snmp_community",
961 ] 969 ]
962 970
963 actions_log = [ "status", "enable", "disable", "clear"] 971 ip_re = (
964 972 r'(?:(?:(?:[3-9]\d?|2(?:5[0-5]|[0-4]?\d)?|1\d{0,2}|0x0*[0-9a-f]{1,2}|'
965 acls = [ "url_regex", "urlpath_regex", "referer_regex", "port", 973 r'0+[1-3]?[0-7]{0,2})(?:\.(?:[3-9]\d?|2(?:5[0-5]|[0-4]?\d)?|1\d{0,2}|'
966 "proto", "req_mime_type", "rep_mime_type", "method", 974 r'0x0*[0-9a-f]{1,2}|0+[1-3]?[0-7]{0,2})){3})|(?!.*::.*::)(?:(?!:)|'
967 "browser", "user", "src", "dst", "time", "dstdomain", "ident", 975 r':(?=:))(?:[0-9a-f]{0,4}(?:(?<=::)|(?<!::):)){6}(?:[0-9a-f]{0,4}'
968 "snmp_community", 976 r'(?:(?<=::)|(?<!::):)[0-9a-f]{0,4}(?:(?<=::)|(?<!:)|(?<=:)(?<!::):)|'
969 ] 977 r'(?:25[0-4]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-4]|2[0-4]\d|1\d\d|'
970 978 r'[1-9]?\d)){3}))'
971 ip_re = r'\b(?:\d{1,3}\.){3}\d{1,3}\b' 979 )
972 980
973 def makelistre(list): 981 def makelistre(list):
974 return r'\b(?:'+'|'.join(list)+r')\b' 982 return r'\b(?:' + '|'.join(list) + r')\b'
975 983
976 tokens = { 984 tokens = {
977 'root': [ 985 'root': [
978 (r'\s+', Text), 986 (r'\s+', Whitespace),
979 (r'#', Comment, 'comment'), 987 (r'#', Comment, 'comment'),
980 (makelistre(keywords), Keyword), 988 (makelistre(keywords), Keyword),
981 (makelistre(opts), Name.Constant), 989 (makelistre(opts), Name.Constant),
982 # Actions 990 # Actions
983 (makelistre(actions), String), 991 (makelistre(actions), String),
984 (r'stats/'+makelistre(actions), String), 992 (r'stats/'+makelistre(actions), String),
985 (r'log/'+makelistre(actions)+r'=', String), 993 (r'log/'+makelistre(actions)+r'=', String),
986 (makelistre(acls), Keyword), 994 (makelistre(acls), Keyword),
987 (ip_re+r'(?:/(?:'+ip_re+r')|\d+)?', Number), 995 (ip_re + r'(?:/(?:' + ip_re + r'|\b\d+\b))?', Number.Float),
988 (r'\b\d+\b', Number), 996 (r'(?:\b\d+\b(?:-\b\d+|%)?)', Number),
989 (r'\S+', Text), 997 (r'\S+', Text),
990 ], 998 ],
991 'comment': [ 999 'comment': [
992 (r'\s*TAG:.*', String.Escape, '#pop'), 1000 (r'\s*TAG:.*', String.Escape, '#pop'),
993 (r'.*', Comment, '#pop'), 1001 (r'.*', Comment, '#pop'),
1008 tokens = { 1016 tokens = {
1009 'root': [ 1017 'root': [
1010 (r'^(Description)', Keyword, 'description'), 1018 (r'^(Description)', Keyword, 'description'),
1011 (r'^(Maintainer)(:\s*)', bygroups(Keyword, Text), 'maintainer'), 1019 (r'^(Maintainer)(:\s*)', bygroups(Keyword, Text), 'maintainer'),
1012 (r'^((Build-)?Depends)', Keyword, 'depends'), 1020 (r'^((Build-)?Depends)', Keyword, 'depends'),
1013 (r'^((?:Python-)?Version)(:\s*)([^\s]+)$', 1021 (r'^((?:Python-)?Version)(:\s*)(\S+)$',
1014 bygroups(Keyword, Text, Number)), 1022 bygroups(Keyword, Text, Number)),
1015 (r'^((?:Installed-)?Size)(:\s*)([^\s]+)$', 1023 (r'^((?:Installed-)?Size)(:\s*)(\S+)$',
1016 bygroups(Keyword, Text, Number)), 1024 bygroups(Keyword, Text, Number)),
1017 (r'^(MD5Sum|SHA1|SHA256)(:\s*)([^\s]+)$', 1025 (r'^(MD5Sum|SHA1|SHA256)(:\s*)(\S+)$',
1018 bygroups(Keyword, Text, Number)), 1026 bygroups(Keyword, Text, Number)),
1019 (r'^([a-zA-Z\-0-9\.]*?)(:\s*)(.*?)$', 1027 (r'^([a-zA-Z\-0-9\.]*?)(:\s*)(.*?)$',
1020 bygroups(Keyword, Whitespace, String)), 1028 bygroups(Keyword, Whitespace, String)),
1021 ], 1029 ],
1022 'maintainer': [ 1030 'maintainer': [
1024 (r'<[^>]+>$', Generic.Strong, '#pop'), 1032 (r'<[^>]+>$', Generic.Strong, '#pop'),
1025 (r',\n?', Text), 1033 (r',\n?', Text),
1026 (r'.', Text), 1034 (r'.', Text),
1027 ], 1035 ],
1028 'description': [ 1036 'description': [
1029 (r'(.*)(Homepage)(: )([^\s]+)', bygroups(Text, String, Name, Name.Class)), 1037 (r'(.*)(Homepage)(: )(\S+)',
1038 bygroups(Text, String, Name, Name.Class)),
1030 (r':.*\n', Generic.Strong), 1039 (r':.*\n', Generic.Strong),
1031 (r' .*\n', Text), 1040 (r' .*\n', Text),
1032 ('', Text, '#pop'), 1041 ('', Text, '#pop'),
1033 ], 1042 ],
1034 'depends': [ 1043 'depends': [
1037 (r'\(', Text, 'depend_vers'), 1046 (r'\(', Text, 'depend_vers'),
1038 (r',', Text), 1047 (r',', Text),
1039 (r'\|', Operator), 1048 (r'\|', Operator),
1040 (r'[\s]+', Text), 1049 (r'[\s]+', Text),
1041 (r'[}\)]\s*$', Text, '#pop'), 1050 (r'[}\)]\s*$', Text, '#pop'),
1042 (r'[}]', Text), 1051 (r'}', Text),
1043 (r'[^,]$', Name.Function, '#pop'), 1052 (r'[^,]$', Name.Function, '#pop'),
1044 (r'([\+\.a-zA-Z0-9-][\s\n]*)', Name.Function), 1053 (r'([\+\.a-zA-Z0-9-])(\s*)', bygroups(Name.Function, Text)),
1045 (r'\[.*?\]', Name.Entity), 1054 (r'\[.*?\]', Name.Entity),
1046 ], 1055 ],
1047 'depend_vers': [ 1056 'depend_vers': [
1048 (r'\),', Text, '#pop'), 1057 (r'\),', Text, '#pop'),
1049 (r'\)[^,]', Text, '#pop:2'), 1058 (r'\)[^,]', Text, '#pop:2'),
1376 ], 1385 ],
1377 1386
1378 # ignored and regular whitespaces in quoted scalars 1387 # ignored and regular whitespaces in quoted scalars
1379 'quoted-scalar-whitespaces': [ 1388 'quoted-scalar-whitespaces': [
1380 # leading and trailing whitespaces are ignored 1389 # leading and trailing whitespaces are ignored
1381 (r'^[ ]+|[ ]+$', Text), 1390 (r'^[ ]+', Text),
1391 (r'[ ]+$', Text),
1382 # line breaks are ignored 1392 # line breaks are ignored
1383 (r'\n+', Text), 1393 (r'\n+', Text),
1384 # other whitespaces are a part of the value 1394 # other whitespaces are a part of the value
1385 (r'[ ]+', Name.Variable), 1395 (r'[ ]+', Name.Variable),
1386 ], 1396 ],
1445 # the scalar ends with an indicator character 1455 # the scalar ends with an indicator character
1446 (r'[ ]*(?=[,:?\[\]{}])', something(Text), '#pop'), 1456 (r'[ ]*(?=[,:?\[\]{}])', something(Text), '#pop'),
1447 # the scalar ends with a comment 1457 # the scalar ends with a comment
1448 (r'[ ]+(?=#)', Text, '#pop'), 1458 (r'[ ]+(?=#)', Text, '#pop'),
1449 # leading and trailing whitespaces are ignored 1459 # leading and trailing whitespaces are ignored
1450 (r'^[ ]+|[ ]+$', Text), 1460 (r'^[ ]+', Text),
1461 (r'[ ]+$', Text),
1451 # line breaks are ignored 1462 # line breaks are ignored
1452 (r'\n+', Text), 1463 (r'\n+', Text),
1453 # other whitespaces are a part of the value 1464 # other whitespaces are a part of the value
1454 (r'[ ]+', Name.Variable), 1465 (r'[ ]+', Name.Variable),
1455 # regular non-whitespace characters 1466 # regular non-whitespace characters
1604 (r'[ \t]+', Text), 1615 (r'[ \t]+', Text),
1605 (r'#.+\n', Comment), 1616 (r'#.+\n', Comment),
1606 ] 1617 ]
1607 } 1618 }
1608 1619
1620
1621 class HttpLexer(RegexLexer):
1622 """
1623 Lexer for HTTP sessions.
1624
1625 *New in Pygments 1.5.*
1626 """
1627
1628 name = 'HTTP'
1629 aliases = ['http']
1630
1631 flags = re.DOTALL
1632
1633 def header_callback(self, match):
1634 if match.group(1).lower() == 'content-type':
1635 content_type = match.group(5).strip()
1636 if ';' in content_type:
1637 content_type = content_type[:content_type.find(';')].strip()
1638 self.content_type = content_type
1639 yield match.start(1), Name.Attribute, match.group(1)
1640 yield match.start(2), Text, match.group(2)
1641 yield match.start(3), Operator, match.group(3)
1642 yield match.start(4), Text, match.group(4)
1643 yield match.start(5), Literal, match.group(5)
1644 yield match.start(6), Text, match.group(6)
1645
1646 def content_callback(self, match):
1647 content_type = getattr(self, 'content_type', None)
1648 content = match.group()
1649 offset = match.start()
1650 if content_type:
1651 from pygments.lexers import get_lexer_for_mimetype
1652 try:
1653 lexer = get_lexer_for_mimetype(content_type)
1654 except ClassNotFound:
1655 pass
1656 else:
1657 for idx, token, value in lexer.get_tokens_unprocessed(content):
1658 yield offset + idx, token, value
1659 return
1660 yield offset, Text, content
1661
1662 tokens = {
1663 'root': [
1664 (r'(GET|POST|PUT|DELETE|HEAD|OPTIONS|TRACE)( +)([^ ]+)( +)'
1665 r'(HTTPS?)(/)(1\.[01])(\r?\n|$)',
1666 bygroups(Name.Function, Text, Name.Namespace, Text,
1667 Keyword.Reserved, Operator, Number, Text),
1668 'headers'),
1669 (r'(HTTPS?)(/)(1\.[01])( +)(\d{3})( +)([^\r\n]+)(\r?\n|$)',
1670 bygroups(Keyword.Reserved, Operator, Number, Text, Number,
1671 Text, Name.Exception, Text),
1672 'headers'),
1673 ],
1674 'headers': [
1675 (r'([^\s:]+)( *)(:)( *)([^\r\n]+)(\r?\n|$)', header_callback),
1676 (r'\r?\n', Text, 'content')
1677 ],
1678 'content': [
1679 (r'.+', content_callback)
1680 ]
1681 }
1682
1683
1684 class PyPyLogLexer(RegexLexer):
1685 """
1686 Lexer for PyPy log files.
1687
1688 *New in Pygments 1.5.*
1689 """
1690 name = "PyPy Log"
1691 aliases = ["pypylog", "pypy"]
1692 filenames = ["*.pypylog"]
1693 mimetypes = ['application/x-pypylog']
1694
1695 tokens = {
1696 "root": [
1697 (r"\[\w+\] {jit-log-.*?$", Keyword, "jit-log"),
1698 (r"\[\w+\] {jit-backend-counts$", Keyword, "jit-backend-counts"),
1699 include("extra-stuff"),
1700 ],
1701 "jit-log": [
1702 (r"\[\w+\] jit-log-.*?}$", Keyword, "#pop"),
1703
1704 (r"^\+\d+: ", Comment),
1705 (r"[ifp]\d+", Name),
1706 (r"ptr\d+", Name),
1707 (r"(\()(\w+(?:\.\w+)?)(\))",
1708 bygroups(Punctuation, Name.Builtin, Punctuation)),
1709 (r"[\[\]=,()]", Punctuation),
1710 (r"(\d+\.\d+|inf|-inf)", Number.Float),
1711 (r"-?\d+", Number.Integer),
1712 (r"'.*'", String),
1713 (r"(None|descr|ConstClass|ConstPtr|TargetToken)", Name),
1714 (r"<.*?>", Name.Builtin),
1715 (r"(label|debug_merge_point|jump|finish)", Name.Class),
1716 (r"(int_add_ovf|int_add|int_sub_ovf|int_sub|int_mul_ovf|int_mul|"
1717 r"int_floordiv|int_mod|int_lshift|int_rshift|int_and|int_or|"
1718 r"int_xor|int_eq|int_ne|int_ge|int_gt|int_le|int_lt|int_is_zero|"
1719 r"int_is_true|"
1720 r"uint_floordiv|uint_ge|uint_lt|"
1721 r"float_add|float_sub|float_mul|float_truediv|"
1722 r"float_eq|float_ne|float_ge|float_gt|float_le|float_lt|float_abs|"
1723 r"ptr_eq|ptr_ne|instance_ptr_eq|instance_ptr_ne|"
1724 r"cast_int_to_float|cast_float_to_int|"
1725 r"force_token|quasiimmut_field|same_as|virtual_ref_finish|"
1726 r"virtual_ref|mark_opaque_ptr|"
1727 r"call_may_force|call_assembler|call_loopinvariant|"
1728 r"call_release_gil|call_pure|call|"
1729 r"new_with_vtable|new_array|newstr|newunicode|new|"
1730 r"arraylen_gc|"
1731 r"getarrayitem_gc_pure|getarrayitem_gc|setarrayitem_gc|"
1732 r"getarrayitem_raw|setarrayitem_raw|getfield_gc_pure|"
1733 r"getfield_gc|getinteriorfield_gc|setinteriorfield_gc|"
1734 r"getfield_raw|setfield_gc|setfield_raw|"
1735 r"strgetitem|strsetitem|strlen|copystrcontent|"
1736 r"unicodegetitem|unicodesetitem|unicodelen|"
1737 r"guard_true|guard_false|guard_value|guard_isnull|"
1738 r"guard_nonnull_class|guard_nonnull|guard_class|guard_no_overflow|"
1739 r"guard_not_forced|guard_no_exception|guard_not_invalidated)",
1740 Name.Builtin),
1741 include("extra-stuff"),
1742 ],
1743 "jit-backend-counts": [
1744 (r"\[\w+\] jit-backend-counts}$", Keyword, "#pop"),
1745 (r":", Punctuation),
1746 (r"\d+", Number),
1747 include("extra-stuff"),
1748 ],
1749 "extra-stuff": [
1750 (r"\s+", Text),
1751 (r"#.*?$", Comment),
1752 ],
1753 }

eric ide

mercurial