641
908
def analyse_text(text):
642
909
if looks_like_xml(text) and '<xsl' in text:
913
class MxmlLexer(RegexLexer):
916
Nested AS3 in <script> tags is highlighted by the appropriate lexer.
918
flags = re.MULTILINE | re.DOTALL
921
filenames = ['*.mxml']
922
mimetimes = ['text/xml', 'application/xml']
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),
938
('-->', Comment, '#pop'),
943
(r'[a-zA-Z0-9_.:-]+\s*=', Name.Attribute, 'attr'),
944
(r'/?\s*>', Name.Tag, '#pop'),
948
('".*?"', String, '#pop'),
949
("'.*?'", String, '#pop'),
950
(r'[^\s>]+', String, '#pop'),
955
class HaxeLexer(RegexLexer):
957
For haXe source code (http://haxe.org/).
961
aliases = ['hx', 'haXe']
963
mimetypes = ['text/haxe']
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)'
970
flags = re.DOTALL | re.MULTILINE
974
include('whitespace'),
976
(key_decl_mod, Keyword.Declaration),
985
(r'//.*?\n', Comment.Single),
986
(r'/\*.*?\*/', Comment.Multiline),
987
(r'#[^\n]*', Comment.Preproc),
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',
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),
1009
include('whitespace'),
1012
include('anonfundef'),
1013
include('literals'),
1015
include('codekeywords'),
1016
(r'[();,\[\]]', Punctuation),
1017
(r'(?:=|\+=|-=|\*=|/=|%=|&=|\|=|\^=|<<=|>>=|>>>=|\|\||&&|'
1018
r'\.\.\.|==|!=|>|<|>=|<=|\||&|\^|<<|>>|>>>|\+|\-|\*|/|%|'
1019
r'!|\+\+|\-\-|~|\.|\?|\:)',
1023
(r'}', Punctuation,'#pop'),
1024
(r'{', Punctuation,'#push'),
1027
# Instance/Block level constructs
1029
(r'(\()(' + key_prop + ')(,)(' + key_prop + ')(\))',
1030
bygroups(Punctuation, Keyword.Reserved, Punctuation,
1031
Keyword.Reserved, Punctuation)),
1034
(r'\bnew\b', Keyword, 'typedecl'),
1037
(r'\b(case)(\s+)(' + ident + ')(\s*)(\()',
1038
bygroups(Keyword.Reserved, Text, Name, Text, Punctuation),
1042
(r'\b(var)(\s+)(' + ident + ')',
1043
bygroups(Keyword.Declaration, Text, Name.Variable), 'vardecl'),
1046
include('whitespace'),
1047
include('typelabel'),
1048
(r'=', Operator,'#pop'),
1049
(r';', Punctuation,'#pop'),
1052
(key_decl_mod,Keyword.Declaration),
1053
(r'\b(var)(\s+)(' + ident + ')',
1054
bygroups(Keyword.Declaration, Text, Name.Variable.Instance),
1057
'instancevardecl': [
1059
include('propertydef'),
1063
(r'\bfunction\b', Keyword.Declaration, 'fundecl'),
1066
(key_decl_mod, Keyword.Declaration),
1067
(r'\b(function)(\s+)(' + ident + ')',
1068
bygroups(Keyword.Declaration, Text, Name.Function), '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'),
1080
include('whitespace'),
1081
(ident, Name.Variable),
1082
include('typelabel'),
1083
include('literals'),
1085
(r',', Punctuation),
1086
(r'\?', Punctuation),
1087
(r'\)', Punctuation, '#pop'),
1091
(r':', Punctuation, 'type'),
1094
include('whitespace'),
1095
(typeid, Name.Class),
1096
(r'<', Punctuation, 'generictypedecl'),
1097
(r'(?=[{}()=,a-z])', Text,'#pop'),
1100
include('whitespace'),
1101
(typeid, Name.Class),
1102
(r'<', Punctuation, 'generictypedecl'),
1103
(r'->', Keyword.Type),
1104
(r'(?=[{}(),;=])', Text, '#pop'),
1106
'generictypedecl': [
1107
include('whitespace'),
1108
(typeid, Name.Class),
1109
(r'<', Punctuation, '#push'),
1110
(r'>', Punctuation, '#pop'),
1111
(r',', Punctuation),
1114
# Top level constructs
1116
(r'(package|import|using)(\s+)([^;]+)(;)',
1117
bygroups(Keyword.Namespace, Text, Name.Namespace,Punctuation)),
1120
(r'typedef', Keyword.Declaration, ('typedefprebody', 'typedecl')),
1123
include('whitespace'),
1124
(r'(=)(\s*)({)', bygroups(Punctuation, Text, Punctuation),
1125
('#pop', 'typedefbody')),
1128
(r'enum', Keyword.Declaration, ('enumdefprebody', 'typedecl')),
1131
include('whitespace'),
1132
(r'{', Punctuation, ('#pop','enumdefbody')),
1135
(r'class', Keyword.Declaration, ('classdefprebody', 'typedecl')),
1137
'classdefprebody': [
1138
include('whitespace'),
1139
(r'(extends|implements)', Keyword.Declaration,'typedecl'),
1140
(r'{', Punctuation, ('#pop', 'classdefbody')),
1143
(r'interface', Keyword.Declaration,
1144
('interfacedefprebody', 'typedecl')),
1146
'interfacedefprebody': [
1147
include('whitespace'),
1148
(r'(extends)', Keyword.Declaration, 'typedecl'),
1149
(r'{', Punctuation, ('#pop', 'classdefbody')),
1153
include('whitespace'),
1154
include('instancevardef'),
1155
include('instancefundef'),
1156
(r'>', Punctuation, 'typedecl'),
1157
(r',', Punctuation),
1158
(r'}', Punctuation, '#pop'),
1161
include('whitespace'),
1162
(ident, Name.Variable.Instance),
1163
(r'\(', Punctuation, 'funargdecl'),
1164
(r';', Punctuation),
1165
(r'}', Punctuation, '#pop'),
1168
include('whitespace'),
1169
include('instancevardef'),
1170
include('instancefundef'),
1171
(r'}', Punctuation, '#pop'),
1172
include('codeblock'),
1176
def analyse_text(text):
1177
if re.match(r'\w+\s*:\s*\w', text): return 0.3
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()
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)
1191
ctx.block_state = None
1192
ctx.block_indentation = None
1193
ctx.stack.append('content')
1195
def _starts_block(token, state):
1196
def callback(lexer, match, ctx):
1197
yield match.start(), token, match.group(0)
1199
if hasattr(ctx, 'last_indentation'):
1200
ctx.block_indentation = ctx.last_indentation
1202
ctx.block_indentation = ''
1204
ctx.block_state = state
1205
ctx.pos = match.end()
1210
class HamlLexer(ExtendedRegexLexer):
1214
*New in Pygments 1.3.*
1218
aliases = ['haml', 'HAML']
1219
filenames = ['*.haml']
1220
mimetypes = ['text/x-haml']
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(?=.* \|)|.)'
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 + ')'
1233
(r'[ \t]*\n', Text),
1234
(r'[ \t]*', _indentation),
1238
(r'\.[a-z0-9_:-]+', Name.Class, 'tag'),
1239
(r'\#[a-z0-9_:-]+', Name.Function, 'tag'),
1243
(r'[&!]?==', Punctuation, 'plain'),
1244
(r'([&!]?[=~])(' + _comma_dot + '*\n)',
1245
bygroups(Punctuation, using(RubyLexer)),
1247
(r'', Text, 'plain'),
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),
1257
(r'/' + _dot + '*\n', _starts_block(Comment, 'html-comment-block'),
1259
(r'-#' + _dot + '*\n', _starts_block(Comment.Preproc,
1260
'haml-comment-block'), '#pop'),
1261
(r'(-)(' + _comma_dot + '*\n)',
1262
bygroups(Punctuation, using(RubyLexer)),
1264
(r':' + _dot + '*\n', _starts_block(Name.Decorator, 'filter-block'),
1266
include('eval-or-plain'),
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'),
1280
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text),
1281
(r'(#\{)(' + _dot + '*?)(\})',
1282
bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
1283
(r'\n', Text, 'root'),
1286
'html-attributes': [
1288
(r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'),
1289
(r'[a-z0-9_:-]+', Name.Attribute),
1290
(r'\)', Text, '#pop'),
1293
'html-attribute-value': [
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'),
1302
'html-comment-block': [
1303
(_dot + '+', Comment),
1304
(r'\n', Text, 'root'),
1307
'haml-comment-block': [
1308
(_dot + '+', Comment.Preproc),
1309
(r'\n', Text, 'root'),
1313
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator),
1314
(r'(#\{)(' + _dot + '*?)(\})',
1315
bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
1316
(r'\n', Text, 'root'),
1321
common_sass_tokens = {
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),
1428
(r'\}', String.Interpol, '#pop'),
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'),
1440
(r'[~\^\*!&\[\]\(\)<>\|+=@:;,./?-]', Operator),
1441
(r'"', String.Double, 'string-double'),
1442
(r"'", String.Single, 'string-single'),
1446
(r'(\\.|#(?=[^\n{])|[^\n"#])+', String.Double),
1447
(r'#\{', String.Interpol, 'interpolation'),
1448
(r'"', String.Double, '#pop'),
1452
(r"(\\.|#(?=[^\n{])|[^\n'#])+", String.Double),
1453
(r'#\{', String.Interpol, 'interpolation'),
1454
(r"'", String.Double, '#pop'),
1458
(r'(\\#|#(?=[^\n{])|[^\n#)])+', String.Other),
1459
(r'#\{', String.Interpol, 'interpolation'),
1460
(r'\)', String.Other, '#pop'),
1464
(r'[\w-]+', Name.Decorator),
1465
(r'#\{', String.Interpol, 'interpolation'),
1466
(r'', Text, '#pop'),
1470
(r'[\w-]+', Name.Class),
1471
(r'#\{', String.Interpol, 'interpolation'),
1472
(r'', Text, '#pop'),
1476
(r'[\w-]+', Name.Namespace),
1477
(r'#\{', String.Interpol, 'interpolation'),
1478
(r'', Text, '#pop'),
1482
(r'(from|to|through)', Operator.Word),
1487
class SassLexer(ExtendedRegexLexer):
1489
For Sass stylesheets.
1491
*New in Pygments 1.3.*
1495
aliases = ['sass', 'SASS']
1496
filenames = ['*.sass']
1497
mimetypes = ['text/x-sass']
1499
flags = re.IGNORECASE
1502
(r'[ \t]*\n', Text),
1503
(r'[ \t]*', _indentation),
1507
(r'//[^\n]*', _starts_block(Comment.Single, 'single-comment'),
1509
(r'/\*[^\n]*', _starts_block(Comment.Multiline, 'multi-comment'),
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'),
1528
(r'.+', Comment.Single),
1529
(r'\n', Text, 'root'),
1533
(r'.+', Comment.Multiline),
1534
(r'\n', Text, 'root'),
1539
(r'[^\s]+', String),
1540
(r'\n', Text, 'root'),
1544
(r'[^\s:="\[]+', Name.Attribute),
1545
(r'#{', String.Interpol, 'interpolation'),
1546
(r'[ \t]*=', Operator, 'value'),
1547
(r'', Text, 'value'),
1551
(r'[^\s:="\[]+', Name.Attribute),
1552
(r'#{', String.Interpol, 'interpolation'),
1553
(r'[ \t]*[=:]', Operator, 'value'),
1557
(r"(\\#|#(?=[^\n{])|\*(?=[^\n/])|[^\n#*])+", Comment.Multiline),
1558
(r'#\{', String.Interpol, 'interpolation'),
1559
(r"\*/", Comment, '#pop'),
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'))
1568
class ScssLexer(RegexLexer):
1570
For SCSS stylesheets.
1575
filenames = ['*.scss']
1576
mimetypes = ['text/x-scss']
1578
flags = re.IGNORECASE | re.DOTALL
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'),
1598
(r'[^\s:="\[]+', Name.Attribute),
1599
(r'#{', String.Interpol, 'interpolation'),
1600
(r'[ \t]*:', Operator, 'value'),
1604
(r"(\\#|#(?=[^{])|\*(?=[^/])|[^#*])+", Comment.Multiline),
1605
(r'#\{', String.Interpol, 'interpolation'),
1606
(r"\*/", Comment, '#pop'),
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')])
1615
class CoffeeScriptLexer(RegexLexer):
1617
For `CoffeeScript`_ source code.
1619
.. _CoffeeScript: http://coffeescript.org
1621
*New in Pygments 1.3.*
1624
name = 'CoffeeScript'
1625
aliases = ['coffee-script', 'coffeescript']
1626
filenames = ['*.coffee']
1627
mimetypes = ['text/coffeescript']
1631
'commentsandwhitespace': [
1633
(r'#.*?\n', Comment.Single),
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'),
1643
('\n', Text, '#pop'),
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',
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',
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),
1677
class DuelLexer(RegexLexer):
1679
Lexer for Duel Views Engine (formerly JBST) markup with JavaScript code blocks.
1680
See http://duelengine.org/.
1681
See http://jsonml.org/jbst/.
1683
*New in Pygments 1.4.*
1687
aliases = ['duel', 'Duel Engine', 'Duel View', 'JBST', 'jbst', 'JsonML+BST']
1688
filenames = ['*.duel','*.jbst']
1689
mimetypes = ['text/x-duel','text/x-jbst']
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)),
1710
class ScamlLexer(ExtendedRegexLexer):
1712
For `Scaml markup <http://scalate.fusesource.org/>`_. Scaml is Haml for Scala.
1714
*New in Pygments 1.4.*
1718
aliases = ['scaml', 'SCAML']
1719
filenames = ['*.scaml']
1720
mimetypes = ['text/x-scaml']
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
1726
# _dot = r'(?: \|\n(?=.* \|)|.)'
1731
(r'[ \t]*\n', Text),
1732
(r'[ \t]*', _indentation),
1736
(r'\.[a-z0-9_:-]+', Name.Class, 'tag'),
1737
(r'\#[a-z0-9_:-]+', Name.Function, 'tag'),
1741
(r'[&!]?==', Punctuation, 'plain'),
1742
(r'([&!]?[=~])(' + _dot + '*\n)',
1743
bygroups(Punctuation, using(ScalaLexer)),
1745
(r'', Text, 'plain'),
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),
1755
(r'/' + _dot + '*\n', _starts_block(Comment, 'html-comment-block'),
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)),
1762
(r'(-)(' + _dot + '*\n)',
1763
bygroups(Punctuation, using(ScalaLexer)),
1765
(r':' + _dot + '*\n', _starts_block(Name.Decorator, 'filter-block'),
1767
include('eval-or-plain'),
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'),
1781
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text),
1782
(r'(#\{)(' + _dot + '*?)(\})',
1783
bygroups(String.Interpol, using(ScalaLexer), String.Interpol)),
1784
(r'\n', Text, 'root'),
1787
'html-attributes': [
1789
(r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'),
1790
(r'[a-z0-9_:-]+', Name.Attribute),
1791
(r'\)', Text, '#pop'),
1794
'html-attribute-value': [
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'),
1803
'html-comment-block': [
1804
(_dot + '+', Comment),
1805
(r'\n', Text, 'root'),
1808
'scaml-comment-block': [
1809
(_dot + '+', Comment.Preproc),
1810
(r'\n', Text, 'root'),
1814
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator),
1815
(r'(#\{)(' + _dot + '*?)(\})',
1816
bygroups(String.Interpol, using(ScalaLexer), String.Interpol)),
1817
(r'\n', Text, 'root'),
1822
class JadeLexer(ExtendedRegexLexer):
1825
Jade is a variant of Scaml, see:
1826
http://scalate.fusesource.org/documentation/scaml-reference.html
1828
*New in Pygments 1.4.*
1832
aliases = ['jade', 'JADE']
1833
filenames = ['*.jade']
1834
mimetypes = ['text/x-jade']
1836
flags = re.IGNORECASE
1841
(r'[ \t]*\n', Text),
1842
(r'[ \t]*', _indentation),
1846
(r'\.[a-z0-9_:-]+', Name.Class, 'tag'),
1847
(r'\#[a-z0-9_:-]+', Name.Function, 'tag'),
1851
(r'[&!]?==', Punctuation, 'plain'),
1852
(r'([&!]?[=~])(' + _dot + '*\n)',
1853
bygroups(Punctuation, using(ScalaLexer)), 'root'),
1854
(r'', Text, 'plain'),
1859
(r'!!!' + _dot + '*\n', Name.Namespace, '#pop'),
1860
(r'(/)(\[' + _dot + '*?\])(' + _dot + '*\n)',
1861
bygroups(Comment, Comment.Special, Comment),
1863
(r'/' + _dot + '*\n', _starts_block(Comment, 'html-comment-block'),
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)),
1870
(r'(-)(' + _dot + '*\n)',
1871
bygroups(Punctuation, using(ScalaLexer)),
1873
(r':' + _dot + '*\n', _starts_block(Name.Decorator, 'filter-block'),
1875
(r'[a-z0-9_:-]+', Name.Tag, 'tag'),
1876
(r'|', Text, 'eval-or-plain'),
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'),
1890
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text),
1891
(r'(#\{)(' + _dot + '*?)(\})',
1892
bygroups(String.Interpol, using(ScalaLexer), String.Interpol)),
1893
(r'\n', Text, 'root'),
1896
'html-attributes': [
1898
(r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'),
1899
(r'[a-z0-9_:-]+', Name.Attribute),
1900
(r'\)', Text, '#pop'),
1903
'html-attribute-value': [
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'),
1912
'html-comment-block': [
1913
(_dot + '+', Comment),
1914
(r'\n', Text, 'root'),
1917
'scaml-comment-block': [
1918
(_dot + '+', Comment.Preproc),
1919
(r'\n', Text, 'root'),
1923
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator),
1924
(r'(#\{)(' + _dot + '*?)(\})',
1925
bygroups(String.Interpol, using(ScalaLexer), String.Interpol)),
1926
(r'\n', Text, 'root'),
1931
class XQueryLexer(ExtendedRegexLexer):
1933
An XQuery lexer, parsing a stream and outputting the tokens needed to
1934
highlight xquery code.
1936
*New in Pygments 1.4.*
1939
aliases = ['xquery', 'xqy']
1940
filenames = ['*.xqy', '*.xquery']
1941
mimetypes = ['text/xquery', 'application/xquery']
1943
xquery_parse_state = []
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]"
1952
ncnamestartchar = r"[A-Z]|_|[a-z]"
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)
1965
entityref = r'&(lt|gt|amp|quot|apos|nbsp);'
1966
charref = r'&#[0-9]+;|&#x[0-9a-fA-F]+;'
1968
stringdouble = r'("((' + entityref + r')|(' + charref + r')|("")|([^&"]))*")'
1969
stringsingle = r"('((" + entityref + r")|(" + charref + r")|('')|([^&']))*')"
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|[!"#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_`\|~]'
1983
# CHAR elements - fix the above elementcontentchar, quotattrcontentchar,
1984
# aposattrcontentchar
1985
#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
1987
flags = re.DOTALL | re.MULTILINE | re.UNICODE
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()
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()
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()
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()
2014
ctx.stack.append('operator')
2015
ctx.pos = match.end(1)
2017
ctx.stack.append(next_state)
2018
ctx.pos = match.end(1)
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
2024
if len(lexer.xquery_parse_state) == 0:
2026
elif len(ctx.stack) > 1:
2027
ctx.stack.append(lexer.xquery_parse_state.pop())
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
2180
(r'(:\))', Comment, '#pop'),
2181
(r'(\(:)', Comment, '#push'),
2182
(r'[^:)]', Comment),
2183
(r'([^:)]|:|\))', Comment),
2189
include('whitespace'),
2190
(r'(\})', popstate_callback),
2191
(r'\(:', Comment, 'comment'),
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',
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'),
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),
2223
(r'(catch)(\s*)', bygroups(Keyword, Text), 'root'),
2226
(stringdouble, String.Double, '#pop'),
2227
(stringsingle, String.Single, '#pop'),
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),
2238
(r';', Punctuation, 'root'),
2239
(ncname, Name.Namespace),
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),
2253
(r'\(:', Comment, 'comment'),
2254
(qname, Name.Variable, 'operator'),
2257
(r'\(:', Comment, 'comment'),
2258
(ncname + r'(:\*)', Name.Variable, 'operator'),
2259
(qname, Name.Variable, 'operator'),
2262
include('whitespace'),
2263
(r'\(:', Comment, 'comment'),
2264
(r'\$', Punctuation, 'varname'),
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',
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'),
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),
2309
(r'\(:', Comment, 'comment'),
2310
(r'\)', Punctuation, '#pop'),
2311
(ncname, bygroups(Name.Variable, Name.Variable)),
2312
(stringdouble, String.Double),
2313
(stringsingle, String.Single),
2316
(r'\(:', Comment, 'comment'),
2317
(r'(\))', popstate_callback),
2318
(r',', Punctuation),
2319
(r'(\{)', pushstate_operator_root_callback),
2320
(r'\?', Punctuation),
2323
(r'(-->)', popstate_xmlcomment_callback),
2324
(r'[^-]{1,2}', Literal),
2325
(r'\u009|\u00A|\u00D|[\u0020-\u00D7FF]|[\u00E000-\u00FFFD]|'
2326
r'[\u0010000-\u0010FFFF]', Literal),
2328
'processing_instruction': [
2329
(r'\s+', Text, 'processing_instruction_content'),
2330
(r'\?>', String.Doc, '#pop'),
2333
'processing_instruction_content': [
2334
(r'\?>', String.Doc, '#pop'),
2335
(r'\u009|\u00A|\u00D|[\u0020-\uD7FF]|[\uE000-\uFFFD]|'
2336
r'[\u10000-\u10FFFF]', Literal),
2339
(r']]>', String.Doc, '#pop'),
2340
(r'\u009|\u00A|\u00D|[\u0020-\uD7FF]|[\uE000-\uFFFD]|'
2341
r'[\u10000-\u10FFFF]', Literal),
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'),
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),
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),
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),
2380
(r'\{\{|\}\}', Literal),
2383
include('whitespace'),
2384
(r'(>)', popstate_tag_callback),
2388
(r'\(:', Comment, 'comment'),
2389
(r'preserve|strip', Keyword, '#pop'),
2391
'declareordering': [
2392
(r'\(:', Comment, 'comment'),
2393
include('whitespace'),
2394
(r'ordered|unordered', Keyword, '#pop'),
2397
include('whitespace'),
2398
(r'\(:', Comment, 'comment'),
2399
(stringdouble, String.Double),
2400
(stringsingle, String.Single),
2401
(r'encoding', Keyword),
2402
(r';', Punctuation, '#pop'),
2405
(qname, Name.Variable, 'pragmacontents'),
2408
(r'#\)', Punctuation, 'operator'),
2409
(r'\u009|\u00A|\u00D|[\u0020-\u00D7FF]|[\u00E000-\u00FFFD]|'
2410
r'[\u0010000-\u0010FFFF]', Literal),
2413
'occurrenceindicator': [
2414
include('whitespace'),
2415
(r'\(:', Comment, 'comment'),
2416
(r'\*|\?|\+', Operator, 'operator'),
2417
(r':=', Operator, 'root'),
2418
(r'', Text, 'operator'),
2421
include('whitespace'),
2422
(qname, Name.Variable, '#pop'),
2425
include('whitespace'),
2426
(r'(\{)', pushstate_operator_root_callback),
2427
(r'(\()', Punctuation, 'root'),
2430
(qname, Name.Variable, 'root'),
2432
'attribute_qname': [
2433
(qname, Name.Variable, 'root'),
2436
include('whitespace'),
2437
(r'\(:', Comment, 'comment'),
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'),
2454
(r'(\})', popstate_callback),
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'),
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'),
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'),
2480
(r'(\))(\s+)(as)', bygroups(Operator, Text, Keyword), 'itemtype'),
2482
(r'(element|attribute|schema-element|schema-attribute|comment|'
2483
r'text|node|document-node)(\s+)(\()',
2484
pushstate_operator_kindtest_callback),
2486
(r'(processing-instruction)(\s+)(\()',
2487
pushstate_operator_kindtestforpi_callback),
2489
(r'(<!--)', pushstate_operator_xmlcomment_callback),
2491
(r'(<\?)', pushstate_operator_processing_instruction_callback),
2493
(r'(<!\[CDATA\[)', pushstate_operator_cdata_section_callback),
2495
# (r'</', Name.Tag, 'end_tag'),
2496
(r'(<)', pushstate_operator_starttag_callback),
2498
(r'(declare)(\s+)(boundary-space)',
2499
bygroups(Keyword, Text, Keyword), 'xmlspace_decl'),
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),
2508
(r'(document|text|processing-instruction|comment)(\s*)(\{)',
2509
pushstate_operator_root_construct_callback),
2511
(r'(attribute)(\s+)(?=' + qname + r')',
2512
bygroups(Keyword, Text), 'attribute_qname'),
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'),
2520
(r'(declare|define)(\s+)(function)',
2521
bygroups(Keyword, Text, Keyword)),
2523
(r'(\{)', pushstate_operator_root_callback),
2525
(r'(unordered|ordered)(\s*)(\{)',
2526
pushstate_operator_order_callback),
2528
(r'(declare)(\s+)(ordering)',
2529
bygroups(Keyword, Text, Keyword), 'declareordering'),
2531
(r'(xquery)(\s+)(version)',
2532
bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'xqueryversion'),
2534
(r'(\(#)', Punctuation, 'pragma'),
2536
# sometimes return can occur in root state
2537
(r'return', Keyword),
2539
(r'(declare)(\s+)(option)', bygroups(Keyword, Text, Keyword),
2542
#URI LITERALS - single and double quoted
2543
(r'(at)(\s+)('+stringdouble+')', String.Double, 'namespacedecl'),
2544
(r'(at)(\s+)('+stringsingle+')', String.Single, 'namespacedecl'),
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)),
2551
(r'(if)(\s*)(\()', bygroups(Keyword, Text, Punctuation)),
2553
(r'then|else', Keyword),
2556
(r'(try)(\s*)', bygroups(Keyword, Text), 'root'),
2557
(r'(catch)(\s*)(\()(\$)',
2558
bygroups(Keyword, Text, Punctuation, Name.Variable), 'varname'),
2560
(r'@' + qname, Name.Attribute),
2561
(r'@\*', Name.Attribute),
2562
(r'@' + ncname, Name.Attribute),
2564
(r'//|/|\+|-|;|,|\(|\)', Punctuation),
2567
(qname + r'(?=\s*[{])', Name.Variable, 'qname_braren'),
2568
(qname + r'(?=\s*[(])', Name.Function, 'qname_braren'),
2569
(qname, Name.Variable, 'operator'),