home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_2372 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  41.6 KB  |  1,335 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import re
  5. from bisect import bisect
  6. from pygments.lexer import Lexer, LexerContext, RegexLexer, ExtendedRegexLexer, bygroups, include, using, this, do_insertions
  7. from pygments.token import Punctuation, Text, Comment, Keyword, Name, String, Generic, Operator, Number, Whitespace, Literal
  8. from pygments.util import get_bool_opt
  9. from pygments.lexers.other import BashLexer
  10. __all__ = [
  11.     'IniLexer',
  12.     'SourcesListLexer',
  13.     'BaseMakefileLexer',
  14.     'MakefileLexer',
  15.     'DiffLexer',
  16.     'IrcLogsLexer',
  17.     'TexLexer',
  18.     'GroffLexer',
  19.     'ApacheConfLexer',
  20.     'BBCodeLexer',
  21.     'MoinWikiLexer',
  22.     'RstLexer',
  23.     'VimLexer',
  24.     'GettextLexer',
  25.     'SquidConfLexer',
  26.     'DebianControlLexer',
  27.     'DarcsPatchLexer',
  28.     'YamlLexer',
  29.     'LighttpdConfLexer',
  30.     'NginxConfLexer',
  31.     'CMakeLexer']
  32.  
  33. class IniLexer(RegexLexer):
  34.     name = 'INI'
  35.     aliases = [
  36.         'ini',
  37.         'cfg']
  38.     filenames = [
  39.         '*.ini',
  40.         '*.cfg',
  41.         '*.properties']
  42.     mimetypes = [
  43.         'text/x-ini']
  44.     tokens = {
  45.         'root': [
  46.             ('\\s+', Text),
  47.             ('[;#].*?$', Comment),
  48.             ('\\[.*?\\]$', Keyword),
  49.             ('(.*?)([ \\t]*)(=)([ \\t]*)(.*?)$', bygroups(Name.Attribute, Text, Operator, Text, String))] }
  50.     
  51.     def analyse_text(text):
  52.         npos = text.find('\n')
  53.         if npos < 3:
  54.             return False
  55.         if text[0] == '[':
  56.             pass
  57.         return text[npos - 1] == ']'
  58.  
  59.  
  60.  
  61. class SourcesListLexer(RegexLexer):
  62.     name = 'Debian Sourcelist'
  63.     aliases = [
  64.         'sourceslist',
  65.         'sources.list']
  66.     filenames = [
  67.         'sources.list']
  68.     mimetype = [
  69.         'application/x-debian-sourceslist']
  70.     tokens = {
  71.         'root': [
  72.             ('\\s+', Text),
  73.             ('#.*?$', Comment),
  74.             ('^(deb(?:-src)?)(\\s+)', bygroups(Keyword, Text), 'distribution')],
  75.         'distribution': [
  76.             ('#.*?$', Comment, '#pop'),
  77.             ('\\$\\(ARCH\\)', Name.Variable),
  78.             ('[^\\s$[]+', String),
  79.             ('\\[', String.Other, 'escaped-distribution'),
  80.             ('\\$', String),
  81.             ('\\s+', Text, 'components')],
  82.         'escaped-distribution': [
  83.             ('\\]', String.Other, '#pop'),
  84.             ('\\$\\(ARCH\\)', Name.Variable),
  85.             ('[^\\]$]+', String.Other),
  86.             ('\\$', String.Other)],
  87.         'components': [
  88.             ('#.*?$', Comment, '#pop:2'),
  89.             ('$', Text, '#pop:2'),
  90.             ('\\s+', Text),
  91.             ('\\S+', Keyword.Pseudo)] }
  92.     
  93.     def analyse_text(text):
  94.         for line in text.split('\n'):
  95.             line = line.strip()
  96.             if not line.startswith('#') and line.startswith('deb ') and line.startswith('deb-src ') or not line:
  97.                 return False
  98.         
  99.         return True
  100.  
  101.  
  102.  
  103. class MakefileLexer(Lexer):
  104.     name = 'Makefile'
  105.     aliases = [
  106.         'make',
  107.         'makefile',
  108.         'mf',
  109.         'bsdmake']
  110.     filenames = [
  111.         '*.mak',
  112.         'Makefile',
  113.         'makefile',
  114.         'Makefile.*',
  115.         'GNUmakefile']
  116.     mimetypes = [
  117.         'text/x-makefile']
  118.     r_special = re.compile('^(?:\\.\\s*(include|undef|error|warning|if|else|elif|endif|for|endfor)|\\s*(ifeq|ifneq|ifdef|ifndef|else|endif|-?include|define|endef|:))(?=\\s)')
  119.     r_comment = re.compile('^\\s*@?#')
  120.     
  121.     def get_tokens_unprocessed(self, text):
  122.         ins = []
  123.         lines = text.splitlines(True)
  124.         done = ''
  125.         lex = BaseMakefileLexer(**self.options)
  126.         backslashflag = False
  127.         for line in lines:
  128.             if self.r_special.match(line) or backslashflag:
  129.                 ins.append((len(done), [
  130.                     (0, Comment.Preproc, line)]))
  131.                 backslashflag = line.strip().endswith('\\')
  132.                 continue
  133.             if self.r_comment.match(line):
  134.                 ins.append((len(done), [
  135.                     (0, Comment, line)]))
  136.                 continue
  137.             done += line
  138.         
  139.         for item in do_insertions(ins, lex.get_tokens_unprocessed(done)):
  140.             yield item
  141.         
  142.  
  143.  
  144.  
  145. class BaseMakefileLexer(RegexLexer):
  146.     name = 'Makefile'
  147.     aliases = [
  148.         'basemake']
  149.     filenames = []
  150.     mimetypes = []
  151.     tokens = {
  152.         'root': [
  153.             ('^(?:[\\t ]+.*\\n|\\n)+', using(BashLexer)),
  154.             ('\\$\\((?:.*\\\\\\n|.*\\n)+', using(BashLexer)),
  155.             ('\\s+', Text),
  156.             ('#.*?\\n', Comment),
  157.             ('(export)(\\s+)(?=[a-zA-Z0-9_${}\\t -]+\\n)', bygroups(Keyword, Text), 'export'),
  158.             ('export\\s+', Keyword),
  159.             ('([a-zA-Z0-9_${}.-]+)(\\s*)([!?:+]?=)([ \\t]*)((?:.*\\\\\\n|.*\\n)+)', bygroups(Name.Variable, Text, Operator, Text, using(BashLexer))),
  160.             ('(?s)"(\\\\\\\\|\\\\.|[^"\\\\])*"', String.Double),
  161.             ("(?s)'(\\\\\\\\|\\\\.|[^'\\\\])*'", String.Single),
  162.             ('([^\\n:]+)(:+)([ \\t]*)', bygroups(Name.Function, Operator, Text), 'block-header')],
  163.         'export': [
  164.             ('[a-zA-Z0-9_${}-]+', Name.Variable),
  165.             ('\\n', Text, '#pop'),
  166.             ('\\s+', Text)],
  167.         'block-header': [
  168.             ('[^,\\\\\\n#]+', Number),
  169.             (',', Punctuation),
  170.             ('#.*?\\n', Comment),
  171.             ('\\\\\\n', Text),
  172.             ('\\\\.', Text),
  173.             ('(?:[\\t ]+.*\\n|\\n)+', using(BashLexer), '#pop')] }
  174.  
  175.  
  176. class DiffLexer(RegexLexer):
  177.     name = 'Diff'
  178.     aliases = [
  179.         'diff',
  180.         'udiff']
  181.     filenames = [
  182.         '*.diff',
  183.         '*.patch']
  184.     mimetypes = [
  185.         'text/x-diff',
  186.         'text/x-patch']
  187.     tokens = {
  188.         'root': [
  189.             (' .*\\n', Text),
  190.             ('\\+.*\\n', Generic.Inserted),
  191.             ('-.*\\n', Generic.Deleted),
  192.             ('!.*\\n', Generic.Strong),
  193.             ('@.*\\n', Generic.Subheading),
  194.             ('([Ii]ndex|diff).*\\n', Generic.Heading),
  195.             ('=.*\\n', Generic.Heading),
  196.             ('.*\\n', Text)] }
  197.     
  198.     def analyse_text(text):
  199.         if text[:7] == 'Index: ':
  200.             return True
  201.         if text[:5] == 'diff ':
  202.             return True
  203.         if text[:4] == '--- ':
  204.             return 0.9
  205.  
  206.  
  207. DPATCH_KEYWORDS = [
  208.     'hunk',
  209.     'addfile',
  210.     'adddir',
  211.     'rmfile',
  212.     'rmdir',
  213.     'move',
  214.     'replace']
  215.  
  216. class DarcsPatchLexer(RegexLexer):
  217.     name = 'Darcs Patch'
  218.     aliases = [
  219.         'dpatch']
  220.     filenames = [
  221.         '*.dpatch',
  222.         '*.darcspatch']
  223.     tokens = {
  224.         'root': [
  225.             ('<', Operator),
  226.             ('>', Operator),
  227.             ('{', Operator),
  228.             ('}', Operator),
  229.             ('(\\[)((?:TAG )?)(.*)(\\n)(.*)(\\*\\*)(\\d+)(\\s?)(\\])', bygroups(Operator, Keyword, Name, Text, Name, Operator, Literal.Date, Text, Operator)),
  230.             ('(\\[)((?:TAG )?)(.*)(\\n)(.*)(\\*\\*)(\\d+)(\\s?)', bygroups(Operator, Keyword, Name, Text, Name, Operator, Literal.Date, Text), 'comment'),
  231.             ('New patches:', Generic.Heading),
  232.             ('Context:', Generic.Heading),
  233.             ('Patch bundle hash:', Generic.Heading),
  234.             ('(\\s*)(%s)(.*\\n)' % '|'.join(DPATCH_KEYWORDS), bygroups(Text, Keyword, Text)),
  235.             ('\\+', Generic.Inserted, 'insert'),
  236.             ('-', Generic.Deleted, 'delete'),
  237.             ('.*\\n', Text)],
  238.         'comment': [
  239.             ('[^\\]].*\\n', Comment),
  240.             ('\\]', Operator, '#pop')],
  241.         'specialText': [
  242.             ('\\n', Text, '#pop'),
  243.             ('\\[_[^_]*_]', Operator)],
  244.         'insert': [
  245.             include('specialText'),
  246.             ('\\[', Generic.Inserted),
  247.             ('[^\\n\\[]*', Generic.Inserted)],
  248.         'delete': [
  249.             include('specialText'),
  250.             ('\\[', Generic.Deleted),
  251.             ('[^\\n\\[]*', Generic.Deleted)] }
  252.  
  253.  
  254. class IrcLogsLexer(RegexLexer):
  255.     name = 'IRC logs'
  256.     aliases = [
  257.         'irc']
  258.     filenames = [
  259.         '*.weechatlog']
  260.     mimetypes = [
  261.         'text/x-irclog']
  262.     flags = re.VERBOSE | re.MULTILINE
  263.     timestamp = '\n        (\n          # irssi / xchat and others\n          (?: \\[|\\()?                  # Opening bracket or paren for the timestamp\n            (?:                        # Timestamp\n                (?: (?:\\d{1,4} [-/]?)+ # Date as - or /-separated groups of digits\n                 [T ])?                # Date/time separator: T or space\n                (?: \\d?\\d [:.]?)+      # Time as :/.-separated groups of 1 or 2 digits\n            )\n          (?: \\]|\\))?\\s+               # Closing bracket or paren for the timestamp\n        |\n          # weechat\n          \\d{4}\\s\\w{3}\\s\\d{2}\\s        # Date\n          \\d{2}:\\d{2}:\\d{2}\\s+         # Time + Whitespace\n        |\n          # xchat\n          \\w{3}\\s\\d{2}\\s               # Date\n          \\d{2}:\\d{2}:\\d{2}\\s+         # Time + Whitespace\n        )?\n    '
  264.     tokens = {
  265.         'root': [
  266.             ('^\\*\\*\\*\\*(.*)\\*\\*\\*\\*$', Comment),
  267.             ('^' + timestamp + '(\\s*<[^>]*>\\s*)$', bygroups(Comment.Preproc, Name.Tag)),
  268.             ('^' + timestamp + '\n                (\\s*<.*?>\\s*)          # Nick ', bygroups(Comment.Preproc, Name.Tag), 'msg'),
  269.             ('^' + timestamp + '\n                (\\s*[*]\\s+)            # Star\n                ([^\\s]+\\s+.*?\\n)       # Nick + rest of message ', bygroups(Comment.Preproc, Keyword, Generic.Inserted)),
  270.             ('^' + timestamp + '\n                (\\s*(?:\\*{3}|<?-[!@=P]?->?)\\s*)  # Star(s) or symbols\n                ([^\\s]+\\s+)                     # Nick + Space\n                (.*?\\n)                         # Rest of message ', bygroups(Comment.Preproc, Keyword, String, Comment)),
  271.             ('^.*?\\n', Text)],
  272.         'msg': [
  273.             ('[^\\s]+:(?!//)', Name.Attribute),
  274.             ('.*\\n', Text, '#pop')] }
  275.  
  276.  
  277. class BBCodeLexer(RegexLexer):
  278.     name = 'BBCode'
  279.     aliases = [
  280.         'bbcode']
  281.     mimetypes = [
  282.         'text/x-bbcode']
  283.     tokens = {
  284.         'root': [
  285.             ('[^[]+', Text),
  286.             ('\\[/?\\w+', Keyword, 'tag'),
  287.             ('\\[', Text)],
  288.         'tag': [
  289.             ('\\s+', Text),
  290.             ('(\\w+)(=)("?[^\\s"\\]]+"?)', bygroups(Name.Attribute, Operator, String)),
  291.             ('(=)("?[^\\s"\\]]+"?)', bygroups(Operator, String)),
  292.             ('\\]', Keyword, '#pop')] }
  293.  
  294.  
  295. class TexLexer(RegexLexer):
  296.     name = 'TeX'
  297.     aliases = [
  298.         'tex',
  299.         'latex']
  300.     filenames = [
  301.         '*.tex',
  302.         '*.aux',
  303.         '*.toc']
  304.     mimetypes = [
  305.         'text/x-tex',
  306.         'text/x-latex']
  307.     tokens = {
  308.         'general': [
  309.             ('%.*?\\n', Comment),
  310.             ('[{}]', Name.Builtin),
  311.             ('[&_^]', Name.Builtin)],
  312.         'root': [
  313.             ('\\\\\\[', String.Backtick, 'displaymath'),
  314.             ('\\\\\\(', String, 'inlinemath'),
  315.             ('\\$\\$', String.Backtick, 'displaymath'),
  316.             ('\\$', String, 'inlinemath'),
  317.             ('\\\\([a-zA-Z]+|.)', Keyword, 'command'),
  318.             include('general'),
  319.             ('[^\\\\$%&_^{}]+', Text)],
  320.         'math': [
  321.             ('\\\\([a-zA-Z]+|.)', Name.Variable),
  322.             include('general'),
  323.             ('[0-9]+', Number),
  324.             ('[-=!+*/()\\[\\]]', Operator),
  325.             ('[^=!+*/()\\[\\]\\\\$%&_^{}0-9-]+', Name.Builtin)],
  326.         'inlinemath': [
  327.             ('\\\\\\)', String, '#pop'),
  328.             ('\\$', String, '#pop'),
  329.             include('math')],
  330.         'displaymath': [
  331.             ('\\\\\\]', String, '#pop'),
  332.             ('\\$\\$', String, '#pop'),
  333.             ('\\$', Name.Builtin),
  334.             include('math')],
  335.         'command': [
  336.             ('\\[.*?\\]', Name.Attribute),
  337.             ('\\*', Keyword),
  338.             ('', Text, '#pop')] }
  339.     
  340.     def analyse_text(text):
  341.         for start in ('\\documentclass', '\\input', '\\documentstyle', '\\relax'):
  342.             if text[:len(start)] == start:
  343.                 return True
  344.         
  345.  
  346.  
  347.  
  348. class GroffLexer(RegexLexer):
  349.     name = 'Groff'
  350.     aliases = [
  351.         'groff',
  352.         'nroff',
  353.         'man']
  354.     filenames = [
  355.         '*.[1234567]',
  356.         '*.man']
  357.     mimetypes = [
  358.         'application/x-troff',
  359.         'text/troff']
  360.     tokens = {
  361.         'root': [
  362.             ('(?i)(\\.)(\\w+)', bygroups(Text, Keyword), 'request'),
  363.             ('\\.', Punctuation, 'request'),
  364.             ('[^\\\\\\n]*', Text, 'textline')],
  365.         'textline': [
  366.             include('escapes'),
  367.             ('[^\\\\\\n]+', Text),
  368.             ('\\n', Text, '#pop')],
  369.         'escapes': [
  370.             ('\\\\"[^\\n]*', Comment),
  371.             ('\\\\[fn]\\w', String.Escape),
  372.             ('\\\\\\(..', String.Escape),
  373.             ('\\\\.\\[.*\\]', String.Escape),
  374.             ('\\\\.', String.Escape),
  375.             ('\\\\\\n', Text, 'request')],
  376.         'request': [
  377.             ('\\n', Text, '#pop'),
  378.             include('escapes'),
  379.             ('"[^\\n"]+"', String.Double),
  380.             ('\\d+', Number),
  381.             ('\\S+', String),
  382.             ('\\s+', Text)] }
  383.     
  384.     def analyse_text(text):
  385.         if text[:1] != '.':
  386.             return False
  387.         if text[:3] == '.\\"':
  388.             return True
  389.         if text[:4] == '.TH ':
  390.             return True
  391.         if text[1:3].isalnum() and text[3].isspace():
  392.             return 0.9
  393.  
  394.  
  395.  
  396. class ApacheConfLexer(RegexLexer):
  397.     name = 'ApacheConf'
  398.     aliases = [
  399.         'apacheconf',
  400.         'aconf',
  401.         'apache']
  402.     filenames = [
  403.         '.htaccess',
  404.         'apache.conf',
  405.         'apache2.conf']
  406.     mimetypes = [
  407.         'text/x-apacheconf']
  408.     flags = re.MULTILINE | re.IGNORECASE
  409.     tokens = {
  410.         'root': [
  411.             ('\\s+', Text),
  412.             ('(#.*?)$', Comment),
  413.             ('(<[^\\s>]+)(?:(\\s+)(.*?))?(>)', bygroups(Name.Tag, Text, String, Name.Tag)),
  414.             ('([a-zA-Z][a-zA-Z0-9]*)(\\s+)', bygroups(Name.Builtin, Text), 'value'),
  415.             ('\\.+', Text)],
  416.         'value': [
  417.             ('$', Text, '#pop'),
  418.             ('[^\\S\\n]+', Text),
  419.             ('\\d+\\.\\d+\\.\\d+\\.\\d+(?:/\\d+)?', Number),
  420.             ('\\d+', Number),
  421.             ('/([a-zA-Z0-9][a-zA-Z0-9_./-]+)', String.Other),
  422.             ('(on|off|none|any|all|double|email|dns|min|minimal|os|productonly|full|emerg|alert|crit|error|warn|notice|info|debug|registry|script|inetd|standalone|user|group)\\b', Keyword),
  423.             ('"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"', String.Double),
  424.             ('[^\\s"]+', Text)] }
  425.  
  426.  
  427. class MoinWikiLexer(RegexLexer):
  428.     name = 'MoinMoin/Trac Wiki markup'
  429.     aliases = [
  430.         'trac-wiki',
  431.         'moin']
  432.     filenames = []
  433.     mimetypes = [
  434.         'text/x-trac-wiki']
  435.     flags = re.MULTILINE | re.IGNORECASE
  436.     tokens = {
  437.         'root': [
  438.             ('^#.*$', Comment),
  439.             ('(!)(\\S+)', bygroups(Keyword, Text)),
  440.             ('^(=+)([^=]+)(=+)(\\s*#.+)?$', bygroups(Generic.Heading, using(this), Generic.Heading, String)),
  441.             ('({{{)(\\n#!.+)?', bygroups(Name.Builtin, Name.Namespace), 'codeblock'),
  442.             ("(\\'\\'\\'?|\\|\\||`|__|~~|\\^|,,|::)", Comment),
  443.             ('^( +)([.*-])( )', bygroups(Text, Name.Builtin, Text)),
  444.             ('^( +)([a-zivx]{1,5}\\.)( )', bygroups(Text, Name.Builtin, Text)),
  445.             ('\\[\\[\\w+.*?\\]\\]', Keyword),
  446.             ('(\\[[^\\s\\]]+)(\\s+[^\\]]+?)?(\\])', bygroups(Keyword, String, Keyword)),
  447.             ('^----+$', Keyword),
  448.             ("[^\\n\\'\\[{!_~^,|]+", Text),
  449.             ('\\n', Text),
  450.             ('.', Text)],
  451.         'codeblock': [
  452.             ('}}}', Name.Builtin, '#pop'),
  453.             ('{{{', Text, '#push'),
  454.             ('[^{}]+', Comment.Preproc),
  455.             ('.', Comment.Preproc)] }
  456.  
  457.  
  458. class RstLexer(RegexLexer):
  459.     name = 'reStructuredText'
  460.     aliases = [
  461.         'rst',
  462.         'rest',
  463.         'restructuredtext']
  464.     filenames = [
  465.         '*.rst',
  466.         '*.rest']
  467.     mimetypes = [
  468.         'text/x-rst',
  469.         'text/prs.fallenstein.rst']
  470.     flags = re.MULTILINE
  471.     
  472.     def _handle_sourcecode(self, match):
  473.         get_lexer_by_name = get_lexer_by_name
  474.         import pygments.lexers
  475.         ClassNotFound = ClassNotFound
  476.         import pygments.util
  477.         yield (match.start(1), Punctuation, match.group(1))
  478.         yield (match.start(2), Text, match.group(2))
  479.         yield (match.start(3), Operator.Word, match.group(3))
  480.         yield (match.start(4), Punctuation, match.group(4))
  481.         yield (match.start(5), Text, match.group(5))
  482.         yield (match.start(6), Keyword, match.group(6))
  483.         yield (match.start(7), Text, match.group(7))
  484.         lexer = None
  485.         if self.handlecodeblocks:
  486.             
  487.             try:
  488.                 lexer = get_lexer_by_name(match.group(6).strip())
  489.             except ClassNotFound:
  490.                 pass
  491.             except:
  492.                 None<EXCEPTION MATCH>ClassNotFound
  493.             
  494.  
  495.         None<EXCEPTION MATCH>ClassNotFound
  496.         indention = match.group(8)
  497.         indention_size = len(indention)
  498.         code = indention + match.group(9) + match.group(10) + match.group(11)
  499.         if lexer is None:
  500.             yield (match.start(8), String, code)
  501.             return None
  502.         ins = []
  503.         codelines = code.splitlines(True)
  504.         code = ''
  505.         for line in codelines:
  506.             if len(line) > indention_size:
  507.                 ins.append((len(code), [
  508.                     (0, Text, line[:indention_size])]))
  509.                 code += line[indention_size:]
  510.                 continue
  511.             lexer is None
  512.             code += line
  513.         
  514.         for item in do_insertions(ins, lexer.get_tokens_unprocessed(code)):
  515.             yield item
  516.         
  517.  
  518.     tokens = {
  519.         'root': [
  520.             ('^(=+|-+|`+|:+|\\.+|\\\'+|"+|~+|\\^+|_+|\\*+|\\++|#+)([ \\t]*\\n)(.+)(\\n)(\\1)(\\n)', bygroups(Generic.Heading, Text, Generic.Heading, Text, Generic.Heading, Text)),
  521.             ('^(\\S.*)(\\n)(={3,}|-{3,}|`{3,}|:{3,}|\\.{3,}|\\\'{3,}|"{3,}|~{3,}|\\^{3,}|_{3,}|\\*{3,}|\\+{3,}|#{3,})(\\n)', bygroups(Generic.Heading, Text, Generic.Heading, Text)),
  522.             ('^(\\s*)([-*+])( .+\\n(?:\\1  .+\\n)*)', bygroups(Text, Number, using(this, state = 'inline'))),
  523.             ('^(\\s*)([0-9#ivxlcmIVXLCM]+\\.)( .+\\n(?:\\1  .+\\n)*)', bygroups(Text, Number, using(this, state = 'inline'))),
  524.             ('^(\\s*)(\\(?[0-9#ivxlcmIVXLCM]+\\))( .+\\n(?:\\1  .+\\n)*)', bygroups(Text, Number, using(this, state = 'inline'))),
  525.             ('^(\\s*)([A-Z]+\\.)( .+\\n(?:\\1  .+\\n)+)', bygroups(Text, Number, using(this, state = 'inline'))),
  526.             ('^(\\s*)(\\(?[A-Za-z]+\\))( .+\\n(?:\\1  .+\\n)+)', bygroups(Text, Number, using(this, state = 'inline'))),
  527.             ('^(\\s*)(\\|)( .+\\n(?:\\|  .+\\n)*)', bygroups(Text, Operator, using(this, state = 'inline'))),
  528.             ('^( *\\.\\.)(\\s*)((?:source)?code)(::)([ \\t]*)([^\\n]+)(\\n[ \\t]*\\n)([ \\t]+)(.*)(\\n)((?:(?:\\8.*|)\\n)+)', _handle_sourcecode),
  529.             ('^( *\\.\\.)(\\s*)([\\w:-]+?)(::)(?:([ \\t]*)(.*))', bygroups(Punctuation, Text, Operator.Word, Punctuation, Text, using(this, state = 'inline'))),
  530.             ('^( *\\.\\.)(\\s*)([\\w\\t ]+:)(.*?)$', bygroups(Punctuation, Text, Name.Tag, using(this, state = 'inline'))),
  531.             ('^( *\\.\\.)(\\s*)(\\[.+\\])(.*?)$', bygroups(Punctuation, Text, Name.Tag, using(this, state = 'inline'))),
  532.             ('^( *\\.\\.)(\\s*)(\\|.+\\|)(\\s*)([\\w:-]+?)(::)(?:([ \\t]*)(.*))', bygroups(Punctuation, Text, Name.Tag, Text, Operator.Word, Punctuation, Text, using(this, state = 'inline'))),
  533.             ('^ *\\.\\..*(\\n( +.*\\n|\\n)+)?', Comment.Preproc),
  534.             ('^( *)(:[a-zA-Z-]+:)(\\s*)$', bygroups(Text, Name.Class, Text)),
  535.             ('^( *)(:.*?:)([ \\t]+)(.*?)$', bygroups(Text, Name.Class, Text, Name.Function)),
  536.             ('^([^ ].*(?<!::)\\n)((?:(?: +.*)\\n)+)', bygroups(using(this, state = 'inline'), using(this, state = 'inline'))),
  537.             ('(::)(\\n[ \\t]*\\n)([ \\t]+)(.*)(\\n)((?:(?:\\3.*|)\\n)+)', bygroups(String.Escape, Text, String, String, Text, String)),
  538.             include('inline')],
  539.         'inline': [
  540.             ('\\\\.', Text),
  541.             ('``', String, 'literal'),
  542.             ('(`.+?)(<.+?>)(`__?)', bygroups(String, String.Interpol, String)),
  543.             ('`.+?`__?', String),
  544.             ('(`.+?`)(:[a-zA-Z0-9:-]+?:)?', bygroups(Name.Variable, Name.Attribute)),
  545.             ('(:[a-zA-Z0-9:-]+?:)(`.+?`)', bygroups(Name.Attribute, Name.Variable)),
  546.             ('\\*\\*.+?\\*\\*', Generic.Strong),
  547.             ('\\*.+?\\*', Generic.Emph),
  548.             ('\\[.*?\\]_', String),
  549.             ('<.+?>', Name.Tag),
  550.             ('[^\\\\\\n\\[*`:]+', Text),
  551.             ('.', Text)],
  552.         'literal': [
  553.             ('[^`\\\\]+', String),
  554.             ('\\\\.', String),
  555.             ('``', String, '#pop'),
  556.             ('[`\\\\]', String)] }
  557.     
  558.     def __init__(self, **options):
  559.         self.handlecodeblocks = get_bool_opt(options, 'handlecodeblocks', True)
  560.         RegexLexer.__init__(self, **options)
  561.  
  562.     
  563.     def analyse_text(text):
  564.         if text[:2] == '..' and text[2:3] != '.':
  565.             return 0.3
  566.         p1 = text.find('\n')
  567.         p2 = text.find('\n', p1 + 1)
  568.         if p2 > -1 and p1 * 2 + 1 == p2 and text[p1 + 1] in '-=' and text[p1 + 1] == text[p2 - 1]:
  569.             return 0.5
  570.  
  571.  
  572.  
  573. class VimLexer(RegexLexer):
  574.     name = 'VimL'
  575.     aliases = [
  576.         'vim']
  577.     filenames = [
  578.         '*.vim',
  579.         '.vimrc']
  580.     mimetypes = [
  581.         'text/x-vim']
  582.     flags = re.MULTILINE
  583.     tokens = {
  584.         'root': [
  585.             ('^\\s*".*', Comment),
  586.             ('(?<=\\s)"[^\\-:.%#=*].*', Comment),
  587.             ('[ \\t]+', Text),
  588.             ('/(\\\\\\\\|\\\\/|[^\\n/])*/', String.Regex),
  589.             ('"(\\\\\\\\|\\\\"|[^\\n"])*"', String.Double),
  590.             ("'(\\\\\\\\|\\\\'|[^\\n'])*'", String.Single),
  591.             ('-?\\d+', Number),
  592.             ('#[0-9a-f]{6}', Number.Hex),
  593.             ('^:', Punctuation),
  594.             ('[()<>+=!|,~-]', Punctuation),
  595.             ('\\b(let|if|else|endif|elseif|fun|function|endfunction)\\b', Keyword),
  596.             ('\\b(NONE|bold|italic|underline|dark|light)\\b', Name.Builtin),
  597.             ('\\b\\w+\\b', Name.Other),
  598.             ('.', Text)] }
  599.     
  600.     def __init__(self, **options):
  601.         command = command
  602.         option = option
  603.         auto = auto
  604.         import pygments.lexers._vimbuiltins
  605.         self._cmd = command
  606.         self._opt = option
  607.         self._aut = auto
  608.         RegexLexer.__init__(self, **options)
  609.  
  610.     
  611.     def is_in(self, w, mapping):
  612.         p = bisect(mapping, (w,))
  613.         if p > 0:
  614.             if mapping[p - 1][0] == w[:len(mapping[p - 1][0])] and mapping[p - 1][1][:len(w)] == w:
  615.                 return True
  616.         
  617.         if p < len(mapping):
  618.             if mapping[p][0] == w[:len(mapping[p][0])]:
  619.                 pass
  620.             return mapping[p][1][:len(w)] == w
  621.         return False
  622.  
  623.     
  624.     def get_tokens_unprocessed(self, text):
  625.         for index, token, value in RegexLexer.get_tokens_unprocessed(self, text):
  626.             if token is Name.Other:
  627.                 if self.is_in(value, self._cmd):
  628.                     yield (index, Keyword, value)
  629.                 elif self.is_in(value, self._opt) or self.is_in(value, self._aut):
  630.                     yield (index, Name.Builtin, value)
  631.                 else:
  632.                     yield (index, Text, value)
  633.             self.is_in(value, self._aut)
  634.             yield (index, token, value)
  635.         
  636.  
  637.  
  638.  
  639. class GettextLexer(RegexLexer):
  640.     name = 'Gettext Catalog'
  641.     aliases = [
  642.         'pot',
  643.         'po']
  644.     filenames = [
  645.         '*.pot',
  646.         '*.po']
  647.     mimetypes = [
  648.         'application/x-gettext',
  649.         'text/x-gettext',
  650.         'text/gettext']
  651.     tokens = {
  652.         'root': [
  653.             ('^#,\\s.*?$', Keyword.Type),
  654.             ('^#:\\s.*?$', Keyword.Declaration),
  655.             ('^(#|#\\.\\s|#\\|\\s|#~\\s|#\\s).*$', Comment.Single),
  656.             ('^(")([\\w-]*:)(.*")$', bygroups(String, Name.Property, String)),
  657.             ('^".*"$', String),
  658.             ('^(msgid|msgid_plural|msgstr)(\\s+)(".*")$', bygroups(Name.Variable, Text, String)),
  659.             ('^(msgstr\\[)(\\d)(\\])(\\s+)(".*")$', bygroups(Name.Variable, Number.Integer, Name.Variable, Text, String))] }
  660.  
  661.  
  662. class SquidConfLexer(RegexLexer):
  663.     name = 'SquidConf'
  664.     aliases = [
  665.         'squidconf',
  666.         'squid.conf',
  667.         'squid']
  668.     filenames = [
  669.         'squid.conf']
  670.     mimetypes = [
  671.         'text/x-squidconf']
  672.     flags = re.IGNORECASE
  673.     keywords = [
  674.         'acl',
  675.         'always_direct',
  676.         'announce_host',
  677.         'announce_period',
  678.         'announce_port',
  679.         'announce_to',
  680.         'anonymize_headers',
  681.         'append_domain',
  682.         'as_whois_server',
  683.         'auth_param_basic',
  684.         'authenticate_children',
  685.         'authenticate_program',
  686.         'authenticate_ttl',
  687.         'broken_posts',
  688.         'buffered_logs',
  689.         'cache_access_log',
  690.         'cache_announce',
  691.         'cache_dir',
  692.         'cache_dns_program',
  693.         'cache_effective_group',
  694.         'cache_effective_user',
  695.         'cache_host',
  696.         'cache_host_acl',
  697.         'cache_host_domain',
  698.         'cache_log',
  699.         'cache_mem',
  700.         'cache_mem_high',
  701.         'cache_mem_low',
  702.         'cache_mgr',
  703.         'cachemgr_passwd',
  704.         'cache_peer',
  705.         'cache_peer_access',
  706.         'cahce_replacement_policy',
  707.         'cache_stoplist',
  708.         'cache_stoplist_pattern',
  709.         'cache_store_log',
  710.         'cache_swap',
  711.         'cache_swap_high',
  712.         'cache_swap_log',
  713.         'cache_swap_low',
  714.         'client_db',
  715.         'client_lifetime',
  716.         'client_netmask',
  717.         'connect_timeout',
  718.         'coredump_dir',
  719.         'dead_peer_timeout',
  720.         'debug_options',
  721.         'delay_access',
  722.         'delay_class',
  723.         'delay_initial_bucket_level',
  724.         'delay_parameters',
  725.         'delay_pools',
  726.         'deny_info',
  727.         'dns_children',
  728.         'dns_defnames',
  729.         'dns_nameservers',
  730.         'dns_testnames',
  731.         'emulate_httpd_log',
  732.         'err_html_text',
  733.         'fake_user_agent',
  734.         'firewall_ip',
  735.         'forwarded_for',
  736.         'forward_snmpd_port',
  737.         'fqdncache_size',
  738.         'ftpget_options',
  739.         'ftpget_program',
  740.         'ftp_list_width',
  741.         'ftp_passive',
  742.         'ftp_user',
  743.         'half_closed_clients',
  744.         'header_access',
  745.         'header_replace',
  746.         'hierarchy_stoplist',
  747.         'high_response_time_warning',
  748.         'high_page_fault_warning',
  749.         'htcp_port',
  750.         'http_access',
  751.         'http_anonymizer',
  752.         'httpd_accel',
  753.         'httpd_accel_host',
  754.         'httpd_accel_port',
  755.         'httpd_accel_uses_host_header',
  756.         'httpd_accel_with_proxy',
  757.         'http_port',
  758.         'http_reply_access',
  759.         'icp_access',
  760.         'icp_hit_stale',
  761.         'icp_port',
  762.         'icp_query_timeout',
  763.         'ident_lookup',
  764.         'ident_lookup_access',
  765.         'ident_timeout',
  766.         'incoming_http_average',
  767.         'incoming_icp_average',
  768.         'inside_firewall',
  769.         'ipcache_high',
  770.         'ipcache_low',
  771.         'ipcache_size',
  772.         'local_domain',
  773.         'local_ip',
  774.         'logfile_rotate',
  775.         'log_fqdn',
  776.         'log_icp_queries',
  777.         'log_mime_hdrs',
  778.         'maximum_object_size',
  779.         'maximum_single_addr_tries',
  780.         'mcast_groups',
  781.         'mcast_icp_query_timeout',
  782.         'mcast_miss_addr',
  783.         'mcast_miss_encode_key',
  784.         'mcast_miss_port',
  785.         'memory_pools',
  786.         'memory_pools_limit',
  787.         'memory_replacement_policy',
  788.         'mime_table',
  789.         'min_http_poll_cnt',
  790.         'min_icp_poll_cnt',
  791.         'minimum_direct_hops',
  792.         'minimum_object_size',
  793.         'minimum_retry_timeout',
  794.         'miss_access',
  795.         'negative_dns_ttl',
  796.         'negative_ttl',
  797.         'neighbor_timeout',
  798.         'neighbor_type_domain',
  799.         'netdb_high',
  800.         'netdb_low',
  801.         'netdb_ping_period',
  802.         'netdb_ping_rate',
  803.         'never_direct',
  804.         'no_cache',
  805.         'passthrough_proxy',
  806.         'pconn_timeout',
  807.         'pid_filename',
  808.         'pinger_program',
  809.         'positive_dns_ttl',
  810.         'prefer_direct',
  811.         'proxy_auth',
  812.         'proxy_auth_realm',
  813.         'query_icmp',
  814.         'quick_abort',
  815.         'quick_abort',
  816.         'quick_abort_max',
  817.         'quick_abort_min',
  818.         'quick_abort_pct',
  819.         'range_offset_limit',
  820.         'read_timeout',
  821.         'redirect_children',
  822.         'redirect_program',
  823.         'redirect_rewrites_host_header',
  824.         'reference_age',
  825.         'reference_age',
  826.         'refresh_pattern',
  827.         'reload_into_ims',
  828.         'request_body_max_size',
  829.         'request_size',
  830.         'request_timeout',
  831.         'shutdown_lifetime',
  832.         'single_parent_bypass',
  833.         'siteselect_timeout',
  834.         'snmp_access',
  835.         'snmp_incoming_address',
  836.         'snmp_port',
  837.         'source_ping',
  838.         'ssl_proxy',
  839.         'store_avg_object_size',
  840.         'store_objects_per_bucket',
  841.         'strip_query_terms',
  842.         'swap_level1_dirs',
  843.         'swap_level2_dirs',
  844.         'tcp_incoming_address',
  845.         'tcp_outgoing_address',
  846.         'tcp_recv_bufsize',
  847.         'test_reachability',
  848.         'udp_hit_obj',
  849.         'udp_hit_obj_size',
  850.         'udp_incoming_address',
  851.         'udp_outgoing_address',
  852.         'unique_hostname',
  853.         'unlinkd_program',
  854.         'uri_whitespace',
  855.         'useragent_log',
  856.         'visible_hostname',
  857.         'wais_relay',
  858.         'wais_relay_host',
  859.         'wais_relay_port']
  860.     opts = [
  861.         'proxy-only',
  862.         'weight',
  863.         'ttl',
  864.         'no-query',
  865.         'default',
  866.         'round-robin',
  867.         'multicast-responder',
  868.         'on',
  869.         'off',
  870.         'all',
  871.         'deny',
  872.         'allow',
  873.         'via',
  874.         'parent',
  875.         'no-digest',
  876.         'heap',
  877.         'lru',
  878.         'realm',
  879.         'children',
  880.         'credentialsttl',
  881.         'none',
  882.         'disable',
  883.         'offline_toggle',
  884.         'diskd',
  885.         'q1',
  886.         'q2']
  887.     actions = [
  888.         'shutdown',
  889.         'info',
  890.         'parameter',
  891.         'server_list',
  892.         'client_list',
  893.         'squid\\.conf']
  894.     actions_stats = [
  895.         'objects',
  896.         'vm_objects',
  897.         'utilization',
  898.         'ipcache',
  899.         'fqdncache',
  900.         'dns',
  901.         'redirector',
  902.         'io',
  903.         'reply_headers',
  904.         'filedescriptors',
  905.         'netdb']
  906.     actions_log = [
  907.         'status',
  908.         'enable',
  909.         'disable',
  910.         'clear']
  911.     acls = [
  912.         'url_regex',
  913.         'urlpath_regex',
  914.         'referer_regex',
  915.         'port',
  916.         'proto',
  917.         'req_mime_type',
  918.         'rep_mime_type',
  919.         'method',
  920.         'browser',
  921.         'user',
  922.         'src',
  923.         'dst',
  924.         'time',
  925.         'dstdomain',
  926.         'ident',
  927.         'snmp_community']
  928.     ip_re = '\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b'
  929.     
  930.     def makelistre(list):
  931.         return '\\b(?:' + '|'.join(list) + ')\\b'
  932.  
  933.     tokens = {
  934.         'root': [
  935.             ('\\s+', Text),
  936.             ('#', Comment, 'comment'),
  937.             (makelistre(keywords), Keyword),
  938.             (makelistre(opts), Name.Constant),
  939.             (makelistre(actions), String),
  940.             ('stats/' + makelistre(actions), String),
  941.             ('log/' + makelistre(actions) + '=', String),
  942.             (makelistre(acls), Keyword),
  943.             (ip_re + '(?:/(?:' + ip_re + ')|\\d+)?', Number),
  944.             ('\\b\\d+\\b', Number),
  945.             ('\\S+', Text)],
  946.         'comment': [
  947.             ('\\s*TAG:.*', String.Escape, '#pop'),
  948.             ('.*', Comment, '#pop')] }
  949.  
  950.  
  951. class DebianControlLexer(RegexLexer):
  952.     name = 'Debian Control file'
  953.     aliases = [
  954.         'control']
  955.     filenames = [
  956.         'control']
  957.     tokens = {
  958.         'root': [
  959.             ('^(Description)', Keyword, 'description'),
  960.             ('^(Maintainer)(:\\s*)', bygroups(Keyword, Text), 'maintainer'),
  961.             ('^((Build-)?Depends)', Keyword, 'depends'),
  962.             ('^((?:Python-)?Version)(:\\s*)([^\\s]+)$', bygroups(Keyword, Text, Number)),
  963.             ('^((?:Installed-)?Size)(:\\s*)([^\\s]+)$', bygroups(Keyword, Text, Number)),
  964.             ('^(MD5Sum|SHA1|SHA256)(:\\s*)([^\\s]+)$', bygroups(Keyword, Text, Number)),
  965.             ('^([a-zA-Z\\-0-9\\.]*?)(:\\s*)(.*?)$', bygroups(Keyword, Whitespace, String))],
  966.         'maintainer': [
  967.             ('<[^>]+>', Generic.Strong),
  968.             ('<[^>]+>$', Generic.Strong, '#pop'),
  969.             (',\\n?', Text),
  970.             ('.', Text)],
  971.         'description': [
  972.             ('(.*)(Homepage)(: )([^\\s]+)', bygroups(Text, String, Name, Name.Class)),
  973.             (':.*\\n', Generic.Strong),
  974.             (' .*\\n', Text),
  975.             ('', Text, '#pop')],
  976.         'depends': [
  977.             (':\\s*', Text),
  978.             ('(\\$)(\\{)(\\w+\\s*:\\s*\\w+)', bygroups(Operator, Text, Name.Entity)),
  979.             ('\\(', Text, 'depend_vers'),
  980.             (',', Text),
  981.             ('\\|', Operator),
  982.             ('[\\s]+', Text),
  983.             ('[}\\)]\\s*$', Text, '#pop'),
  984.             ('[}]', Text),
  985.             ('[^,]$', Name.Function, '#pop'),
  986.             ('([\\+\\.a-zA-Z0-9-][\\s\\n]*)', Name.Function),
  987.             ('\\[.*?\\]', Name.Entity)],
  988.         'depend_vers': [
  989.             ('\\),', Text, '#pop'),
  990.             ('\\)[^,]', Text, '#pop:2'),
  991.             ('([><=]+)(\\s*)([^\\)]+)', bygroups(Operator, Text, Number))] }
  992.  
  993.  
  994. class YamlLexerContext(LexerContext):
  995.     
  996.     def __init__(self, *args, **kwds):
  997.         super(YamlLexerContext, self).__init__(*args, **kwds)
  998.         self.indent_stack = []
  999.         self.indent = -1
  1000.         self.next_indent = 0
  1001.         self.block_scalar_indent = None
  1002.  
  1003.  
  1004.  
  1005. class YamlLexer(ExtendedRegexLexer):
  1006.     name = 'YAML'
  1007.     aliases = [
  1008.         'yaml']
  1009.     filenames = [
  1010.         '*.yaml',
  1011.         '*.yml']
  1012.     mimetypes = [
  1013.         'text/x-yaml']
  1014.     
  1015.     def something(token_class):
  1016.         
  1017.         def callback(lexer, match, context):
  1018.             text = match.group()
  1019.             if not text:
  1020.                 return None
  1021.             yield (match.start(), token_class, text)
  1022.             text
  1023.             context.pos = match.end()
  1024.  
  1025.         return callback
  1026.  
  1027.     
  1028.     def reset_indent(token_class):
  1029.         
  1030.         def callback(lexer, match, context):
  1031.             text = match.group()
  1032.             context.indent_stack = []
  1033.             context.indent = -1
  1034.             context.next_indent = 0
  1035.             context.block_scalar_indent = None
  1036.             yield (match.start(), token_class, text)
  1037.             context.pos = match.end()
  1038.  
  1039.         return callback
  1040.  
  1041.     
  1042.     def save_indent(token_class, start = False):
  1043.         
  1044.         def callback(lexer, match, context):
  1045.             text = match.group()
  1046.             extra = ''
  1047.             context.pos = match.end()
  1048.  
  1049.         return callback
  1050.  
  1051.     
  1052.     def set_indent(token_class, implicit = False):
  1053.         
  1054.         def callback(lexer, match, context):
  1055.             text = match.group()
  1056.             if context.indent < context.next_indent:
  1057.                 context.indent_stack.append(context.indent)
  1058.                 context.indent = context.next_indent
  1059.             
  1060.             if not implicit:
  1061.                 context.next_indent += len(text)
  1062.             
  1063.             yield (match.start(), token_class, text)
  1064.             context.pos = match.end()
  1065.  
  1066.         return callback
  1067.  
  1068.     
  1069.     def set_block_scalar_indent(token_class):
  1070.         
  1071.         def callback(lexer, match, context):
  1072.             text = match.group()
  1073.             context.block_scalar_indent = None
  1074.             if not text:
  1075.                 return None
  1076.             increment = match.group(1)
  1077.             if increment:
  1078.                 current_indent = max(context.indent, 0)
  1079.                 increment = int(increment)
  1080.                 context.block_scalar_indent = current_indent + increment
  1081.             
  1082.             if text:
  1083.                 yield (match.start(), token_class, text)
  1084.                 context.pos = match.end()
  1085.             
  1086.  
  1087.         return callback
  1088.  
  1089.     
  1090.     def parse_block_scalar_empty_line(indent_token_class, content_token_class):
  1091.         
  1092.         def callback(lexer, match, context):
  1093.             text = match.group()
  1094.             if context.block_scalar_indent is None or len(text) <= context.block_scalar_indent:
  1095.                 if text:
  1096.                     yield (match.start(), indent_token_class, text)
  1097.                 
  1098.             else:
  1099.                 indentation = text[:context.block_scalar_indent]
  1100.                 content = text[context.block_scalar_indent:]
  1101.                 yield (match.start(), indent_token_class, indentation)
  1102.                 yield (match.start() + context.block_scalar_indent, content_token_class, content)
  1103.             context.pos = match.end()
  1104.  
  1105.         return callback
  1106.  
  1107.     
  1108.     def parse_block_scalar_indent(token_class):
  1109.         
  1110.         def callback(lexer, match, context):
  1111.             text = match.group()
  1112.             if context.block_scalar_indent is None:
  1113.                 if len(text) <= max(context.indent, 0):
  1114.                     context.stack.pop()
  1115.                     context.stack.pop()
  1116.                     return None
  1117.                 context.block_scalar_indent = len(text)
  1118.             elif len(text) < context.block_scalar_indent:
  1119.                 context.stack.pop()
  1120.                 context.stack.pop()
  1121.                 return None
  1122.             if text:
  1123.                 yield (match.start(), token_class, text)
  1124.                 context.pos = match.end()
  1125.             
  1126.  
  1127.         return callback
  1128.  
  1129.     
  1130.     def parse_plain_scalar_indent(token_class):
  1131.         
  1132.         def callback(lexer, match, context):
  1133.             text = match.group()
  1134.             if len(text) <= context.indent:
  1135.                 context.stack.pop()
  1136.                 context.stack.pop()
  1137.                 return None
  1138.  
  1139.         return callback
  1140.  
  1141.     tokens = {
  1142.         'root': [
  1143.             ('[ ]+(?=#|$)', Text),
  1144.             ('\\n+', Text),
  1145.             ('#[^\\n]*', Comment.Single),
  1146.             ('^%YAML(?=[ ]|$)', reset_indent(Name.Tag), 'yaml-directive'),
  1147.             ('^%TAG(?=[ ]|$)', reset_indent(Name.Tag), 'tag-directive'),
  1148.             ('^(?:---|\\.\\.\\.)(?=[ ]|$)', reset_indent(Name.Namespace), 'block-line'),
  1149.             ('[ ]*(?![ \\t\\n\\r\\f\\v]|$)', save_indent(Text, start = True), ('block-line', 'indentation'))],
  1150.         'ignored-line': [
  1151.             ('[ ]+(?=#|$)', Text),
  1152.             ('#[^\\n]*', Comment.Single),
  1153.             ('\\n', Text, '#pop:2')],
  1154.         'yaml-directive': [
  1155.             ('([ ]+)([0-9]+\\.[0-9]+)', bygroups(Text, Number), 'ignored-line')],
  1156.         'tag-directive': [
  1157.             ("([ ]+)(!|![0-9A-Za-z_-]*!)([ ]+)(!|!?[0-9A-Za-z;/?:@&=+$,_.!~*\\'()\\[\\]%-]+)", bygroups(Text, Keyword.Type, Text, Keyword.Type), 'ignored-line')],
  1158.         'indentation': [
  1159.             ('[ ]*$', something(Text), '#pop:2'),
  1160.             ('[ ]+(?=[?:-](?:[ ]|$))', save_indent(Text)),
  1161.             ('[?:-](?=[ ]|$)', set_indent(Punctuation.Indicator)),
  1162.             ('[ ]*', save_indent(Text), '#pop')],
  1163.         'block-line': [
  1164.             ('[ ]*(?=#|$)', something(Text), '#pop'),
  1165.             ('[ ]+', Text),
  1166.             include('descriptors'),
  1167.             include('block-nodes'),
  1168.             include('flow-nodes'),
  1169.             ('(?=[^ \\t\\n\\r\\f\\v?:,\\[\\]{}#&*!|>\\\'"%@`-]|[?:-][^ \\t\\n\\r\\f\\v])', something(Name.Variable), 'plain-scalar-in-block-context')],
  1170.         'descriptors': [
  1171.             ("!<[0-9A-Za-z;/?:@&=+$,_.!~*\\'()\\[\\]%-]+>", Keyword.Type),
  1172.             ("!(?:[0-9A-Za-z_-]+)?(?:![0-9A-Za-z;/?:@&=+$,_.!~*\\'()\\[\\]%-]+)?", Keyword.Type),
  1173.             ('&[0-9A-Za-z_-]+', Name.Label),
  1174.             ('\\*[0-9A-Za-z_-]+', Name.Variable)],
  1175.         'block-nodes': [
  1176.             (':(?=[ ]|$)', set_indent(Punctuation.Indicator, implicit = True)),
  1177.             ('[|>]', Punctuation.Indicator, ('block-scalar-content', 'block-scalar-header'))],
  1178.         'flow-nodes': [
  1179.             ('\\[', Punctuation.Indicator, 'flow-sequence'),
  1180.             ('\\{', Punctuation.Indicator, 'flow-mapping'),
  1181.             ("\\'", String, 'single-quoted-scalar'),
  1182.             ('\\"', String, 'double-quoted-scalar')],
  1183.         'flow-collection': [
  1184.             ('[ ]+', Text),
  1185.             ('\\n+', Text),
  1186.             ('#[^\\n]*', Comment.Single),
  1187.             ('[?:,]', Punctuation.Indicator),
  1188.             include('descriptors'),
  1189.             include('flow-nodes'),
  1190.             ('(?=[^ \\t\\n\\r\\f\\v?:,\\[\\]{}#&*!|>\\\'"%@`])', something(Name.Variable), 'plain-scalar-in-flow-context')],
  1191.         'flow-sequence': [
  1192.             include('flow-collection'),
  1193.             ('\\]', Punctuation.Indicator, '#pop')],
  1194.         'flow-mapping': [
  1195.             include('flow-collection'),
  1196.             ('\\}', Punctuation.Indicator, '#pop')],
  1197.         'block-scalar-content': [
  1198.             ('\\n', Text),
  1199.             ('^[ ]+$', parse_block_scalar_empty_line(Text, Name.Constant)),
  1200.             ('^[ ]*', parse_block_scalar_indent(Text)),
  1201.             ('[^\\n\\r\\f\\v]+', Name.Constant)],
  1202.         'block-scalar-header': [
  1203.             ('([1-9])?[+-]?(?=[ ]|$)', set_block_scalar_indent(Punctuation.Indicator), 'ignored-line'),
  1204.             ('[+-]?([1-9])?(?=[ ]|$)', set_block_scalar_indent(Punctuation.Indicator), 'ignored-line')],
  1205.         'quoted-scalar-whitespaces': [
  1206.             ('^[ ]+|[ ]+$', Text),
  1207.             ('\\n+', Text),
  1208.             ('[ ]+', Name.Variable)],
  1209.         'single-quoted-scalar': [
  1210.             include('quoted-scalar-whitespaces'),
  1211.             ("\\'\\'", String.Escape),
  1212.             ("[^ \\t\\n\\r\\f\\v\\']+", String),
  1213.             ("\\'", String, '#pop')],
  1214.         'double-quoted-scalar': [
  1215.             include('quoted-scalar-whitespaces'),
  1216.             ('\\\\[0abt\\tn\\nvfre "\\\\N_LP]', String),
  1217.             ('\\\\(?:x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})', String.Escape),
  1218.             ('[^ \\t\\n\\r\\f\\v\\"\\\\]+', String),
  1219.             ('"', String, '#pop')],
  1220.         'plain-scalar-in-block-context-new-line': [
  1221.             ('^[ ]+$', Text),
  1222.             ('\\n+', Text),
  1223.             ('^(?=---|\\.\\.\\.)', something(Name.Namespace), '#pop:3'),
  1224.             ('^[ ]*', parse_plain_scalar_indent(Text), '#pop')],
  1225.         'plain-scalar-in-block-context': [
  1226.             ('[ ]*(?=:[ ]|:$)', something(Text), '#pop'),
  1227.             ('[ ]+(?=#)', Text, '#pop'),
  1228.             ('[ ]+$', Text),
  1229.             ('\\n+', Text, 'plain-scalar-in-block-context-new-line'),
  1230.             ('[ ]+', Literal.Scalar.Plain),
  1231.             ('(?::(?![ \\t\\n\\r\\f\\v])|[^ \\t\\n\\r\\f\\v:])+', Literal.Scalar.Plain)],
  1232.         'plain-scalar-in-flow-context': [
  1233.             ('[ ]*(?=[,:?\\[\\]{}])', something(Text), '#pop'),
  1234.             ('[ ]+(?=#)', Text, '#pop'),
  1235.             ('^[ ]+|[ ]+$', Text),
  1236.             ('\\n+', Text),
  1237.             ('[ ]+', Name.Variable),
  1238.             ('[^ \\t\\n\\r\\f\\v,:?\\[\\]{}]+', Name.Variable)] }
  1239.     
  1240.     def get_tokens_unprocessed(self, text = None, context = None):
  1241.         if context is None:
  1242.             context = YamlLexerContext(text, 0)
  1243.         
  1244.         return super(YamlLexer, self).get_tokens_unprocessed(text, context)
  1245.  
  1246.  
  1247.  
  1248. class LighttpdConfLexer(RegexLexer):
  1249.     name = 'Lighttpd configuration file'
  1250.     aliases = [
  1251.         'lighty',
  1252.         'lighttpd']
  1253.     filenames = []
  1254.     mimetypes = [
  1255.         'text/x-lighttpd-conf']
  1256.     tokens = {
  1257.         'root': [
  1258.             ('#.*\\n', Comment.Single),
  1259.             ('/\\S*', Name),
  1260.             ('[a-zA-Z._-]+', Keyword),
  1261.             ('\\d+\\.\\d+\\.\\d+\\.\\d+(?:/\\d+)?', Number),
  1262.             ('[0-9]+', Number),
  1263.             ('=>|=~|\\+=|==|=|\\+', Operator),
  1264.             ('\\$[A-Z]+', Name.Builtin),
  1265.             ('[(){}\\[\\],]', Punctuation),
  1266.             ('"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"', String.Double),
  1267.             ('\\s+', Text)] }
  1268.  
  1269.  
  1270. class NginxConfLexer(RegexLexer):
  1271.     name = 'Nginx configuration file'
  1272.     aliases = [
  1273.         'nginx']
  1274.     filenames = []
  1275.     mimetypes = [
  1276.         'text/x-nginx-conf']
  1277.     tokens = {
  1278.         'root': [
  1279.             ('(include)(\\s+)([^\\s;]+)', bygroups(Keyword, Text, Name)),
  1280.             ('[^\\s;#]+', Keyword, 'stmt'),
  1281.             include('base')],
  1282.         'block': [
  1283.             ('}', Punctuation, '#pop:2'),
  1284.             ('[^\\s;#]+', Keyword.Namespace, 'stmt'),
  1285.             include('base')],
  1286.         'stmt': [
  1287.             ('{', Punctuation, 'block'),
  1288.             (';', Punctuation, '#pop'),
  1289.             include('base')],
  1290.         'base': [
  1291.             ('#.*\\n', Comment.Single),
  1292.             ('on|off', Name.Constant),
  1293.             ('\\$[^\\s;#()]+', Name.Variable),
  1294.             ('([a-z0-9.-]+)(:)([0-9]+)', bygroups(Name, Punctuation, Number.Integer)),
  1295.             ('[a-z-]+/[a-z-+]+', String),
  1296.             ('[0-9]+[km]?\\b', Number.Integer),
  1297.             ('(~)(\\s*)([^\\s{]+)', bygroups(Punctuation, Text, String.Regex)),
  1298.             ('[:=~]', Punctuation),
  1299.             ('[^\\s;#{}$]+', String),
  1300.             ('/[^\\s;#]*', Name),
  1301.             ('\\s+', Text),
  1302.             ('[$;]', Text)] }
  1303.  
  1304.  
  1305. class CMakeLexer(RegexLexer):
  1306.     name = 'CMake'
  1307.     aliases = [
  1308.         'cmake']
  1309.     filenames = [
  1310.         '*.cmake']
  1311.     mimetypes = [
  1312.         'text/x-cmake']
  1313.     tokens = {
  1314.         'root': [
  1315.             ('\\b([A-Za-z_]+)([ \\t]*)(\\()', bygroups(Name.Builtin, Text, Punctuation), 'args'),
  1316.             include('keywords'),
  1317.             include('ws')],
  1318.         'args': [
  1319.             ('\\(', Punctuation, '#push'),
  1320.             ('\\)', Punctuation, '#pop'),
  1321.             ('(\\${)(.+?)(})', bygroups(Operator, Name.Variable, Operator)),
  1322.             ('(?s)".*?"', String.Double),
  1323.             ('\\\\\\S+', String),
  1324.             ('[^\\)$"# \\t\\n]+', String),
  1325.             ('\\n', Text),
  1326.             include('keywords'),
  1327.             include('ws')],
  1328.         'string': [],
  1329.         'keywords': [
  1330.             ('\\b(WIN32|UNIX|APPLE|CYGWIN|BORLAND|MINGW|MSVC|MSVC_IDE|MSVC60|MSVC70|MSVC71|MSVC80|MSVC90)\\b', Keyword)],
  1331.         'ws': [
  1332.             ('[ \\t]+', Text),
  1333.             ('#.+\\n', Comment)] }
  1334.  
  1335.