~ubuntu-branches/ubuntu/raring/wxwidgets2.8/raring

« back to all changes in this revision

Viewing changes to wxPython/wx/tools/Editra/src/extern/pygments/lexers/web.py

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-01-07 13:59:25 UTC
  • mfrom: (1.1.9) (5.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120107135925-2601miy9ullcon9j
Tags: 2.8.12.1-6ubuntu1
* Resync from Debian, changes that were kept:
  - debian/rules: re-enable mediactrl. This allows libwx_gtk2u_media-2.8 to be
    built, as this is required by some applications (LP: #632984)
  - debian/control: Build-dep on libxt-dev for mediactrl.
  - Patches
    + fix-bashism-in-example
* Add conflict on python-wxgtk2.8 (<< 2.8.12.1-6ubuntu1~) to python-wxversion
  to guarantee upgrade ordering when moving from pycentral to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
    Lexers for web-related languages and markup.
7
7
 
8
 
    :copyright: 2006-2008 by Georg Brandl, Armin Ronacher,
9
 
                Tim Hatch <tim@timhatch.com>, Stou Sandalski.
10
 
    :license: BSD, see LICENSE for more details.
 
8
    :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
 
9
    :license: BSD, see LICENSE for details.
11
10
"""
12
11
 
13
12
import re
14
 
try:
15
 
    set
16
 
except NameError:
17
 
    from sets import Set as set
 
13
import copy
18
14
 
19
 
from pygments.lexer import RegexLexer, bygroups, using, include, this
20
 
from pygments.token import \
21
 
     Text, Comment, Operator, Keyword, Name, String, Number, Other, Punctuation
 
15
from pygments.lexer import RegexLexer, ExtendedRegexLexer, bygroups, using, \
 
16
     include, this
 
17
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
 
18
     Number, Other, Punctuation, Literal
22
19
from pygments.util import get_bool_opt, get_list_opt, looks_like_xml, \
23
20
                          html_doctype_matches
 
21
from pygments.lexers.agile import RubyLexer
 
22
from pygments.lexers.compiled import ScalaLexer
24
23
 
25
24
 
26
25
__all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'CssLexer',
27
 
           'PhpLexer', 'ActionScriptLexer', 'XsltLexer', 'ActionScript3Lexer']
 
26
           'PhpLexer', 'ActionScriptLexer', 'XsltLexer', 'ActionScript3Lexer',
 
27
           'MxmlLexer', 'HaxeLexer', 'HamlLexer', 'SassLexer', 'ScssLexer',
 
28
           'ObjectiveJLexer', 'CoffeeScriptLexer', 'DuelLexer', 'ScamlLexer',
 
29
           'JadeLexer', 'XQueryLexer']
28
30
 
29
31
 
30
32
class JavascriptLexer(RegexLexer):
35
37
    name = 'JavaScript'
36
38
    aliases = ['js', 'javascript']
37
39
    filenames = ['*.js']
38
 
    mimetypes = ['application/x-javascript', 'text/x-javascript', 'text/javascript']
 
40
    mimetypes = ['application/javascript', 'application/x-javascript',
 
41
                 'text/x-javascript', 'text/javascript']
39
42
 
40
43
    flags = re.DOTALL
41
44
    tokens = {
42
 
        'root': [
 
45
        'commentsandwhitespace': [
43
46
            (r'\s+', Text),
44
47
            (r'<!--', Comment),
45
 
            (r'//.*?\n', Comment),
46
 
            (r'/\*.*?\*/', Comment),
47
 
            (r'/(\\\\|\\/|[^/\n])*/[gim]+\b', String.Regex),
48
 
            (r'/(\\\\|\\/|[^/\n])*/(?=\s*[,);])', String.Regex),
49
 
            (r'/(\\\\|\\/|[^/\n])*/(?=\s*\.[a-z])', String.Regex),
50
 
            (r'[~\^\*!%&<>\|+=:;,/?\\-]+', Operator),
51
 
            (r'[{}\[\]();.]', Punctuation),
52
 
            (r'(for|in|while|do|break|return|continue|if|else|throw|try|'
53
 
             r'catch|new|typeof|instanceof|this)\b', Keyword),
54
 
            (r'(var|with|const|label|function)\b', Keyword.Declaration),
 
48
            (r'//.*?\n', Comment.Single),
 
49
            (r'/\*.*?\*/', Comment.Multiline)
 
50
        ],
 
51
        'slashstartsregex': [
 
52
            include('commentsandwhitespace'),
 
53
            (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
 
54
             r'([gim]+\b|\B)', String.Regex, '#pop'),
 
55
            (r'(?=/)', Text, ('#pop', 'badregex')),
 
56
            (r'', Text, '#pop')
 
57
        ],
 
58
        'badregex': [
 
59
            ('\n', Text, '#pop')
 
60
        ],
 
61
        'root': [
 
62
            (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
 
63
            include('commentsandwhitespace'),
 
64
            (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
 
65
             r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'),
 
66
            (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
 
67
            (r'[})\].]', Punctuation),
 
68
            (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|'
 
69
             r'throw|try|catch|finally|new|delete|typeof|instanceof|void|'
 
70
             r'this)\b', Keyword, 'slashstartsregex'),
 
71
            (r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
 
72
            (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|'
 
73
             r'extends|final|float|goto|implements|import|int|interface|long|native|'
 
74
             r'package|private|protected|public|short|static|super|synchronized|throws|'
 
75
             r'transient|volatile)\b', Keyword.Reserved),
55
76
            (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
56
77
            (r'(Array|Boolean|Date|Error|Function|Math|netscape|'
57
78
             r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
85
106
    tokens = {
86
107
        'root': [
87
108
            (r'\s+', Text),
88
 
            (r'//.*?\n', Comment),
89
 
            (r'/\*.*?\*/', Comment),
 
109
            (r'//.*?\n', Comment.Single),
 
110
            (r'/\*.*?\*/', Comment.Multiline),
90
111
            (r'/(\\\\|\\/|[^/\n])*/[gim]*', String.Regex),
91
112
            (r'[~\^\*!%&<>\|+=:;,/?\\-]+', Operator),
92
113
            (r'[{}\[\]();.]+', Punctuation),
151
172
        ]
152
173
    }
153
174
 
 
175
    def analyse_text(text):
 
176
        return 0.05
 
177
 
154
178
 
155
179
class ActionScript3Lexer(RegexLexer):
156
180
    """
193
217
             r'static|import|extends|implements|interface|intrinsic|return|super|'
194
218
             r'dynamic|function|const|get|namespace|package|set)\b',
195
219
             Keyword.Declaration),
196
 
            (r'(true|false|null|NaN|Infinity|-Infinity|undefined|Void)\b',
 
220
            (r'(true|false|null|NaN|Infinity|-Infinity|undefined|void)\b',
197
221
             Keyword.Constant),
198
222
            (r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|'
199
223
             r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|'
208
232
            (r'[~\^\*!%&<>\|+=:;,/?\\{}\[\]();.-]+', Operator),
209
233
        ],
210
234
        'funcparams': [
211
 
            (r'(' + identifier + r')(\s*)(:)(\s*)(' + identifier + r'|\*)(\s*)(,?)',
212
 
             bygroups(Name, Text, Operator, Text, Keyword.Type, Text, Operator)),
 
235
            (r'\s+', Text),
 
236
            (r'(\s*)(\.\.\.)?(' + identifier + r')(\s*)(:)(\s*)(' +
 
237
             identifier + r'|\*)(\s*)',
 
238
             bygroups(Text, Punctuation, Name, Text, Operator, Text,
 
239
                      Keyword.Type, Text), 'defval'),
213
240
            (r'\)', Operator, 'type')
214
241
        ],
215
242
        'type': [
216
 
            (r'(\s*)(:)(' + identifier + r'|\*)',
217
 
             bygroups(Text, Operator, Keyword.Type), '#pop:2')
 
243
            (r'(\s*)(:)(\s*)(' + identifier + r'|\*)',
 
244
             bygroups(Text, Operator, Text, Keyword.Type), '#pop:2'),
 
245
            (r'\s*', Text, '#pop:2')
 
246
        ],
 
247
        'defval': [
 
248
            (r'(=)(\s*)([^(),]+)(\s*)(,?)',
 
249
             bygroups(Operator, Text, using(this), Text, Operator), '#pop'),
 
250
            (r',?', Operator, '#pop')
218
251
        ]
219
252
    }
220
253
 
 
254
    def analyse_text(text):
 
255
        if re.match(r'\w+\s*:\s*\w', text): return 0.3
 
256
        return 0.1
 
257
 
221
258
 
222
259
class CssLexer(RegexLexer):
223
260
    """
278
315
             r'list-style|margin-bottom|margin-left|margin-right|'
279
316
             r'margin-top|margin|marker-offset|marks|max-height|max-width|'
280
317
             r'min-height|min-width|opacity|orphans|outline|outline-color|'
281
 
             r'outline-style|outline-width|overflow|padding-bottom|'
 
318
             r'outline-style|outline-width|overflow(?:-x|-y|)|padding-bottom|'
282
319
             r'padding-left|padding-right|padding-top|padding|page|'
283
320
             r'page-break-after|page-break-before|page-break-inside|'
284
321
             r'pause-after|pause-before|pause|pitch|pitch-range|'
345
382
            (r'\!important', Comment.Preproc),
346
383
            (r'/\*(?:.|\n)*?\*/', Comment),
347
384
            (r'\#[a-zA-Z0-9]{1,6}', Number),
348
 
            (r'[\.-]?[0-9]*[\.]?[0-9]+(em|px|\%|pt|pc|in|mm|cm|ex)', Number),
 
385
            (r'[\.-]?[0-9]*[\.]?[0-9]+(em|px|\%|pt|pc|in|mm|cm|ex|s)\b', Number),
349
386
            (r'-?[0-9]+', Number),
350
387
            (r'[~\^\*!%&<>\|+=@:,./?-]+', Operator),
351
388
            (r'[\[\]();]+', Punctuation),
356
393
    }
357
394
 
358
395
 
 
396
class ObjectiveJLexer(RegexLexer):
 
397
    """
 
398
    For Objective-J source code with preprocessor directives.
 
399
 
 
400
    *New in Pygments 1.3.*
 
401
    """
 
402
 
 
403
    name = 'Objective-J'
 
404
    aliases = ['objective-j', 'objectivej', 'obj-j', 'objj']
 
405
    filenames = ['*.j']
 
406
    mimetypes = ['text/x-objective-j']
 
407
 
 
408
    #: optional Comment or Whitespace
 
409
    _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)*'
 
410
 
 
411
    flags = re.DOTALL | re.MULTILINE
 
412
 
 
413
    tokens = {
 
414
        'root': [
 
415
            include('whitespace'),
 
416
 
 
417
            # function definition
 
418
            (r'^(' + _ws + r'[\+-]' + _ws + r')([\(a-zA-Z_].*?[^\(])(' + _ws + '{)',
 
419
             bygroups(using(this), using(this, state='function_signature'),
 
420
                      using(this))),
 
421
 
 
422
            # class definition
 
423
            (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text),
 
424
             'classname'),
 
425
            (r'(@class|@protocol)(\s*)', bygroups(Keyword, Text),
 
426
             'forward_classname'),
 
427
            (r'(\s*)(@end)(\s*)', bygroups(Text, Keyword, Text)),
 
428
 
 
429
            include('statements'),
 
430
            ('[{\(\)}]', Punctuation),
 
431
            (';', Punctuation),
 
432
        ],
 
433
        'whitespace': [
 
434
            (r'(@import)(\s+)("(\\\\|\\"|[^"])*")',
 
435
             bygroups(Comment.Preproc, Text, String.Double)),
 
436
            (r'(@import)(\s+)(<(\\\\|\\>|[^>])*>)',
 
437
             bygroups(Comment.Preproc, Text, String.Double)),
 
438
            (r'(#(?:include|import))(\s+)("(\\\\|\\"|[^"])*")',
 
439
             bygroups(Comment.Preproc, Text, String.Double)),
 
440
            (r'(#(?:include|import))(\s+)(<(\\\\|\\>|[^>])*>)',
 
441
             bygroups(Comment.Preproc, Text, String.Double)),
 
442
 
 
443
            (r'#if\s+0', Comment.Preproc, 'if0'),
 
444
            (r'#', Comment.Preproc, 'macro'),
 
445
 
 
446
            (r'\n', Text),
 
447
            (r'\s+', Text),
 
448
            (r'\\\n', Text), # line continuation
 
449
            (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
 
450
            (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
 
451
            (r'<!--', Comment),
 
452
        ],
 
453
        'slashstartsregex': [
 
454
            include('whitespace'),
 
455
            (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
 
456
             r'([gim]+\b|\B)', String.Regex, '#pop'),
 
457
            (r'(?=/)', Text, ('#pop', 'badregex')),
 
458
            (r'', Text, '#pop'),
 
459
        ],
 
460
        'badregex': [
 
461
            ('\n', Text, '#pop'),
 
462
        ],
 
463
        'statements': [
 
464
            (r'(L|@)?"', String, 'string'),
 
465
            (r"(L|@)?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
 
466
             String.Char),
 
467
            (r'"(\\\\|\\"|[^"])*"', String.Double),
 
468
            (r"'(\\\\|\\'|[^'])*'", String.Single),
 
469
            (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
 
470
            (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
 
471
            (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
 
472
            (r'0[0-7]+[Ll]?', Number.Oct),
 
473
            (r'\d+[Ll]?', Number.Integer),
 
474
 
 
475
            (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
 
476
 
 
477
            (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
 
478
             r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?',
 
479
             Operator, 'slashstartsregex'),
 
480
            (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
 
481
            (r'[})\].]', Punctuation),
 
482
 
 
483
            (r'(for|in|while|do|break|return|continue|switch|case|default|if|'
 
484
             r'else|throw|try|catch|finally|new|delete|typeof|instanceof|void|'
 
485
             r'prototype|__proto__)\b', Keyword, 'slashstartsregex'),
 
486
 
 
487
            (r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
 
488
 
 
489
            (r'(@selector|@private|@protected|@public|@encode|'
 
490
             r'@synchronized|@try|@throw|@catch|@finally|@end|@property|'
 
491
             r'@synthesize|@dynamic|@for|@accessors|new)\b', Keyword),
 
492
 
 
493
            (r'(int|long|float|short|double|char|unsigned|signed|void|'
 
494
             r'id|BOOL|bool|boolean|IBOutlet|IBAction|SEL|@outlet|@action)\b',
 
495
             Keyword.Type),
 
496
 
 
497
            (r'(self|super)\b', Name.Builtin),
 
498
 
 
499
            (r'(TRUE|YES|FALSE|NO|Nil|nil|NULL)\b', Keyword.Constant),
 
500
            (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
 
501
            (r'(ABS|ASIN|ACOS|ATAN|ATAN2|SIN|COS|TAN|EXP|POW|CEIL|FLOOR|ROUND|'
 
502
             r'MIN|MAX|RAND|SQRT|E|LN2|LN10|LOG2E|LOG10E|PI|PI2|PI_2|SQRT1_2|'
 
503
             r'SQRT2)\b', Keyword.Constant),
 
504
 
 
505
            (r'(Array|Boolean|Date|Error|Function|Math|netscape|'
 
506
             r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
 
507
             r'decodeURIComponent|encodeURI|encodeURIComponent|'
 
508
             r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
 
509
             r'window)\b', Name.Builtin),
 
510
 
 
511
            (r'([$a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r')(?=\()',
 
512
             bygroups(Name.Function, using(this))),
 
513
 
 
514
            (r'[$a-zA-Z_][a-zA-Z0-9_]*', Name),
 
515
        ],
 
516
        'classname' : [
 
517
            # interface definition that inherits
 
518
            (r'([a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r':' + _ws +
 
519
             r')([a-zA-Z_][a-zA-Z0-9_]*)?',
 
520
             bygroups(Name.Class, using(this), Name.Class), '#pop'),
 
521
            # interface definition for a category
 
522
            (r'([a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r'\()([a-zA-Z_][a-zA-Z0-9_]*)(\))',
 
523
             bygroups(Name.Class, using(this), Name.Label, Text), '#pop'),
 
524
            # simple interface / implementation
 
525
            (r'([a-zA-Z_][a-zA-Z0-9_]*)', Name.Class, '#pop'),
 
526
        ],
 
527
        'forward_classname' : [
 
528
            (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*,\s*)',
 
529
             bygroups(Name.Class, Text), '#push'),
 
530
            (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*;?)',
 
531
             bygroups(Name.Class, Text), '#pop'),
 
532
        ],
 
533
        'function_signature': [
 
534
            include('whitespace'),
 
535
 
 
536
            # start of a selector w/ parameters
 
537
            (r'(\(' + _ws + r')'                # open paren
 
538
             r'([a-zA-Z_][a-zA-Z0-9_]+)'        # return type
 
539
             r'(' + _ws + r'\)' + _ws + r')'    # close paren
 
540
             r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name
 
541
             bygroups(using(this), Keyword.Type, using(this),
 
542
                 Name.Function), 'function_parameters'),
 
543
 
 
544
            # no-param function
 
545
            (r'(\(' + _ws + r')'                # open paren
 
546
             r'([a-zA-Z_][a-zA-Z0-9_]+)'        # return type
 
547
             r'(' + _ws + r'\)' + _ws + r')'    # close paren
 
548
             r'([$a-zA-Z_][a-zA-Z0-9_]+)',      # function name
 
549
             bygroups(using(this), Keyword.Type, using(this),
 
550
                 Name.Function), "#pop"),
 
551
 
 
552
            # no return type given, start of a selector w/ parameters
 
553
            (r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name
 
554
             bygroups (Name.Function), 'function_parameters'),
 
555
 
 
556
            # no return type given, no-param function
 
557
            (r'([$a-zA-Z_][a-zA-Z0-9_]+)',      # function name
 
558
             bygroups(Name.Function), "#pop"),
 
559
 
 
560
            ('', Text, '#pop'),
 
561
        ],
 
562
        'function_parameters': [
 
563
            include('whitespace'),
 
564
 
 
565
            # parameters
 
566
            (r'(\(' + _ws + ')'                 # open paren
 
567
             r'([^\)]+)'                        # type
 
568
             r'(' + _ws + r'\)' + _ws + r')+'   # close paren
 
569
             r'([$a-zA-Z_][a-zA-Z0-9_]+)',      # param name
 
570
             bygroups(using(this), Keyword.Type, using(this), Text)),
 
571
 
 
572
            # one piece of a selector name
 
573
            (r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)',     # function name
 
574
             Name.Function),
 
575
 
 
576
            # smallest possible selector piece
 
577
            (r'(:)', Name.Function),
 
578
 
 
579
            # var args
 
580
            (r'(,' + _ws + r'...)', using(this)),
 
581
 
 
582
            # param name
 
583
            (r'([$a-zA-Z_][a-zA-Z0-9_]+)', Text),
 
584
        ],
 
585
        'expression' : [
 
586
            (r'([$a-zA-Z_][a-zA-Z0-9_]*)(\()', bygroups(Name.Function,
 
587
                                                        Punctuation)),
 
588
            (r'(\))', Punctuation, "#pop"),
 
589
        ],
 
590
        'string': [
 
591
            (r'"', String, '#pop'),
 
592
            (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
 
593
            (r'[^\\"\n]+', String), # all other characters
 
594
            (r'\\\n', String), # line continuation
 
595
            (r'\\', String), # stray backslash
 
596
        ],
 
597
        'macro': [
 
598
            (r'[^/\n]+', Comment.Preproc),
 
599
            (r'/[*](.|\n)*?[*]/', Comment.Multiline),
 
600
            (r'//.*?\n', Comment.Single, '#pop'),
 
601
            (r'/', Comment.Preproc),
 
602
            (r'(?<=\\)\n', Comment.Preproc),
 
603
            (r'\n', Comment.Preproc, '#pop'),
 
604
        ],
 
605
        'if0': [
 
606
            (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
 
607
            (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
 
608
            (r'.*?\n', Comment),
 
609
        ]
 
610
    }
 
611
 
 
612
    def analyse_text(text):
 
613
        if re.search('^\s*@import\s+[<"]', text, re.MULTILINE):
 
614
            # special directive found in most Objective-J files
 
615
            return True
 
616
        return False
 
617
 
 
618
 
359
619
class HtmlLexer(RegexLexer):
360
620
    """
361
621
    For HTML 4 and XHTML 1 markup. Nested JavaScript and CSS is highlighted
459
719
        ],
460
720
        'php': [
461
721
            (r'\?>', Comment.Preproc, '#pop'),
462
 
            (r'<<<([a-zA-Z_][a-zA-Z0-9_]*)\n.*?\n\1\;?\n', String),
 
722
            (r'<<<(\'?)([a-zA-Z_][a-zA-Z0-9_]*)\1\n.*?\n\2\;?\n', String),
463
723
            (r'\s+', Text),
464
 
            (r'#.*?\n', Comment),
465
 
            (r'//.*?\n', Comment),
 
724
            (r'#.*?\n', Comment.Single),
 
725
            (r'//.*?\n', Comment.Single),
 
726
            # put the empty comment here, it is otherwise seen as
 
727
            # the start of a docstring
 
728
            (r'/\*\*/', Comment.Multiline),
466
729
            (r'/\*\*.*?\*/', String.Doc),
467
 
            (r'/\*.*?\*/', Comment),
 
730
            (r'/\*.*?\*/', Comment.Multiline),
468
731
            (r'(->|::)(\s*)([a-zA-Z_][a-zA-Z0-9_]*)',
469
732
             bygroups(Operator, Text, Name.Attribute)),
470
733
            (r'[~!%^&*+=|:.<>/?@-]+', Operator),
471
734
            (r'[\[\]{}();,]+', Punctuation),
472
735
            (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
 
736
            (r'(function)(\s*)(?=\()', bygroups(Keyword, Text)),
473
737
            (r'(function)(\s+)(&?)(\s*)',
474
738
              bygroups(Keyword, Text, Operator, Text), 'functionname'),
475
739
            (r'(const)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)',
483
747
             r'endif|list|__LINE__|endswitch|new|__sleep|endwhile|not|'
484
748
             r'array|__wakeup|E_ALL|NULL|final|php_user_filter|interface|'
485
749
             r'implements|public|private|protected|abstract|clone|try|'
486
 
             r'catch|throw|this)\b', Keyword),
 
750
             r'catch|throw|this|use|namespace)\b', Keyword),
487
751
            ('(true|false|null)\b', Keyword.Constant),
488
752
            (r'\$\{\$+[a-zA-Z_][a-zA-Z0-9_]*\}', Name.Variable),
489
753
            (r'\$+[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable),
490
 
            ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
491
 
            (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|"
492
 
             r"0[xX][0-9a-fA-F]+[Ll]?", Number),
 
754
            (r'[\\a-zA-Z_][\\a-zA-Z0-9_]*', Name.Other),
 
755
            (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
 
756
            (r'\d+[eE][+-]?[0-9]+', Number.Float),
 
757
            (r'0[0-7]+', Number.Oct),
 
758
            (r'0[xX][a-fA-F0-9]+', Number.Hex),
 
759
            (r'\d+', Number.Integer),
493
760
            (r"'([^'\\]*(?:\\.[^'\\]*)*)'", String.Single),
494
761
            (r'`([^`\\]*(?:\\.[^`\\]*)*)`', String.Backtick),
495
762
            (r'"', String.Double, 'string'),
496
763
        ],
497
764
        'classname': [
498
 
            (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
 
765
            (r'[a-zA-Z_][\\a-zA-Z0-9_]*', Name.Class, '#pop')
499
766
        ],
500
767
        'functionname': [
501
768
            (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop')
503
770
        'string': [
504
771
            (r'"', String.Double, '#pop'),
505
772
            (r'[^{$"\\]+', String.Double),
506
 
            (r'\\([nrt\"$]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2})', String.Escape),
 
773
            (r'\\([nrt\"$\\]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2})', String.Escape),
507
774
            (r'\$[a-zA-Z_][a-zA-Z0-9_]*(\[\S+\]|->[a-zA-Z_][a-zA-Z0-9_]*)?',
508
775
             String.Interpol),
509
776
            (r'(\{\$\{)(.*?)(\}\})',
641
908
    def analyse_text(text):
642
909
        if looks_like_xml(text) and '<xsl' in text:
643
910
            return 0.8
 
911
 
 
912
 
 
913
class MxmlLexer(RegexLexer):
 
914
    """
 
915
    For MXML markup.
 
916
    Nested AS3 in <script> tags is highlighted by the appropriate lexer.
 
917
    """
 
918
    flags = re.MULTILINE | re.DOTALL
 
919
    name = 'MXML'
 
920
    aliases = ['mxml']
 
921
    filenames = ['*.mxml']
 
922
    mimetimes = ['text/xml', 'application/xml']
 
923
 
 
924
    tokens = {
 
925
            'root': [
 
926
                ('[^<&]+', Text),
 
927
                (r'&\S*?;', Name.Entity),
 
928
                (r'(\<\!\[CDATA\[)(.*?)(\]\]\>)',
 
929
                 bygroups(String, using(ActionScript3Lexer), String)),
 
930
                ('<!--', Comment, 'comment'),
 
931
                (r'<\?.*?\?>', Comment.Preproc),
 
932
                ('<![^>]*>', Comment.Preproc),
 
933
                (r'<\s*[a-zA-Z0-9:._-]+', Name.Tag, 'tag'),
 
934
                (r'<\s*/\s*[a-zA-Z0-9:._-]+\s*>', Name.Tag),
 
935
            ],
 
936
            'comment': [
 
937
                ('[^-]+', Comment),
 
938
                ('-->', Comment, '#pop'),
 
939
                ('-', Comment),
 
940
            ],
 
941
            'tag': [
 
942
                (r'\s+', Text),
 
943
                (r'[a-zA-Z0-9_.:-]+\s*=', Name.Attribute, 'attr'),
 
944
                (r'/?\s*>', Name.Tag, '#pop'),
 
945
            ],
 
946
            'attr': [
 
947
                ('\s+', Text),
 
948
                ('".*?"', String, '#pop'),
 
949
                ("'.*?'", String, '#pop'),
 
950
                (r'[^\s>]+', String, '#pop'),
 
951
            ],
 
952
        }
 
953
 
 
954
 
 
955
class HaxeLexer(RegexLexer):
 
956
    """
 
957
    For haXe source code (http://haxe.org/).
 
958
    """
 
959
 
 
960
    name = 'haXe'
 
961
    aliases = ['hx', 'haXe']
 
962
    filenames = ['*.hx']
 
963
    mimetypes = ['text/haxe']
 
964
 
 
965
    ident = r'(?:[a-zA-Z_][a-zA-Z0-9_]*)'
 
966
    typeid = r'(?:(?:[a-z0-9_\.])*[A-Z_][A-Za-z0-9_]*)'
 
967
    key_prop = r'(?:default|null|never)'
 
968
    key_decl_mod = r'(?:public|private|override|static|inline|extern|dynamic)'
 
969
 
 
970
    flags = re.DOTALL | re.MULTILINE
 
971
 
 
972
    tokens = {
 
973
        'root': [
 
974
            include('whitespace'),
 
975
            include('comments'),
 
976
            (key_decl_mod, Keyword.Declaration),
 
977
            include('enumdef'),
 
978
            include('typedef'),
 
979
            include('classdef'),
 
980
            include('imports'),
 
981
        ],
 
982
 
 
983
        # General constructs
 
984
        'comments': [
 
985
            (r'//.*?\n', Comment.Single),
 
986
            (r'/\*.*?\*/', Comment.Multiline),
 
987
            (r'#[^\n]*', Comment.Preproc),
 
988
        ],
 
989
        'whitespace': [
 
990
            include('comments'),
 
991
            (r'\s+', Text),
 
992
        ],
 
993
        'codekeywords': [
 
994
            (r'\b(if|else|while|do|for|in|break|continue|'
 
995
             r'return|switch|case|try|catch|throw|null|trace|'
 
996
             r'new|this|super|untyped|cast|callback|here)\b',
 
997
             Keyword.Reserved),
 
998
        ],
 
999
        'literals': [
 
1000
            (r'0[xX][0-9a-fA-F]+', Number.Hex),
 
1001
            (r'[0-9]+', Number.Integer),
 
1002
            (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
 
1003
            (r"'(\\\\|\\'|[^'])*'", String.Single),
 
1004
            (r'"(\\\\|\\"|[^"])*"', String.Double),
 
1005
            (r'~/([^\n])*?/[gisx]*', String.Regex),
 
1006
            (r'\b(true|false|null)\b', Keyword.Constant),
 
1007
        ],
 
1008
        'codeblock': [
 
1009
          include('whitespace'),
 
1010
          include('new'),
 
1011
          include('case'),
 
1012
          include('anonfundef'),
 
1013
          include('literals'),
 
1014
          include('vardef'),
 
1015
          include('codekeywords'),
 
1016
          (r'[();,\[\]]', Punctuation),
 
1017
          (r'(?:=|\+=|-=|\*=|/=|%=|&=|\|=|\^=|<<=|>>=|>>>=|\|\||&&|'
 
1018
           r'\.\.\.|==|!=|>|<|>=|<=|\||&|\^|<<|>>|>>>|\+|\-|\*|/|%|'
 
1019
           r'!|\+\+|\-\-|~|\.|\?|\:)',
 
1020
           Operator),
 
1021
          (ident, Name),
 
1022
 
 
1023
          (r'}', Punctuation,'#pop'),
 
1024
          (r'{', Punctuation,'#push'),
 
1025
        ],
 
1026
 
 
1027
        # Instance/Block level constructs
 
1028
        'propertydef': [
 
1029
            (r'(\()(' + key_prop + ')(,)(' + key_prop + ')(\))',
 
1030
             bygroups(Punctuation, Keyword.Reserved, Punctuation,
 
1031
                      Keyword.Reserved, Punctuation)),
 
1032
        ],
 
1033
        'new': [
 
1034
            (r'\bnew\b', Keyword, 'typedecl'),
 
1035
        ],
 
1036
        'case': [
 
1037
            (r'\b(case)(\s+)(' + ident + ')(\s*)(\()',
 
1038
             bygroups(Keyword.Reserved, Text, Name, Text, Punctuation),
 
1039
             'funargdecl'),
 
1040
        ],
 
1041
        'vardef': [
 
1042
            (r'\b(var)(\s+)(' + ident + ')',
 
1043
             bygroups(Keyword.Declaration, Text, Name.Variable), 'vardecl'),
 
1044
        ],
 
1045
        'vardecl': [
 
1046
            include('whitespace'),
 
1047
            include('typelabel'),
 
1048
            (r'=', Operator,'#pop'),
 
1049
            (r';', Punctuation,'#pop'),
 
1050
        ],
 
1051
        'instancevardef': [
 
1052
            (key_decl_mod,Keyword.Declaration),
 
1053
            (r'\b(var)(\s+)(' + ident + ')',
 
1054
             bygroups(Keyword.Declaration, Text, Name.Variable.Instance),
 
1055
             'instancevardecl'),
 
1056
        ],
 
1057
        'instancevardecl': [
 
1058
            include('vardecl'),
 
1059
            include('propertydef'),
 
1060
        ],
 
1061
 
 
1062
        'anonfundef': [
 
1063
            (r'\bfunction\b', Keyword.Declaration, 'fundecl'),
 
1064
        ],
 
1065
        'instancefundef': [
 
1066
            (key_decl_mod, Keyword.Declaration),
 
1067
            (r'\b(function)(\s+)(' + ident + ')',
 
1068
             bygroups(Keyword.Declaration, Text, Name.Function), 'fundecl'),
 
1069
        ],
 
1070
        'fundecl': [
 
1071
            include('whitespace'),
 
1072
            include('typelabel'),
 
1073
            include('generictypedecl'),
 
1074
            (r'\(',Punctuation,'funargdecl'),
 
1075
            (r'(?=[a-zA-Z0-9_])',Text,'#pop'),
 
1076
            (r'{',Punctuation,('#pop','codeblock')),
 
1077
            (r';',Punctuation,'#pop'),
 
1078
        ],
 
1079
        'funargdecl': [
 
1080
            include('whitespace'),
 
1081
            (ident, Name.Variable),
 
1082
            include('typelabel'),
 
1083
            include('literals'),
 
1084
            (r'=', Operator),
 
1085
            (r',', Punctuation),
 
1086
            (r'\?', Punctuation),
 
1087
            (r'\)', Punctuation, '#pop'),
 
1088
        ],
 
1089
 
 
1090
        'typelabel': [
 
1091
            (r':', Punctuation, 'type'),
 
1092
        ],
 
1093
        'typedecl': [
 
1094
            include('whitespace'),
 
1095
            (typeid, Name.Class),
 
1096
            (r'<', Punctuation, 'generictypedecl'),
 
1097
            (r'(?=[{}()=,a-z])', Text,'#pop'),
 
1098
        ],
 
1099
        'type': [
 
1100
            include('whitespace'),
 
1101
            (typeid, Name.Class),
 
1102
            (r'<', Punctuation, 'generictypedecl'),
 
1103
            (r'->', Keyword.Type),
 
1104
            (r'(?=[{}(),;=])', Text, '#pop'),
 
1105
        ],
 
1106
        'generictypedecl': [
 
1107
            include('whitespace'),
 
1108
            (typeid, Name.Class),
 
1109
            (r'<', Punctuation, '#push'),
 
1110
            (r'>', Punctuation, '#pop'),
 
1111
            (r',', Punctuation),
 
1112
        ],
 
1113
 
 
1114
        # Top level constructs
 
1115
        'imports': [
 
1116
            (r'(package|import|using)(\s+)([^;]+)(;)',
 
1117
             bygroups(Keyword.Namespace, Text, Name.Namespace,Punctuation)),
 
1118
        ],
 
1119
        'typedef': [
 
1120
            (r'typedef', Keyword.Declaration, ('typedefprebody', 'typedecl')),
 
1121
        ],
 
1122
        'typedefprebody': [
 
1123
            include('whitespace'),
 
1124
            (r'(=)(\s*)({)', bygroups(Punctuation, Text, Punctuation),
 
1125
             ('#pop', 'typedefbody')),
 
1126
        ],
 
1127
        'enumdef': [
 
1128
            (r'enum', Keyword.Declaration, ('enumdefprebody', 'typedecl')),
 
1129
        ],
 
1130
        'enumdefprebody': [
 
1131
            include('whitespace'),
 
1132
            (r'{', Punctuation, ('#pop','enumdefbody')),
 
1133
        ],
 
1134
        'classdef': [
 
1135
            (r'class', Keyword.Declaration, ('classdefprebody', 'typedecl')),
 
1136
        ],
 
1137
        'classdefprebody': [
 
1138
            include('whitespace'),
 
1139
            (r'(extends|implements)', Keyword.Declaration,'typedecl'),
 
1140
            (r'{', Punctuation, ('#pop', 'classdefbody')),
 
1141
        ],
 
1142
        'interfacedef': [
 
1143
            (r'interface', Keyword.Declaration,
 
1144
             ('interfacedefprebody', 'typedecl')),
 
1145
        ],
 
1146
        'interfacedefprebody': [
 
1147
            include('whitespace'),
 
1148
            (r'(extends)', Keyword.Declaration, 'typedecl'),
 
1149
            (r'{', Punctuation, ('#pop', 'classdefbody')),
 
1150
        ],
 
1151
 
 
1152
        'typedefbody': [
 
1153
          include('whitespace'),
 
1154
          include('instancevardef'),
 
1155
          include('instancefundef'),
 
1156
          (r'>', Punctuation, 'typedecl'),
 
1157
          (r',', Punctuation),
 
1158
          (r'}', Punctuation, '#pop'),
 
1159
        ],
 
1160
        'enumdefbody': [
 
1161
          include('whitespace'),
 
1162
          (ident, Name.Variable.Instance),
 
1163
          (r'\(', Punctuation, 'funargdecl'),
 
1164
          (r';', Punctuation),
 
1165
          (r'}', Punctuation, '#pop'),
 
1166
        ],
 
1167
        'classdefbody': [
 
1168
          include('whitespace'),
 
1169
          include('instancevardef'),
 
1170
          include('instancefundef'),
 
1171
          (r'}', Punctuation, '#pop'),
 
1172
          include('codeblock'),
 
1173
        ],
 
1174
    }
 
1175
 
 
1176
    def analyse_text(text):
 
1177
        if re.match(r'\w+\s*:\s*\w', text): return 0.3
 
1178
 
 
1179
 
 
1180
def _indentation(lexer, match, ctx):
 
1181
    indentation = match.group(0)
 
1182
    yield match.start(), Text, indentation
 
1183
    ctx.last_indentation = indentation
 
1184
    ctx.pos = match.end()
 
1185
 
 
1186
    if hasattr(ctx, 'block_state') and ctx.block_state and \
 
1187
            indentation.startswith(ctx.block_indentation) and \
 
1188
            indentation != ctx.block_indentation:
 
1189
        ctx.stack.append(ctx.block_state)
 
1190
    else:
 
1191
        ctx.block_state = None
 
1192
        ctx.block_indentation = None
 
1193
        ctx.stack.append('content')
 
1194
 
 
1195
def _starts_block(token, state):
 
1196
    def callback(lexer, match, ctx):
 
1197
        yield match.start(), token, match.group(0)
 
1198
 
 
1199
        if hasattr(ctx, 'last_indentation'):
 
1200
            ctx.block_indentation = ctx.last_indentation
 
1201
        else:
 
1202
            ctx.block_indentation = ''
 
1203
 
 
1204
        ctx.block_state = state
 
1205
        ctx.pos = match.end()
 
1206
 
 
1207
    return callback
 
1208
 
 
1209
 
 
1210
class HamlLexer(ExtendedRegexLexer):
 
1211
    """
 
1212
    For Haml markup.
 
1213
 
 
1214
    *New in Pygments 1.3.*
 
1215
    """
 
1216
 
 
1217
    name = 'Haml'
 
1218
    aliases = ['haml', 'HAML']
 
1219
    filenames = ['*.haml']
 
1220
    mimetypes = ['text/x-haml']
 
1221
 
 
1222
    flags = re.IGNORECASE
 
1223
    # Haml can include " |\n" anywhere,
 
1224
    # which is ignored and used to wrap long lines.
 
1225
    # To accomodate this, use this custom faux dot instead.
 
1226
    _dot = r'(?: \|\n(?=.* \|)|.)'
 
1227
 
 
1228
    # In certain places, a comma at the end of the line
 
1229
    # allows line wrapping as well.
 
1230
    _comma_dot = r'(?:,\s*\n|' + _dot + ')'
 
1231
    tokens = {
 
1232
        'root': [
 
1233
            (r'[ \t]*\n', Text),
 
1234
            (r'[ \t]*', _indentation),
 
1235
        ],
 
1236
 
 
1237
        'css': [
 
1238
            (r'\.[a-z0-9_:-]+', Name.Class, 'tag'),
 
1239
            (r'\#[a-z0-9_:-]+', Name.Function, 'tag'),
 
1240
        ],
 
1241
 
 
1242
        'eval-or-plain': [
 
1243
            (r'[&!]?==', Punctuation, 'plain'),
 
1244
            (r'([&!]?[=~])(' + _comma_dot + '*\n)',
 
1245
             bygroups(Punctuation, using(RubyLexer)),
 
1246
             'root'),
 
1247
            (r'', Text, 'plain'),
 
1248
        ],
 
1249
 
 
1250
        'content': [
 
1251
            include('css'),
 
1252
            (r'%[a-z0-9_:-]+', Name.Tag, 'tag'),
 
1253
            (r'!!!' + _dot + '*\n', Name.Namespace, '#pop'),
 
1254
            (r'(/)(\[' + _dot + '*?\])(' + _dot + '*\n)',
 
1255
             bygroups(Comment, Comment.Special, Comment),
 
1256
             '#pop'),
 
1257
            (r'/' + _dot + '*\n', _starts_block(Comment, 'html-comment-block'),
 
1258
             '#pop'),
 
1259
            (r'-#' + _dot + '*\n', _starts_block(Comment.Preproc,
 
1260
                                                 'haml-comment-block'), '#pop'),
 
1261
            (r'(-)(' + _comma_dot + '*\n)',
 
1262
             bygroups(Punctuation, using(RubyLexer)),
 
1263
             '#pop'),
 
1264
            (r':' + _dot + '*\n', _starts_block(Name.Decorator, 'filter-block'),
 
1265
             '#pop'),
 
1266
            include('eval-or-plain'),
 
1267
        ],
 
1268
 
 
1269
        'tag': [
 
1270
            include('css'),
 
1271
            (r'\{(,\n|' + _dot + ')*?\}', using(RubyLexer)),
 
1272
            (r'\[' + _dot + '*?\]', using(RubyLexer)),
 
1273
            (r'\(', Text, 'html-attributes'),
 
1274
            (r'/[ \t]*\n', Punctuation, '#pop:2'),
 
1275
            (r'[<>]{1,2}(?=[ \t=])', Punctuation),
 
1276
            include('eval-or-plain'),
 
1277
        ],
 
1278
 
 
1279
        'plain': [
 
1280
            (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text),
 
1281
            (r'(#\{)(' + _dot + '*?)(\})',
 
1282
             bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
 
1283
            (r'\n', Text, 'root'),
 
1284
        ],
 
1285
 
 
1286
        'html-attributes': [
 
1287
            (r'\s+', Text),
 
1288
            (r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'),
 
1289
            (r'[a-z0-9_:-]+', Name.Attribute),
 
1290
            (r'\)', Text, '#pop'),
 
1291
        ],
 
1292
 
 
1293
        'html-attribute-value': [
 
1294
            (r'[ \t]+', Text),
 
1295
            (r'[a-z0-9_]+', Name.Variable, '#pop'),
 
1296
            (r'@[a-z0-9_]+', Name.Variable.Instance, '#pop'),
 
1297
            (r'\$[a-z0-9_]+', Name.Variable.Global, '#pop'),
 
1298
            (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'),
 
1299
            (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'),
 
1300
        ],
 
1301
 
 
1302
        'html-comment-block': [
 
1303
            (_dot + '+', Comment),
 
1304
            (r'\n', Text, 'root'),
 
1305
        ],
 
1306
 
 
1307
        'haml-comment-block': [
 
1308
            (_dot + '+', Comment.Preproc),
 
1309
            (r'\n', Text, 'root'),
 
1310
        ],
 
1311
 
 
1312
        'filter-block': [
 
1313
            (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator),
 
1314
            (r'(#\{)(' + _dot + '*?)(\})',
 
1315
             bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
 
1316
            (r'\n', Text, 'root'),
 
1317
        ],
 
1318
    }
 
1319
 
 
1320
 
 
1321
common_sass_tokens = {
 
1322
    'value': [
 
1323
        (r'[ \t]+', Text),
 
1324
        (r'[!$][\w-]+', Name.Variable),
 
1325
        (r'url\(', String.Other, 'string-url'),
 
1326
        (r'[a-z_-][\w-]*(?=\()', Name.Function),
 
1327
        (r'(azimuth|background-attachment|background-color|'
 
1328
         r'background-image|background-position|background-repeat|'
 
1329
         r'background|border-bottom-color|border-bottom-style|'
 
1330
         r'border-bottom-width|border-left-color|border-left-style|'
 
1331
         r'border-left-width|border-right|border-right-color|'
 
1332
         r'border-right-style|border-right-width|border-top-color|'
 
1333
         r'border-top-style|border-top-width|border-bottom|'
 
1334
         r'border-collapse|border-left|border-width|border-color|'
 
1335
         r'border-spacing|border-style|border-top|border|caption-side|'
 
1336
         r'clear|clip|color|content|counter-increment|counter-reset|'
 
1337
         r'cue-after|cue-before|cue|cursor|direction|display|'
 
1338
         r'elevation|empty-cells|float|font-family|font-size|'
 
1339
         r'font-size-adjust|font-stretch|font-style|font-variant|'
 
1340
         r'font-weight|font|height|letter-spacing|line-height|'
 
1341
         r'list-style-type|list-style-image|list-style-position|'
 
1342
         r'list-style|margin-bottom|margin-left|margin-right|'
 
1343
         r'margin-top|margin|marker-offset|marks|max-height|max-width|'
 
1344
         r'min-height|min-width|opacity|orphans|outline|outline-color|'
 
1345
         r'outline-style|outline-width|overflow|padding-bottom|'
 
1346
         r'padding-left|padding-right|padding-top|padding|page|'
 
1347
         r'page-break-after|page-break-before|page-break-inside|'
 
1348
         r'pause-after|pause-before|pause|pitch|pitch-range|'
 
1349
         r'play-during|position|quotes|richness|right|size|'
 
1350
         r'speak-header|speak-numeral|speak-punctuation|speak|'
 
1351
         r'speech-rate|stress|table-layout|text-align|text-decoration|'
 
1352
         r'text-indent|text-shadow|text-transform|top|unicode-bidi|'
 
1353
         r'vertical-align|visibility|voice-family|volume|white-space|'
 
1354
         r'widows|width|word-spacing|z-index|bottom|left|'
 
1355
         r'above|absolute|always|armenian|aural|auto|avoid|baseline|'
 
1356
         r'behind|below|bidi-override|blink|block|bold|bolder|both|'
 
1357
         r'capitalize|center-left|center-right|center|circle|'
 
1358
         r'cjk-ideographic|close-quote|collapse|condensed|continuous|'
 
1359
         r'crop|crosshair|cross|cursive|dashed|decimal-leading-zero|'
 
1360
         r'decimal|default|digits|disc|dotted|double|e-resize|embed|'
 
1361
         r'extra-condensed|extra-expanded|expanded|fantasy|far-left|'
 
1362
         r'far-right|faster|fast|fixed|georgian|groove|hebrew|help|'
 
1363
         r'hidden|hide|higher|high|hiragana-iroha|hiragana|icon|'
 
1364
         r'inherit|inline-table|inline|inset|inside|invert|italic|'
 
1365
         r'justify|katakana-iroha|katakana|landscape|larger|large|'
 
1366
         r'left-side|leftwards|level|lighter|line-through|list-item|'
 
1367
         r'loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|'
 
1368
         r'lower|low|medium|message-box|middle|mix|monospace|'
 
1369
         r'n-resize|narrower|ne-resize|no-close-quote|no-open-quote|'
 
1370
         r'no-repeat|none|normal|nowrap|nw-resize|oblique|once|'
 
1371
         r'open-quote|outset|outside|overline|pointer|portrait|px|'
 
1372
         r'relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|'
 
1373
         r'rightwards|s-resize|sans-serif|scroll|se-resize|'
 
1374
         r'semi-condensed|semi-expanded|separate|serif|show|silent|'
 
1375
         r'slow|slower|small-caps|small-caption|smaller|soft|solid|'
 
1376
         r'spell-out|square|static|status-bar|super|sw-resize|'
 
1377
         r'table-caption|table-cell|table-column|table-column-group|'
 
1378
         r'table-footer-group|table-header-group|table-row|'
 
1379
         r'table-row-group|text|text-bottom|text-top|thick|thin|'
 
1380
         r'transparent|ultra-condensed|ultra-expanded|underline|'
 
1381
         r'upper-alpha|upper-latin|upper-roman|uppercase|url|'
 
1382
         r'visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|'
 
1383
         r'x-low|x-small|x-soft|xx-large|xx-small|yes)\b', Name.Constant),
 
1384
        (r'(indigo|gold|firebrick|indianred|darkolivegreen|'
 
1385
         r'darkseagreen|mediumvioletred|mediumorchid|chartreuse|'
 
1386
         r'mediumslateblue|springgreen|crimson|lightsalmon|brown|'
 
1387
         r'turquoise|olivedrab|cyan|skyblue|darkturquoise|'
 
1388
         r'goldenrod|darkgreen|darkviolet|darkgray|lightpink|'
 
1389
         r'darkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|'
 
1390
         r'violet|orchid|ghostwhite|honeydew|cornflowerblue|'
 
1391
         r'darkblue|darkkhaki|mediumpurple|cornsilk|bisque|slategray|'
 
1392
         r'darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|'
 
1393
         r'gainsboro|mediumturquoise|floralwhite|coral|lightgrey|'
 
1394
         r'lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|'
 
1395
         r'greenyellow|royalblue|lightseagreen|mistyrose|sienna|'
 
1396
         r'lightcoral|orangered|navajowhite|palegreen|burlywood|'
 
1397
         r'seashell|mediumspringgreen|papayawhip|blanchedalmond|'
 
1398
         r'peru|aquamarine|darkslategray|ivory|dodgerblue|'
 
1399
         r'lemonchiffon|chocolate|orange|forestgreen|slateblue|'
 
1400
         r'mintcream|antiquewhite|darkorange|cadetblue|moccasin|'
 
1401
         r'limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|'
 
1402
         r'plum|darkgoldenrod|sandybrown|magenta|tan|'
 
1403
         r'rosybrown|pink|lightblue|palevioletred|mediumseagreen|'
 
1404
         r'dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|'
 
1405
         r'paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|'
 
1406
         r'lightslategray|lawngreen|lightgreen|tomato|hotpink|'
 
1407
         r'lightyellow|lavenderblush|linen|mediumaquamarine|'
 
1408
         r'blueviolet|peachpuff)\b', Name.Entity),
 
1409
        (r'(black|silver|gray|white|maroon|red|purple|fuchsia|green|'
 
1410
         r'lime|olive|yellow|navy|blue|teal|aqua)\b', Name.Builtin),
 
1411
        (r'\!(important|default)', Name.Exception),
 
1412
        (r'(true|false)', Name.Pseudo),
 
1413
        (r'(and|or|not)', Operator.Word),
 
1414
        (r'/\*', Comment.Multiline, 'inline-comment'),
 
1415
        (r'//[^\n]*', Comment.Single),
 
1416
        (r'\#[a-z0-9]{1,6}', Number.Hex),
 
1417
        (r'(-?\d+)(\%|[a-z]+)?', bygroups(Number.Integer, Keyword.Type)),
 
1418
        (r'(-?\d*\.\d+)(\%|[a-z]+)?', bygroups(Number.Float, Keyword.Type)),
 
1419
        (r'#{', String.Interpol, 'interpolation'),
 
1420
        (r'[~\^\*!&%<>\|+=@:,./?-]+', Operator),
 
1421
        (r'[\[\]()]+', Punctuation),
 
1422
        (r'"', String.Double, 'string-double'),
 
1423
        (r"'", String.Single, 'string-single'),
 
1424
        (r'[a-z_-][\w-]*', Name),
 
1425
    ],
 
1426
 
 
1427
    'interpolation': [
 
1428
        (r'\}', String.Interpol, '#pop'),
 
1429
        include('value'),
 
1430
    ],
 
1431
 
 
1432
    'selector': [
 
1433
        (r'[ \t]+', Text),
 
1434
        (r'\:', Name.Decorator, 'pseudo-class'),
 
1435
        (r'\.', Name.Class, 'class'),
 
1436
        (r'\#', Name.Namespace, 'id'),
 
1437
        (r'[a-zA-Z0-9_-]+', Name.Tag),
 
1438
        (r'#\{', String.Interpol, 'interpolation'),
 
1439
        (r'&', Keyword),
 
1440
        (r'[~\^\*!&\[\]\(\)<>\|+=@:;,./?-]', Operator),
 
1441
        (r'"', String.Double, 'string-double'),
 
1442
        (r"'", String.Single, 'string-single'),
 
1443
    ],
 
1444
 
 
1445
    'string-double': [
 
1446
        (r'(\\.|#(?=[^\n{])|[^\n"#])+', String.Double),
 
1447
        (r'#\{', String.Interpol, 'interpolation'),
 
1448
        (r'"', String.Double, '#pop'),
 
1449
    ],
 
1450
 
 
1451
    'string-single': [
 
1452
        (r"(\\.|#(?=[^\n{])|[^\n'#])+", String.Double),
 
1453
        (r'#\{', String.Interpol, 'interpolation'),
 
1454
        (r"'", String.Double, '#pop'),
 
1455
    ],
 
1456
 
 
1457
    'string-url': [
 
1458
        (r'(\\#|#(?=[^\n{])|[^\n#)])+', String.Other),
 
1459
        (r'#\{', String.Interpol, 'interpolation'),
 
1460
        (r'\)', String.Other, '#pop'),
 
1461
    ],
 
1462
 
 
1463
    'pseudo-class': [
 
1464
        (r'[\w-]+', Name.Decorator),
 
1465
        (r'#\{', String.Interpol, 'interpolation'),
 
1466
        (r'', Text, '#pop'),
 
1467
    ],
 
1468
 
 
1469
    'class': [
 
1470
        (r'[\w-]+', Name.Class),
 
1471
        (r'#\{', String.Interpol, 'interpolation'),
 
1472
        (r'', Text, '#pop'),
 
1473
    ],
 
1474
 
 
1475
    'id': [
 
1476
        (r'[\w-]+', Name.Namespace),
 
1477
        (r'#\{', String.Interpol, 'interpolation'),
 
1478
        (r'', Text, '#pop'),
 
1479
    ],
 
1480
 
 
1481
    'for': [
 
1482
        (r'(from|to|through)', Operator.Word),
 
1483
        include('value'),
 
1484
    ],
 
1485
}
 
1486
 
 
1487
class SassLexer(ExtendedRegexLexer):
 
1488
    """
 
1489
    For Sass stylesheets.
 
1490
 
 
1491
    *New in Pygments 1.3.*
 
1492
    """
 
1493
 
 
1494
    name = 'Sass'
 
1495
    aliases = ['sass', 'SASS']
 
1496
    filenames = ['*.sass']
 
1497
    mimetypes = ['text/x-sass']
 
1498
 
 
1499
    flags = re.IGNORECASE
 
1500
    tokens = {
 
1501
        'root': [
 
1502
            (r'[ \t]*\n', Text),
 
1503
            (r'[ \t]*', _indentation),
 
1504
        ],
 
1505
 
 
1506
        'content': [
 
1507
            (r'//[^\n]*', _starts_block(Comment.Single, 'single-comment'),
 
1508
             'root'),
 
1509
            (r'/\*[^\n]*', _starts_block(Comment.Multiline, 'multi-comment'),
 
1510
             'root'),
 
1511
            (r'@import', Keyword, 'import'),
 
1512
            (r'@for', Keyword, 'for'),
 
1513
            (r'@(debug|warn|if|while)', Keyword, 'value'),
 
1514
            (r'(@mixin)( [\w-]+)', bygroups(Keyword, Name.Function), 'value'),
 
1515
            (r'(@include)( [\w-]+)', bygroups(Keyword, Name.Decorator), 'value'),
 
1516
            (r'@extend', Keyword, 'selector'),
 
1517
            (r'@[a-z0-9_-]+', Keyword, 'selector'),
 
1518
            (r'=[\w-]+', Name.Function, 'value'),
 
1519
            (r'\+[\w-]+', Name.Decorator, 'value'),
 
1520
            (r'([!$][\w-]\w*)([ \t]*(?:(?:\|\|)?=|:))',
 
1521
             bygroups(Name.Variable, Operator), 'value'),
 
1522
            (r':', Name.Attribute, 'old-style-attr'),
 
1523
            (r'(?=.+?[=:]([^a-z]|$))', Name.Attribute, 'new-style-attr'),
 
1524
            (r'', Text, 'selector'),
 
1525
        ],
 
1526
 
 
1527
        'single-comment': [
 
1528
            (r'.+', Comment.Single),
 
1529
            (r'\n', Text, 'root'),
 
1530
        ],
 
1531
 
 
1532
        'multi-comment': [
 
1533
            (r'.+', Comment.Multiline),
 
1534
            (r'\n', Text, 'root'),
 
1535
        ],
 
1536
 
 
1537
        'import': [
 
1538
            (r'[ \t]+', Text),
 
1539
            (r'[^\s]+', String),
 
1540
            (r'\n', Text, 'root'),
 
1541
        ],
 
1542
 
 
1543
        'old-style-attr': [
 
1544
            (r'[^\s:="\[]+', Name.Attribute),
 
1545
            (r'#{', String.Interpol, 'interpolation'),
 
1546
            (r'[ \t]*=', Operator, 'value'),
 
1547
            (r'', Text, 'value'),
 
1548
        ],
 
1549
 
 
1550
        'new-style-attr': [
 
1551
            (r'[^\s:="\[]+', Name.Attribute),
 
1552
            (r'#{', String.Interpol, 'interpolation'),
 
1553
            (r'[ \t]*[=:]', Operator, 'value'),
 
1554
        ],
 
1555
 
 
1556
        'inline-comment': [
 
1557
            (r"(\\#|#(?=[^\n{])|\*(?=[^\n/])|[^\n#*])+", Comment.Multiline),
 
1558
            (r'#\{', String.Interpol, 'interpolation'),
 
1559
            (r"\*/", Comment, '#pop'),
 
1560
        ],
 
1561
    }
 
1562
    for group, common in common_sass_tokens.iteritems():
 
1563
        tokens[group] = copy.copy(common)
 
1564
    tokens['value'].append((r'\n', Text, 'root'))
 
1565
    tokens['selector'].append((r'\n', Text, 'root'))
 
1566
 
 
1567
 
 
1568
class ScssLexer(RegexLexer):
 
1569
    """
 
1570
    For SCSS stylesheets.
 
1571
    """
 
1572
 
 
1573
    name = 'SCSS'
 
1574
    aliases = ['scss']
 
1575
    filenames = ['*.scss']
 
1576
    mimetypes = ['text/x-scss']
 
1577
 
 
1578
    flags = re.IGNORECASE | re.DOTALL
 
1579
    tokens = {
 
1580
        'root': [
 
1581
            (r'\s+', Text),
 
1582
            (r'//.*?\n', Comment.Single),
 
1583
            (r'/\*.*?\*/', Comment.Multiline),
 
1584
            (r'@import', Keyword, 'value'),
 
1585
            (r'@for', Keyword, 'for'),
 
1586
            (r'@(debug|warn|if|while)', Keyword, 'value'),
 
1587
            (r'(@mixin)( [\w-]+)', bygroups(Keyword, Name.Function), 'value'),
 
1588
            (r'(@include)( [\w-]+)', bygroups(Keyword, Name.Decorator), 'value'),
 
1589
            (r'@extend', Keyword, 'selector'),
 
1590
            (r'@[a-z0-9_-]+', Keyword, 'selector'),
 
1591
            (r'(\$[\w-]\w*)([ \t]*:)', bygroups(Name.Variable, Operator), 'value'),
 
1592
            (r'(?=[^;{}][;}])', Name.Attribute, 'attr'),
 
1593
            (r'(?=[^;{}:]+:[^a-z])', Name.Attribute, 'attr'),
 
1594
            (r'', Text, 'selector'),
 
1595
        ],
 
1596
 
 
1597
        'attr': [
 
1598
            (r'[^\s:="\[]+', Name.Attribute),
 
1599
            (r'#{', String.Interpol, 'interpolation'),
 
1600
            (r'[ \t]*:', Operator, 'value'),
 
1601
        ],
 
1602
 
 
1603
        'inline-comment': [
 
1604
            (r"(\\#|#(?=[^{])|\*(?=[^/])|[^#*])+", Comment.Multiline),
 
1605
            (r'#\{', String.Interpol, 'interpolation'),
 
1606
            (r"\*/", Comment, '#pop'),
 
1607
        ],
 
1608
    }
 
1609
    for group, common in common_sass_tokens.iteritems():
 
1610
        tokens[group] = copy.copy(common)
 
1611
    tokens['value'].extend([(r'\n', Text), (r'[;{}]', Punctuation, 'root')])
 
1612
    tokens['selector'].extend([(r'\n', Text), (r'[;{}]', Punctuation, 'root')])
 
1613
 
 
1614
 
 
1615
class CoffeeScriptLexer(RegexLexer):
 
1616
    """
 
1617
    For `CoffeeScript`_ source code.
 
1618
 
 
1619
    .. _CoffeeScript: http://coffeescript.org
 
1620
 
 
1621
    *New in Pygments 1.3.*
 
1622
    """
 
1623
 
 
1624
    name = 'CoffeeScript'
 
1625
    aliases = ['coffee-script', 'coffeescript']
 
1626
    filenames = ['*.coffee']
 
1627
    mimetypes = ['text/coffeescript']
 
1628
 
 
1629
    flags = re.DOTALL
 
1630
    tokens = {
 
1631
        'commentsandwhitespace': [
 
1632
            (r'\s+', Text),
 
1633
            (r'#.*?\n', Comment.Single),
 
1634
        ],
 
1635
        'slashstartsregex': [
 
1636
            include('commentsandwhitespace'),
 
1637
            (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
 
1638
             r'([gim]+\b|\B)', String.Regex, '#pop'),
 
1639
            (r'(?=/)', Text, ('#pop', 'badregex')),
 
1640
            (r'', Text, '#pop'),
 
1641
        ],
 
1642
        'badregex': [
 
1643
            ('\n', Text, '#pop'),
 
1644
        ],
 
1645
        'root': [
 
1646
            (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
 
1647
            include('commentsandwhitespace'),
 
1648
            (r'\+\+|--|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|=|'
 
1649
             r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*`%&\|\^/])=?',
 
1650
             Operator, 'slashstartsregex'),
 
1651
            (r'\([^()]*\)\s*->', Name.Function),
 
1652
            (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
 
1653
            (r'[})\].]', Punctuation),
 
1654
            (r'(for|in|of|while|break|return|continue|switch|when|then|if|else|'
 
1655
             r'throw|try|catch|finally|new|delete|typeof|instanceof|super|'
 
1656
             r'extends|this|class|by)\b', Keyword, 'slashstartsregex'),
 
1657
            (r'(true|false|yes|no|on|off|null|NaN|Infinity|undefined)\b',
 
1658
             Keyword.Constant),
 
1659
            (r'(Array|Boolean|Date|Error|Function|Math|netscape|'
 
1660
             r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
 
1661
             r'decodeURIComponent|encodeURI|encodeURIComponent|'
 
1662
             r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b',
 
1663
             Name.Builtin),
 
1664
            (r'[$a-zA-Z_][a-zA-Z0-9_\.:]*\s*[:=]\s', Name.Variable,
 
1665
              'slashstartsregex'),
 
1666
            (r'@[$a-zA-Z_][a-zA-Z0-9_\.:]*\s*[:=]\s', Name.Variable.Instance,
 
1667
              'slashstartsregex'),
 
1668
            (r'@?[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other, 'slashstartsregex'),
 
1669
            (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
 
1670
            (r'0x[0-9a-fA-F]+', Number.Hex),
 
1671
            (r'[0-9]+', Number.Integer),
 
1672
            (r'"(\\\\|\\"|[^"])*"', String.Double),
 
1673
            (r"'(\\\\|\\'|[^'])*'", String.Single),
 
1674
        ]
 
1675
    }
 
1676
 
 
1677
class DuelLexer(RegexLexer):
 
1678
    """
 
1679
    Lexer for Duel Views Engine (formerly JBST) markup with JavaScript code blocks.
 
1680
    See http://duelengine.org/.
 
1681
    See http://jsonml.org/jbst/.
 
1682
 
 
1683
    *New in Pygments 1.4.*
 
1684
    """
 
1685
 
 
1686
    name = 'Duel'
 
1687
    aliases = ['duel', 'Duel Engine', 'Duel View', 'JBST', 'jbst', 'JsonML+BST']
 
1688
    filenames = ['*.duel','*.jbst']
 
1689
    mimetypes = ['text/x-duel','text/x-jbst']
 
1690
 
 
1691
    flags = re.DOTALL
 
1692
 
 
1693
    tokens = {
 
1694
        'root': [
 
1695
            (r'(<%[@=#!:]?)(.*?)(%>)',
 
1696
             bygroups(Name.Tag, using(JavascriptLexer), Name.Tag)),
 
1697
            (r'(<%\$)(.*?)(:)(.*?)(%>)',
 
1698
             bygroups(Name.Tag, Name.Function, Punctuation, String, Name.Tag)),
 
1699
            (r'(<%--)(.*?)(--%>)',
 
1700
             bygroups(Name.Tag, Comment.Multiline, Name.Tag)),
 
1701
            (r'(<script.*?>)(.*?)(</script>)',
 
1702
             bygroups(using(HtmlLexer),
 
1703
                      using(JavascriptLexer), using(HtmlLexer))),
 
1704
            (r'(.+?)(?=<)', using(HtmlLexer)),
 
1705
            (r'.+', using(HtmlLexer)),
 
1706
        ],
 
1707
    }
 
1708
 
 
1709
 
 
1710
class ScamlLexer(ExtendedRegexLexer):
 
1711
    """
 
1712
    For `Scaml markup <http://scalate.fusesource.org/>`_.  Scaml is Haml for Scala.
 
1713
 
 
1714
    *New in Pygments 1.4.*
 
1715
    """
 
1716
 
 
1717
    name = 'Scaml'
 
1718
    aliases = ['scaml', 'SCAML']
 
1719
    filenames = ['*.scaml']
 
1720
    mimetypes = ['text/x-scaml']
 
1721
 
 
1722
    flags = re.IGNORECASE
 
1723
    # Scaml does not yet support the " |\n" notation to
 
1724
    # wrap long lines.  Once it does, use the custom faux
 
1725
    # dot instead.
 
1726
    # _dot = r'(?: \|\n(?=.* \|)|.)'
 
1727
    _dot = r'.'
 
1728
 
 
1729
    tokens = {
 
1730
        'root': [
 
1731
            (r'[ \t]*\n', Text),
 
1732
            (r'[ \t]*', _indentation),
 
1733
        ],
 
1734
 
 
1735
        'css': [
 
1736
            (r'\.[a-z0-9_:-]+', Name.Class, 'tag'),
 
1737
            (r'\#[a-z0-9_:-]+', Name.Function, 'tag'),
 
1738
        ],
 
1739
 
 
1740
        'eval-or-plain': [
 
1741
            (r'[&!]?==', Punctuation, 'plain'),
 
1742
            (r'([&!]?[=~])(' + _dot + '*\n)',
 
1743
             bygroups(Punctuation, using(ScalaLexer)),
 
1744
             'root'),
 
1745
            (r'', Text, 'plain'),
 
1746
        ],
 
1747
 
 
1748
        'content': [
 
1749
            include('css'),
 
1750
            (r'%[a-z0-9_:-]+', Name.Tag, 'tag'),
 
1751
            (r'!!!' + _dot + '*\n', Name.Namespace, '#pop'),
 
1752
            (r'(/)(\[' + _dot + '*?\])(' + _dot + '*\n)',
 
1753
             bygroups(Comment, Comment.Special, Comment),
 
1754
             '#pop'),
 
1755
            (r'/' + _dot + '*\n', _starts_block(Comment, 'html-comment-block'),
 
1756
             '#pop'),
 
1757
            (r'-#' + _dot + '*\n', _starts_block(Comment.Preproc,
 
1758
                                                 'scaml-comment-block'), '#pop'),
 
1759
            (r'(-@\s*)(import)?(' + _dot + '*\n)',
 
1760
             bygroups(Punctuation, Keyword, using(ScalaLexer)),
 
1761
             '#pop'),
 
1762
            (r'(-)(' + _dot + '*\n)',
 
1763
             bygroups(Punctuation, using(ScalaLexer)),
 
1764
             '#pop'),
 
1765
            (r':' + _dot + '*\n', _starts_block(Name.Decorator, 'filter-block'),
 
1766
             '#pop'),
 
1767
            include('eval-or-plain'),
 
1768
        ],
 
1769
 
 
1770
        'tag': [
 
1771
            include('css'),
 
1772
            (r'\{(,\n|' + _dot + ')*?\}', using(ScalaLexer)),
 
1773
            (r'\[' + _dot + '*?\]', using(ScalaLexer)),
 
1774
            (r'\(', Text, 'html-attributes'),
 
1775
            (r'/[ \t]*\n', Punctuation, '#pop:2'),
 
1776
            (r'[<>]{1,2}(?=[ \t=])', Punctuation),
 
1777
            include('eval-or-plain'),
 
1778
        ],
 
1779
 
 
1780
        'plain': [
 
1781
            (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text),
 
1782
            (r'(#\{)(' + _dot + '*?)(\})',
 
1783
             bygroups(String.Interpol, using(ScalaLexer), String.Interpol)),
 
1784
            (r'\n', Text, 'root'),
 
1785
        ],
 
1786
 
 
1787
        'html-attributes': [
 
1788
            (r'\s+', Text),
 
1789
            (r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'),
 
1790
            (r'[a-z0-9_:-]+', Name.Attribute),
 
1791
            (r'\)', Text, '#pop'),
 
1792
        ],
 
1793
 
 
1794
        'html-attribute-value': [
 
1795
            (r'[ \t]+', Text),
 
1796
            (r'[a-z0-9_]+', Name.Variable, '#pop'),
 
1797
            (r'@[a-z0-9_]+', Name.Variable.Instance, '#pop'),
 
1798
            (r'\$[a-z0-9_]+', Name.Variable.Global, '#pop'),
 
1799
            (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'),
 
1800
            (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'),
 
1801
        ],
 
1802
 
 
1803
        'html-comment-block': [
 
1804
            (_dot + '+', Comment),
 
1805
            (r'\n', Text, 'root'),
 
1806
        ],
 
1807
 
 
1808
        'scaml-comment-block': [
 
1809
            (_dot + '+', Comment.Preproc),
 
1810
            (r'\n', Text, 'root'),
 
1811
        ],
 
1812
 
 
1813
        'filter-block': [
 
1814
            (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator),
 
1815
            (r'(#\{)(' + _dot + '*?)(\})',
 
1816
             bygroups(String.Interpol, using(ScalaLexer), String.Interpol)),
 
1817
            (r'\n', Text, 'root'),
 
1818
        ],
 
1819
    }
 
1820
 
 
1821
 
 
1822
class JadeLexer(ExtendedRegexLexer):
 
1823
    """
 
1824
    For Jade markup.
 
1825
    Jade is a variant of Scaml, see:
 
1826
    http://scalate.fusesource.org/documentation/scaml-reference.html
 
1827
 
 
1828
    *New in Pygments 1.4.*
 
1829
    """
 
1830
 
 
1831
    name = 'Jade'
 
1832
    aliases = ['jade', 'JADE']
 
1833
    filenames = ['*.jade']
 
1834
    mimetypes = ['text/x-jade']
 
1835
 
 
1836
    flags = re.IGNORECASE
 
1837
    _dot = r'.'
 
1838
 
 
1839
    tokens = {
 
1840
        'root': [
 
1841
            (r'[ \t]*\n', Text),
 
1842
            (r'[ \t]*', _indentation),
 
1843
        ],
 
1844
 
 
1845
        'css': [
 
1846
            (r'\.[a-z0-9_:-]+', Name.Class, 'tag'),
 
1847
            (r'\#[a-z0-9_:-]+', Name.Function, 'tag'),
 
1848
        ],
 
1849
 
 
1850
        'eval-or-plain': [
 
1851
            (r'[&!]?==', Punctuation, 'plain'),
 
1852
            (r'([&!]?[=~])(' + _dot + '*\n)',
 
1853
             bygroups(Punctuation, using(ScalaLexer)),  'root'),
 
1854
            (r'', Text, 'plain'),
 
1855
        ],
 
1856
 
 
1857
        'content': [
 
1858
            include('css'),
 
1859
            (r'!!!' + _dot + '*\n', Name.Namespace, '#pop'),
 
1860
            (r'(/)(\[' + _dot + '*?\])(' + _dot + '*\n)',
 
1861
             bygroups(Comment, Comment.Special, Comment),
 
1862
             '#pop'),
 
1863
            (r'/' + _dot + '*\n', _starts_block(Comment, 'html-comment-block'),
 
1864
             '#pop'),
 
1865
            (r'-#' + _dot + '*\n', _starts_block(Comment.Preproc,
 
1866
                                                 'scaml-comment-block'), '#pop'),
 
1867
            (r'(-@\s*)(import)?(' + _dot + '*\n)',
 
1868
             bygroups(Punctuation, Keyword, using(ScalaLexer)),
 
1869
             '#pop'),
 
1870
            (r'(-)(' + _dot + '*\n)',
 
1871
             bygroups(Punctuation, using(ScalaLexer)),
 
1872
             '#pop'),
 
1873
            (r':' + _dot + '*\n', _starts_block(Name.Decorator, 'filter-block'),
 
1874
             '#pop'),
 
1875
            (r'[a-z0-9_:-]+', Name.Tag, 'tag'),
 
1876
            (r'|', Text, 'eval-or-plain'),
 
1877
        ],
 
1878
 
 
1879
        'tag': [
 
1880
            include('css'),
 
1881
            (r'\{(,\n|' + _dot + ')*?\}', using(ScalaLexer)),
 
1882
            (r'\[' + _dot + '*?\]', using(ScalaLexer)),
 
1883
            (r'\(', Text, 'html-attributes'),
 
1884
            (r'/[ \t]*\n', Punctuation, '#pop:2'),
 
1885
            (r'[<>]{1,2}(?=[ \t=])', Punctuation),
 
1886
            include('eval-or-plain'),
 
1887
        ],
 
1888
 
 
1889
        'plain': [
 
1890
            (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text),
 
1891
            (r'(#\{)(' + _dot + '*?)(\})',
 
1892
             bygroups(String.Interpol, using(ScalaLexer), String.Interpol)),
 
1893
            (r'\n', Text, 'root'),
 
1894
        ],
 
1895
 
 
1896
        'html-attributes': [
 
1897
            (r'\s+', Text),
 
1898
            (r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'),
 
1899
            (r'[a-z0-9_:-]+', Name.Attribute),
 
1900
            (r'\)', Text, '#pop'),
 
1901
        ],
 
1902
 
 
1903
        'html-attribute-value': [
 
1904
            (r'[ \t]+', Text),
 
1905
            (r'[a-z0-9_]+', Name.Variable, '#pop'),
 
1906
            (r'@[a-z0-9_]+', Name.Variable.Instance, '#pop'),
 
1907
            (r'\$[a-z0-9_]+', Name.Variable.Global, '#pop'),
 
1908
            (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'),
 
1909
            (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'),
 
1910
        ],
 
1911
 
 
1912
        'html-comment-block': [
 
1913
            (_dot + '+', Comment),
 
1914
            (r'\n', Text, 'root'),
 
1915
        ],
 
1916
 
 
1917
        'scaml-comment-block': [
 
1918
            (_dot + '+', Comment.Preproc),
 
1919
            (r'\n', Text, 'root'),
 
1920
        ],
 
1921
 
 
1922
        'filter-block': [
 
1923
            (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator),
 
1924
            (r'(#\{)(' + _dot + '*?)(\})',
 
1925
             bygroups(String.Interpol, using(ScalaLexer), String.Interpol)),
 
1926
            (r'\n', Text, 'root'),
 
1927
        ],
 
1928
    }
 
1929
 
 
1930
 
 
1931
class XQueryLexer(ExtendedRegexLexer):
 
1932
    """
 
1933
    An XQuery lexer, parsing a stream and outputting the tokens needed to
 
1934
    highlight xquery code.
 
1935
 
 
1936
    *New in Pygments 1.4.*
 
1937
    """
 
1938
    name = 'XQuery'
 
1939
    aliases = ['xquery', 'xqy']
 
1940
    filenames = ['*.xqy', '*.xquery']
 
1941
    mimetypes = ['text/xquery', 'application/xquery']
 
1942
 
 
1943
    xquery_parse_state = []
 
1944
 
 
1945
    # FIX UNICODE LATER
 
1946
    #ncnamestartchar = (
 
1947
    #    ur"[A-Z]|_|[a-z]|[\u00C0-\u00D6]|[\u00D8-\u00F6]|[\u00F8-\u02FF]|"
 
1948
    #    ur"[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|"
 
1949
    #    ur"[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]|"
 
1950
    #    ur"[\u10000-\uEFFFF]"
 
1951
    #)
 
1952
    ncnamestartchar = r"[A-Z]|_|[a-z]"
 
1953
    # FIX UNICODE LATER
 
1954
    #ncnamechar = ncnamestartchar + (ur"|-|\.|[0-9]|\u00B7|[\u0300-\u036F]|"
 
1955
    #                                ur"[\u203F-\u2040]")
 
1956
    ncnamechar = ncnamestartchar + r"|-|\.|[0-9]"
 
1957
    ncname = "((%s)+(%s)*)" % (ncnamestartchar, ncnamechar)
 
1958
    pitarget_namestartchar = r"[A-KN-WY-Z]|_|:|[a-kn-wy-z]"
 
1959
    pitarget_namechar = pitarget_namestartchar + r"|-|\.|[0-9]"
 
1960
    pitarget = "(%s)+(%s)*" % (pitarget_namestartchar, pitarget_namechar)
 
1961
    prefixedname = "%s:%s" % (ncname, ncname)
 
1962
    unprefixedname = ncname
 
1963
    qname = "((%s)|(%s))" %(prefixedname, unprefixedname)
 
1964
 
 
1965
    entityref = r'&(lt|gt|amp|quot|apos|nbsp);'
 
1966
    charref = r'&#[0-9]+;|&#x[0-9a-fA-F]+;'
 
1967
 
 
1968
    stringdouble = r'("((' + entityref + r')|(' + charref + r')|("")|([^&"]))*")'
 
1969
    stringsingle = r"('((" + entityref + r")|(" + charref + r")|('')|([^&']))*')"
 
1970
 
 
1971
    # FIX UNICODE LATER
 
1972
    #elementcontentchar = (ur'\t|\r|\n|[\u0020-\u0025]|[\u0028-\u003b]|'
 
1973
    #                      ur'[\u003d-\u007a]|\u007c|[\u007e-\u007F]')
 
1974
    elementcontentchar = r'[A-Za-z]|\s|\d|[!"#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_\'`\|~]'
 
1975
    #quotattrcontentchar = (ur'\t|\r|\n|[\u0020-\u0021]|[\u0023-\u0025]|'
 
1976
    #                       ur'[\u0027-\u003b]|[\u003d-\u007a]|\u007c|[\u007e-\u007F]')
 
1977
    quotattrcontentchar = r'[A-Za-z]|\s|\d|[!#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_\'`\|~]'
 
1978
    #aposattrcontentchar = (ur'\t|\r|\n|[\u0020-\u0025]|[\u0028-\u003b]|'
 
1979
    #                       ur'[\u003d-\u007a]|\u007c|[\u007e-\u007F]')
 
1980
    aposattrcontentchar = r'[A-Za-z]|\s|\d|[!"#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_`\|~]'
 
1981
 
 
1982
 
 
1983
    # CHAR elements - fix the above elementcontentchar, quotattrcontentchar,
 
1984
    #                 aposattrcontentchar
 
1985
    #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
 
1986
 
 
1987
    flags = re.DOTALL | re.MULTILINE | re.UNICODE
 
1988
 
 
1989
    def operator_root_callback(lexer, match, ctx):
 
1990
        yield match.start(), Operator, match.group(1)
 
1991
        # transition to root always - don't pop off stack
 
1992
        ctx.stack = ['root']
 
1993
        ctx.pos = match.end()
 
1994
 
 
1995
    def popstate_tag_callback(lexer, match, ctx):
 
1996
        yield match.start(), Name.Tag, match.group(1)
 
1997
        ctx.stack.append(lexer.xquery_parse_state.pop())
 
1998
        ctx.pos = match.end()
 
1999
 
 
2000
    def popstate_xmlcomment_callback(lexer, match, ctx):
 
2001
        yield match.start(), String.Doc, match.group(1)
 
2002
        ctx.stack.append(lexer.xquery_parse_state.pop())
 
2003
        ctx.pos = match.end()
 
2004
 
 
2005
    def popstate_kindtest_callback(lexer, match, ctx):
 
2006
        yield match.start(), Punctuation, match.group(1)
 
2007
        next_state = lexer.xquery_parse_state.pop()
 
2008
        if next_state == 'occurrenceindicator':
 
2009
            if re.match("[?*+]+", match.group(2)):
 
2010
                yield match.start(), Punctuation, match.group(2)
 
2011
                ctx.stack.append('operator')
 
2012
                ctx.pos = match.end()
 
2013
            else:
 
2014
                ctx.stack.append('operator')
 
2015
                ctx.pos = match.end(1)
 
2016
        else:
 
2017
            ctx.stack.append(next_state)
 
2018
            ctx.pos = match.end(1)
 
2019
 
 
2020
    def popstate_callback(lexer, match, ctx):
 
2021
        yield match.start(), Punctuation, match.group(1)
 
2022
        # if we have run out of our state stack, pop whatever is on the pygments
 
2023
        # state stack
 
2024
        if len(lexer.xquery_parse_state) == 0:
 
2025
            ctx.stack.pop()
 
2026
        elif len(ctx.stack) > 1:
 
2027
            ctx.stack.append(lexer.xquery_parse_state.pop())
 
2028
        else:
 
2029
            # i don't know if i'll need this, but in case, default back to root
 
2030
            ctx.stack = ['root']
 
2031
        ctx.pos = match.end()
 
2032
 
 
2033
    def pushstate_element_content_starttag_callback(lexer, match, ctx):
 
2034
        yield match.start(), Name.Tag, match.group(1)
 
2035
        lexer.xquery_parse_state.append('element_content')
 
2036
        ctx.stack.append('start_tag')
 
2037
        ctx.pos = match.end()
 
2038
 
 
2039
    def pushstate_cdata_section_callback(lexer, match, ctx):
 
2040
        yield match.start(), String.Doc, match.group(1)
 
2041
        ctx.stack.append('cdata_section')
 
2042
        lexer.xquery_parse_state.append(ctx.state.pop)
 
2043
        ctx.pos = match.end()
 
2044
 
 
2045
    def pushstate_starttag_callback(lexer, match, ctx):
 
2046
        yield match.start(), Name.Tag, match.group(1)
 
2047
        lexer.xquery_parse_state.append(ctx.state.pop)
 
2048
        ctx.stack.append('start_tag')
 
2049
        ctx.pos = match.end()
 
2050
 
 
2051
    def pushstate_operator_order_callback(lexer, match, ctx):
 
2052
        yield match.start(), Keyword, match.group(1)
 
2053
        yield match.start(), Text, match.group(2)
 
2054
        yield match.start(), Punctuation, match.group(3)
 
2055
        ctx.stack = ['root']
 
2056
        lexer.xquery_parse_state.append('operator')
 
2057
        ctx.pos = match.end()
 
2058
 
 
2059
    def pushstate_operator_root_validate(lexer, match, ctx):
 
2060
        yield match.start(), Keyword, match.group(1)
 
2061
        yield match.start(), Text, match.group(2)
 
2062
        yield match.start(), Punctuation, match.group(3)
 
2063
        ctx.stack = ['root']
 
2064
        lexer.xquery_parse_state.append('operator')
 
2065
        ctx.pos = match.end()
 
2066
 
 
2067
    def pushstate_operator_root_validate_withmode(lexer, match, ctx):
 
2068
        yield match.start(), Keyword, match.group(1)
 
2069
        yield match.start(), Text, match.group(2)
 
2070
        yield match.start(), Keyword, match.group(3)
 
2071
        ctx.stack = ['root']
 
2072
        lexer.xquery_parse_state.append('operator')
 
2073
        ctx.pos = match.end()
 
2074
 
 
2075
    def pushstate_operator_processing_instruction_callback(lexer, match, ctx):
 
2076
        yield match.start(), String.Doc, match.group(1)
 
2077
        ctx.stack.append('processing_instruction')
 
2078
        lexer.xquery_parse_state.append('operator')
 
2079
        ctx.pos = match.end()
 
2080
 
 
2081
    def pushstate_element_content_processing_instruction_callback(lexer, match, ctx):
 
2082
        yield match.start(), String.Doc, match.group(1)
 
2083
        ctx.stack.append('processing_instruction')
 
2084
        lexer.xquery_parse_state.append('element_content')
 
2085
        ctx.pos = match.end()
 
2086
 
 
2087
    def pushstate_element_content_cdata_section_callback(lexer, match, ctx):
 
2088
        yield match.start(), String.Doc, match.group(1)
 
2089
        ctx.stack.append('cdata_section')
 
2090
        lexer.xquery_parse_state.append('element_content')
 
2091
        ctx.pos = match.end()
 
2092
 
 
2093
    def pushstate_operator_cdata_section_callback(lexer, match, ctx):
 
2094
        yield match.start(), String.Doc, match.group(1)
 
2095
        ctx.stack.append('cdata_section')
 
2096
        lexer.xquery_parse_state.append('operator')
 
2097
        ctx.pos = match.end()
 
2098
 
 
2099
    def pushstate_element_content_xmlcomment_callback(lexer, match, ctx):
 
2100
        yield match.start(), String.Doc, match.group(1)
 
2101
        ctx.stack.append('xml_comment')
 
2102
        lexer.xquery_parse_state.append('element_content')
 
2103
        ctx.pos = match.end()
 
2104
 
 
2105
    def pushstate_operator_xmlcomment_callback(lexer, match, ctx):
 
2106
        yield match.start(), String.Doc, match.group(1)
 
2107
        ctx.stack.append('xml_comment')
 
2108
        lexer.xquery_parse_state.append('operator')
 
2109
        ctx.pos = match.end()
 
2110
 
 
2111
    def pushstate_kindtest_callback(lexer, match, ctx):
 
2112
        yield match.start(), Keyword, match.group(1)
 
2113
        yield match.start(), Text, match.group(2)
 
2114
        yield match.start(), Punctuation, match.group(3)
 
2115
        lexer.xquery_parse_state.append('kindtest')
 
2116
        ctx.stack.append('kindtest')
 
2117
        ctx.pos = match.end()
 
2118
 
 
2119
    def pushstate_operator_kindtestforpi_callback(lexer, match, ctx):
 
2120
        yield match.start(), Keyword, match.group(1)
 
2121
        yield match.start(), Text, match.group(2)
 
2122
        yield match.start(), Punctuation, match.group(3)
 
2123
        lexer.xquery_parse_state.append('operator')
 
2124
        ctx.stack.append('kindtestforpi')
 
2125
        ctx.pos = match.end()
 
2126
 
 
2127
    def pushstate_operator_kindtest_callback(lexer, match, ctx):
 
2128
        yield match.start(), Keyword, match.group(1)
 
2129
        yield match.start(), Text, match.group(2)
 
2130
        yield match.start(), Punctuation, match.group(3)
 
2131
        lexer.xquery_parse_state.append('operator')
 
2132
        ctx.stack.append('kindtest')
 
2133
        ctx.pos = match.end()
 
2134
 
 
2135
    def pushstate_occurrenceindicator_kindtest_callback(lexer, match, ctx):
 
2136
        yield match.start(), Name.Tag, match.group(1)
 
2137
        yield match.start(), Text, match.group(2)
 
2138
        yield match.start(), Punctuation, match.group(3)
 
2139
        lexer.xquery_parse_state.append('occurrenceindicator')
 
2140
        ctx.stack.append('kindtest')
 
2141
        ctx.pos = match.end()
 
2142
 
 
2143
    def pushstate_operator_starttag_callback(lexer, match, ctx):
 
2144
        yield match.start(), Name.Tag, match.group(1)
 
2145
        lexer.xquery_parse_state.append('operator')
 
2146
        ctx.stack.append('start_tag')
 
2147
        ctx.pos = match.end()
 
2148
 
 
2149
    def pushstate_operator_root_callback(lexer, match, ctx):
 
2150
        yield match.start(), Punctuation, match.group(1)
 
2151
        lexer.xquery_parse_state.append('operator')
 
2152
        ctx.stack = ['root']#.append('root')
 
2153
        ctx.pos = match.end()
 
2154
 
 
2155
    def pushstate_operator_root_construct_callback(lexer, match, ctx):
 
2156
        yield match.start(), Keyword, match.group(1)
 
2157
        yield match.start(), Text, match.group(2)
 
2158
        yield match.start(), Punctuation, match.group(3)
 
2159
        lexer.xquery_parse_state.append('operator')
 
2160
        ctx.stack = ['root']
 
2161
        ctx.pos = match.end()
 
2162
 
 
2163
    def pushstate_root_callback(lexer, match, ctx):
 
2164
        yield match.start(), Punctuation, match.group(1)
 
2165
        cur_state = ctx.stack.pop()
 
2166
        lexer.xquery_parse_state.append(cur_state)
 
2167
        ctx.stack = ['root']#.append('root')
 
2168
        ctx.pos = match.end()
 
2169
 
 
2170
    def pushstate_operator_callback(lexer, match, ctx):
 
2171
        yield match.start(), Keyword, match.group(1)
 
2172
        yield match.start(), Text, match.group(2)
 
2173
        yield match.start(), Punctuation, match.group(3)
 
2174
        lexer.xquery_parse_state.append('operator')
 
2175
        ctx.pos = match.end()
 
2176
 
 
2177
    tokens = {
 
2178
        'comment': [
 
2179
            # xquery comments
 
2180
            (r'(:\))', Comment, '#pop'),
 
2181
            (r'(\(:)', Comment, '#push'),
 
2182
            (r'[^:)]', Comment),
 
2183
            (r'([^:)]|:|\))', Comment),
 
2184
        ],
 
2185
        'whitespace': [
 
2186
            (r'\s+', Text),
 
2187
        ],
 
2188
        'operator': [
 
2189
            include('whitespace'),
 
2190
            (r'(\})', popstate_callback),
 
2191
            (r'\(:', Comment, 'comment'),
 
2192
 
 
2193
            (r'(\{)', pushstate_root_callback),
 
2194
            (r'then|else|external|at|div|except', Keyword, 'root'),
 
2195
            (r'is|mod|order\s+by|stable\s+order\s+by', Keyword, 'root'),
 
2196
            (r'and|or', Operator.Word, 'root'),
 
2197
            (r'(eq|ge|gt|le|lt|ne|idiv|intersect|in)(?=\b)',
 
2198
             Operator.Word, 'root'),
 
2199
            (r'return|satisfies|to|union|where|preserve\s+strip',
 
2200
             Keyword, 'root'),
 
2201
            (r'(::|;|>=|>>|>|\[|<=|<<|<|-|\*|!=|\+|//|/|\||:=|,|=)',
 
2202
             operator_root_callback),
 
2203
            (r'(castable|cast)(\s+)(as)',
 
2204
             bygroups(Keyword, Text, Keyword), 'singletype'),
 
2205
            (r'(instance)(\s+)(of)|(treat)(\s+)(as)',
 
2206
             bygroups(Keyword, Text, Keyword), 'itemtype'),
 
2207
            (r'(case)|(as)', Keyword, 'itemtype'),
 
2208
            (r'(\))(\s*)(as)',
 
2209
             bygroups(Punctuation, Text, Keyword), 'itemtype'),
 
2210
            (r'\$', Name.Variable, 'varname'),
 
2211
            (r'(for|let)(\s+)(\$)',
 
2212
             bygroups(Keyword, Text, Name.Variable), 'varname'),
 
2213
            #(r'\)|\?|\]', Punctuation, '#push'),
 
2214
            (r'\)|\?|\]', Punctuation),
 
2215
            (r'(empty)(\s+)(greatest|least)', bygroups(Keyword, Text, Keyword)),
 
2216
            (r'ascending|descending|default', Keyword, '#push'),
 
2217
            (r'external', Keyword),
 
2218
            (r'collation', Keyword, 'uritooperator'),
 
2219
            # finally catch all string literals and stay in operator state
 
2220
            (stringdouble, String.Double),
 
2221
            (stringsingle, String.Single),
 
2222
 
 
2223
            (r'(catch)(\s*)', bygroups(Keyword, Text), 'root'),
 
2224
        ],
 
2225
        'uritooperator': [
 
2226
            (stringdouble, String.Double, '#pop'),
 
2227
            (stringsingle, String.Single, '#pop'),
 
2228
        ],
 
2229
        'namespacedecl': [
 
2230
            include('whitespace'),
 
2231
            (r'\(:', Comment, 'comment'),
 
2232
            (r'(at)(\s+)'+stringdouble, bygroups(Keyword, Text, String.Double)),
 
2233
            (r"(at)(\s+)"+stringsingle, bygroups(Keyword, Text, String.Single)),
 
2234
            (stringdouble, String.Double),
 
2235
            (stringsingle, String.Single),
 
2236
            (r',', Punctuation),
 
2237
            (r'=', Operator),
 
2238
            (r';', Punctuation, 'root'),
 
2239
            (ncname, Name.Namespace),
 
2240
        ],
 
2241
        'namespacekeyword': [
 
2242
            include('whitespace'),
 
2243
            (r'\(:', Comment, 'comment'),
 
2244
            (stringdouble, String.Double, 'namespacedecl'),
 
2245
            (stringsingle, String.Single, 'namespacedecl'),
 
2246
            (r'inherit|no-inherit', Keyword, 'root'),
 
2247
            (r'namespace', Keyword, 'namespacedecl'),
 
2248
            (r'(default)(\s+)(element)', bygroups(Keyword, Text, Keyword)),
 
2249
            (r'preserve|no-preserve', Keyword),
 
2250
            (r',', Punctuation),
 
2251
        ],
 
2252
        'varname': [
 
2253
            (r'\(:', Comment, 'comment'),
 
2254
            (qname, Name.Variable, 'operator'),
 
2255
        ],
 
2256
        'singletype': [
 
2257
            (r'\(:', Comment, 'comment'),
 
2258
            (ncname + r'(:\*)', Name.Variable, 'operator'),
 
2259
            (qname, Name.Variable, 'operator'),
 
2260
        ],
 
2261
        'itemtype': [
 
2262
            include('whitespace'),
 
2263
            (r'\(:', Comment, 'comment'),
 
2264
            (r'\$', Punctuation, 'varname'),
 
2265
            (r'void\s*\(\s*\)',
 
2266
             bygroups(Keyword, Text, Punctuation, Text, Punctuation), 'operator'),
 
2267
            (r'(element|attribute|schema-element|schema-attribute|comment|text|'
 
2268
             r'node|binary|document-node)(\s*)(\()',
 
2269
             pushstate_occurrenceindicator_kindtest_callback),
 
2270
            # Marklogic specific type?
 
2271
            (r'(processing-instruction)(\s*)(\()',
 
2272
             bygroups(Keyword, Text, Punctuation),
 
2273
             ('occurrenceindicator', 'kindtestforpi')),
 
2274
            (r'(item)(\s*)(\()(\s*)(\))(?=[*+?])',
 
2275
             bygroups(Keyword, Text, Punctuation, Text, Punctuation),
 
2276
             'occurrenceindicator'),
 
2277
            (r'\(\#', Punctuation, 'pragma'),
 
2278
            (r';', Punctuation, '#pop'),
 
2279
            (r'then|else', Keyword, '#pop'),
 
2280
            (r'(at)(\s+)' + stringdouble,
 
2281
             bygroups(Keyword, Text, String.Double), 'namespacedecl'),
 
2282
            (r'(at)(\s+)' + stringsingle,
 
2283
             bygroups(Keyword, Text, String.Single), 'namespacedecl'),
 
2284
            (r'except|intersect|in|is|return|satisfies|to|union|where',
 
2285
             Keyword, 'root'),
 
2286
            (r'and|div|eq|ge|gt|le|lt|ne|idiv|mod|or', Operator.Word, 'root'),
 
2287
            (r':=|=|,|>=|>>|>|\[|\(|<=|<<|<|-|!=|\|', Operator, 'root'),
 
2288
            (r'external|at', Keyword, 'root'),
 
2289
            (r'(stable)(\s+)(order)(\s+)(by)',
 
2290
             bygroups(Keyword, Text, Keyword, Text, Keyword), 'root'),
 
2291
            (r'(castable|cast)(\s+)(as)',
 
2292
             bygroups(Keyword, Text, Keyword), 'singletype'),
 
2293
            (r'(instance)(\s+)(of)|(treat)(\s+)(as)',
 
2294
             bygroups(Keyword, Text, Keyword)),
 
2295
            (r'case|as', Keyword, 'itemtype'),
 
2296
            (r'(\))(\s*)(as)', bygroups(Operator, Text, Keyword), 'itemtype'),
 
2297
            (ncname + r'(:\*)', Keyword.Type, 'operator'),
 
2298
            (qname, Keyword.Type, 'occurrenceindicator'),
 
2299
        ],
 
2300
        'kindtest': [
 
2301
            (r'\(:', Comment, 'comment'),
 
2302
            (r'({)', Punctuation, 'root'),
 
2303
            (r'(\))([*+?]?)', popstate_kindtest_callback),
 
2304
            (r'\*', Name, 'closekindtest'),
 
2305
            (qname, Name, 'closekindtest'),
 
2306
            (r'(element|schema-element)(\s*)(\()', pushstate_kindtest_callback),
 
2307
        ],
 
2308
        'kindtestforpi': [
 
2309
            (r'\(:', Comment, 'comment'),
 
2310
            (r'\)', Punctuation, '#pop'),
 
2311
            (ncname, bygroups(Name.Variable, Name.Variable)),
 
2312
            (stringdouble, String.Double),
 
2313
            (stringsingle, String.Single),
 
2314
        ],
 
2315
        'closekindtest': [
 
2316
            (r'\(:', Comment, 'comment'),
 
2317
            (r'(\))', popstate_callback),
 
2318
            (r',', Punctuation),
 
2319
            (r'(\{)', pushstate_operator_root_callback),
 
2320
            (r'\?', Punctuation),
 
2321
        ],
 
2322
        'xml_comment': [
 
2323
            (r'(-->)', popstate_xmlcomment_callback),
 
2324
            (r'[^-]{1,2}', Literal),
 
2325
            (r'\u009|\u00A|\u00D|[\u0020-\u00D7FF]|[\u00E000-\u00FFFD]|'
 
2326
             r'[\u0010000-\u0010FFFF]', Literal),
 
2327
        ],
 
2328
        'processing_instruction': [
 
2329
            (r'\s+', Text, 'processing_instruction_content'),
 
2330
            (r'\?>', String.Doc, '#pop'),
 
2331
            (pitarget, Name),
 
2332
        ],
 
2333
        'processing_instruction_content': [
 
2334
            (r'\?>', String.Doc, '#pop'),
 
2335
            (r'\u009|\u00A|\u00D|[\u0020-\uD7FF]|[\uE000-\uFFFD]|'
 
2336
             r'[\u10000-\u10FFFF]', Literal),
 
2337
        ],
 
2338
        'cdata_section': [
 
2339
            (r']]>', String.Doc, '#pop'),
 
2340
            (r'\u009|\u00A|\u00D|[\u0020-\uD7FF]|[\uE000-\uFFFD]|'
 
2341
             r'[\u10000-\u10FFFF]', Literal),
 
2342
        ],
 
2343
        'start_tag': [
 
2344
            include('whitespace'),
 
2345
            (r'(/>)', popstate_tag_callback),
 
2346
            (r'>', Name.Tag, 'element_content'),
 
2347
            (r'"', Punctuation, 'quot_attribute_content'),
 
2348
            (r"'", Punctuation, 'apos_attribute_content'),
 
2349
            (r'=', Operator),
 
2350
            (qname, Name.Tag),
 
2351
        ],
 
2352
        'quot_attribute_content': [
 
2353
            (r'"', Punctuation, 'start_tag'),
 
2354
            (r'(\{)', pushstate_root_callback),
 
2355
            (r'""', Name.Attribute),
 
2356
            (quotattrcontentchar, Name.Attribute),
 
2357
            (entityref, Name.Attribute),
 
2358
            (charref, Name.Attribute),
 
2359
            (r'\{\{|\}\}', Name.Attribute),
 
2360
        ],
 
2361
        'apos_attribute_content': [
 
2362
            (r"'", Punctuation, 'start_tag'),
 
2363
            (r'\{', Punctuation, 'root'),
 
2364
            (r"''", Name.Attribute),
 
2365
            (aposattrcontentchar, Name.Attribute),
 
2366
            (entityref, Name.Attribute),
 
2367
            (charref, Name.Attribute),
 
2368
            (r'\{\{|\}\}', Name.Attribute),
 
2369
        ],
 
2370
        'element_content': [
 
2371
            (r'</', Name.Tag, 'end_tag'),
 
2372
            (r'(\{)', pushstate_root_callback),
 
2373
            (r'(<!--)', pushstate_element_content_xmlcomment_callback),
 
2374
            (r'(<\?)', pushstate_element_content_processing_instruction_callback),
 
2375
            (r'(<!\[CDATA\[)', pushstate_element_content_cdata_section_callback),
 
2376
            (r'(<)', pushstate_element_content_starttag_callback),
 
2377
            (elementcontentchar, Literal),
 
2378
            (entityref, Literal),
 
2379
            (charref, Literal),
 
2380
            (r'\{\{|\}\}', Literal),
 
2381
        ],
 
2382
        'end_tag': [
 
2383
            include('whitespace'),
 
2384
            (r'(>)', popstate_tag_callback),
 
2385
            (qname, Name.Tag),
 
2386
        ],
 
2387
        'xmlspace_decl': [
 
2388
            (r'\(:', Comment, 'comment'),
 
2389
            (r'preserve|strip', Keyword, '#pop'),
 
2390
        ],
 
2391
        'declareordering': [
 
2392
            (r'\(:', Comment, 'comment'),
 
2393
            include('whitespace'),
 
2394
            (r'ordered|unordered', Keyword, '#pop'),
 
2395
        ],
 
2396
        'xqueryversion': [
 
2397
            include('whitespace'),
 
2398
            (r'\(:', Comment, 'comment'),
 
2399
            (stringdouble, String.Double),
 
2400
            (stringsingle, String.Single),
 
2401
            (r'encoding', Keyword),
 
2402
            (r';', Punctuation, '#pop'),
 
2403
        ],
 
2404
        'pragma': [
 
2405
            (qname, Name.Variable, 'pragmacontents'),
 
2406
        ],
 
2407
        'pragmacontents': [
 
2408
            (r'#\)', Punctuation, 'operator'),
 
2409
            (r'\u009|\u00A|\u00D|[\u0020-\u00D7FF]|[\u00E000-\u00FFFD]|'
 
2410
             r'[\u0010000-\u0010FFFF]', Literal),
 
2411
            (r'(\s*)', Text),
 
2412
        ],
 
2413
        'occurrenceindicator': [
 
2414
            include('whitespace'),
 
2415
            (r'\(:', Comment, 'comment'),
 
2416
            (r'\*|\?|\+', Operator, 'operator'),
 
2417
            (r':=', Operator, 'root'),
 
2418
            (r'', Text, 'operator'),
 
2419
        ],
 
2420
        'option': [
 
2421
            include('whitespace'),
 
2422
            (qname, Name.Variable, '#pop'),
 
2423
        ],
 
2424
        'qname_braren': [
 
2425
            include('whitespace'),
 
2426
            (r'(\{)', pushstate_operator_root_callback),
 
2427
            (r'(\()', Punctuation, 'root'),
 
2428
        ],
 
2429
        'element_qname': [
 
2430
            (qname, Name.Variable, 'root'),
 
2431
        ],
 
2432
        'attribute_qname': [
 
2433
            (qname, Name.Variable, 'root'),
 
2434
        ],
 
2435
        'root': [
 
2436
            include('whitespace'),
 
2437
            (r'\(:', Comment, 'comment'),
 
2438
 
 
2439
            # handle operator state
 
2440
            # order on numbers matters - handle most complex first
 
2441
            (r'\d+(\.\d*)?[eE][\+\-]?\d+', Number.Double, 'operator'),
 
2442
            (r'(\.\d+)[eE][\+\-]?\d+', Number.Double, 'operator'),
 
2443
            (r'(\.\d+|\d+\.\d*)', Number, 'operator'),
 
2444
            (r'(\d+)', Number.Integer, 'operator'),
 
2445
            (r'(\.\.|\.|\)|\*)', Punctuation, 'operator'),
 
2446
            (r'(declare)(\s+)(construction)',
 
2447
             bygroups(Keyword, Text, Keyword), 'operator'),
 
2448
            (r'(declare)(\s+)(default)(\s+)(order)',
 
2449
             bygroups(Keyword, Text, Keyword, Text, Keyword), 'operator'),
 
2450
            (ncname + ':\*', Name, 'operator'),
 
2451
            (stringdouble, String.Double, 'operator'),
 
2452
            (stringsingle, String.Single, 'operator'),
 
2453
 
 
2454
            (r'(\})', popstate_callback),
 
2455
 
 
2456
            #NAMESPACE DECL
 
2457
            (r'(declare)(\s+)(default)(\s+)(collation)',
 
2458
             bygroups(Keyword, Text, Keyword, Text, Keyword)),
 
2459
            (r'(module|declare)(\s+)(namespace)',
 
2460
             bygroups(Keyword, Text, Keyword), 'namespacedecl'),
 
2461
            (r'(declare)(\s+)(base-uri)',
 
2462
             bygroups(Keyword, Text, Keyword), 'namespacedecl'),
 
2463
 
 
2464
            #NAMESPACE KEYWORD
 
2465
            (r'(declare)(\s+)(default)(\s+)(element|function)',
 
2466
             bygroups(Keyword, Text, Keyword, Text, Keyword), 'namespacekeyword'),
 
2467
            (r'(import)(\s+)(schema|module)',
 
2468
             bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'namespacekeyword'),
 
2469
            (r'(declare)(\s+)(copy-namespaces)',
 
2470
             bygroups(Keyword, Text, Keyword), 'namespacekeyword'),
 
2471
 
 
2472
            #VARNAMEs
 
2473
            (r'(for|let|some|every)(\s+)(\$)',
 
2474
             bygroups(Keyword, Text, Name.Variable), 'varname'),
 
2475
            (r'\$', Name.Variable, 'varname'),
 
2476
            (r'(declare)(\s+)(variable)(\s+)(\$)',
 
2477
             bygroups(Keyword, Text, Keyword, Text, Name.Variable), 'varname'),
 
2478
 
 
2479
            #ITEMTYPE
 
2480
            (r'(\))(\s+)(as)', bygroups(Operator, Text, Keyword), 'itemtype'),
 
2481
 
 
2482
            (r'(element|attribute|schema-element|schema-attribute|comment|'
 
2483
             r'text|node|document-node)(\s+)(\()',
 
2484
             pushstate_operator_kindtest_callback),
 
2485
 
 
2486
            (r'(processing-instruction)(\s+)(\()',
 
2487
             pushstate_operator_kindtestforpi_callback),
 
2488
 
 
2489
            (r'(<!--)', pushstate_operator_xmlcomment_callback),
 
2490
 
 
2491
            (r'(<\?)', pushstate_operator_processing_instruction_callback),
 
2492
 
 
2493
            (r'(<!\[CDATA\[)', pushstate_operator_cdata_section_callback),
 
2494
 
 
2495
            # (r'</', Name.Tag, 'end_tag'),
 
2496
            (r'(<)', pushstate_operator_starttag_callback),
 
2497
 
 
2498
            (r'(declare)(\s+)(boundary-space)',
 
2499
             bygroups(Keyword, Text, Keyword), 'xmlspace_decl'),
 
2500
 
 
2501
            (r'(validate)(\s+)(lax|strict)',
 
2502
             pushstate_operator_root_validate_withmode),
 
2503
            (r'(validate)(\s*)(\{)', pushstate_operator_root_validate),
 
2504
            (r'(typeswitch)(\s*)(\()', bygroups(Keyword, Text, Punctuation)),
 
2505
            (r'(element|attribute)(\s*)(\{)',
 
2506
             pushstate_operator_root_construct_callback),
 
2507
 
 
2508
            (r'(document|text|processing-instruction|comment)(\s*)(\{)',
 
2509
             pushstate_operator_root_construct_callback),
 
2510
            #ATTRIBUTE
 
2511
            (r'(attribute)(\s+)(?=' + qname + r')',
 
2512
             bygroups(Keyword, Text), 'attribute_qname'),
 
2513
            #ELEMENT
 
2514
            (r'(element)(\s+)(?=' +qname+ r')',
 
2515
             bygroups(Keyword, Text), 'element_qname'),
 
2516
            #PROCESSING_INSTRUCTION
 
2517
            (r'(processing-instruction)(\s+)' + ncname + r'(\s*)(\{)',
 
2518
             bygroups(Keyword, Text, Name.Variable, Text, Punctuation), 'operator'),
 
2519
 
 
2520
            (r'(declare|define)(\s+)(function)',
 
2521
             bygroups(Keyword, Text, Keyword)),
 
2522
 
 
2523
            (r'(\{)', pushstate_operator_root_callback),
 
2524
 
 
2525
            (r'(unordered|ordered)(\s*)(\{)',
 
2526
             pushstate_operator_order_callback),
 
2527
 
 
2528
            (r'(declare)(\s+)(ordering)',
 
2529
             bygroups(Keyword, Text, Keyword), 'declareordering'),
 
2530
 
 
2531
            (r'(xquery)(\s+)(version)',
 
2532
             bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'xqueryversion'),
 
2533
 
 
2534
            (r'(\(#)', Punctuation, 'pragma'),
 
2535
 
 
2536
            # sometimes return can occur in root state
 
2537
            (r'return', Keyword),
 
2538
 
 
2539
            (r'(declare)(\s+)(option)', bygroups(Keyword, Text, Keyword),
 
2540
             'option'),
 
2541
 
 
2542
            #URI LITERALS - single and double quoted
 
2543
            (r'(at)(\s+)('+stringdouble+')', String.Double, 'namespacedecl'),
 
2544
            (r'(at)(\s+)('+stringsingle+')', String.Single, 'namespacedecl'),
 
2545
 
 
2546
            (r'(ancestor-or-self|ancestor|attribute|child|descendant-or-self)(::)',
 
2547
             bygroups(Keyword, Punctuation)),
 
2548
            (r'(descendant|following-sibling|following|parent|preceding-sibling'
 
2549
             r'|preceding|self)(::)', bygroups(Keyword, Punctuation)),
 
2550
 
 
2551
            (r'(if)(\s*)(\()', bygroups(Keyword, Text, Punctuation)),
 
2552
 
 
2553
            (r'then|else', Keyword),
 
2554
 
 
2555
            # ML specific
 
2556
            (r'(try)(\s*)', bygroups(Keyword, Text), 'root'),
 
2557
            (r'(catch)(\s*)(\()(\$)',
 
2558
             bygroups(Keyword, Text, Punctuation, Name.Variable), 'varname'),
 
2559
 
 
2560
            (r'@' + qname, Name.Attribute),
 
2561
            (r'@\*', Name.Attribute),
 
2562
            (r'@' + ncname, Name.Attribute),
 
2563
 
 
2564
            (r'//|/|\+|-|;|,|\(|\)', Punctuation),
 
2565
 
 
2566
            # STANDALONE QNAMES
 
2567
            (qname + r'(?=\s*[{])', Name.Variable, 'qname_braren'),
 
2568
            (qname + r'(?=\s*[(])', Name.Function, 'qname_braren'),
 
2569
            (qname, Name.Variable, 'operator'),
 
2570
        ]
 
2571
    }
 
2572