ThirdParty/Pygments/pygments/lexers/web.py

changeset 684
2f29a0b6e1c7
parent 12
1d8dd9706f46
child 808
8f85926125ef
equal deleted inserted replaced
682:91114a975eda 684:2f29a0b6e1c7
3 pygments.lexers.web 3 pygments.lexers.web
4 ~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for web-related languages and markup. 6 Lexers for web-related languages and markup.
7 7
8 :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 import re 12 import re
13 try: 13
14 set 14 from pygments.lexer import RegexLexer, ExtendedRegexLexer, bygroups, using, \
15 except NameError: 15 include, this
16 from sets import Set as set
17
18 from pygments.lexer import RegexLexer, bygroups, using, include, this
19 from pygments.token import \ 16 from pygments.token import \
20 Text, Comment, Operator, Keyword, Name, String, Number, Other, Punctuation 17 Text, Comment, Operator, Keyword, Name, String, Number, Other, Punctuation
21 from pygments.util import get_bool_opt, get_list_opt, looks_like_xml, \ 18 from pygments.util import get_bool_opt, get_list_opt, looks_like_xml, \
22 html_doctype_matches 19 html_doctype_matches
20 from pygments.lexers.agile import RubyLexer
23 21
24 22
25 __all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'CssLexer', 23 __all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'CssLexer',
26 'PhpLexer', 'ActionScriptLexer', 'XsltLexer', 'ActionScript3Lexer', 24 'PhpLexer', 'ActionScriptLexer', 'XsltLexer', 'ActionScript3Lexer',
27 'MxmlLexer'] 25 'MxmlLexer', 'HaxeLexer', 'HamlLexer', 'SassLexer',
26 'ObjectiveJLexer', 'CoffeeScriptLexer']
28 27
29 28
30 class JavascriptLexer(RegexLexer): 29 class JavascriptLexer(RegexLexer):
31 """ 30 """
32 For JavaScript source code. 31 For JavaScript source code.
310 r'font-weight|font|height|letter-spacing|line-height|' 309 r'font-weight|font|height|letter-spacing|line-height|'
311 r'list-style-type|list-style-image|list-style-position|' 310 r'list-style-type|list-style-image|list-style-position|'
312 r'list-style|margin-bottom|margin-left|margin-right|' 311 r'list-style|margin-bottom|margin-left|margin-right|'
313 r'margin-top|margin|marker-offset|marks|max-height|max-width|' 312 r'margin-top|margin|marker-offset|marks|max-height|max-width|'
314 r'min-height|min-width|opacity|orphans|outline|outline-color|' 313 r'min-height|min-width|opacity|orphans|outline|outline-color|'
315 r'outline-style|outline-width|overflow|padding-bottom|' 314 r'outline-style|outline-width|overflow(?:-x|-y|)|padding-bottom|'
316 r'padding-left|padding-right|padding-top|padding|page|' 315 r'padding-left|padding-right|padding-top|padding|page|'
317 r'page-break-after|page-break-before|page-break-inside|' 316 r'page-break-after|page-break-before|page-break-inside|'
318 r'pause-after|pause-before|pause|pitch|pitch-range|' 317 r'pause-after|pause-before|pause|pitch|pitch-range|'
319 r'play-during|position|quotes|richness|right|size|' 318 r'play-during|position|quotes|richness|right|size|'
320 r'speak-header|speak-numeral|speak-punctuation|speak|' 319 r'speak-header|speak-numeral|speak-punctuation|speak|'
388 (r'[a-zA-Z][a-zA-Z0-9]+', Name) 387 (r'[a-zA-Z][a-zA-Z0-9]+', Name)
389 ] 388 ]
390 } 389 }
391 390
392 391
392 class ObjectiveJLexer(RegexLexer):
393 """
394 For Objective-J source code with preprocessor directives.
395
396 *New in Pygments 1.3.*
397 """
398
399 name = 'Objective-J'
400 aliases = ['objective-j', 'objectivej', 'obj-j', 'objj']
401 filenames = ['*.j']
402 mimetypes = ['text/x-objective-j']
403
404 #: optional Comment or Whitespace
405 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)*'
406
407 flags = re.DOTALL | re.MULTILINE
408
409 tokens = {
410 'root': [
411 include('whitespace'),
412
413 # function definition
414 (r'^(' + _ws + r'[\+-]' + _ws + r')([\(a-zA-Z_].*?[^\(])(' + _ws + '{)',
415 bygroups(using(this), using(this, state='function_signature'),
416 using(this))),
417
418 # class definition
419 (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text),
420 'classname'),
421 (r'(@class|@protocol)(\s*)', bygroups(Keyword, Text),
422 'forward_classname'),
423 (r'(\s*)(@end)(\s*)', bygroups(Text, Keyword, Text)),
424
425 include('statements'),
426 ('[{\(\)}]', Punctuation),
427 (';', Punctuation),
428 ],
429 'whitespace': [
430 (r'(@import)(\s+)("(\\\\|\\"|[^"])*")',
431 bygroups(Comment.Preproc, Text, String.Double)),
432 (r'(@import)(\s+)(<(\\\\|\\>|[^>])*>)',
433 bygroups(Comment.Preproc, Text, String.Double)),
434 (r'(#(?:include|import))(\s+)("(\\\\|\\"|[^"])*")',
435 bygroups(Comment.Preproc, Text, String.Double)),
436 (r'(#(?:include|import))(\s+)(<(\\\\|\\>|[^>])*>)',
437 bygroups(Comment.Preproc, Text, String.Double)),
438
439 (r'#if\s+0', Comment.Preproc, 'if0'),
440 (r'#', Comment.Preproc, 'macro'),
441
442 (r'\n', Text),
443 (r'\s+', Text),
444 (r'\\\n', Text), # line continuation
445 (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
446 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
447 (r'<!--', Comment),
448 ],
449 'slashstartsregex': [
450 include('whitespace'),
451 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
452 r'([gim]+\b|\B)', String.Regex, '#pop'),
453 (r'(?=/)', Text, ('#pop', 'badregex')),
454 (r'', Text, '#pop'),
455 ],
456 'badregex': [
457 ('\n', Text, '#pop'),
458 ],
459 'statements': [
460 (r'(L|@)?"', String, 'string'),
461 (r"(L|@)?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
462 String.Char),
463 (r'"(\\\\|\\"|[^"])*"', String.Double),
464 (r"'(\\\\|\\'|[^'])*'", String.Single),
465 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
466 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
467 (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
468 (r'0[0-7]+[Ll]?', Number.Oct),
469 (r'\d+[Ll]?', Number.Integer),
470
471 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
472
473 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
474 r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?',
475 Operator, 'slashstartsregex'),
476 (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
477 (r'[})\].]', Punctuation),
478
479 (r'(for|in|while|do|break|return|continue|switch|case|default|if|'
480 r'else|throw|try|catch|finally|new|delete|typeof|instanceof|void|'
481 r'prototype|__proto__)\b', Keyword, 'slashstartsregex'),
482
483 (r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
484
485 (r'(@selector|@private|@protected|@public|@encode|'
486 r'@synchronized|@try|@throw|@catch|@finally|@end|@property|'
487 r'@synthesize|@dynamic|@for|@accessors|new)\b', Keyword),
488
489 (r'(int|long|float|short|double|char|unsigned|signed|void|'
490 r'id|BOOL|bool|boolean|IBOutlet|IBAction|SEL|@outlet|@action)\b',
491 Keyword.Type),
492
493 (r'(self|super)\b', Name.Builtin),
494
495 (r'(TRUE|YES|FALSE|NO|Nil|nil|NULL)\b', Keyword.Constant),
496 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
497 (r'(ABS|ASIN|ACOS|ATAN|ATAN2|SIN|COS|TAN|EXP|POW|CEIL|FLOOR|ROUND|'
498 r'MIN|MAX|RAND|SQRT|E|LN2|LN10|LOG2E|LOG10E|PI|PI2|PI_2|SQRT1_2|'
499 r'SQRT2)\b', Keyword.Constant),
500
501 (r'(Array|Boolean|Date|Error|Function|Math|netscape|'
502 r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
503 r'decodeURIComponent|encodeURI|encodeURIComponent|'
504 r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
505 r'window)\b', Name.Builtin),
506
507 (r'([$a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r')(?=\()',
508 bygroups(Name.Function, using(this))),
509
510 (r'[$a-zA-Z_][a-zA-Z0-9_]*', Name),
511 ],
512 'classname' : [
513 # interface definition that inherits
514 (r'([a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r':' + _ws +
515 r')([a-zA-Z_][a-zA-Z0-9_]*)?',
516 bygroups(Name.Class, using(this), Name.Class), '#pop'),
517 # interface definition for a category
518 (r'([a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r'\()([a-zA-Z_][a-zA-Z0-9_]*)(\))',
519 bygroups(Name.Class, using(this), Name.Label, Text), '#pop'),
520 # simple interface / implementation
521 (r'([a-zA-Z_][a-zA-Z0-9_]*)', Name.Class, '#pop'),
522 ],
523 'forward_classname' : [
524 (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*,\s*)',
525 bygroups(Name.Class, Text), '#push'),
526 (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*;?)',
527 bygroups(Name.Class, Text), '#pop'),
528 ],
529 'function_signature': [
530 include('whitespace'),
531
532 # start of a selector w/ parameters
533 (r'(\(' + _ws + r')' # open paren
534 r'([a-zA-Z_][a-zA-Z0-9_]+)' # return type
535 r'(' + _ws + r'\)' + _ws + r')' # close paren
536 r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name
537 bygroups(using(this), Keyword.Type, using(this),
538 Name.Function), 'function_parameters'),
539
540 # no-param function
541 (r'(\(' + _ws + r')' # open paren
542 r'([a-zA-Z_][a-zA-Z0-9_]+)' # return type
543 r'(' + _ws + r'\)' + _ws + r')' # close paren
544 r'([$a-zA-Z_][a-zA-Z0-9_]+)', # function name
545 bygroups(using(this), Keyword.Type, using(this),
546 Name.Function), "#pop"),
547
548 # no return type given, start of a selector w/ parameters
549 (r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name
550 bygroups (Name.Function), 'function_parameters'),
551
552 # no return type given, no-param function
553 (r'([$a-zA-Z_][a-zA-Z0-9_]+)', # function name
554 bygroups(Name.Function), "#pop"),
555
556 ('', Text, '#pop'),
557 ],
558 'function_parameters': [
559 include('whitespace'),
560
561 # parameters
562 (r'(\(' + _ws + ')' # open paren
563 r'([^\)]+)' # type
564 r'(' + _ws + r'\)' + _ws + r')+' # close paren
565 r'([$a-zA-Z_][a-zA-Z0-9_]+)', # param name
566 bygroups(using(this), Keyword.Type, using(this), Text)),
567
568 # one piece of a selector name
569 (r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name
570 Name.Function),
571
572 # smallest possible selector piece
573 (r'(:)', Name.Function),
574
575 # var args
576 (r'(,' + _ws + r'...)', using(this)),
577
578 # param name
579 (r'([$a-zA-Z_][a-zA-Z0-9_]+)', Text),
580 ],
581 'expression' : [
582 (r'([$a-zA-Z_][a-zA-Z0-9_]*)(\()', bygroups(Name.Function,
583 Punctuation)),
584 (r'(\))', Punctuation, "#pop"),
585 ],
586 'string': [
587 (r'"', String, '#pop'),
588 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
589 (r'[^\\"\n]+', String), # all other characters
590 (r'\\\n', String), # line continuation
591 (r'\\', String), # stray backslash
592 ],
593 'macro': [
594 (r'[^/\n]+', Comment.Preproc),
595 (r'/[*](.|\n)*?[*]/', Comment.Multiline),
596 (r'//.*?\n', Comment.Single, '#pop'),
597 (r'/', Comment.Preproc),
598 (r'(?<=\\)\n', Comment.Preproc),
599 (r'\n', Comment.Preproc, '#pop'),
600 ],
601 'if0': [
602 (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
603 (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
604 (r'.*?\n', Comment),
605 ]
606 }
607
608 def analyse_text(text):
609 if re.search('^\s*@import\s+[<"]', text, re.MULTILINE):
610 # special directive found in most Objective-J files
611 return True
612 return False
613
614
393 class HtmlLexer(RegexLexer): 615 class HtmlLexer(RegexLexer):
394 """ 616 """
395 For HTML 4 and XHTML 1 markup. Nested JavaScript and CSS is highlighted 617 For HTML 4 and XHTML 1 markup. Nested JavaScript and CSS is highlighted
396 by the appropriate lexer. 618 by the appropriate lexer.
397 """ 619 """
491 (r'[^<]+', Other), 713 (r'[^<]+', Other),
492 (r'<', Other) 714 (r'<', Other)
493 ], 715 ],
494 'php': [ 716 'php': [
495 (r'\?>', Comment.Preproc, '#pop'), 717 (r'\?>', Comment.Preproc, '#pop'),
496 (r'<<<([a-zA-Z_][a-zA-Z0-9_]*)\n.*?\n\1\;?\n', String), 718 (r'<<<(\'?)([a-zA-Z_][a-zA-Z0-9_]*)\1\n.*?\n\2\;?\n', String),
497 (r'\s+', Text), 719 (r'\s+', Text),
498 (r'#.*?\n', Comment.Single), 720 (r'#.*?\n', Comment.Single),
499 (r'//.*?\n', Comment.Single), 721 (r'//.*?\n', Comment.Single),
500 # put the empty comment here, it is otherwise seen as 722 # put the empty comment here, it is otherwise seen as
501 # the start of a docstring 723 # the start of a docstring
505 (r'(->|::)(\s*)([a-zA-Z_][a-zA-Z0-9_]*)', 727 (r'(->|::)(\s*)([a-zA-Z_][a-zA-Z0-9_]*)',
506 bygroups(Operator, Text, Name.Attribute)), 728 bygroups(Operator, Text, Name.Attribute)),
507 (r'[~!%^&*+=|:.<>/?@-]+', Operator), 729 (r'[~!%^&*+=|:.<>/?@-]+', Operator),
508 (r'[\[\]{}();,]+', Punctuation), 730 (r'[\[\]{}();,]+', Punctuation),
509 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), 731 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
732 (r'(function)(\s*)(?=\()', bygroups(Keyword, Text)),
510 (r'(function)(\s+)(&?)(\s*)', 733 (r'(function)(\s+)(&?)(\s*)',
511 bygroups(Keyword, Text, Operator, Text), 'functionname'), 734 bygroups(Keyword, Text, Operator, Text), 'functionname'),
512 (r'(const)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)', 735 (r'(const)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)',
513 bygroups(Keyword, Text, Name.Constant)), 736 bygroups(Keyword, Text, Name.Constant)),
514 (r'(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|' 737 (r'(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|'
518 r'echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|' 741 r'echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|'
519 r'virtual|endfor|include_once|while|endforeach|global|__FILE__|' 742 r'virtual|endfor|include_once|while|endforeach|global|__FILE__|'
520 r'endif|list|__LINE__|endswitch|new|__sleep|endwhile|not|' 743 r'endif|list|__LINE__|endswitch|new|__sleep|endwhile|not|'
521 r'array|__wakeup|E_ALL|NULL|final|php_user_filter|interface|' 744 r'array|__wakeup|E_ALL|NULL|final|php_user_filter|interface|'
522 r'implements|public|private|protected|abstract|clone|try|' 745 r'implements|public|private|protected|abstract|clone|try|'
523 r'catch|throw|this)\b', Keyword), 746 r'catch|throw|this|use|namespace)\b', Keyword),
524 ('(true|false|null)\b', Keyword.Constant), 747 ('(true|false|null)\b', Keyword.Constant),
525 (r'\$\{\$+[a-zA-Z_][a-zA-Z0-9_]*\}', Name.Variable), 748 (r'\$\{\$+[a-zA-Z_][a-zA-Z0-9_]*\}', Name.Variable),
526 (r'\$+[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable), 749 (r'\$+[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable),
527 ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Other), 750 (r'[\\a-zA-Z_][\\a-zA-Z0-9_]*', Name.Other),
528 (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|" 751 (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|"
529 r"0[xX][0-9a-fA-F]+[Ll]?", Number), 752 r"0[xX][0-9a-fA-F]+[Ll]?", Number),
530 (r"'([^'\\]*(?:\\.[^'\\]*)*)'", String.Single), 753 (r"'([^'\\]*(?:\\.[^'\\]*)*)'", String.Single),
531 (r'`([^`\\]*(?:\\.[^`\\]*)*)`', String.Backtick), 754 (r'`([^`\\]*(?:\\.[^`\\]*)*)`', String.Backtick),
532 (r'"', String.Double, 'string'), 755 (r'"', String.Double, 'string'),
533 ], 756 ],
534 'classname': [ 757 'classname': [
535 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop') 758 (r'[a-zA-Z_][\\a-zA-Z0-9_]*', Name.Class, '#pop')
536 ], 759 ],
537 'functionname': [ 760 'functionname': [
538 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop') 761 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop')
539 ], 762 ],
540 'string': [ 763 'string': [
676 yield index, token, value 899 yield index, token, value
677 900
678 def analyse_text(text): 901 def analyse_text(text):
679 if looks_like_xml(text) and '<xsl' in text: 902 if looks_like_xml(text) and '<xsl' in text:
680 return 0.8 903 return 0.8
681
682 904
683 905
684 class MxmlLexer(RegexLexer): 906 class MxmlLexer(RegexLexer):
685 """ 907 """
686 For MXML markup. 908 For MXML markup.
719 ('".*?"', String, '#pop'), 941 ('".*?"', String, '#pop'),
720 ("'.*?'", String, '#pop'), 942 ("'.*?'", String, '#pop'),
721 (r'[^\s>]+', String, '#pop'), 943 (r'[^\s>]+', String, '#pop'),
722 ], 944 ],
723 } 945 }
946
947
948 class HaxeLexer(RegexLexer):
949 """
950 For haXe source code (http://haxe.org/).
951 """
952
953 name = 'haXe'
954 aliases = ['hx', 'haXe']
955 filenames = ['*.hx']
956 mimetypes = ['text/haxe']
957
958 ident = r'(?:[a-zA-Z_][a-zA-Z0-9_]*)'
959 typeid = r'(?:(?:[a-z0-9_\.])*[A-Z_][A-Za-z0-9_]*)'
960 key_prop = r'(?:default|null|never)'
961 key_decl_mod = r'(?:public|private|override|static|inline|extern|dynamic)'
962
963 flags = re.DOTALL | re.MULTILINE
964
965 tokens = {
966 'root': [
967 include('whitespace'),
968 include('comments'),
969 (key_decl_mod, Keyword.Declaration),
970 include('enumdef'),
971 include('typedef'),
972 include('classdef'),
973 include('imports'),
974 ],
975
976 # General constructs
977 'comments': [
978 (r'//.*?\n', Comment.Single),
979 (r'/\*.*?\*/', Comment.Multiline),
980 (r'#[^\n]*', Comment.Preproc),
981 ],
982 'whitespace': [
983 include('comments'),
984 (r'\s+', Text),
985 ],
986 'codekeywords': [
987 (r'\b(if|else|while|do|for|in|break|continue|'
988 r'return|switch|case|try|catch|throw|null|trace|'
989 r'new|this|super|untyped|cast|callback|here)\b',
990 Keyword.Reserved),
991 ],
992 'literals': [
993 (r'0[xX][0-9a-fA-F]+', Number.Hex),
994 (r'[0-9]+', Number.Integer),
995 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
996 (r"'(\\\\|\\'|[^'])*'", String.Single),
997 (r'"(\\\\|\\"|[^"])*"', String.Double),
998 (r'~/([^\n])*?/[gisx]*', String.Regex),
999 (r'\b(true|false|null)\b', Keyword.Constant),
1000 ],
1001 'codeblock': [
1002 include('whitespace'),
1003 include('new'),
1004 include('case'),
1005 include('anonfundef'),
1006 include('literals'),
1007 include('vardef'),
1008 include('codekeywords'),
1009 (r'[();,\[\]]', Punctuation),
1010 (r'(?:=|\+=|-=|\*=|/=|%=|&=|\|=|\^=|<<=|>>=|>>>=|\|\||&&|'
1011 r'\.\.\.|==|!=|>|<|>=|<=|\||&|\^|<<|>>|>>>|\+|\-|\*|/|%|'
1012 r'!|\+\+|\-\-|~|\.|\?|\:)',
1013 Operator),
1014 (ident, Name),
1015
1016 (r'}', Punctuation,'#pop'),
1017 (r'{', Punctuation,'#push'),
1018 ],
1019
1020 # Instance/Block level constructs
1021 'propertydef': [
1022 (r'(\()(' + key_prop + ')(,)(' + key_prop + ')(\))',
1023 bygroups(Punctuation, Keyword.Reserved, Punctuation,
1024 Keyword.Reserved, Punctuation)),
1025 ],
1026 'new': [
1027 (r'\bnew\b', Keyword, 'typedecl'),
1028 ],
1029 'case': [
1030 (r'\b(case)(\s+)(' + ident + ')(\s*)(\()',
1031 bygroups(Keyword.Reserved, Text, Name, Text, Punctuation),
1032 'funargdecl'),
1033 ],
1034 'vardef': [
1035 (r'\b(var)(\s+)(' + ident + ')',
1036 bygroups(Keyword.Declaration, Text, Name.Variable), 'vardecl'),
1037 ],
1038 'vardecl': [
1039 include('whitespace'),
1040 include('typelabel'),
1041 (r'=', Operator,'#pop'),
1042 (r';', Punctuation,'#pop'),
1043 ],
1044 'instancevardef': [
1045 (key_decl_mod,Keyword.Declaration),
1046 (r'\b(var)(\s+)(' + ident + ')',
1047 bygroups(Keyword.Declaration, Text, Name.Variable.Instance),
1048 'instancevardecl'),
1049 ],
1050 'instancevardecl': [
1051 include('vardecl'),
1052 include('propertydef'),
1053 ],
1054
1055 'anonfundef': [
1056 (r'\bfunction\b', Keyword.Declaration, 'fundecl'),
1057 ],
1058 'instancefundef': [
1059 (key_decl_mod, Keyword.Declaration),
1060 (r'\b(function)(\s+)(' + ident + ')',
1061 bygroups(Keyword.Declaration, Text, Name.Function), 'fundecl'),
1062 ],
1063 'fundecl': [
1064 include('whitespace'),
1065 include('typelabel'),
1066 include('generictypedecl'),
1067 (r'\(',Punctuation,'funargdecl'),
1068 (r'(?=[a-zA-Z0-9_])',Text,'#pop'),
1069 (r'{',Punctuation,('#pop','codeblock')),
1070 (r';',Punctuation,'#pop'),
1071 ],
1072 'funargdecl': [
1073 include('whitespace'),
1074 (ident, Name.Variable),
1075 include('typelabel'),
1076 include('literals'),
1077 (r'=', Operator),
1078 (r',', Punctuation),
1079 (r'\?', Punctuation),
1080 (r'\)', Punctuation, '#pop'),
1081 ],
1082
1083 'typelabel': [
1084 (r':', Punctuation, 'type'),
1085 ],
1086 'typedecl': [
1087 include('whitespace'),
1088 (typeid, Name.Class),
1089 (r'<', Punctuation, 'generictypedecl'),
1090 (r'(?=[{}()=,a-z])', Text,'#pop'),
1091 ],
1092 'type': [
1093 include('whitespace'),
1094 (typeid, Name.Class),
1095 (r'<', Punctuation, 'generictypedecl'),
1096 (r'->', Keyword.Type),
1097 (r'(?=[{}(),;=])', Text, '#pop'),
1098 ],
1099 'generictypedecl': [
1100 include('whitespace'),
1101 (typeid, Name.Class),
1102 (r'<', Punctuation, '#push'),
1103 (r'>', Punctuation, '#pop'),
1104 (r',', Punctuation),
1105 ],
1106
1107 # Top level constructs
1108 'imports': [
1109 (r'(package|import|using)(\s+)([^;]+)(;)',
1110 bygroups(Keyword.Namespace, Text, Name.Namespace,Punctuation)),
1111 ],
1112 'typedef': [
1113 (r'typedef', Keyword.Declaration, ('typedefprebody', 'typedecl')),
1114 ],
1115 'typedefprebody': [
1116 include('whitespace'),
1117 (r'(=)(\s*)({)', bygroups(Punctuation, Text, Punctuation),
1118 ('#pop', 'typedefbody')),
1119 ],
1120 'enumdef': [
1121 (r'enum', Keyword.Declaration, ('enumdefprebody', 'typedecl')),
1122 ],
1123 'enumdefprebody': [
1124 include('whitespace'),
1125 (r'{', Punctuation, ('#pop','enumdefbody')),
1126 ],
1127 'classdef': [
1128 (r'class', Keyword.Declaration, ('classdefprebody', 'typedecl')),
1129 ],
1130 'classdefprebody': [
1131 include('whitespace'),
1132 (r'(extends|implements)', Keyword.Declaration,'typedecl'),
1133 (r'{', Punctuation, ('#pop', 'classdefbody')),
1134 ],
1135 'interfacedef': [
1136 (r'interface', Keyword.Declaration,
1137 ('interfacedefprebody', 'typedecl')),
1138 ],
1139 'interfacedefprebody': [
1140 include('whitespace'),
1141 (r'(extends)', Keyword.Declaration, 'typedecl'),
1142 (r'{', Punctuation, ('#pop', 'classdefbody')),
1143 ],
1144
1145 'typedefbody': [
1146 include('whitespace'),
1147 include('instancevardef'),
1148 include('instancefundef'),
1149 (r'>', Punctuation, 'typedecl'),
1150 (r',', Punctuation),
1151 (r'}', Punctuation, '#pop'),
1152 ],
1153 'enumdefbody': [
1154 include('whitespace'),
1155 (ident, Name.Variable.Instance),
1156 (r'\(', Punctuation, 'funargdecl'),
1157 (r';', Punctuation),
1158 (r'}', Punctuation, '#pop'),
1159 ],
1160 'classdefbody': [
1161 include('whitespace'),
1162 include('instancevardef'),
1163 include('instancefundef'),
1164 (r'}', Punctuation, '#pop'),
1165 include('codeblock'),
1166 ],
1167 }
1168
1169 def analyse_text(text):
1170 if re.match(r'\w+\s*:\s*\w', text): return 0.3
1171
1172
1173 def _indentation(lexer, match, ctx):
1174 indentation = match.group(0)
1175 yield match.start(), Text, indentation
1176 ctx.last_indentation = indentation
1177 ctx.pos = match.end()
1178
1179 if hasattr(ctx, 'block_state') and ctx.block_state and \
1180 indentation.startswith(ctx.block_indentation) and \
1181 indentation != ctx.block_indentation:
1182 ctx.stack.append(ctx.block_state)
1183 else:
1184 ctx.block_state = None
1185 ctx.block_indentation = None
1186 ctx.stack.append('content')
1187
1188 def _starts_block(token, state):
1189 def callback(lexer, match, ctx):
1190 yield match.start(), token, match.group(0)
1191
1192 if hasattr(ctx, 'last_indentation'):
1193 ctx.block_indentation = ctx.last_indentation
1194 else:
1195 ctx.block_indentation = ''
1196
1197 ctx.block_state = state
1198 ctx.pos = match.end()
1199
1200 return callback
1201
1202
1203 class HamlLexer(ExtendedRegexLexer):
1204 """
1205 For Haml markup.
1206
1207 *New in Pygments 1.3.*
1208 """
1209
1210 name = 'Haml'
1211 aliases = ['haml', 'HAML']
1212 filenames = ['*.haml']
1213 mimetypes = ['text/x-haml']
1214
1215 flags = re.IGNORECASE
1216 # Haml can include " |\n" anywhere,
1217 # which is ignored and used to wrap long lines.
1218 # To accomodate this, use this custom faux dot instead.
1219 _dot = r'(?: \|\n(?=.* \|)|.)'
1220 tokens = {
1221 'root': [
1222 (r'[ \t]*\n', Text),
1223 (r'[ \t]*', _indentation),
1224 ],
1225
1226 'css': [
1227 (r'\.[a-z0-9_:-]+', Name.Class, 'tag'),
1228 (r'\#[a-z0-9_:-]+', Name.Function, 'tag'),
1229 ],
1230
1231 'eval-or-plain': [
1232 (r'[&!]?==', Punctuation, 'plain'),
1233 (r'([&!]?[=~])(' + _dot + '*\n)',
1234 bygroups(Punctuation, using(RubyLexer)),
1235 'root'),
1236 (r'', Text, 'plain'),
1237 ],
1238
1239 'content': [
1240 include('css'),
1241 (r'%[a-z0-9_:-]+', Name.Tag, 'tag'),
1242 (r'!!!' + _dot + '*\n', Name.Namespace, '#pop'),
1243 (r'(/)(\[' + _dot + '*?\])(' + _dot + '*\n)',
1244 bygroups(Comment, Comment.Special, Comment),
1245 '#pop'),
1246 (r'/' + _dot + '*\n', _starts_block(Comment, 'html-comment-block'),
1247 '#pop'),
1248 (r'-#' + _dot + '*\n', _starts_block(Comment.Preproc,
1249 'haml-comment-block'), '#pop'),
1250 (r'(-)(' + _dot + '*\n)',
1251 bygroups(Punctuation, using(RubyLexer)),
1252 '#pop'),
1253 (r':' + _dot + '*\n', _starts_block(Name.Decorator, 'filter-block'),
1254 '#pop'),
1255 include('eval-or-plain'),
1256 ],
1257
1258 'tag': [
1259 include('css'),
1260 (r'\{(,\n|' + _dot + ')*?\}', using(RubyLexer)),
1261 (r'\[' + _dot + '*?\]', using(RubyLexer)),
1262 (r'\(', Text, 'html-attributes'),
1263 (r'/[ \t]*\n', Punctuation, '#pop:2'),
1264 (r'[<>]{1,2}(?=[ \t=])', Punctuation),
1265 include('eval-or-plain'),
1266 ],
1267
1268 'plain': [
1269 (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text),
1270 (r'(#\{)(' + _dot + '*?)(\})',
1271 bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
1272 (r'\n', Text, 'root'),
1273 ],
1274
1275 'html-attributes': [
1276 (r'\s+', Text),
1277 (r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'),
1278 (r'[a-z0-9_:-]+', Name.Attribute),
1279 (r'\)', Text, '#pop'),
1280 ],
1281
1282 'html-attribute-value': [
1283 (r'[ \t]+', Text),
1284 (r'[a-z0-9_]+', Name.Variable, '#pop'),
1285 (r'@[a-z0-9_]+', Name.Variable.Instance, '#pop'),
1286 (r'\$[a-z0-9_]+', Name.Variable.Global, '#pop'),
1287 (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'),
1288 (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'),
1289 ],
1290
1291 'html-comment-block': [
1292 (_dot + '+', Comment),
1293 (r'\n', Text, 'root'),
1294 ],
1295
1296 'haml-comment-block': [
1297 (_dot + '+', Comment.Preproc),
1298 (r'\n', Text, 'root'),
1299 ],
1300
1301 'filter-block': [
1302 (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator),
1303 (r'(#\{)(' + _dot + '*?)(\})',
1304 bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
1305 (r'\n', Text, 'root'),
1306 ],
1307 }
1308
1309
1310 class SassLexer(ExtendedRegexLexer):
1311 """
1312 For Sass stylesheets.
1313
1314 *New in Pygments 1.3.*
1315 """
1316
1317 name = 'Sass'
1318 aliases = ['sass', 'SASS']
1319 filenames = ['*.sass']
1320 mimetypes = ['text/x-sass']
1321
1322 flags = re.IGNORECASE
1323 tokens = {
1324 'root': [
1325 (r'[ \t]*\n', Text),
1326 (r'[ \t]*', _indentation),
1327 ],
1328
1329 'content': [
1330 (r'//[^\n]*', _starts_block(Comment.Single, 'single-comment'),
1331 'root'),
1332 (r'/\*[^\n]*', _starts_block(Comment.Multiline, 'multi-comment'),
1333 'root'),
1334 (r'@import', Keyword, 'import'),
1335 (r'@for', Keyword, 'for'),
1336 (r'@(debug|if|while)', Keyword, 'script'),
1337 (r'@[a-z0-9_-]+', Keyword, 'selector'),
1338 (r'=[\w-]+', Name.Function, 'script'),
1339 (r'\+[\w-]+', Name.Decorator, 'script'),
1340 (r'(![a-z_]\w*)([ \t]*(?:\|\|)?=)',
1341 bygroups(Name.Variable, Operator), 'script'),
1342 (r':', Name.Attribute, 'old-style-attr'),
1343 (r'(?=[^\s:"\[]+\s*[=:]([ \t]|$))', Name.Attribute, 'new-style-attr'),
1344 (r'', Text, 'selector'),
1345 ],
1346
1347 'single-comment': [
1348 (r'.+', Comment.Single),
1349 (r'\n', Text, 'root'),
1350 ],
1351
1352 'multi-comment': [
1353 (r'.+', Comment.Multiline),
1354 (r'\n', Text, 'root'),
1355 ],
1356
1357 'import': [
1358 (r'[ \t]+', Text),
1359 (r'[^\s]+', String),
1360 (r'\n', Text, 'root'),
1361 ],
1362
1363 'for': [
1364 (r'(from|to|through)', Operator.Word),
1365 include('script'),
1366 ],
1367
1368 'old-style-attr': [
1369 (r'[^\s:="\[]+', Name.Attribute),
1370 (r'#{', String.Interpol, 'interpolation'),
1371 (r'[ \t]*=', Operator, 'script'),
1372 (r'', Text, 'value'),
1373 ],
1374
1375 'new-style-attr': [
1376 (r'[^\s:="\[]+', Name.Attribute),
1377 (r'#{', String.Interpol, 'interpolation'),
1378 (r'[ \t]*=', Operator, 'script'),
1379 (r':', Name.Attribute, 'value'),
1380 ],
1381
1382 'value': [
1383 (r'[ \t]+', Text),
1384 (r'url\(', String.Other, 'string-url'),
1385 (r'(azimuth|background-attachment|background-color|'
1386 r'background-image|background-position|background-repeat|'
1387 r'background|border-bottom-color|border-bottom-style|'
1388 r'border-bottom-width|border-left-color|border-left-style|'
1389 r'border-left-width|border-right|border-right-color|'
1390 r'border-right-style|border-right-width|border-top-color|'
1391 r'border-top-style|border-top-width|border-bottom|'
1392 r'border-collapse|border-left|border-width|border-color|'
1393 r'border-spacing|border-style|border-top|border|caption-side|'
1394 r'clear|clip|color|content|counter-increment|counter-reset|'
1395 r'cue-after|cue-before|cue|cursor|direction|display|'
1396 r'elevation|empty-cells|float|font-family|font-size|'
1397 r'font-size-adjust|font-stretch|font-style|font-variant|'
1398 r'font-weight|font|height|letter-spacing|line-height|'
1399 r'list-style-type|list-style-image|list-style-position|'
1400 r'list-style|margin-bottom|margin-left|margin-right|'
1401 r'margin-top|margin|marker-offset|marks|max-height|max-width|'
1402 r'min-height|min-width|opacity|orphans|outline|outline-color|'
1403 r'outline-style|outline-width|overflow|padding-bottom|'
1404 r'padding-left|padding-right|padding-top|padding|page|'
1405 r'page-break-after|page-break-before|page-break-inside|'
1406 r'pause-after|pause-before|pause|pitch|pitch-range|'
1407 r'play-during|position|quotes|richness|right|size|'
1408 r'speak-header|speak-numeral|speak-punctuation|speak|'
1409 r'speech-rate|stress|table-layout|text-align|text-decoration|'
1410 r'text-indent|text-shadow|text-transform|top|unicode-bidi|'
1411 r'vertical-align|visibility|voice-family|volume|white-space|'
1412 r'widows|width|word-spacing|z-index|bottom|left|'
1413 r'above|absolute|always|armenian|aural|auto|avoid|baseline|'
1414 r'behind|below|bidi-override|blink|block|bold|bolder|both|'
1415 r'capitalize|center-left|center-right|center|circle|'
1416 r'cjk-ideographic|close-quote|collapse|condensed|continuous|'
1417 r'crop|crosshair|cross|cursive|dashed|decimal-leading-zero|'
1418 r'decimal|default|digits|disc|dotted|double|e-resize|embed|'
1419 r'extra-condensed|extra-expanded|expanded|fantasy|far-left|'
1420 r'far-right|faster|fast|fixed|georgian|groove|hebrew|help|'
1421 r'hidden|hide|higher|high|hiragana-iroha|hiragana|icon|'
1422 r'inherit|inline-table|inline|inset|inside|invert|italic|'
1423 r'justify|katakana-iroha|katakana|landscape|larger|large|'
1424 r'left-side|leftwards|level|lighter|line-through|list-item|'
1425 r'loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|'
1426 r'lower|low|medium|message-box|middle|mix|monospace|'
1427 r'n-resize|narrower|ne-resize|no-close-quote|no-open-quote|'
1428 r'no-repeat|none|normal|nowrap|nw-resize|oblique|once|'
1429 r'open-quote|outset|outside|overline|pointer|portrait|px|'
1430 r'relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|'
1431 r'rightwards|s-resize|sans-serif|scroll|se-resize|'
1432 r'semi-condensed|semi-expanded|separate|serif|show|silent|'
1433 r'slow|slower|small-caps|small-caption|smaller|soft|solid|'
1434 r'spell-out|square|static|status-bar|super|sw-resize|'
1435 r'table-caption|table-cell|table-column|table-column-group|'
1436 r'table-footer-group|table-header-group|table-row|'
1437 r'table-row-group|text|text-bottom|text-top|thick|thin|'
1438 r'transparent|ultra-condensed|ultra-expanded|underline|'
1439 r'upper-alpha|upper-latin|upper-roman|uppercase|url|'
1440 r'visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|'
1441 r'x-low|x-small|x-soft|xx-large|xx-small|yes)\b', Name.Constant),
1442 (r'(indigo|gold|firebrick|indianred|yellow|darkolivegreen|'
1443 r'darkseagreen|mediumvioletred|mediumorchid|chartreuse|'
1444 r'mediumslateblue|black|springgreen|crimson|lightsalmon|brown|'
1445 r'turquoise|olivedrab|cyan|silver|skyblue|gray|darkturquoise|'
1446 r'goldenrod|darkgreen|darkviolet|darkgray|lightpink|teal|'
1447 r'darkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|'
1448 r'violet|navy|orchid|blue|ghostwhite|honeydew|cornflowerblue|'
1449 r'darkblue|darkkhaki|mediumpurple|cornsilk|red|bisque|slategray|'
1450 r'darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|'
1451 r'gainsboro|mediumturquoise|floralwhite|coral|purple|lightgrey|'
1452 r'lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|'
1453 r'greenyellow|royalblue|lightseagreen|mistyrose|sienna|'
1454 r'lightcoral|orangered|navajowhite|lime|palegreen|burlywood|'
1455 r'seashell|mediumspringgreen|fuchsia|papayawhip|blanchedalmond|'
1456 r'peru|aquamarine|white|darkslategray|ivory|dodgerblue|'
1457 r'lemonchiffon|chocolate|orange|forestgreen|slateblue|olive|'
1458 r'mintcream|antiquewhite|darkorange|cadetblue|moccasin|'
1459 r'limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|'
1460 r'plum|aqua|darkgoldenrod|maroon|sandybrown|magenta|tan|'
1461 r'rosybrown|pink|lightblue|palevioletred|mediumseagreen|'
1462 r'dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|'
1463 r'paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|'
1464 r'lightslategray|lawngreen|lightgreen|tomato|hotpink|'
1465 r'lightyellow|lavenderblush|linen|mediumaquamarine|green|'
1466 r'blueviolet|peachpuff)\b', Name.Entity),
1467 (r'\!important', Name.Exception),
1468 (r'/\*', Comment, 'inline-comment'),
1469 (r'\#[a-z0-9]{1,6}', Number.Hex),
1470 (r'(-?\d+)(\%|[a-z]+)?', bygroups(Number.Integer, Keyword.Type)),
1471 (r'(-?\d*\.\d+)(\%|[a-z]+)?', bygroups(Number.Float, Keyword.Type)),
1472 (r'#{', String.Interpol, 'interpolation'),
1473 (r'[~\^\*!&%<>\|+=@:,./?-]+', Operator),
1474 (r'[\[\]();]+', Punctuation),
1475 (r'"', String.Double, 'string-double'),
1476 (r"'", String.Single, 'string-single'),
1477 (r'[a-z][\w-]*', Name),
1478 (r'\n', Text, 'root'),
1479 ],
1480
1481 'script': [
1482 (r'[ \t]+', Text),
1483 (r'![\w_]+', Name.Variable),
1484 (r'[+\-*/%=(),!><]', Operator),
1485 (r'"', String.Double, 'string-double'),
1486 (r"'", String.Single, 'string-single'),
1487 (r'\#[a-z0-9]{1,6}', Number.Hex),
1488 (r'(-?\d+)(\%|[a-z]+)?', bygroups(Number.Integer, Keyword.Type)),
1489 (r'(-?\d*\.\d+)(\%|[a-z]+)?', bygroups(Number.Float, Keyword.Type)),
1490 (r'(black|silver|gray|white|maroon|red|purple|fuchsia|green|'
1491 r'lime|olive|yellow|navy|blue|teal|aqua)\b', Name.Builtin),
1492 (r'(true|false)', Name.Pseudo),
1493 (r'(and|or|not)', Operator.Word),
1494 (r'(\\.|[^\s\\+*\/%(),=!])+(?=[ \t]*\()', Name.Function),
1495 (r'(\\.|[^\s\\+*\/%(),=!])+', Name),
1496 (r'\n', Text, 'root'),
1497 ],
1498
1499 'interpolation': [
1500 (r'\}', String.Interpol, '#pop'),
1501 include('script'),
1502 ],
1503
1504 'selector': [
1505 (r'[ \t]+', Text),
1506 (r'\:', Name.Decorator, 'pseudo-class'),
1507 (r'\.', Name.Class, 'class'),
1508 (r'\#', Name.Namespace, 'id'),
1509 (r'[a-zA-Z0-9_-]+', Name.Tag),
1510 (r'#\{', String.Interpol, 'interpolation'),
1511 (r'&', Keyword),
1512 (r'[~\^\*!&\[\]\(\)<>\|+=@:;,./?-]', Operator),
1513 (r'"', String.Double, 'string-double'),
1514 (r"'", String.Single, 'string-single'),
1515 (r'\n', Text, 'root'),
1516 ],
1517
1518 'string-double': [
1519 (r'(\\.|#(?=[^\n{])|[^\n"#])+', String.Double),
1520 (r'#\{', String.Interpol, 'interpolation'),
1521 (r'"', String.Double, '#pop'),
1522 ],
1523
1524 'string-single': [
1525 (r"(\\.|#(?=[^\n{])|[^\n'#])+", String.Double),
1526 (r'#\{', String.Interpol, 'interpolation'),
1527 (r"'", String.Double, '#pop'),
1528 ],
1529
1530 'string-url': [
1531 (r'(\\#|#(?=[^\n{])|[^\n#)])+', String.Other),
1532 (r'#\{', String.Interpol, 'interpolation'),
1533 (r'\)', String.Other, '#pop'),
1534 ],
1535
1536 'inline-comment': [
1537 (r"(\\#|#(?=[^\n{])|\*(?=[^\n/])|[^\n#*])+", Comment),
1538 (r'#\{', String.Interpol, 'interpolation'),
1539 (r"\*/", Comment, '#pop'),
1540 ],
1541
1542 'pseudo-class': [
1543 (r'[\w-]+', Name.Decorator),
1544 (r'#\{', String.Interpol, 'interpolation'),
1545 (r'', Text, '#pop'),
1546 ],
1547
1548 'class': [
1549 (r'[\w-]+', Name.Class),
1550 (r'#\{', String.Interpol, 'interpolation'),
1551 (r'', Text, '#pop'),
1552 ],
1553
1554 'id': [
1555 (r'[\w-]+', Name.Namespace),
1556 (r'#\{', String.Interpol, 'interpolation'),
1557 (r'', Text, '#pop'),
1558 ],
1559 }
1560
1561
1562 class CoffeeScriptLexer(RegexLexer):
1563 """
1564 For `CoffeeScript`_ source code.
1565
1566 .. _CoffeeScript: http://jashkenas.github.com/coffee-script/
1567
1568 *New in Pygments 1.3.*
1569 """
1570
1571 name = 'CoffeeScript'
1572 aliases = ['coffee-script', 'coffeescript']
1573 filenames = ['*.coffee']
1574 mimetypes = ['text/coffeescript']
1575
1576 flags = re.DOTALL
1577 tokens = {
1578 'commentsandwhitespace': [
1579 (r'\s+', Text),
1580 (r'#.*?\n', Comment.Single),
1581 ],
1582 'slashstartsregex': [
1583 include('commentsandwhitespace'),
1584 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
1585 r'([gim]+\b|\B)', String.Regex, '#pop'),
1586 (r'(?=/)', Text, ('#pop', 'badregex')),
1587 (r'', Text, '#pop'),
1588 ],
1589 'badregex': [
1590 ('\n', Text, '#pop'),
1591 ],
1592 'root': [
1593 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
1594 include('commentsandwhitespace'),
1595 (r'\+\+|--|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|'
1596 r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*`%&\|\^/])=?',
1597 Operator, 'slashstartsregex'),
1598 (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
1599 (r'[})\].]', Punctuation),
1600 (r'(for|in|of|while|break|return|continue|switch|when|then|if|else|'
1601 r'throw|try|catch|finally|new|delete|typeof|instanceof|super|'
1602 r'extends|this)\b', Keyword, 'slashstartsregex'),
1603 (r'(true|false|yes|no|on|off|null|NaN|Infinity|undefined)\b',
1604 Keyword.Constant),
1605 (r'(Array|Boolean|Date|Error|Function|Math|netscape|'
1606 r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
1607 r'decodeURIComponent|encodeURI|encodeURIComponent|'
1608 r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
1609 r'window)\b', Name.Builtin),
1610 (r'[$a-zA-Z_][a-zA-Z0-9_\.:]*:\s', Name.Variable,
1611 'slashstartsregex'),
1612 (r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
1613 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
1614 (r'0x[0-9a-fA-F]+', Number.Hex),
1615 (r'[0-9]+', Number.Integer),
1616 (r'"(\\\\|\\"|[^"])*"', String.Double),
1617 (r"'(\\\\|\\'|[^'])*'", String.Single),
1618 ]
1619 }

eric ide

mercurial