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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import re
  5. from pygments.lexer import RegexLexer, DelegatingLexer, bygroups, using, this
  6. from pygments.token import Punctuation, Text, Comment, Operator, Keyword, Name, String, Number, Literal, Other
  7. from pygments.util import get_choice_opt
  8. from pygments import unistring as uni
  9. from pygments.lexers.web import XmlLexer
  10. __all__ = [
  11.     'CSharpLexer',
  12.     'BooLexer',
  13.     'VbNetLexer',
  14.     'CSharpAspxLexer',
  15.     'VbNetAspxLexer']
  16.  
  17. def _escape(st):
  18.     return st.replace(u'\\', u'\\\\').replace(u'-', u'\\-').replace(u'[', u'\\[').replace(u']', u'\\]')
  19.  
  20.  
  21. class CSharpLexer(RegexLexer):
  22.     name = 'C#'
  23.     aliases = [
  24.         'csharp',
  25.         'c#']
  26.     filenames = [
  27.         '*.cs']
  28.     mimetypes = [
  29.         'text/x-csharp']
  30.     flags = re.MULTILINE | re.DOTALL | re.UNICODE
  31.     levels = {
  32.         'none': '@?[_a-zA-Z][a-zA-Z0-9_]*',
  33.         'basic': '@?[_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + ']' + '[' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + uni.Nd + uni.Pc + uni.Cf + uni.Mn + uni.Mc + ']*',
  34.         'full': '@?(?:_|[^' + _escape(uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl')) + '])' + '[^' + _escape(uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', 'Nd', 'Pc', 'Cf', 'Mn', 'Mc')) + ']*' }
  35.     tokens = { }
  36.     token_variants = True
  37.     for levelname, cs_ident in levels.items():
  38.         tokens[levelname] = {
  39.             'root': [
  40.                 ('^([ \\t]*(?:' + cs_ident + '(?:\\[\\])?\\s+)+?)(' + cs_ident + ')(\\s*)(\\()', bygroups(using(this), Name.Function, Text, Punctuation)),
  41.                 ('^\\s*\\[.*?\\]', Name.Attribute),
  42.                 ('[^\\S\\n]+', Text),
  43.                 ('\\\\\\n', Text),
  44.                 ('//.*?\\n', Comment.Single),
  45.                 ('/[*](.|\\n)*?[*]/', Comment.Multiline),
  46.                 ('\\n', Text),
  47.                 ('[~!%^&*()+=|\\[\\]:;,.<>/?-]', Punctuation),
  48.                 ('[{}]', Punctuation),
  49.                 ('@"(\\\\\\\\|\\\\"|[^"])*"', String),
  50.                 ('"(\\\\\\\\|\\\\"|[^"\\n])*["\\n]', String),
  51.                 ("'\\\\.'|'[^\\\\]'", String.Char),
  52.                 ('[0-9](\\.[0-9]*)?([eE][+-][0-9]+)?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?', Number),
  53.                 ('#[ \\t]*(if|endif|else|elif|define|undef|line|error|warning|region|endregion|pragma)\\b.*?\\n', Comment.Preproc),
  54.                 ('\\b(extern)(\\s+)(alias)\\b', bygroups(Keyword, Text, Keyword)),
  55.                 ('(abstract|as|base|break|case|catch|checked|const|continue|default|delegate|do|else|enum|event|explicit|extern|false|finally|fixed|for|foreach|goto|if|implicit|in|interface|internal|is|lock|new|null|operator|out|override|params|private|protected|public|readonly|ref|return|sealed|sizeof|stackalloc|static|switch|this|throw|true|try|typeof|unchecked|unsafe|virtual|void|while|get|set|new|partial|yield|add|remove|value)\\b', Keyword),
  56.                 ('(global)(::)', bygroups(Keyword, Punctuation)),
  57.                 ('(bool|byte|char|decimal|double|float|int|long|object|sbyte|short|string|uint|ulong|ushort)\\b\\??', Keyword.Type),
  58.                 ('(class|struct)(\\s+)', bygroups(Keyword, Text), 'class'),
  59.                 ('(namespace|using)(\\s+)', bygroups(Keyword, Text), 'namespace'),
  60.                 (cs_ident, Name)],
  61.             'class': [
  62.                 (cs_ident, Name.Class, '#pop')],
  63.             'namespace': [
  64.                 ('(?=\\()', Text, '#pop'),
  65.                 ('(' + cs_ident + '|\\.)+', Name.Namespace, '#pop')] }
  66.     
  67.     
  68.     def __init__(self, **options):
  69.         level = get_choice_opt(options, 'unicodelevel', self.tokens.keys(), 'basic')
  70.         if level not in self._all_tokens:
  71.             self._tokens = self.__class__.process_tokendef(level)
  72.         else:
  73.             self._tokens = self._all_tokens[level]
  74.         RegexLexer.__init__(self, **options)
  75.  
  76.  
  77.  
  78. class BooLexer(RegexLexer):
  79.     name = 'Boo'
  80.     aliases = [
  81.         'boo']
  82.     filenames = [
  83.         '*.boo']
  84.     mimetypes = [
  85.         'text/x-boo']
  86.     tokens = {
  87.         'root': [
  88.             ('\\s+', Text),
  89.             ('(#|//).*$', Comment.Single),
  90.             ('/[*]', Comment.Multiline, 'comment'),
  91.             ('[]{}:(),.;[]', Punctuation),
  92.             ('\\\\\\n', Text),
  93.             ('\\\\', Text),
  94.             ('(in|is|and|or|not)\\b', Operator.Word),
  95.             ('/(\\\\\\\\|\\\\/|[^/\\s])/', String.Regex),
  96.             ('@/(\\\\\\\\|\\\\/|[^/])*/', String.Regex),
  97.             ('=~|!=|==|<<|>>|[-+/*%=<>&^|]', Operator),
  98.             ('(as|abstract|callable|constructor|destructor|do|import|enum|event|final|get|interface|internal|of|override|partial|private|protected|public|return|set|static|struct|transient|virtual|yield|super|and|break|cast|continue|elif|else|ensure|except|for|given|goto|if|in|is|isa|not|or|otherwise|pass|raise|ref|try|unless|when|while|from|as)\\b', Keyword),
  99.             ('def(?=\\s+\\(.*?\\))', Keyword),
  100.             ('(def)(\\s+)', bygroups(Keyword, Text), 'funcname'),
  101.             ('(class)(\\s+)', bygroups(Keyword, Text), 'classname'),
  102.             ('(namespace)(\\s+)', bygroups(Keyword, Text), 'namespace'),
  103.             ('(?<!\\.)(true|false|null|self|__eval__|__switch__|array|assert|checked|enumerate|filter|getter|len|lock|map|matrix|max|min|normalArrayIndexing|print|property|range|rawArrayIndexing|required|typeof|unchecked|using|yieldAll|zip)\\b', Name.Builtin),
  104.             ('"""(\\\\|\\"|.*?)"""', String.Double),
  105.             ('"(\\\\|\\"|[^"]*?)"', String.Double),
  106.             ("'(\\\\|\\'|[^']*?)'", String.Single),
  107.             ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
  108.             ('(\\d+\\.\\d*|\\d*\\.\\d+)([fF][+-]?[0-9]+)?', Number.Float),
  109.             ('[0-9][0-9\\.]*(m|ms|d|h|s)', Number),
  110.             ('0\\d+', Number.Oct),
  111.             ('0x[a-fA-F0-9]+', Number.Hex),
  112.             ('\\d+L', Number.Integer.Long),
  113.             ('\\d+', Number.Integer)],
  114.         'comment': [
  115.             ('/[*]', Comment.Multiline, '#push'),
  116.             ('[*]/', Comment.Multiline, '#pop'),
  117.             ('[^/*]', Comment.Multiline),
  118.             ('[*/]', Comment.Multiline)],
  119.         'funcname': [
  120.             ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop')],
  121.         'classname': [
  122.             ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')],
  123.         'namespace': [
  124.             ('[a-zA-Z_][a-zA-Z0-9_.]*', Name.Namespace, '#pop')] }
  125.  
  126.  
  127. class VbNetLexer(RegexLexer):
  128.     name = 'VB.net'
  129.     aliases = [
  130.         'vb.net',
  131.         'vbnet']
  132.     filenames = [
  133.         '*.vb',
  134.         '*.bas']
  135.     mimetypes = [
  136.         'text/x-vbnet',
  137.         'text/x-vba']
  138.     flags = re.MULTILINE | re.IGNORECASE
  139.     tokens = {
  140.         'root': [
  141.             ('^\\s*<.*?>', Name.Attribute),
  142.             ('\\s+', Text),
  143.             ('\\n', Text),
  144.             ('rem\\b.*?\\n', Comment),
  145.             ("'.*?\\n", Comment),
  146.             ('#If\\s.*?\\sThen|#ElseIf\\s.*?\\sThen|#End\\s+If|#Const|#ExternalSource.*?\\n|#End\\s+ExternalSource|#Region.*?\\n|#End\\s+Region|#ExternalChecksum', Comment.Preproc),
  147.             ('[\\(\\){}!#,.:]', Punctuation),
  148.             ('Option\\s+(Strict|Explicit|Compare)\\s+(On|Off|Binary|Text)', Keyword.Declaration),
  149.             ('(?<!\\.)(AddHandler|Alias|ByRef|ByVal|Call|Case|Catch|CBool|CByte|CChar|CDate|CDec|CDbl|CInt|CLng|CObj|Const|Continue|CSByte|CShort|CSng|CStr|CType|CUInt|CULng|CUShort|Declare|Default|Delegate|Dim|DirectCast|Do|Each|Else|ElseIf|End|EndIf|Enum|Erase|Error|Event|Exit|False|Finally|For|Friend|Function|Get|Global|GoSub|GoTo|Handles|If|Implements|Imports|Inherits|Interface|Let|Lib|Loop|Me|Module|MustInherit|MustOverride|MyBase|MyClass|Namespace|Narrowing|New|Next|Not|Nothing|NotInheritable|NotOverridable|Of|On|Operator|Option|Optional|Overloads|Overridable|Overrides|ParamArray|Partial|Private|Property|Protected|Public|RaiseEvent|ReadOnly|ReDim|RemoveHandler|Resume|Return|Select|Set|Shadows|Shared|Single|Static|Step|Stop|Structure|Sub|SyncLock|Then|Throw|To|True|Try|TryCast|Wend|Using|When|While|Widening|With|WithEvents|WriteOnly)\\b', Keyword),
  150.             ('(?<!\\.)(Function|Sub|Property)(\\s+)', bygroups(Keyword, Text), 'funcname'),
  151.             ('(?<!\\.)(Class|Structure|Enum)(\\s+)', bygroups(Keyword, Text), 'classname'),
  152.             ('(?<!\\.)(Namespace|Imports)(\\s+)', bygroups(Keyword, Text), 'namespace'),
  153.             ('(?<!\\.)(Boolean|Byte|Char|Date|Decimal|Double|Integer|Long|Object|SByte|Short|Single|String|Variant|UInteger|ULong|UShort)\\b', Keyword.Type),
  154.             ('(?<!\\.)(AddressOf|And|AndAlso|As|GetType|In|Is|IsNot|Like|Mod|Or|OrElse|TypeOf|Xor)\\b', Operator.Word),
  155.             ('&=|[*]=|/=|\\\\=|\\^=|\\+=|-=|<<=|>>=|<<|>>|:=|<=|>=|<>|[-&*/\\\\^+=<>]', Operator),
  156.             ('"', String, 'string'),
  157.             ('[a-zA-Z_][a-zA-Z0-9_]*[%&@!#$]?', Name),
  158.             ('#.*?#', Literal.Date),
  159.             ('(\\d+\\.\\d*|\\d*\\.\\d+)([fF][+-]?[0-9]+)?', Number.Float),
  160.             ('\\d+([SILDFR]|US|UI|UL)?', Number.Integer),
  161.             ('&H[0-9a-f]+([SILDFR]|US|UI|UL)?', Number.Integer),
  162.             ('&O[0-7]+([SILDFR]|US|UI|UL)?', Number.Integer),
  163.             ('_\\n', Text)],
  164.         'string': [
  165.             ('""', String),
  166.             ('"C?', String, '#pop'),
  167.             ('[^"]+', String)],
  168.         'funcname': [
  169.             ('[a-z_][a-z0-9_]*', Name.Function, '#pop')],
  170.         'classname': [
  171.             ('[a-z_][a-z0-9_]*', Name.Class, '#pop')],
  172.         'namespace': [
  173.             ('[a-z_][a-z0-9_.]*', Name.Namespace, '#pop')] }
  174.  
  175.  
  176. class GenericAspxLexer(RegexLexer):
  177.     name = 'aspx-gen'
  178.     filenames = []
  179.     mimetypes = []
  180.     flags = re.DOTALL
  181.     tokens = {
  182.         'root': [
  183.             ('(<%[@=#]?)(.*?)(%>)', bygroups(Name.Tag, Other, Name.Tag)),
  184.             ('(<script.*?>)(.*?)(</script>)', bygroups(using(XmlLexer), Other, using(XmlLexer))),
  185.             ('(.+?)(?=<)', using(XmlLexer)),
  186.             ('.+', using(XmlLexer))] }
  187.  
  188.  
  189. class CSharpAspxLexer(DelegatingLexer):
  190.     name = 'aspx-cs'
  191.     aliases = [
  192.         'aspx-cs']
  193.     filenames = [
  194.         '*.aspx',
  195.         '*.asax',
  196.         '*.ascx',
  197.         '*.ashx',
  198.         '*.asmx',
  199.         '*.axd']
  200.     mimetypes = []
  201.     
  202.     def __init__(self, **options):
  203.         super(CSharpAspxLexer, self).__init__(CSharpLexer, GenericAspxLexer, **options)
  204.  
  205.     
  206.     def analyse_text(text):
  207.         if re.search('Page\\s*Language="C#"', text, re.I) is not None:
  208.             return 0.2
  209.         if re.search('script[^>]+language=["\\\']C#', text, re.I) is not None:
  210.             return 0.15
  211.         return 0.001
  212.  
  213.  
  214.  
  215. class VbNetAspxLexer(DelegatingLexer):
  216.     name = 'aspx-vb'
  217.     aliases = [
  218.         'aspx-vb']
  219.     filenames = [
  220.         '*.aspx',
  221.         '*.asax',
  222.         '*.ascx',
  223.         '*.ashx',
  224.         '*.asmx',
  225.         '*.axd']
  226.     mimetypes = []
  227.     
  228.     def __init__(self, **options):
  229.         super(VbNetAspxLexer, self).__init__(VbNetLexer, GenericAspxLexer, **options)
  230.  
  231.     
  232.     def analyse_text(text):
  233.         if re.search('Page\\s*Language="Vb"', text, re.I) is not None:
  234.             return 0.2
  235.         if re.search('script[^>]+language=["\\\']vb', text, re.I) is not None:
  236.             return 0.15
  237.  
  238.  
  239.