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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import re
  5. from pygments.lexer import RegexLexer, ExtendedRegexLexer, bygroups, using, include, this
  6. from pygments.token import Text, Comment, Operator, Keyword, Name, String, Number, Other, Punctuation
  7. from pygments.util import get_bool_opt, get_list_opt, looks_like_xml, html_doctype_matches
  8. from pygments.lexers.agile import RubyLexer
  9. __all__ = [
  10.     'HtmlLexer',
  11.     'XmlLexer',
  12.     'JavascriptLexer',
  13.     'CssLexer',
  14.     'PhpLexer',
  15.     'ActionScriptLexer',
  16.     'XsltLexer',
  17.     'ActionScript3Lexer',
  18.     'MxmlLexer',
  19.     'HaxeLexer',
  20.     'HamlLexer',
  21.     'SassLexer',
  22.     'ObjectiveJLexer',
  23.     'CoffeeScriptLexer']
  24.  
  25. class JavascriptLexer(RegexLexer):
  26.     name = 'JavaScript'
  27.     aliases = [
  28.         'js',
  29.         'javascript']
  30.     filenames = [
  31.         '*.js']
  32.     mimetypes = [
  33.         'application/x-javascript',
  34.         'text/x-javascript',
  35.         'text/javascript']
  36.     flags = re.DOTALL
  37.     tokens = {
  38.         'commentsandwhitespace': [
  39.             ('\\s+', Text),
  40.             ('<!--', Comment),
  41.             ('//.*?\\n', Comment.Single),
  42.             ('/\\*.*?\\*/', Comment.Multiline)],
  43.         'slashstartsregex': [
  44.             include('commentsandwhitespace'),
  45.             ('/(\\\\.|[^[/\\\\\\n]|\\[(\\\\.|[^\\]\\\\\\n])*])+/([gim]+\\b|\\B)', String.Regex, '#pop'),
  46.             ('(?=/)', Text, ('#pop', 'badregex')),
  47.             ('', Text, '#pop')],
  48.         'badregex': [
  49.             ('\n', Text, '#pop')],
  50.         'root': [
  51.             ('^(?=\\s|/|<!--)', Text, 'slashstartsregex'),
  52.             include('commentsandwhitespace'),
  53.             ('\\+\\+|--|~|&&|\\?|:|\\|\\||\\\\(?=\\n)|(<<|>>>?|==?|!=?|[-<>+*%&\\|\\^/])=?', Operator, 'slashstartsregex'),
  54.             ('[{(\\[;,]', Punctuation, 'slashstartsregex'),
  55.             ('[})\\].]', Punctuation),
  56.             ('(for|in|while|do|break|return|continue|switch|case|default|if|else|throw|try|catch|finally|new|delete|typeof|instanceof|void|this)\\b', Keyword, 'slashstartsregex'),
  57.             ('(var|with|function)\\b', Keyword.Declaration, 'slashstartsregex'),
  58.             ('(abstract|boolean|byte|char|class|const|debugger|double|enum|export|extends|final|float|goto|implements|import|int|interface|long|native|package|private|protected|public|short|static|super|synchronized|throws|transient|volatile)\\b', Keyword.Reserved),
  59.             ('(true|false|null|NaN|Infinity|undefined)\\b', Keyword.Constant),
  60.             ('(Array|Boolean|Date|Error|Function|Math|netscape|Number|Object|Packages|RegExp|String|sun|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|window)\\b', Name.Builtin),
  61.             ('[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
  62.             ('[0-9][0-9]*\\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
  63.             ('0x[0-9a-fA-F]+', Number.Hex),
  64.             ('[0-9]+', Number.Integer),
  65.             ('"(\\\\\\\\|\\\\"|[^"])*"', String.Double),
  66.             ("'(\\\\\\\\|\\\\'|[^'])*'", String.Single)] }
  67.  
  68.  
  69. class ActionScriptLexer(RegexLexer):
  70.     name = 'ActionScript'
  71.     aliases = [
  72.         'as',
  73.         'actionscript']
  74.     filenames = [
  75.         '*.as']
  76.     mimetypes = [
  77.         'application/x-actionscript',
  78.         'text/x-actionscript',
  79.         'text/actionscript']
  80.     flags = re.DOTALL
  81.     tokens = {
  82.         'root': [
  83.             ('\\s+', Text),
  84.             ('//.*?\\n', Comment.Single),
  85.             ('/\\*.*?\\*/', Comment.Multiline),
  86.             ('/(\\\\\\\\|\\\\/|[^/\\n])*/[gim]*', String.Regex),
  87.             ('[~\\^\\*!%&<>\\|+=:;,/?\\\\-]+', Operator),
  88.             ('[{}\\[\\]();.]+', Punctuation),
  89.             ('(case|default|for|each|in|while|do|break|return|continue|if|else|throw|try|catch|var|with|new|typeof|arguments|instanceof|this|switch)\\b', Keyword),
  90.             ('(class|public|final|internal|native|override|private|protected|static|import|extends|implements|interface|intrinsic|return|super|dynamic|function|const|get|namespace|package|set)\\b', Keyword.Declaration),
  91.             ('(true|false|null|NaN|Infinity|-Infinity|undefined|Void)\\b', Keyword.Constant),
  92.             ('(Accessibility|AccessibilityProperties|ActionScriptVersion|ActivityEvent|AntiAliasType|ApplicationDomain|AsBroadcaster|Array|AsyncErrorEvent|AVM1Movie|BevelFilter|Bitmap|BitmapData|BitmapDataChannel|BitmapFilter|BitmapFilterQuality|BitmapFilterType|BlendMode|BlurFilter|Boolean|ByteArray|Camera|Capabilities|CapsStyle|Class|Color|ColorMatrixFilter|ColorTransform|ContextMenu|ContextMenuBuiltInItems|ContextMenuEvent|ContextMenuItem|ConvultionFilter|CSMSettings|DataEvent|Date|DefinitionError|DeleteObjectSample|Dictionary|DisplacmentMapFilter|DisplayObject|DisplacmentMapFilterMode|DisplayObjectContainer|DropShadowFilter|Endian|EOFError|Error|ErrorEvent|EvalError|Event|EventDispatcher|EventPhase|ExternalInterface|FileFilter|FileReference|FileReferenceList|FocusDirection|FocusEvent|Font|FontStyle|FontType|FrameLabel|FullScreenEvent|Function|GlowFilter|GradientBevelFilter|GradientGlowFilter|GradientType|Graphics|GridFitType|HTTPStatusEvent|IBitmapDrawable|ID3Info|IDataInput|IDataOutput|IDynamicPropertyOutputIDynamicPropertyWriter|IEventDispatcher|IExternalizable|IllegalOperationError|IME|IMEConversionMode|IMEEvent|int|InteractiveObject|InterpolationMethod|InvalidSWFError|InvokeEvent|IOError|IOErrorEvent|JointStyle|Key|Keyboard|KeyboardEvent|KeyLocation|LineScaleMode|Loader|LoaderContext|LoaderInfo|LoadVars|LocalConnection|Locale|Math|Matrix|MemoryError|Microphone|MorphShape|Mouse|MouseEvent|MovieClip|MovieClipLoader|Namespace|NetConnection|NetStatusEvent|NetStream|NewObjectSample|Number|Object|ObjectEncoding|PixelSnapping|Point|PrintJob|PrintJobOptions|PrintJobOrientation|ProgressEvent|Proxy|QName|RangeError|Rectangle|ReferenceError|RegExp|Responder|Sample|Scene|ScriptTimeoutError|Security|SecurityDomain|SecurityError|SecurityErrorEvent|SecurityPanel|Selection|Shape|SharedObject|SharedObjectFlushStatus|SimpleButton|Socket|Sound|SoundChannel|SoundLoaderContext|SoundMixer|SoundTransform|SpreadMethod|Sprite|StackFrame|StackOverflowError|Stage|StageAlign|StageDisplayState|StageQuality|StageScaleMode|StaticText|StatusEvent|String|StyleSheet|SWFVersion|SyncEvent|SyntaxError|System|TextColorType|TextField|TextFieldAutoSize|TextFieldType|TextFormat|TextFormatAlign|TextLineMetrics|TextRenderer|TextSnapshot|Timer|TimerEvent|Transform|TypeError|uint|URIError|URLLoader|URLLoaderDataFormat|URLRequest|URLRequestHeader|URLRequestMethod|URLStream|URLVariabeles|VerifyError|Video|XML|XMLDocument|XMLList|XMLNode|XMLNodeType|XMLSocket|XMLUI)\\b', Name.Builtin),
  93.             ('(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|unescape)\\b', Name.Function),
  94.             ('[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
  95.             ('[0-9][0-9]*\\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
  96.             ('0x[0-9a-f]+', Number.Hex),
  97.             ('[0-9]+', Number.Integer),
  98.             ('"(\\\\\\\\|\\\\"|[^"])*"', String.Double),
  99.             ("'(\\\\\\\\|\\\\'|[^'])*'", String.Single)] }
  100.     
  101.     def analyse_text(text):
  102.         return 0.05
  103.  
  104.  
  105.  
  106. class ActionScript3Lexer(RegexLexer):
  107.     name = 'ActionScript 3'
  108.     aliases = [
  109.         'as3',
  110.         'actionscript3']
  111.     filenames = [
  112.         '*.as']
  113.     mimetypes = [
  114.         'application/x-actionscript',
  115.         'text/x-actionscript',
  116.         'text/actionscript']
  117.     identifier = '[$a-zA-Z_][a-zA-Z0-9_]*'
  118.     flags = re.DOTALL | re.MULTILINE
  119.     tokens = {
  120.         'root': [
  121.             ('\\s+', Text),
  122.             ('(function\\s+)(' + identifier + ')(\\s*)(\\()', bygroups(Keyword.Declaration, Name.Function, Text, Operator), 'funcparams'),
  123.             ('(var|const)(\\s+)(' + identifier + ')(\\s*)(:)(\\s*)(' + identifier + ')', bygroups(Keyword.Declaration, Text, Name, Text, Punctuation, Text, Keyword.Type)),
  124.             ('(import|package)(\\s+)((?:' + identifier + '|\\.)+)(\\s*)', bygroups(Keyword, Text, Name.Namespace, Text)),
  125.             ('(new)(\\s+)(' + identifier + ')(\\s*)(\\()', bygroups(Keyword, Text, Keyword.Type, Text, Operator)),
  126.             ('//.*?\\n', Comment.Single),
  127.             ('/\\*.*?\\*/', Comment.Multiline),
  128.             ('/(\\\\\\\\|\\\\/|[^\\n])*/[gisx]*', String.Regex),
  129.             ('(\\.)(' + identifier + ')', bygroups(Operator, Name.Attribute)),
  130.             ('(case|default|for|each|in|while|do|break|return|continue|if|else|throw|try|catch|with|new|typeof|arguments|instanceof|this|switch|import|include|as|is)\\b', Keyword),
  131.             ('(class|public|final|internal|native|override|private|protected|static|import|extends|implements|interface|intrinsic|return|super|dynamic|function|const|get|namespace|package|set)\\b', Keyword.Declaration),
  132.             ('(true|false|null|NaN|Infinity|-Infinity|undefined|void)\\b', Keyword.Constant),
  133.             ('(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|unescape)\\b', Name.Function),
  134.             (identifier, Name),
  135.             ('[0-9][0-9]*\\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
  136.             ('0x[0-9a-f]+', Number.Hex),
  137.             ('[0-9]+', Number.Integer),
  138.             ('"(\\\\\\\\|\\\\"|[^"])*"', String.Double),
  139.             ("'(\\\\\\\\|\\\\'|[^'])*'", String.Single),
  140.             ('[~\\^\\*!%&<>\\|+=:;,/?\\\\{}\\[\\]();.-]+', Operator)],
  141.         'funcparams': [
  142.             ('\\s+', Text),
  143.             ('(\\s*)(\\.\\.\\.)?(' + identifier + ')(\\s*)(:)(\\s*)(' + identifier + '|\\*)(\\s*)', bygroups(Text, Punctuation, Name, Text, Operator, Text, Keyword.Type, Text), 'defval'),
  144.             ('\\)', Operator, 'type')],
  145.         'type': [
  146.             ('(\\s*)(:)(\\s*)(' + identifier + '|\\*)', bygroups(Text, Operator, Text, Keyword.Type), '#pop:2'),
  147.             ('\\s*', Text, '#pop:2')],
  148.         'defval': [
  149.             ('(=)(\\s*)([^(),]+)(\\s*)(,?)', bygroups(Operator, Text, using(this), Text, Operator), '#pop'),
  150.             (',?', Operator, '#pop')] }
  151.     
  152.     def analyse_text(text):
  153.         if re.match('\\w+\\s*:\\s*\\w', text):
  154.             return 0.3
  155.         return 0.1
  156.  
  157.  
  158.  
  159. class CssLexer(RegexLexer):
  160.     name = 'CSS'
  161.     aliases = [
  162.         'css']
  163.     filenames = [
  164.         '*.css']
  165.     mimetypes = [
  166.         'text/css']
  167.     tokens = {
  168.         'root': [
  169.             include('basics')],
  170.         'basics': [
  171.             ('\\s+', Text),
  172.             ('/\\*(?:.|\\n)*?\\*/', Comment),
  173.             ('{', Punctuation, 'content'),
  174.             ('\\:[a-zA-Z0-9_-]+', Name.Decorator),
  175.             ('\\.[a-zA-Z0-9_-]+', Name.Class),
  176.             ('\\#[a-zA-Z0-9_-]+', Name.Function),
  177.             ('@[a-zA-Z0-9_-]+', Keyword, 'atrule'),
  178.             ('[a-zA-Z0-9_-]+', Name.Tag),
  179.             ('[~\\^\\*!%&\\[\\]\\(\\)<>\\|+=@:;,./?-]', Operator),
  180.             ('"(\\\\\\\\|\\\\"|[^"])*"', String.Double),
  181.             ("'(\\\\\\\\|\\\\'|[^'])*'", String.Single)],
  182.         'atrule': [
  183.             ('{', Punctuation, 'atcontent'),
  184.             (';', Punctuation, '#pop'),
  185.             include('basics')],
  186.         'atcontent': [
  187.             include('basics'),
  188.             ('}', Punctuation, '#pop:2')],
  189.         'content': [
  190.             ('\\s+', Text),
  191.             ('}', Punctuation, '#pop'),
  192.             ('url\\(.*?\\)', String.Other),
  193.             ('^@.*?$', Comment.Preproc),
  194.             ('(azimuth|background-attachment|background-color|background-image|background-position|background-repeat|background|border-bottom-color|border-bottom-style|border-bottom-width|border-left-color|border-left-style|border-left-width|border-right|border-right-color|border-right-style|border-right-width|border-top-color|border-top-style|border-top-width|border-bottom|border-collapse|border-left|border-width|border-color|border-spacing|border-style|border-top|border|caption-side|clear|clip|color|content|counter-increment|counter-reset|cue-after|cue-before|cue|cursor|direction|display|elevation|empty-cells|float|font-family|font-size|font-size-adjust|font-stretch|font-style|font-variant|font-weight|font|height|letter-spacing|line-height|list-style-type|list-style-image|list-style-position|list-style|margin-bottom|margin-left|margin-right|margin-top|margin|marker-offset|marks|max-height|max-width|min-height|min-width|opacity|orphans|outline|outline-color|outline-style|outline-width|overflow(?:-x|-y|)|padding-bottom|padding-left|padding-right|padding-top|padding|page|page-break-after|page-break-before|page-break-inside|pause-after|pause-before|pause|pitch|pitch-range|play-during|position|quotes|richness|right|size|speak-header|speak-numeral|speak-punctuation|speak|speech-rate|stress|table-layout|text-align|text-decoration|text-indent|text-shadow|text-transform|top|unicode-bidi|vertical-align|visibility|voice-family|volume|white-space|widows|width|word-spacing|z-index|bottom|left|above|absolute|always|armenian|aural|auto|avoid|baseline|behind|below|bidi-override|blink|block|bold|bolder|both|capitalize|center-left|center-right|center|circle|cjk-ideographic|close-quote|collapse|condensed|continuous|crop|crosshair|cross|cursive|dashed|decimal-leading-zero|decimal|default|digits|disc|dotted|double|e-resize|embed|extra-condensed|extra-expanded|expanded|fantasy|far-left|far-right|faster|fast|fixed|georgian|groove|hebrew|help|hidden|hide|higher|high|hiragana-iroha|hiragana|icon|inherit|inline-table|inline|inset|inside|invert|italic|justify|katakana-iroha|katakana|landscape|larger|large|left-side|leftwards|level|lighter|line-through|list-item|loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|lower|low|medium|message-box|middle|mix|monospace|n-resize|narrower|ne-resize|no-close-quote|no-open-quote|no-repeat|none|normal|nowrap|nw-resize|oblique|once|open-quote|outset|outside|overline|pointer|portrait|px|relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|rightwards|s-resize|sans-serif|scroll|se-resize|semi-condensed|semi-expanded|separate|serif|show|silent|slow|slower|small-caps|small-caption|smaller|soft|solid|spell-out|square|static|status-bar|super|sw-resize|table-caption|table-cell|table-column|table-column-group|table-footer-group|table-header-group|table-row|table-row-group|text|text-bottom|text-top|thick|thin|transparent|ultra-condensed|ultra-expanded|underline|upper-alpha|upper-latin|upper-roman|uppercase|url|visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|x-low|x-small|x-soft|xx-large|xx-small|yes)\\b', Keyword),
  195.             ('(indigo|gold|firebrick|indianred|yellow|darkolivegreen|darkseagreen|mediumvioletred|mediumorchid|chartreuse|mediumslateblue|black|springgreen|crimson|lightsalmon|brown|turquoise|olivedrab|cyan|silver|skyblue|gray|darkturquoise|goldenrod|darkgreen|darkviolet|darkgray|lightpink|teal|darkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|violet|navy|orchid|blue|ghostwhite|honeydew|cornflowerblue|darkblue|darkkhaki|mediumpurple|cornsilk|red|bisque|slategray|darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|gainsboro|mediumturquoise|floralwhite|coral|purple|lightgrey|lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|greenyellow|royalblue|lightseagreen|mistyrose|sienna|lightcoral|orangered|navajowhite|lime|palegreen|burlywood|seashell|mediumspringgreen|fuchsia|papayawhip|blanchedalmond|peru|aquamarine|white|darkslategray|ivory|dodgerblue|lemonchiffon|chocolate|orange|forestgreen|slateblue|olive|mintcream|antiquewhite|darkorange|cadetblue|moccasin|limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|plum|aqua|darkgoldenrod|maroon|sandybrown|magenta|tan|rosybrown|pink|lightblue|palevioletred|mediumseagreen|dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|lightslategray|lawngreen|lightgreen|tomato|hotpink|lightyellow|lavenderblush|linen|mediumaquamarine|green|blueviolet|peachpuff)\\b', Name.Builtin),
  196.             ('\\!important', Comment.Preproc),
  197.             ('/\\*(?:.|\\n)*?\\*/', Comment),
  198.             ('\\#[a-zA-Z0-9]{1,6}', Number),
  199.             ('[\\.-]?[0-9]*[\\.]?[0-9]+(em|px|\\%|pt|pc|in|mm|cm|ex)', Number),
  200.             ('-?[0-9]+', Number),
  201.             ('[~\\^\\*!%&<>\\|+=@:,./?-]+', Operator),
  202.             ('[\\[\\]();]+', Punctuation),
  203.             ('"(\\\\\\\\|\\\\"|[^"])*"', String.Double),
  204.             ("'(\\\\\\\\|\\\\'|[^'])*'", String.Single),
  205.             ('[a-zA-Z][a-zA-Z0-9]+', Name)] }
  206.  
  207.  
  208. class ObjectiveJLexer(RegexLexer):
  209.     name = 'Objective-J'
  210.     aliases = [
  211.         'objective-j',
  212.         'objectivej',
  213.         'obj-j',
  214.         'objj']
  215.     filenames = [
  216.         '*.j']
  217.     mimetypes = [
  218.         'text/x-objective-j']
  219.     _ws = '(?:\\s|//.*?\\n|/[*].*?[*]/)*'
  220.     flags = re.DOTALL | re.MULTILINE
  221.     tokens = {
  222.         'root': [
  223.             include('whitespace'),
  224.             ('^(' + _ws + '[\\+-]' + _ws + ')([\\(a-zA-Z_].*?[^\\(])(' + _ws + '{)', bygroups(using(this), using(this, state = 'function_signature'), using(this))),
  225.             ('(@interface|@implementation)(\\s+)', bygroups(Keyword, Text), 'classname'),
  226.             ('(@class|@protocol)(\\s*)', bygroups(Keyword, Text), 'forward_classname'),
  227.             ('(\\s*)(@end)(\\s*)', bygroups(Text, Keyword, Text)),
  228.             include('statements'),
  229.             ('[{\\(\\)}]', Punctuation),
  230.             (';', Punctuation)],
  231.         'whitespace': [
  232.             ('(@import)(\\s+)("(\\\\\\\\|\\\\"|[^"])*")', bygroups(Comment.Preproc, Text, String.Double)),
  233.             ('(@import)(\\s+)(<(\\\\\\\\|\\\\>|[^>])*>)', bygroups(Comment.Preproc, Text, String.Double)),
  234.             ('(#(?:include|import))(\\s+)("(\\\\\\\\|\\\\"|[^"])*")', bygroups(Comment.Preproc, Text, String.Double)),
  235.             ('(#(?:include|import))(\\s+)(<(\\\\\\\\|\\\\>|[^>])*>)', bygroups(Comment.Preproc, Text, String.Double)),
  236.             ('#if\\s+0', Comment.Preproc, 'if0'),
  237.             ('#', Comment.Preproc, 'macro'),
  238.             ('\\n', Text),
  239.             ('\\s+', Text),
  240.             ('\\\\\\n', Text),
  241.             ('//(\\n|(.|\\n)*?[^\\\\]\\n)', Comment.Single),
  242.             ('/(\\\\\\n)?[*](.|\\n)*?[*](\\\\\\n)?/', Comment.Multiline),
  243.             ('<!--', Comment)],
  244.         'slashstartsregex': [
  245.             include('whitespace'),
  246.             ('/(\\\\.|[^[/\\\\\\n]|\\[(\\\\.|[^\\]\\\\\\n])*])+/([gim]+\\b|\\B)', String.Regex, '#pop'),
  247.             ('(?=/)', Text, ('#pop', 'badregex')),
  248.             ('', Text, '#pop')],
  249.         'badregex': [
  250.             ('\n', Text, '#pop')],
  251.         'statements': [
  252.             ('(L|@)?"', String, 'string'),
  253.             ("(L|@)?'(\\\\.|\\\\[0-7]{1,3}|\\\\x[a-fA-F0-9]{1,2}|[^\\\\\\'\\n])'", String.Char),
  254.             ('"(\\\\\\\\|\\\\"|[^"])*"', String.Double),
  255.             ("'(\\\\\\\\|\\\\'|[^'])*'", String.Single),
  256.             ('(\\d+\\.\\d*|\\.\\d+|\\d+)[eE][+-]?\\d+[lL]?', Number.Float),
  257.             ('(\\d+\\.\\d*|\\.\\d+|\\d+[fF])[fF]?', Number.Float),
  258.             ('0x[0-9a-fA-F]+[Ll]?', Number.Hex),
  259.             ('0[0-7]+[Ll]?', Number.Oct),
  260.             ('\\d+[Ll]?', Number.Integer),
  261.             ('^(?=\\s|/|<!--)', Text, 'slashstartsregex'),
  262.             ('\\+\\+|--|~|&&|\\?|:|\\|\\||\\\\(?=\\n)|(<<|>>>?|==?|!=?|[-<>+*%&\\|\\^/])=?', Operator, 'slashstartsregex'),
  263.             ('[{(\\[;,]', Punctuation, 'slashstartsregex'),
  264.             ('[})\\].]', Punctuation),
  265.             ('(for|in|while|do|break|return|continue|switch|case|default|if|else|throw|try|catch|finally|new|delete|typeof|instanceof|void|prototype|__proto__)\\b', Keyword, 'slashstartsregex'),
  266.             ('(var|with|function)\\b', Keyword.Declaration, 'slashstartsregex'),
  267.             ('(@selector|@private|@protected|@public|@encode|@synchronized|@try|@throw|@catch|@finally|@end|@property|@synthesize|@dynamic|@for|@accessors|new)\\b', Keyword),
  268.             ('(int|long|float|short|double|char|unsigned|signed|void|id|BOOL|bool|boolean|IBOutlet|IBAction|SEL|@outlet|@action)\\b', Keyword.Type),
  269.             ('(self|super)\\b', Name.Builtin),
  270.             ('(TRUE|YES|FALSE|NO|Nil|nil|NULL)\\b', Keyword.Constant),
  271.             ('(true|false|null|NaN|Infinity|undefined)\\b', Keyword.Constant),
  272.             ('(ABS|ASIN|ACOS|ATAN|ATAN2|SIN|COS|TAN|EXP|POW|CEIL|FLOOR|ROUND|MIN|MAX|RAND|SQRT|E|LN2|LN10|LOG2E|LOG10E|PI|PI2|PI_2|SQRT1_2|SQRT2)\\b', Keyword.Constant),
  273.             ('(Array|Boolean|Date|Error|Function|Math|netscape|Number|Object|Packages|RegExp|String|sun|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|window)\\b', Name.Builtin),
  274.             ('([$a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + ')(?=\\()', bygroups(Name.Function, using(this))),
  275.             ('[$a-zA-Z_][a-zA-Z0-9_]*', Name)],
  276.         'classname': [
  277.             ('([a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + ':' + _ws + ')([a-zA-Z_][a-zA-Z0-9_]*)?', bygroups(Name.Class, using(this), Name.Class), '#pop'),
  278.             ('([a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + '\\()([a-zA-Z_][a-zA-Z0-9_]*)(\\))', bygroups(Name.Class, using(this), Name.Label, Text), '#pop'),
  279.             ('([a-zA-Z_][a-zA-Z0-9_]*)', Name.Class, '#pop')],
  280.         'forward_classname': [
  281.             ('([a-zA-Z_][a-zA-Z0-9_]*)(\\s*,\\s*)', bygroups(Name.Class, Text), '#push'),
  282.             ('([a-zA-Z_][a-zA-Z0-9_]*)(\\s*;?)', bygroups(Name.Class, Text), '#pop')],
  283.         'function_signature': [
  284.             include('whitespace'),
  285.             ('(\\(' + _ws + ')([a-zA-Z_][a-zA-Z0-9_]+)(' + _ws + '\\)' + _ws + ')([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + ':)', bygroups(using(this), Keyword.Type, using(this), Name.Function), 'function_parameters'),
  286.             ('(\\(' + _ws + ')([a-zA-Z_][a-zA-Z0-9_]+)(' + _ws + '\\)' + _ws + ')([$a-zA-Z_][a-zA-Z0-9_]+)', bygroups(using(this), Keyword.Type, using(this), Name.Function), '#pop'),
  287.             ('([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + ':)', bygroups(Name.Function), 'function_parameters'),
  288.             ('([$a-zA-Z_][a-zA-Z0-9_]+)', bygroups(Name.Function), '#pop'),
  289.             ('', Text, '#pop')],
  290.         'function_parameters': [
  291.             include('whitespace'),
  292.             ('(\\(' + _ws + ')([^\\)]+)(' + _ws + '\\)' + _ws + ')+([$a-zA-Z_][a-zA-Z0-9_]+)', bygroups(using(this), Keyword.Type, using(this), Text)),
  293.             ('([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + ':)', Name.Function),
  294.             ('(:)', Name.Function),
  295.             ('(,' + _ws + '...)', using(this)),
  296.             ('([$a-zA-Z_][a-zA-Z0-9_]+)', Text)],
  297.         'expression': [
  298.             ('([$a-zA-Z_][a-zA-Z0-9_]*)(\\()', bygroups(Name.Function, Punctuation)),
  299.             ('(\\))', Punctuation, '#pop')],
  300.         'string': [
  301.             ('"', String, '#pop'),
  302.             ('\\\\([\\\\abfnrtv"\\\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
  303.             ('[^\\\\"\\n]+', String),
  304.             ('\\\\\\n', String),
  305.             ('\\\\', String)],
  306.         'macro': [
  307.             ('[^/\\n]+', Comment.Preproc),
  308.             ('/[*](.|\\n)*?[*]/', Comment.Multiline),
  309.             ('//.*?\\n', Comment.Single, '#pop'),
  310.             ('/', Comment.Preproc),
  311.             ('(?<=\\\\)\\n', Comment.Preproc),
  312.             ('\\n', Comment.Preproc, '#pop')],
  313.         'if0': [
  314.             ('^\\s*#if.*?(?<!\\\\)\\n', Comment.Preproc, '#push'),
  315.             ('^\\s*#endif.*?(?<!\\\\)\\n', Comment.Preproc, '#pop'),
  316.             ('.*?\\n', Comment)] }
  317.     
  318.     def analyse_text(text):
  319.         if re.search('^\\s*@import\\s+[<"]', text, re.MULTILINE):
  320.             return True
  321.         return False
  322.  
  323.  
  324.  
  325. class HtmlLexer(RegexLexer):
  326.     name = 'HTML'
  327.     aliases = [
  328.         'html']
  329.     filenames = [
  330.         '*.html',
  331.         '*.htm',
  332.         '*.xhtml',
  333.         '*.xslt']
  334.     mimetypes = [
  335.         'text/html',
  336.         'application/xhtml+xml']
  337.     flags = re.IGNORECASE | re.DOTALL
  338.     tokens = {
  339.         'root': [
  340.             ('[^<&]+', Text),
  341.             ('&\\S*?;', Name.Entity),
  342.             ('\\<\\!\\[CDATA\\[.*?\\]\\]\\>', Comment.Preproc),
  343.             ('<!--', Comment, 'comment'),
  344.             ('<\\?.*?\\?>', Comment.Preproc),
  345.             ('<![^>]*>', Comment.Preproc),
  346.             ('<\\s*script\\s*', Name.Tag, ('script-content', 'tag')),
  347.             ('<\\s*style\\s*', Name.Tag, ('style-content', 'tag')),
  348.             ('<\\s*[a-zA-Z0-9:]+', Name.Tag, 'tag'),
  349.             ('<\\s*/\\s*[a-zA-Z0-9:]+\\s*>', Name.Tag)],
  350.         'comment': [
  351.             ('[^-]+', Comment),
  352.             ('-->', Comment, '#pop'),
  353.             ('-', Comment)],
  354.         'tag': [
  355.             ('\\s+', Text),
  356.             ('[a-zA-Z0-9_:-]+\\s*=', Name.Attribute, 'attr'),
  357.             ('[a-zA-Z0-9_:-]+', Name.Attribute),
  358.             ('/?\\s*>', Name.Tag, '#pop')],
  359.         'script-content': [
  360.             ('<\\s*/\\s*script\\s*>', Name.Tag, '#pop'),
  361.             ('.+?(?=<\\s*/\\s*script\\s*>)', using(JavascriptLexer))],
  362.         'style-content': [
  363.             ('<\\s*/\\s*style\\s*>', Name.Tag, '#pop'),
  364.             ('.+?(?=<\\s*/\\s*style\\s*>)', using(CssLexer))],
  365.         'attr': [
  366.             ('".*?"', String, '#pop'),
  367.             ("'.*?'", String, '#pop'),
  368.             ('[^\\s>]+', String, '#pop')] }
  369.     
  370.     def analyse_text(text):
  371.         if html_doctype_matches(text):
  372.             return 0.5
  373.  
  374.  
  375.  
  376. class PhpLexer(RegexLexer):
  377.     name = 'PHP'
  378.     aliases = [
  379.         'php',
  380.         'php3',
  381.         'php4',
  382.         'php5']
  383.     filenames = [
  384.         '*.php',
  385.         '*.php[345]']
  386.     mimetypes = [
  387.         'text/x-php']
  388.     flags = re.IGNORECASE | re.DOTALL | re.MULTILINE
  389.     tokens = {
  390.         'root': [
  391.             ('<\\?(php)?', Comment.Preproc, 'php'),
  392.             ('[^<]+', Other),
  393.             ('<', Other)],
  394.         'php': [
  395.             ('\\?>', Comment.Preproc, '#pop'),
  396.             ("<<<(\\'?)([a-zA-Z_][a-zA-Z0-9_]*)\\1\\n.*?\\n\\2\\;?\\n", String),
  397.             ('\\s+', Text),
  398.             ('#.*?\\n', Comment.Single),
  399.             ('//.*?\\n', Comment.Single),
  400.             ('/\\*\\*/', Comment.Multiline),
  401.             ('/\\*\\*.*?\\*/', String.Doc),
  402.             ('/\\*.*?\\*/', Comment.Multiline),
  403.             ('(->|::)(\\s*)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Operator, Text, Name.Attribute)),
  404.             ('[~!%^&*+=|:.<>/?@-]+', Operator),
  405.             ('[\\[\\]{}();,]+', Punctuation),
  406.             ('(class)(\\s+)', bygroups(Keyword, Text), 'classname'),
  407.             ('(function)(\\s*)(?=\\()', bygroups(Keyword, Text)),
  408.             ('(function)(\\s+)(&?)(\\s*)', bygroups(Keyword, Text, Operator, Text), 'functionname'),
  409.             ('(const)(\\s+)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Keyword, Text, Name.Constant)),
  410.             ('(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|eval|PHP_OS|break|exit|case|extends|PHP_VERSION|cfunction|FALSE|print|for|require|continue|foreach|require_once|declare|return|default|static|do|switch|die|stdClass|echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|virtual|endfor|include_once|while|endforeach|global|__FILE__|endif|list|__LINE__|endswitch|new|__sleep|endwhile|not|array|__wakeup|E_ALL|NULL|final|php_user_filter|interface|implements|public|private|protected|abstract|clone|try|catch|throw|this|use|namespace)\\b', Keyword),
  411.             ('(true|false|null)\x08', Keyword.Constant),
  412.             ('\\$\\{\\$+[a-zA-Z_][a-zA-Z0-9_]*\\}', Name.Variable),
  413.             ('\\$+[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable),
  414.             ('[\\\\a-zA-Z_][\\\\a-zA-Z0-9_]*', Name.Other),
  415.             ('[0-9](\\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?', Number),
  416.             ("'([^'\\\\]*(?:\\\\.[^'\\\\]*)*)'", String.Single),
  417.             ('`([^`\\\\]*(?:\\\\.[^`\\\\]*)*)`', String.Backtick),
  418.             ('"', String.Double, 'string')],
  419.         'classname': [
  420.             ('[a-zA-Z_][\\\\a-zA-Z0-9_]*', Name.Class, '#pop')],
  421.         'functionname': [
  422.             ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop')],
  423.         'string': [
  424.             ('"', String.Double, '#pop'),
  425.             ('[^{$"\\\\]+', String.Double),
  426.             ('\\\\([nrt\\"$]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2})', String.Escape),
  427.             ('\\$[a-zA-Z_][a-zA-Z0-9_]*(\\[\\S+\\]|->[a-zA-Z_][a-zA-Z0-9_]*)?', String.Interpol),
  428.             ('(\\{\\$\\{)(.*?)(\\}\\})', bygroups(String.Interpol, using(this, _startinline = True), String.Interpol)),
  429.             ('(\\{)(\\$.*?)(\\})', bygroups(String.Interpol, using(this, _startinline = True), String.Interpol)),
  430.             ('(\\$\\{)(\\S+)(\\})', bygroups(String.Interpol, Name.Variable, String.Interpol)),
  431.             ('[${\\\\]+', String.Double)] }
  432.     
  433.     def __init__(self, **options):
  434.         self.funcnamehighlighting = get_bool_opt(options, 'funcnamehighlighting', True)
  435.         self.disabledmodules = get_list_opt(options, 'disabledmodules', [
  436.             'unknown'])
  437.         self.startinline = get_bool_opt(options, 'startinline', False)
  438.         if '_startinline' in options:
  439.             self.startinline = options.pop('_startinline')
  440.         
  441.         self._functions = set()
  442.         if self.funcnamehighlighting:
  443.             MODULES = MODULES
  444.             import pygments.lexers._phpbuiltins
  445.             for key, value in MODULES.iteritems():
  446.                 if key not in self.disabledmodules:
  447.                     self._functions.update(value)
  448.                     continue
  449.             
  450.         
  451.         RegexLexer.__init__(self, **options)
  452.  
  453.     
  454.     def get_tokens_unprocessed(self, text):
  455.         stack = [
  456.             'root']
  457.         if self.startinline:
  458.             stack.append('php')
  459.         
  460.         for index, token, value in RegexLexer.get_tokens_unprocessed(self, text, stack):
  461.             if token is Name.Other:
  462.                 if value in self._functions:
  463.                     yield (index, Name.Builtin, value)
  464.                     continue
  465.                 
  466.             
  467.             yield (index, token, value)
  468.         
  469.  
  470.     
  471.     def analyse_text(text):
  472.         rv = 0
  473.         if re.search('<\\?(?!xml)', text):
  474.             rv += 0.3
  475.         
  476.         if '?>' in text:
  477.             rv += 0.1
  478.         
  479.         return rv
  480.  
  481.  
  482.  
  483. class XmlLexer(RegexLexer):
  484.     flags = re.MULTILINE | re.DOTALL
  485.     name = 'XML'
  486.     aliases = [
  487.         'xml']
  488.     filenames = [
  489.         '*.xml',
  490.         '*.xsl',
  491.         '*.rss',
  492.         '*.xslt',
  493.         '*.xsd',
  494.         '*.wsdl']
  495.     mimetypes = [
  496.         'text/xml',
  497.         'application/xml',
  498.         'image/svg+xml',
  499.         'application/rss+xml',
  500.         'application/atom+xml',
  501.         'application/xsl+xml',
  502.         'application/xslt+xml']
  503.     tokens = {
  504.         'root': [
  505.             ('[^<&]+', Text),
  506.             ('&\\S*?;', Name.Entity),
  507.             ('\\<\\!\\[CDATA\\[.*?\\]\\]\\>', Comment.Preproc),
  508.             ('<!--', Comment, 'comment'),
  509.             ('<\\?.*?\\?>', Comment.Preproc),
  510.             ('<![^>]*>', Comment.Preproc),
  511.             ('<\\s*[a-zA-Z0-9:._-]+', Name.Tag, 'tag'),
  512.             ('<\\s*/\\s*[a-zA-Z0-9:._-]+\\s*>', Name.Tag)],
  513.         'comment': [
  514.             ('[^-]+', Comment),
  515.             ('-->', Comment, '#pop'),
  516.             ('-', Comment)],
  517.         'tag': [
  518.             ('\\s+', Text),
  519.             ('[a-zA-Z0-9_.:-]+\\s*=', Name.Attribute, 'attr'),
  520.             ('/?\\s*>', Name.Tag, '#pop')],
  521.         'attr': [
  522.             ('\\s+', Text),
  523.             ('".*?"', String, '#pop'),
  524.             ("'.*?'", String, '#pop'),
  525.             ('[^\\s>]+', String, '#pop')] }
  526.     
  527.     def analyse_text(text):
  528.         if looks_like_xml(text):
  529.             return 0.5
  530.  
  531.  
  532.  
  533. class XsltLexer(XmlLexer):
  534.     name = 'XSLT'
  535.     aliases = [
  536.         'xslt']
  537.     filenames = [
  538.         '*.xsl',
  539.         '*.xslt']
  540.     EXTRA_KEYWORDS = set([
  541.         'apply-imports',
  542.         'apply-templates',
  543.         'attribute',
  544.         'attribute-set',
  545.         'call-template',
  546.         'choose',
  547.         'comment',
  548.         'copy',
  549.         'copy-of',
  550.         'decimal-format',
  551.         'element',
  552.         'fallback',
  553.         'for-each',
  554.         'if',
  555.         'import',
  556.         'include',
  557.         'key',
  558.         'message',
  559.         'namespace-alias',
  560.         'number',
  561.         'otherwise',
  562.         'output',
  563.         'param',
  564.         'preserve-space',
  565.         'processing-instruction',
  566.         'sort',
  567.         'strip-space',
  568.         'stylesheet',
  569.         'template',
  570.         'text',
  571.         'transform',
  572.         'value-of',
  573.         'variable',
  574.         'when',
  575.         'with-param'])
  576.     
  577.     def get_tokens_unprocessed(self, text):
  578.         for index, token, value in XmlLexer.get_tokens_unprocessed(self, text):
  579.             m = re.match('</?xsl:([^>]*)/?>?', value)
  580.             if token is Name.Tag and m and m.group(1) in self.EXTRA_KEYWORDS:
  581.                 yield (index, Keyword, value)
  582.                 continue
  583.             yield (index, token, value)
  584.         
  585.  
  586.     
  587.     def analyse_text(text):
  588.         if looks_like_xml(text) and '<xsl' in text:
  589.             return 0.8
  590.  
  591.  
  592.  
  593. class MxmlLexer(RegexLexer):
  594.     flags = re.MULTILINE | re.DOTALL
  595.     name = 'MXML'
  596.     aliases = [
  597.         'mxml']
  598.     filenames = [
  599.         '*.mxml']
  600.     mimetimes = [
  601.         'text/xml',
  602.         'application/xml']
  603.     tokens = {
  604.         'root': [
  605.             ('[^<&]+', Text),
  606.             ('&\\S*?;', Name.Entity),
  607.             ('(\\<\\!\\[CDATA\\[)(.*?)(\\]\\]\\>)', bygroups(String, using(ActionScript3Lexer), String)),
  608.             ('<!--', Comment, 'comment'),
  609.             ('<\\?.*?\\?>', Comment.Preproc),
  610.             ('<![^>]*>', Comment.Preproc),
  611.             ('<\\s*[a-zA-Z0-9:._-]+', Name.Tag, 'tag'),
  612.             ('<\\s*/\\s*[a-zA-Z0-9:._-]+\\s*>', Name.Tag)],
  613.         'comment': [
  614.             ('[^-]+', Comment),
  615.             ('-->', Comment, '#pop'),
  616.             ('-', Comment)],
  617.         'tag': [
  618.             ('\\s+', Text),
  619.             ('[a-zA-Z0-9_.:-]+\\s*=', Name.Attribute, 'attr'),
  620.             ('/?\\s*>', Name.Tag, '#pop')],
  621.         'attr': [
  622.             ('\\s+', Text),
  623.             ('".*?"', String, '#pop'),
  624.             ("'.*?'", String, '#pop'),
  625.             ('[^\\s>]+', String, '#pop')] }
  626.  
  627.  
  628. class HaxeLexer(RegexLexer):
  629.     name = 'haXe'
  630.     aliases = [
  631.         'hx',
  632.         'haXe']
  633.     filenames = [
  634.         '*.hx']
  635.     mimetypes = [
  636.         'text/haxe']
  637.     ident = '(?:[a-zA-Z_][a-zA-Z0-9_]*)'
  638.     typeid = '(?:(?:[a-z0-9_\\.])*[A-Z_][A-Za-z0-9_]*)'
  639.     key_prop = '(?:default|null|never)'
  640.     key_decl_mod = '(?:public|private|override|static|inline|extern|dynamic)'
  641.     flags = re.DOTALL | re.MULTILINE
  642.     tokens = {
  643.         'root': [
  644.             include('whitespace'),
  645.             include('comments'),
  646.             (key_decl_mod, Keyword.Declaration),
  647.             include('enumdef'),
  648.             include('typedef'),
  649.             include('classdef'),
  650.             include('imports')],
  651.         'comments': [
  652.             ('//.*?\\n', Comment.Single),
  653.             ('/\\*.*?\\*/', Comment.Multiline),
  654.             ('#[^\\n]*', Comment.Preproc)],
  655.         'whitespace': [
  656.             include('comments'),
  657.             ('\\s+', Text)],
  658.         'codekeywords': [
  659.             ('\\b(if|else|while|do|for|in|break|continue|return|switch|case|try|catch|throw|null|trace|new|this|super|untyped|cast|callback|here)\\b', Keyword.Reserved)],
  660.         'literals': [
  661.             ('0[xX][0-9a-fA-F]+', Number.Hex),
  662.             ('[0-9]+', Number.Integer),
  663.             ('[0-9][0-9]*\\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
  664.             ("'(\\\\\\\\|\\\\'|[^'])*'", String.Single),
  665.             ('"(\\\\\\\\|\\\\"|[^"])*"', String.Double),
  666.             ('~/([^\\n])*?/[gisx]*', String.Regex),
  667.             ('\\b(true|false|null)\\b', Keyword.Constant)],
  668.         'codeblock': [
  669.             include('whitespace'),
  670.             include('new'),
  671.             include('case'),
  672.             include('anonfundef'),
  673.             include('literals'),
  674.             include('vardef'),
  675.             include('codekeywords'),
  676.             ('[();,\\[\\]]', Punctuation),
  677.             ('(?:=|\\+=|-=|\\*=|/=|%=|&=|\\|=|\\^=|<<=|>>=|>>>=|\\|\\||&&|\\.\\.\\.|==|!=|>|<|>=|<=|\\||&|\\^|<<|>>|>>>|\\+|\\-|\\*|/|%|!|\\+\\+|\\-\\-|~|\\.|\\?|\\:)', Operator),
  678.             (ident, Name),
  679.             ('}', Punctuation, '#pop'),
  680.             ('{', Punctuation, '#push')],
  681.         'propertydef': [
  682.             ('(\\()(' + key_prop + ')(,)(' + key_prop + ')(\\))', bygroups(Punctuation, Keyword.Reserved, Punctuation, Keyword.Reserved, Punctuation))],
  683.         'new': [
  684.             ('\\bnew\\b', Keyword, 'typedecl')],
  685.         'case': [
  686.             ('\\b(case)(\\s+)(' + ident + ')(\\s*)(\\()', bygroups(Keyword.Reserved, Text, Name, Text, Punctuation), 'funargdecl')],
  687.         'vardef': [
  688.             ('\\b(var)(\\s+)(' + ident + ')', bygroups(Keyword.Declaration, Text, Name.Variable), 'vardecl')],
  689.         'vardecl': [
  690.             include('whitespace'),
  691.             include('typelabel'),
  692.             ('=', Operator, '#pop'),
  693.             (';', Punctuation, '#pop')],
  694.         'instancevardef': [
  695.             (key_decl_mod, Keyword.Declaration),
  696.             ('\\b(var)(\\s+)(' + ident + ')', bygroups(Keyword.Declaration, Text, Name.Variable.Instance), 'instancevardecl')],
  697.         'instancevardecl': [
  698.             include('vardecl'),
  699.             include('propertydef')],
  700.         'anonfundef': [
  701.             ('\\bfunction\\b', Keyword.Declaration, 'fundecl')],
  702.         'instancefundef': [
  703.             (key_decl_mod, Keyword.Declaration),
  704.             ('\\b(function)(\\s+)(' + ident + ')', bygroups(Keyword.Declaration, Text, Name.Function), 'fundecl')],
  705.         'fundecl': [
  706.             include('whitespace'),
  707.             include('typelabel'),
  708.             include('generictypedecl'),
  709.             ('\\(', Punctuation, 'funargdecl'),
  710.             ('(?=[a-zA-Z0-9_])', Text, '#pop'),
  711.             ('{', Punctuation, ('#pop', 'codeblock')),
  712.             (';', Punctuation, '#pop')],
  713.         'funargdecl': [
  714.             include('whitespace'),
  715.             (ident, Name.Variable),
  716.             include('typelabel'),
  717.             include('literals'),
  718.             ('=', Operator),
  719.             (',', Punctuation),
  720.             ('\\?', Punctuation),
  721.             ('\\)', Punctuation, '#pop')],
  722.         'typelabel': [
  723.             (':', Punctuation, 'type')],
  724.         'typedecl': [
  725.             include('whitespace'),
  726.             (typeid, Name.Class),
  727.             ('<', Punctuation, 'generictypedecl'),
  728.             ('(?=[{}()=,a-z])', Text, '#pop')],
  729.         'type': [
  730.             include('whitespace'),
  731.             (typeid, Name.Class),
  732.             ('<', Punctuation, 'generictypedecl'),
  733.             ('->', Keyword.Type),
  734.             ('(?=[{}(),;=])', Text, '#pop')],
  735.         'generictypedecl': [
  736.             include('whitespace'),
  737.             (typeid, Name.Class),
  738.             ('<', Punctuation, '#push'),
  739.             ('>', Punctuation, '#pop'),
  740.             (',', Punctuation)],
  741.         'imports': [
  742.             ('(package|import|using)(\\s+)([^;]+)(;)', bygroups(Keyword.Namespace, Text, Name.Namespace, Punctuation))],
  743.         'typedef': [
  744.             ('typedef', Keyword.Declaration, ('typedefprebody', 'typedecl'))],
  745.         'typedefprebody': [
  746.             include('whitespace'),
  747.             ('(=)(\\s*)({)', bygroups(Punctuation, Text, Punctuation), ('#pop', 'typedefbody'))],
  748.         'enumdef': [
  749.             ('enum', Keyword.Declaration, ('enumdefprebody', 'typedecl'))],
  750.         'enumdefprebody': [
  751.             include('whitespace'),
  752.             ('{', Punctuation, ('#pop', 'enumdefbody'))],
  753.         'classdef': [
  754.             ('class', Keyword.Declaration, ('classdefprebody', 'typedecl'))],
  755.         'classdefprebody': [
  756.             include('whitespace'),
  757.             ('(extends|implements)', Keyword.Declaration, 'typedecl'),
  758.             ('{', Punctuation, ('#pop', 'classdefbody'))],
  759.         'interfacedef': [
  760.             ('interface', Keyword.Declaration, ('interfacedefprebody', 'typedecl'))],
  761.         'interfacedefprebody': [
  762.             include('whitespace'),
  763.             ('(extends)', Keyword.Declaration, 'typedecl'),
  764.             ('{', Punctuation, ('#pop', 'classdefbody'))],
  765.         'typedefbody': [
  766.             include('whitespace'),
  767.             include('instancevardef'),
  768.             include('instancefundef'),
  769.             ('>', Punctuation, 'typedecl'),
  770.             (',', Punctuation),
  771.             ('}', Punctuation, '#pop')],
  772.         'enumdefbody': [
  773.             include('whitespace'),
  774.             (ident, Name.Variable.Instance),
  775.             ('\\(', Punctuation, 'funargdecl'),
  776.             (';', Punctuation),
  777.             ('}', Punctuation, '#pop')],
  778.         'classdefbody': [
  779.             include('whitespace'),
  780.             include('instancevardef'),
  781.             include('instancefundef'),
  782.             ('}', Punctuation, '#pop'),
  783.             include('codeblock')] }
  784.     
  785.     def analyse_text(text):
  786.         if re.match('\\w+\\s*:\\s*\\w', text):
  787.             return 0.3
  788.  
  789.  
  790.  
  791. def _indentation(lexer, match, ctx):
  792.     indentation = match.group(0)
  793.     yield (match.start(), Text, indentation)
  794.     ctx.last_indentation = indentation
  795.     ctx.pos = match.end()
  796.     if hasattr(ctx, 'block_state') and ctx.block_state and indentation.startswith(ctx.block_indentation) and indentation != ctx.block_indentation:
  797.         ctx.stack.append(ctx.block_state)
  798.     else:
  799.         ctx.block_state = None
  800.         ctx.block_indentation = None
  801.         ctx.stack.append('content')
  802.  
  803.  
  804. def _starts_block(token, state):
  805.     
  806.     def callback(lexer, match, ctx):
  807.         yield (match.start(), token, match.group(0))
  808.         if hasattr(ctx, 'last_indentation'):
  809.             ctx.block_indentation = ctx.last_indentation
  810.         else:
  811.             ctx.block_indentation = ''
  812.         ctx.block_state = state
  813.         ctx.pos = match.end()
  814.  
  815.     return callback
  816.  
  817.  
  818. class HamlLexer(ExtendedRegexLexer):
  819.     name = 'Haml'
  820.     aliases = [
  821.         'haml',
  822.         'HAML']
  823.     filenames = [
  824.         '*.haml']
  825.     mimetypes = [
  826.         'text/x-haml']
  827.     flags = re.IGNORECASE
  828.     _dot = '(?: \\|\\n(?=.* \\|)|.)'
  829.     tokens = {
  830.         'root': [
  831.             ('[ \\t]*\\n', Text),
  832.             ('[ \\t]*', _indentation)],
  833.         'css': [
  834.             ('\\.[a-z0-9_:-]+', Name.Class, 'tag'),
  835.             ('\\#[a-z0-9_:-]+', Name.Function, 'tag')],
  836.         'eval-or-plain': [
  837.             ('[&!]?==', Punctuation, 'plain'),
  838.             ('([&!]?[=~])(' + _dot + '*\n)', bygroups(Punctuation, using(RubyLexer)), 'root'),
  839.             ('', Text, 'plain')],
  840.         'content': [
  841.             include('css'),
  842.             ('%[a-z0-9_:-]+', Name.Tag, 'tag'),
  843.             ('!!!' + _dot + '*\n', Name.Namespace, '#pop'),
  844.             ('(/)(\\[' + _dot + '*?\\])(' + _dot + '*\n)', bygroups(Comment, Comment.Special, Comment), '#pop'),
  845.             ('/' + _dot + '*\n', _starts_block(Comment, 'html-comment-block'), '#pop'),
  846.             ('-#' + _dot + '*\n', _starts_block(Comment.Preproc, 'haml-comment-block'), '#pop'),
  847.             ('(-)(' + _dot + '*\n)', bygroups(Punctuation, using(RubyLexer)), '#pop'),
  848.             (':' + _dot + '*\n', _starts_block(Name.Decorator, 'filter-block'), '#pop'),
  849.             include('eval-or-plain')],
  850.         'tag': [
  851.             include('css'),
  852.             ('\\{(,\\n|' + _dot + ')*?\\}', using(RubyLexer)),
  853.             ('\\[' + _dot + '*?\\]', using(RubyLexer)),
  854.             ('\\(', Text, 'html-attributes'),
  855.             ('/[ \\t]*\\n', Punctuation, '#pop:2'),
  856.             ('[<>]{1,2}(?=[ \\t=])', Punctuation),
  857.             include('eval-or-plain')],
  858.         'plain': [
  859.             ('([^#\\n]|#[^{\\n]|(\\\\\\\\)*\\\\#\\{)+', Text),
  860.             ('(#\\{)(' + _dot + '*?)(\\})', bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
  861.             ('\\n', Text, 'root')],
  862.         'html-attributes': [
  863.             ('\\s+', Text),
  864.             ('[a-z0-9_:-]+[ \\t]*=', Name.Attribute, 'html-attribute-value'),
  865.             ('[a-z0-9_:-]+', Name.Attribute),
  866.             ('\\)', Text, '#pop')],
  867.         'html-attribute-value': [
  868.             ('[ \\t]+', Text),
  869.             ('[a-z0-9_]+', Name.Variable, '#pop'),
  870.             ('@[a-z0-9_]+', Name.Variable.Instance, '#pop'),
  871.             ('\\$[a-z0-9_]+', Name.Variable.Global, '#pop'),
  872.             ("'(\\\\\\\\|\\\\'|[^'\\n])*'", String, '#pop'),
  873.             ('"(\\\\\\\\|\\\\"|[^"\\n])*"', String, '#pop')],
  874.         'html-comment-block': [
  875.             (_dot + '+', Comment),
  876.             ('\\n', Text, 'root')],
  877.         'haml-comment-block': [
  878.             (_dot + '+', Comment.Preproc),
  879.             ('\\n', Text, 'root')],
  880.         'filter-block': [
  881.             ('([^#\\n]|#[^{\\n]|(\\\\\\\\)*\\\\#\\{)+', Name.Decorator),
  882.             ('(#\\{)(' + _dot + '*?)(\\})', bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
  883.             ('\\n', Text, 'root')] }
  884.  
  885.  
  886. class SassLexer(ExtendedRegexLexer):
  887.     name = 'Sass'
  888.     aliases = [
  889.         'sass',
  890.         'SASS']
  891.     filenames = [
  892.         '*.sass']
  893.     mimetypes = [
  894.         'text/x-sass']
  895.     flags = re.IGNORECASE
  896.     tokens = {
  897.         'root': [
  898.             ('[ \\t]*\\n', Text),
  899.             ('[ \\t]*', _indentation)],
  900.         'content': [
  901.             ('//[^\\n]*', _starts_block(Comment.Single, 'single-comment'), 'root'),
  902.             ('/\\*[^\\n]*', _starts_block(Comment.Multiline, 'multi-comment'), 'root'),
  903.             ('@import', Keyword, 'import'),
  904.             ('@for', Keyword, 'for'),
  905.             ('@(debug|if|while)', Keyword, 'script'),
  906.             ('@[a-z0-9_-]+', Keyword, 'selector'),
  907.             ('=[\\w-]+', Name.Function, 'script'),
  908.             ('\\+[\\w-]+', Name.Decorator, 'script'),
  909.             ('(![a-z_]\\w*)([ \\t]*(?:\\|\\|)?=)', bygroups(Name.Variable, Operator), 'script'),
  910.             (':', Name.Attribute, 'old-style-attr'),
  911.             ('(?=[^\\s:"\\[]+\\s*[=:]([ \\t]|$))', Name.Attribute, 'new-style-attr'),
  912.             ('', Text, 'selector')],
  913.         'single-comment': [
  914.             ('.+', Comment.Single),
  915.             ('\\n', Text, 'root')],
  916.         'multi-comment': [
  917.             ('.+', Comment.Multiline),
  918.             ('\\n', Text, 'root')],
  919.         'import': [
  920.             ('[ \\t]+', Text),
  921.             ('[^\\s]+', String),
  922.             ('\\n', Text, 'root')],
  923.         'for': [
  924.             ('(from|to|through)', Operator.Word),
  925.             include('script')],
  926.         'old-style-attr': [
  927.             ('[^\\s:="\\[]+', Name.Attribute),
  928.             ('#{', String.Interpol, 'interpolation'),
  929.             ('[ \\t]*=', Operator, 'script'),
  930.             ('', Text, 'value')],
  931.         'new-style-attr': [
  932.             ('[^\\s:="\\[]+', Name.Attribute),
  933.             ('#{', String.Interpol, 'interpolation'),
  934.             ('[ \\t]*=', Operator, 'script'),
  935.             (':', Name.Attribute, 'value')],
  936.         'value': [
  937.             ('[ \\t]+', Text),
  938.             ('url\\(', String.Other, 'string-url'),
  939.             ('(azimuth|background-attachment|background-color|background-image|background-position|background-repeat|background|border-bottom-color|border-bottom-style|border-bottom-width|border-left-color|border-left-style|border-left-width|border-right|border-right-color|border-right-style|border-right-width|border-top-color|border-top-style|border-top-width|border-bottom|border-collapse|border-left|border-width|border-color|border-spacing|border-style|border-top|border|caption-side|clear|clip|color|content|counter-increment|counter-reset|cue-after|cue-before|cue|cursor|direction|display|elevation|empty-cells|float|font-family|font-size|font-size-adjust|font-stretch|font-style|font-variant|font-weight|font|height|letter-spacing|line-height|list-style-type|list-style-image|list-style-position|list-style|margin-bottom|margin-left|margin-right|margin-top|margin|marker-offset|marks|max-height|max-width|min-height|min-width|opacity|orphans|outline|outline-color|outline-style|outline-width|overflow|padding-bottom|padding-left|padding-right|padding-top|padding|page|page-break-after|page-break-before|page-break-inside|pause-after|pause-before|pause|pitch|pitch-range|play-during|position|quotes|richness|right|size|speak-header|speak-numeral|speak-punctuation|speak|speech-rate|stress|table-layout|text-align|text-decoration|text-indent|text-shadow|text-transform|top|unicode-bidi|vertical-align|visibility|voice-family|volume|white-space|widows|width|word-spacing|z-index|bottom|left|above|absolute|always|armenian|aural|auto|avoid|baseline|behind|below|bidi-override|blink|block|bold|bolder|both|capitalize|center-left|center-right|center|circle|cjk-ideographic|close-quote|collapse|condensed|continuous|crop|crosshair|cross|cursive|dashed|decimal-leading-zero|decimal|default|digits|disc|dotted|double|e-resize|embed|extra-condensed|extra-expanded|expanded|fantasy|far-left|far-right|faster|fast|fixed|georgian|groove|hebrew|help|hidden|hide|higher|high|hiragana-iroha|hiragana|icon|inherit|inline-table|inline|inset|inside|invert|italic|justify|katakana-iroha|katakana|landscape|larger|large|left-side|leftwards|level|lighter|line-through|list-item|loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|lower|low|medium|message-box|middle|mix|monospace|n-resize|narrower|ne-resize|no-close-quote|no-open-quote|no-repeat|none|normal|nowrap|nw-resize|oblique|once|open-quote|outset|outside|overline|pointer|portrait|px|relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|rightwards|s-resize|sans-serif|scroll|se-resize|semi-condensed|semi-expanded|separate|serif|show|silent|slow|slower|small-caps|small-caption|smaller|soft|solid|spell-out|square|static|status-bar|super|sw-resize|table-caption|table-cell|table-column|table-column-group|table-footer-group|table-header-group|table-row|table-row-group|text|text-bottom|text-top|thick|thin|transparent|ultra-condensed|ultra-expanded|underline|upper-alpha|upper-latin|upper-roman|uppercase|url|visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|x-low|x-small|x-soft|xx-large|xx-small|yes)\\b', Name.Constant),
  940.             ('(indigo|gold|firebrick|indianred|yellow|darkolivegreen|darkseagreen|mediumvioletred|mediumorchid|chartreuse|mediumslateblue|black|springgreen|crimson|lightsalmon|brown|turquoise|olivedrab|cyan|silver|skyblue|gray|darkturquoise|goldenrod|darkgreen|darkviolet|darkgray|lightpink|teal|darkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|violet|navy|orchid|blue|ghostwhite|honeydew|cornflowerblue|darkblue|darkkhaki|mediumpurple|cornsilk|red|bisque|slategray|darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|gainsboro|mediumturquoise|floralwhite|coral|purple|lightgrey|lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|greenyellow|royalblue|lightseagreen|mistyrose|sienna|lightcoral|orangered|navajowhite|lime|palegreen|burlywood|seashell|mediumspringgreen|fuchsia|papayawhip|blanchedalmond|peru|aquamarine|white|darkslategray|ivory|dodgerblue|lemonchiffon|chocolate|orange|forestgreen|slateblue|olive|mintcream|antiquewhite|darkorange|cadetblue|moccasin|limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|plum|aqua|darkgoldenrod|maroon|sandybrown|magenta|tan|rosybrown|pink|lightblue|palevioletred|mediumseagreen|dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|lightslategray|lawngreen|lightgreen|tomato|hotpink|lightyellow|lavenderblush|linen|mediumaquamarine|green|blueviolet|peachpuff)\\b', Name.Entity),
  941.             ('\\!important', Name.Exception),
  942.             ('/\\*', Comment, 'inline-comment'),
  943.             ('\\#[a-z0-9]{1,6}', Number.Hex),
  944.             ('(-?\\d+)(\\%|[a-z]+)?', bygroups(Number.Integer, Keyword.Type)),
  945.             ('(-?\\d*\\.\\d+)(\\%|[a-z]+)?', bygroups(Number.Float, Keyword.Type)),
  946.             ('#{', String.Interpol, 'interpolation'),
  947.             ('[~\\^\\*!&%<>\\|+=@:,./?-]+', Operator),
  948.             ('[\\[\\]();]+', Punctuation),
  949.             ('"', String.Double, 'string-double'),
  950.             ("'", String.Single, 'string-single'),
  951.             ('[a-z][\\w-]*', Name),
  952.             ('\\n', Text, 'root')],
  953.         'script': [
  954.             ('[ \\t]+', Text),
  955.             ('![\\w_]+', Name.Variable),
  956.             ('[+\\-*/%=(),!><]', Operator),
  957.             ('"', String.Double, 'string-double'),
  958.             ("'", String.Single, 'string-single'),
  959.             ('\\#[a-z0-9]{1,6}', Number.Hex),
  960.             ('(-?\\d+)(\\%|[a-z]+)?', bygroups(Number.Integer, Keyword.Type)),
  961.             ('(-?\\d*\\.\\d+)(\\%|[a-z]+)?', bygroups(Number.Float, Keyword.Type)),
  962.             ('(black|silver|gray|white|maroon|red|purple|fuchsia|green|lime|olive|yellow|navy|blue|teal|aqua)\\b', Name.Builtin),
  963.             ('(true|false)', Name.Pseudo),
  964.             ('(and|or|not)', Operator.Word),
  965.             ('(\\\\.|[^\\s\\\\+*\\/%(),=!])+(?=[ \\t]*\\()', Name.Function),
  966.             ('(\\\\.|[^\\s\\\\+*\\/%(),=!])+', Name),
  967.             ('\\n', Text, 'root')],
  968.         'interpolation': [
  969.             ('\\}', String.Interpol, '#pop'),
  970.             include('script')],
  971.         'selector': [
  972.             ('[ \\t]+', Text),
  973.             ('\\:', Name.Decorator, 'pseudo-class'),
  974.             ('\\.', Name.Class, 'class'),
  975.             ('\\#', Name.Namespace, 'id'),
  976.             ('[a-zA-Z0-9_-]+', Name.Tag),
  977.             ('#\\{', String.Interpol, 'interpolation'),
  978.             ('&', Keyword),
  979.             ('[~\\^\\*!&\\[\\]\\(\\)<>\\|+=@:;,./?-]', Operator),
  980.             ('"', String.Double, 'string-double'),
  981.             ("'", String.Single, 'string-single'),
  982.             ('\\n', Text, 'root')],
  983.         'string-double': [
  984.             ('(\\\\.|#(?=[^\\n{])|[^\\n"#])+', String.Double),
  985.             ('#\\{', String.Interpol, 'interpolation'),
  986.             ('"', String.Double, '#pop')],
  987.         'string-single': [
  988.             ("(\\\\.|#(?=[^\\n{])|[^\\n'#])+", String.Double),
  989.             ('#\\{', String.Interpol, 'interpolation'),
  990.             ("'", String.Double, '#pop')],
  991.         'string-url': [
  992.             ('(\\\\#|#(?=[^\\n{])|[^\\n#)])+', String.Other),
  993.             ('#\\{', String.Interpol, 'interpolation'),
  994.             ('\\)', String.Other, '#pop')],
  995.         'inline-comment': [
  996.             ('(\\\\#|#(?=[^\\n{])|\\*(?=[^\\n/])|[^\\n#*])+', Comment),
  997.             ('#\\{', String.Interpol, 'interpolation'),
  998.             ('\\*/', Comment, '#pop')],
  999.         'pseudo-class': [
  1000.             ('[\\w-]+', Name.Decorator),
  1001.             ('#\\{', String.Interpol, 'interpolation'),
  1002.             ('', Text, '#pop')],
  1003.         'class': [
  1004.             ('[\\w-]+', Name.Class),
  1005.             ('#\\{', String.Interpol, 'interpolation'),
  1006.             ('', Text, '#pop')],
  1007.         'id': [
  1008.             ('[\\w-]+', Name.Namespace),
  1009.             ('#\\{', String.Interpol, 'interpolation'),
  1010.             ('', Text, '#pop')] }
  1011.  
  1012.  
  1013. class CoffeeScriptLexer(RegexLexer):
  1014.     name = 'CoffeeScript'
  1015.     aliases = [
  1016.         'coffee-script',
  1017.         'coffeescript']
  1018.     filenames = [
  1019.         '*.coffee']
  1020.     mimetypes = [
  1021.         'text/coffeescript']
  1022.     flags = re.DOTALL
  1023.     tokens = {
  1024.         'commentsandwhitespace': [
  1025.             ('\\s+', Text),
  1026.             ('#.*?\\n', Comment.Single)],
  1027.         'slashstartsregex': [
  1028.             include('commentsandwhitespace'),
  1029.             ('/(\\\\.|[^[/\\\\\\n]|\\[(\\\\.|[^\\]\\\\\\n])*])+/([gim]+\\b|\\B)', String.Regex, '#pop'),
  1030.             ('(?=/)', Text, ('#pop', 'badregex')),
  1031.             ('', Text, '#pop')],
  1032.         'badregex': [
  1033.             ('\n', Text, '#pop')],
  1034.         'root': [
  1035.             ('^(?=\\s|/|<!--)', Text, 'slashstartsregex'),
  1036.             include('commentsandwhitespace'),
  1037.             ('\\+\\+|--|~|&&|\\band\\b|\\bor\\b|\\bis\\b|\\bisnt\\b|\\bnot\\b|\\?|:|\\|\\||\\\\(?=\\n)|(<<|>>>?|==?|!=?|[-<>+*`%&\\|\\^/])=?', Operator, 'slashstartsregex'),
  1038.             ('[{(\\[;,]', Punctuation, 'slashstartsregex'),
  1039.             ('[})\\].]', Punctuation),
  1040.             ('(for|in|of|while|break|return|continue|switch|when|then|if|else|throw|try|catch|finally|new|delete|typeof|instanceof|super|extends|this)\\b', Keyword, 'slashstartsregex'),
  1041.             ('(true|false|yes|no|on|off|null|NaN|Infinity|undefined)\\b', Keyword.Constant),
  1042.             ('(Array|Boolean|Date|Error|Function|Math|netscape|Number|Object|Packages|RegExp|String|sun|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|window)\\b', Name.Builtin),
  1043.             ('[$a-zA-Z_][a-zA-Z0-9_\\.:]*:\\s', Name.Variable, 'slashstartsregex'),
  1044.             ('[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
  1045.             ('[0-9][0-9]*\\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
  1046.             ('0x[0-9a-fA-F]+', Number.Hex),
  1047.             ('[0-9]+', Number.Integer),
  1048.             ('"(\\\\\\\\|\\\\"|[^"])*"', String.Double),
  1049.             ("'(\\\\\\\\|\\\\'|[^'])*'", String.Single)] }
  1050.  
  1051.