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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import re
  5. from pygments.lexer import RegexLexer, DelegatingLexer, include, bygroups, using
  6. from pygments.token import Punctuation, Other, Text, Comment, Operator, Keyword, Name, String, Number, Whitespace
  7. from pygments.lexers.compiled import JavaLexer, CLexer, CppLexer, ObjectiveCLexer, DLexer
  8. from pygments.lexers.dotnet import CSharpLexer
  9. from pygments.lexers.agile import RubyLexer, PythonLexer, PerlLexer
  10. from pygments.lexers.web import ActionScriptLexer
  11. __all__ = [
  12.     'RagelLexer',
  13.     'RagelEmbeddedLexer',
  14.     'RagelCLexer',
  15.     'RagelDLexer',
  16.     'RagelCppLexer',
  17.     'RagelObjectiveCLexer',
  18.     'RagelRubyLexer',
  19.     'RagelJavaLexer',
  20.     'AntlrLexer',
  21.     'AntlrPythonLexer',
  22.     'AntlrPerlLexer',
  23.     'AntlrRubyLexer',
  24.     'AntlrCppLexer',
  25.     'AntlrCSharpLexer',
  26.     'AntlrObjectiveCLexer',
  27.     'AntlrJavaLexer',
  28.     'AntlrActionScriptLexer']
  29.  
  30. class RagelLexer(RegexLexer):
  31.     name = 'Ragel'
  32.     aliases = [
  33.         'ragel']
  34.     filenames = []
  35.     tokens = {
  36.         'whitespace': [
  37.             ('\\s+', Whitespace)],
  38.         'comments': [
  39.             ('\\#.*$', Comment)],
  40.         'keywords': [
  41.             ('(access|action|alphtype)\\b', Keyword),
  42.             ('(getkey|write|machine|include)\\b', Keyword),
  43.             ('(any|ascii|extend|alpha|digit|alnum|lower|upper)\\b', Keyword),
  44.             ('(xdigit|cntrl|graph|print|punct|space|zlen|empty)\\b', Keyword)],
  45.         'numbers': [
  46.             ('0x[0-9A-Fa-f]+', Number.Hex),
  47.             ('[+-]?[0-9]+', Number.Integer)],
  48.         'literals': [
  49.             ('"(\\\\\\\\|\\\\"|[^"])*"', String),
  50.             ("'(\\\\\\\\|\\\\'|[^'])*'", String),
  51.             ('\\[(\\\\\\\\|\\\\\\]|[^\\]])*\\]', String),
  52.             ('/(?!\\*)(\\\\\\\\|\\\\/|[^/])*/', String.Regex)],
  53.         'identifiers': [
  54.             ('[a-zA-Z_][a-zA-Z_0-9]*', Name.Variable)],
  55.         'operators': [
  56.             (',', Operator),
  57.             ('\\||&|-|--', Operator),
  58.             ('\\.|<:|:>|:>>', Operator),
  59.             (':', Operator),
  60.             ('->', Operator),
  61.             ('(>|\\$|%|<|@|<>)(/|eof\\b)', Operator),
  62.             ('(>|\\$|%|<|@|<>)(!|err\\b)', Operator),
  63.             ('(>|\\$|%|<|@|<>)(\\^|lerr\\b)', Operator),
  64.             ('(>|\\$|%|<|@|<>)(~|to\\b)', Operator),
  65.             ('(>|\\$|%|<|@|<>)(\\*|from\\b)', Operator),
  66.             ('>|@|\\$|%', Operator),
  67.             ('\\*|\\?|\\+|{[0-9]*,[0-9]*}', Operator),
  68.             ('!|\\^', Operator),
  69.             ('\\(|\\)', Operator)],
  70.         'root': [
  71.             include('literals'),
  72.             include('whitespace'),
  73.             include('comments'),
  74.             include('keywords'),
  75.             include('numbers'),
  76.             include('identifiers'),
  77.             include('operators'),
  78.             ('{', Punctuation, 'host'),
  79.             ('=', Operator),
  80.             (';', Punctuation)],
  81.         'host': [
  82.             ('(' + '|'.join(('[^{}\\\'"/#]+', '[^\\\\][\\\\][{}]', '"(\\\\\\\\|\\\\"|[^"])*"', "'(\\\\\\\\|\\\\'|[^'])*'", '//.*$\\n?', '/\\*(.|\\n)*?\\*/', '\\#.*$\\n?', '/(?!\\*)(\\\\\\\\|\\\\/|[^/])*/', '/')) + ')+', Other),
  83.             ('{', Punctuation, '#push'),
  84.             ('}', Punctuation, '#pop')] }
  85.  
  86.  
  87. class RagelEmbeddedLexer(RegexLexer):
  88.     name = 'Embedded Ragel'
  89.     aliases = [
  90.         'ragel-em']
  91.     filenames = [
  92.         '*.rl']
  93.     tokens = {
  94.         'root': [
  95.             ('(' + '|'.join(('[^%\\\'"/#]+', '%(?=[^%]|$)', '"(\\\\\\\\|\\\\"|[^"])*"', "'(\\\\\\\\|\\\\'|[^'])*'", '/\\*(.|\\n)*?\\*/', '//.*$\\n?', '\\#.*$\\n?', '/(?!\\*)(\\\\\\\\|\\\\/|[^/])*/', '/')) + ')+', Other),
  96.             ('(%%)(?![{%])(.*)($|;)(\\n?)', bygroups(Punctuation, using(RagelLexer), Punctuation, Text)),
  97.             ('(%%%%|%%){', Punctuation, 'multi-line-fsm')],
  98.         'multi-line-fsm': [
  99.             ('(' + '|'.join(('(' + '|'.join(('[^}\\\'"\\[/#]', '}(?=[^%]|$)', '}%(?=[^%]|$)', '[^\\\\][\\\\][{}]', '(>|\\$|%|<|@|<>)/', '/(?!\\*)(\\\\\\\\|\\\\/|[^/])*/\\*', '/(?=[^/\\*]|$)')) + ')+', '"(\\\\\\\\|\\\\"|[^"])*"', "'(\\\\\\\\|\\\\'|[^'])*'", '\\[(\\\\\\\\|\\\\\\]|[^\\]])*\\]', '/\\*(.|\\n)*?\\*/', '//.*$\\n?', '\\#.*$\\n?')) + ')+', using(RagelLexer)),
  100.             ('}%%', Punctuation, '#pop')] }
  101.     
  102.     def analyse_text(text):
  103.         if not '@LANG: indep' in text:
  104.             pass
  105.         return 0.1
  106.  
  107.  
  108.  
  109. class RagelRubyLexer(DelegatingLexer):
  110.     name = 'Ragel in Ruby Host'
  111.     aliases = [
  112.         'ragel-ruby',
  113.         'ragel-rb']
  114.     filenames = [
  115.         '*.rl']
  116.     
  117.     def __init__(self, **options):
  118.         super(RagelRubyLexer, self).__init__(RubyLexer, RagelEmbeddedLexer, **options)
  119.  
  120.     
  121.     def analyse_text(text):
  122.         return '@LANG: ruby' in text
  123.  
  124.  
  125.  
  126. class RagelCLexer(DelegatingLexer):
  127.     name = 'Ragel in C Host'
  128.     aliases = [
  129.         'ragel-c']
  130.     filenames = [
  131.         '*.rl']
  132.     
  133.     def __init__(self, **options):
  134.         super(RagelCLexer, self).__init__(CLexer, RagelEmbeddedLexer, **options)
  135.  
  136.     
  137.     def analyse_text(text):
  138.         return '@LANG: c' in text
  139.  
  140.  
  141.  
  142. class RagelDLexer(DelegatingLexer):
  143.     name = 'Ragel in D Host'
  144.     aliases = [
  145.         'ragel-d']
  146.     filenames = [
  147.         '*.rl']
  148.     
  149.     def __init__(self, **options):
  150.         super(RagelDLexer, self).__init__(DLexer, RagelEmbeddedLexer, **options)
  151.  
  152.     
  153.     def analyse_text(text):
  154.         return '@LANG: d' in text
  155.  
  156.  
  157.  
  158. class RagelCppLexer(DelegatingLexer):
  159.     name = 'Ragel in CPP Host'
  160.     aliases = [
  161.         'ragel-cpp']
  162.     filenames = [
  163.         '*.rl']
  164.     
  165.     def __init__(self, **options):
  166.         super(RagelCppLexer, self).__init__(CppLexer, RagelEmbeddedLexer, **options)
  167.  
  168.     
  169.     def analyse_text(text):
  170.         return '@LANG: c++' in text
  171.  
  172.  
  173.  
  174. class RagelObjectiveCLexer(DelegatingLexer):
  175.     name = 'Ragel in Objective C Host'
  176.     aliases = [
  177.         'ragel-objc']
  178.     filenames = [
  179.         '*.rl']
  180.     
  181.     def __init__(self, **options):
  182.         super(RagelObjectiveCLexer, self).__init__(ObjectiveCLexer, RagelEmbeddedLexer, **options)
  183.  
  184.     
  185.     def analyse_text(text):
  186.         return '@LANG: objc' in text
  187.  
  188.  
  189.  
  190. class RagelJavaLexer(DelegatingLexer):
  191.     name = 'Ragel in Java Host'
  192.     aliases = [
  193.         'ragel-java']
  194.     filenames = [
  195.         '*.rl']
  196.     
  197.     def __init__(self, **options):
  198.         super(RagelJavaLexer, self).__init__(JavaLexer, RagelEmbeddedLexer, **options)
  199.  
  200.     
  201.     def analyse_text(text):
  202.         return '@LANG: java' in text
  203.  
  204.  
  205.  
  206. class AntlrLexer(RegexLexer):
  207.     name = 'ANTLR'
  208.     aliases = [
  209.         'antlr']
  210.     filenames = []
  211.     _id = '[A-Za-z][A-Za-z_0-9]*'
  212.     _TOKEN_REF = '[A-Z][A-Za-z_0-9]*'
  213.     _RULE_REF = '[a-z][A-Za-z_0-9]*'
  214.     _STRING_LITERAL = "\\'(?:\\\\\\\\|\\\\\\'|[^\\']*)\\'"
  215.     _INT = '[0-9]+'
  216.     tokens = {
  217.         'whitespace': [
  218.             ('\\s+', Whitespace)],
  219.         'comments': [
  220.             ('//.*$', Comment),
  221.             ('/\\*(.|\\n)*?\\*/', Comment)],
  222.         'root': [
  223.             include('whitespace'),
  224.             include('comments'),
  225.             ('(lexer|parser|tree)?(\\s*)(grammar\\b)(\\s*)(' + _id + ')(;)', bygroups(Keyword, Whitespace, Keyword, Whitespace, Name.Class, Punctuation)),
  226.             ('options\\b', Keyword, 'options'),
  227.             ('tokens\\b', Keyword, 'tokens'),
  228.             ('(scope)(\\s*)(' + _id + ')(\\s*)({)', bygroups(Keyword, Whitespace, Name.Variable, Whitespace, Punctuation), 'action'),
  229.             ('(catch|finally)\\b', Keyword, 'exception'),
  230.             ('(@' + _id + ')(\\s*)(::)?(\\s*)(' + _id + ')(\\s*)({)', bygroups(Name.Label, Whitespace, Punctuation, Whitespace, Name.Label, Whitespace, Punctuation), 'action'),
  231.             ('((?:protected|private|public|fragment)\\b)?(\\s*)(' + _id + ')(!)?', bygroups(Keyword, Whitespace, Name.Label, Punctuation), ('rule-alts', 'rule-prelims'))],
  232.         'exception': [
  233.             ('\\n', Whitespace, '#pop'),
  234.             ('\\s', Whitespace),
  235.             include('comments'),
  236.             ('\\[', Punctuation, 'nested-arg-action'),
  237.             ('\\{', Punctuation, 'action')],
  238.         'rule-prelims': [
  239.             include('whitespace'),
  240.             include('comments'),
  241.             ('returns\\b', Keyword),
  242.             ('\\[', Punctuation, 'nested-arg-action'),
  243.             ('\\{', Punctuation, 'action'),
  244.             ('(throws)(\\s+)(' + _id + ')', bygroups(Keyword, Whitespace, Name.Label)),
  245.             ('(?:(,)(\\s*)(' + _id + '))+', bygroups(Punctuation, Whitespace, Name.Label)),
  246.             ('options\\b', Keyword, 'options'),
  247.             ('(scope)(\\s+)({)', bygroups(Keyword, Whitespace, Punctuation), 'action'),
  248.             ('(scope)(\\s+)(' + _id + ')(\\s*)(;)', bygroups(Keyword, Whitespace, Name.Label, Whitespace, Punctuation)),
  249.             ('(@' + _id + ')(\\s*)({)', bygroups(Name.Label, Whitespace, Punctuation), 'action'),
  250.             (':', Punctuation, '#pop')],
  251.         'rule-alts': [
  252.             include('whitespace'),
  253.             include('comments'),
  254.             ('options\\b', Keyword, 'options'),
  255.             (':', Punctuation),
  256.             ("'(\\\\\\\\|\\\\'|[^'])*'", String),
  257.             ('"(\\\\\\\\|\\\\"|[^"])*"', String),
  258.             ('<<([^>]|>[^>])>>', String),
  259.             ('\\$?[A-Z_][A-Za-z_0-9]*', Name.Constant),
  260.             ('\\$?[a-z_][A-Za-z_0-9]*', Name.Variable),
  261.             ('(\\+|\\||->|=>|=|\\(|\\)|\\.\\.|\\.|\\?|\\*|\\^|!|\\#|~)', Operator),
  262.             (',', Punctuation),
  263.             ('\\[', Punctuation, 'nested-arg-action'),
  264.             ('\\{', Punctuation, 'action'),
  265.             (';', Punctuation, '#pop')],
  266.         'tokens': [
  267.             include('whitespace'),
  268.             include('comments'),
  269.             ('{', Punctuation),
  270.             ('(' + _TOKEN_REF + ')(\\s*)(=)?(\\s*)(' + _STRING_LITERAL + ')?(\\s*)(;)', bygroups(Name.Label, Whitespace, Punctuation, Whitespace, String, Whitespace, Punctuation)),
  271.             ('}', Punctuation, '#pop')],
  272.         'options': [
  273.             include('whitespace'),
  274.             include('comments'),
  275.             ('{', Punctuation),
  276.             ('(' + _id + ')(\\s*)(=)(\\s*)(' + '|'.join((_id, _STRING_LITERAL, _INT, '\\*')) + ')(\\s*)(;)', bygroups(Name.Variable, Whitespace, Punctuation, Whitespace, Text, Whitespace, Punctuation)),
  277.             ('}', Punctuation, '#pop')],
  278.         'action': [
  279.             ('(' + '|'.join(('[^\\${}\\\'"/\\\\]+', '"(\\\\\\\\|\\\\"|[^"])*"', "'(\\\\\\\\|\\\\'|[^'])*'", '//.*$\\n?', '/\\*(.|\\n)*?\\*/', '/(?!\\*)(\\\\\\\\|\\\\/|[^/])*/', '\\\\(?!%)', '/')) + ')+', Other),
  280.             ('(\\\\)(%)', bygroups(Punctuation, Other)),
  281.             ('(\\$[a-zA-Z]+)(\\.?)(text|value)?', bygroups(Name.Variable, Punctuation, Name.Property)),
  282.             ('{', Punctuation, '#push'),
  283.             ('}', Punctuation, '#pop')],
  284.         'nested-arg-action': [
  285.             ('(' + '|'.join(('[^\\$\\[\\]\\\'"/]+', '"(\\\\\\\\|\\\\"|[^"])*"', "'(\\\\\\\\|\\\\'|[^'])*'", '//.*$\\n?', '/\\*(.|\\n)*?\\*/', '/(?!\\*)(\\\\\\\\|\\\\/|[^/])*/', '/')) + ')+', Other),
  286.             ('\\[', Punctuation, '#push'),
  287.             ('\\]', Punctuation, '#pop'),
  288.             ('(\\$[a-zA-Z]+)(\\.?)(text|value)?', bygroups(Name.Variable, Punctuation, Name.Property)),
  289.             ('(\\\\\\\\|\\\\\\]|\\\\\\[|[^\\[\\]])+', Other)] }
  290.     
  291.     def analyse_text(text):
  292.         return re.search('^\\s*grammar\\s+[a-zA-Z0-9]+\\s*;', text, re.M)
  293.  
  294.  
  295.  
  296. class AntlrCppLexer(DelegatingLexer):
  297.     name = 'ANTLR With CPP Target'
  298.     aliases = [
  299.         'antlr-cpp']
  300.     filenames = [
  301.         '*.G',
  302.         '*.g']
  303.     
  304.     def __init__(self, **options):
  305.         super(AntlrCppLexer, self).__init__(CppLexer, AntlrLexer, **options)
  306.  
  307.     
  308.     def analyse_text(text):
  309.         if AntlrLexer.analyse_text(text):
  310.             pass
  311.         return re.search('^\\s*language\\s*=\\s*C\\s*;', text, re.M)
  312.  
  313.  
  314.  
  315. class AntlrObjectiveCLexer(DelegatingLexer):
  316.     name = 'ANTLR With ObjectiveC Target'
  317.     aliases = [
  318.         'antlr-objc']
  319.     filenames = [
  320.         '*.G',
  321.         '*.g']
  322.     
  323.     def __init__(self, **options):
  324.         super(AntlrObjectiveCLexer, self).__init__(ObjectiveCLexer, AntlrLexer, **options)
  325.  
  326.     
  327.     def analyse_text(text):
  328.         if AntlrLexer.analyse_text(text):
  329.             pass
  330.         return re.search('^\\s*language\\s*=\\s*ObjC\\s*;', text)
  331.  
  332.  
  333.  
  334. class AntlrCSharpLexer(DelegatingLexer):
  335.     name = 'ANTLR With C# Target'
  336.     aliases = [
  337.         'antlr-csharp',
  338.         'antlr-c#']
  339.     filenames = [
  340.         '*.G',
  341.         '*.g']
  342.     
  343.     def __init__(self, **options):
  344.         super(AntlrCSharpLexer, self).__init__(CSharpLexer, AntlrLexer, **options)
  345.  
  346.     
  347.     def analyse_text(text):
  348.         if AntlrLexer.analyse_text(text):
  349.             pass
  350.         return re.search('^\\s*language\\s*=\\s*CSharp2\\s*;', text, re.M)
  351.  
  352.  
  353.  
  354. class AntlrPythonLexer(DelegatingLexer):
  355.     name = 'ANTLR With Python Target'
  356.     aliases = [
  357.         'antlr-python']
  358.     filenames = [
  359.         '*.G',
  360.         '*.g']
  361.     
  362.     def __init__(self, **options):
  363.         super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer, **options)
  364.  
  365.     
  366.     def analyse_text(text):
  367.         if AntlrLexer.analyse_text(text):
  368.             pass
  369.         return re.search('^\\s*language\\s*=\\s*Python\\s*;', text, re.M)
  370.  
  371.  
  372.  
  373. class AntlrJavaLexer(DelegatingLexer):
  374.     name = 'ANTLR With Java Target'
  375.     aliases = [
  376.         'antlr-java']
  377.     filenames = [
  378.         '*.G',
  379.         '*.g']
  380.     
  381.     def __init__(self, **options):
  382.         super(AntlrJavaLexer, self).__init__(JavaLexer, AntlrLexer, **options)
  383.  
  384.     
  385.     def analyse_text(text):
  386.         if AntlrLexer.analyse_text(text):
  387.             pass
  388.         return 0.9
  389.  
  390.  
  391.  
  392. class AntlrRubyLexer(DelegatingLexer):
  393.     name = 'ANTLR With Ruby Target'
  394.     aliases = [
  395.         'antlr-ruby',
  396.         'antlr-rb']
  397.     filenames = [
  398.         '*.G',
  399.         '*.g']
  400.     
  401.     def __init__(self, **options):
  402.         super(AntlrRubyLexer, self).__init__(RubyLexer, AntlrLexer, **options)
  403.  
  404.     
  405.     def analyse_text(text):
  406.         if AntlrLexer.analyse_text(text):
  407.             pass
  408.         return re.search('^\\s*language\\s*=\\s*Ruby\\s*;', text, re.M)
  409.  
  410.  
  411.  
  412. class AntlrPerlLexer(DelegatingLexer):
  413.     name = 'ANTLR With Perl Target'
  414.     aliases = [
  415.         'antlr-perl']
  416.     filenames = [
  417.         '*.G',
  418.         '*.g']
  419.     
  420.     def __init__(self, **options):
  421.         super(AntlrPerlLexer, self).__init__(PerlLexer, AntlrLexer, **options)
  422.  
  423.     
  424.     def analyse_text(text):
  425.         if AntlrLexer.analyse_text(text):
  426.             pass
  427.         return re.search('^\\s*language\\s*=\\s*Perl5\\s*;', text, re.M)
  428.  
  429.  
  430.  
  431. class AntlrActionScriptLexer(DelegatingLexer):
  432.     name = 'ANTLR With ActionScript Target'
  433.     aliases = [
  434.         'antlr-as',
  435.         'antlr-actionscript']
  436.     filenames = [
  437.         '*.G',
  438.         '*.g']
  439.     
  440.     def __init__(self, **options):
  441.         super(AntlrActionScriptLexer, self).__init__(ActionScriptLexer, AntlrLexer, **options)
  442.  
  443.     
  444.     def analyse_text(text):
  445.         if AntlrLexer.analyse_text(text):
  446.             pass
  447.         return re.search('^\\s*language\\s*=\\s*ActionScript\\s*;', text, re.M)
  448.  
  449.  
  450.