1
# -*- coding: utf-8 -*-
6
Lexers for web-related languages and markup.
8
:copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
9
:license: BSD, see LICENSE for details.
14
from pygments.lexer import RegexLexer, ExtendedRegexLexer, bygroups, using, \
16
from pygments.token import \
17
Text, Comment, Operator, Keyword, Name, String, Number, Other, Punctuation
18
from pygments.util import get_bool_opt, get_list_opt, looks_like_xml, \
20
from pygments.lexers.agile import RubyLexer
23
__all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'CssLexer',
24
'PhpLexer', 'ActionScriptLexer', 'XsltLexer', 'ActionScript3Lexer',
25
'MxmlLexer', 'HaxeLexer', 'HamlLexer', 'SassLexer',
26
'ObjectiveJLexer', 'CoffeeScriptLexer']
29
class JavascriptLexer(RegexLexer):
31
For JavaScript source code.
35
aliases = ['js', 'javascript']
37
mimetypes = ['application/x-javascript', 'text/x-javascript', 'text/javascript']
41
'commentsandwhitespace': [
44
(r'//.*?\n', Comment.Single),
45
(r'/\*.*?\*/', Comment.Multiline)
48
include('commentsandwhitespace'),
49
(r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
50
r'([gim]+\b|\B)', String.Regex, '#pop'),
51
(r'(?=/)', Text, ('#pop', 'badregex')),
58
(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
59
include('commentsandwhitespace'),
60
(r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
61
r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'),
62
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
63
(r'[})\].]', Punctuation),
64
(r'(for|in|while|do|break|return|continue|switch|case|default|if|else|'
65
r'throw|try|catch|finally|new|delete|typeof|instanceof|void|'
66
r'this)\b', Keyword, 'slashstartsregex'),
67
(r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
68
(r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|'
69
r'extends|final|float|goto|implements|import|int|interface|long|native|'
70
r'package|private|protected|public|short|static|super|synchronized|throws|'
71
r'transient|volatile)\b', Keyword.Reserved),
72
(r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
73
(r'(Array|Boolean|Date|Error|Function|Math|netscape|'
74
r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
75
r'decodeURIComponent|encodeURI|encodeURIComponent|'
76
r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
77
r'window)\b', Name.Builtin),
78
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
79
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
80
(r'0x[0-9a-fA-F]+', Number.Hex),
81
(r'[0-9]+', Number.Integer),
82
(r'"(\\\\|\\"|[^"])*"', String.Double),
83
(r"'(\\\\|\\'|[^'])*'", String.Single),
88
class ActionScriptLexer(RegexLexer):
90
For ActionScript source code.
92
*New in Pygments 0.9.*
96
aliases = ['as', 'actionscript']
98
mimetypes = ['application/x-actionscript', 'text/x-actionscript',
105
(r'//.*?\n', Comment.Single),
106
(r'/\*.*?\*/', Comment.Multiline),
107
(r'/(\\\\|\\/|[^/\n])*/[gim]*', String.Regex),
108
(r'[~\^\*!%&<>\|+=:;,/?\\-]+', Operator),
109
(r'[{}\[\]();.]+', Punctuation),
110
(r'(case|default|for|each|in|while|do|break|return|continue|if|else|'
111
r'throw|try|catch|var|with|new|typeof|arguments|instanceof|this|'
112
r'switch)\b', Keyword),
113
(r'(class|public|final|internal|native|override|private|protected|'
114
r'static|import|extends|implements|interface|intrinsic|return|super|'
115
r'dynamic|function|const|get|namespace|package|set)\b',
116
Keyword.Declaration),
117
(r'(true|false|null|NaN|Infinity|-Infinity|undefined|Void)\b',
119
(r'(Accessibility|AccessibilityProperties|ActionScriptVersion|'
120
r'ActivityEvent|AntiAliasType|ApplicationDomain|AsBroadcaster|Array|'
121
r'AsyncErrorEvent|AVM1Movie|BevelFilter|Bitmap|BitmapData|'
122
r'BitmapDataChannel|BitmapFilter|BitmapFilterQuality|BitmapFilterType|'
123
r'BlendMode|BlurFilter|Boolean|ByteArray|Camera|Capabilities|CapsStyle|'
124
r'Class|Color|ColorMatrixFilter|ColorTransform|ContextMenu|'
125
r'ContextMenuBuiltInItems|ContextMenuEvent|ContextMenuItem|'
126
r'ConvultionFilter|CSMSettings|DataEvent|Date|DefinitionError|'
127
r'DeleteObjectSample|Dictionary|DisplacmentMapFilter|DisplayObject|'
128
r'DisplacmentMapFilterMode|DisplayObjectContainer|DropShadowFilter|'
129
r'Endian|EOFError|Error|ErrorEvent|EvalError|Event|EventDispatcher|'
130
r'EventPhase|ExternalInterface|FileFilter|FileReference|'
131
r'FileReferenceList|FocusDirection|FocusEvent|Font|FontStyle|FontType|'
132
r'FrameLabel|FullScreenEvent|Function|GlowFilter|GradientBevelFilter|'
133
r'GradientGlowFilter|GradientType|Graphics|GridFitType|HTTPStatusEvent|'
134
r'IBitmapDrawable|ID3Info|IDataInput|IDataOutput|IDynamicPropertyOutput'
135
r'IDynamicPropertyWriter|IEventDispatcher|IExternalizable|'
136
r'IllegalOperationError|IME|IMEConversionMode|IMEEvent|int|'
137
r'InteractiveObject|InterpolationMethod|InvalidSWFError|InvokeEvent|'
138
r'IOError|IOErrorEvent|JointStyle|Key|Keyboard|KeyboardEvent|KeyLocation|'
139
r'LineScaleMode|Loader|LoaderContext|LoaderInfo|LoadVars|LocalConnection|'
140
r'Locale|Math|Matrix|MemoryError|Microphone|MorphShape|Mouse|MouseEvent|'
141
r'MovieClip|MovieClipLoader|Namespace|NetConnection|NetStatusEvent|'
142
r'NetStream|NewObjectSample|Number|Object|ObjectEncoding|PixelSnapping|'
143
r'Point|PrintJob|PrintJobOptions|PrintJobOrientation|ProgressEvent|Proxy|'
144
r'QName|RangeError|Rectangle|ReferenceError|RegExp|Responder|Sample|Scene|'
145
r'ScriptTimeoutError|Security|SecurityDomain|SecurityError|'
146
r'SecurityErrorEvent|SecurityPanel|Selection|Shape|SharedObject|'
147
r'SharedObjectFlushStatus|SimpleButton|Socket|Sound|SoundChannel|'
148
r'SoundLoaderContext|SoundMixer|SoundTransform|SpreadMethod|Sprite|'
149
r'StackFrame|StackOverflowError|Stage|StageAlign|StageDisplayState|'
150
r'StageQuality|StageScaleMode|StaticText|StatusEvent|String|StyleSheet|'
151
r'SWFVersion|SyncEvent|SyntaxError|System|TextColorType|TextField|'
152
r'TextFieldAutoSize|TextFieldType|TextFormat|TextFormatAlign|'
153
r'TextLineMetrics|TextRenderer|TextSnapshot|Timer|TimerEvent|Transform|'
154
r'TypeError|uint|URIError|URLLoader|URLLoaderDataFormat|URLRequest|'
155
r'URLRequestHeader|URLRequestMethod|URLStream|URLVariabeles|VerifyError|'
156
r'Video|XML|XMLDocument|XMLList|XMLNode|XMLNodeType|XMLSocket|XMLUI)\b',
158
(r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|'
159
r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|'
160
r'isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|'
161
r'unescape)\b',Name.Function),
162
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
163
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
164
(r'0x[0-9a-f]+', Number.Hex),
165
(r'[0-9]+', Number.Integer),
166
(r'"(\\\\|\\"|[^"])*"', String.Double),
167
(r"'(\\\\|\\'|[^'])*'", String.Single),
171
def analyse_text(text):
175
class ActionScript3Lexer(RegexLexer):
177
For ActionScript 3 source code.
179
*New in Pygments 0.11.*
182
name = 'ActionScript 3'
183
aliases = ['as3', 'actionscript3']
185
mimetypes = ['application/x-actionscript', 'text/x-actionscript',
188
identifier = r'[$a-zA-Z_][a-zA-Z0-9_]*'
190
flags = re.DOTALL | re.MULTILINE
194
(r'(function\s+)(' + identifier + r')(\s*)(\()',
195
bygroups(Keyword.Declaration, Name.Function, Text, Operator),
197
(r'(var|const)(\s+)(' + identifier + r')(\s*)(:)(\s*)(' + identifier + r')',
198
bygroups(Keyword.Declaration, Text, Name, Text, Punctuation, Text,
200
(r'(import|package)(\s+)((?:' + identifier + r'|\.)+)(\s*)',
201
bygroups(Keyword, Text, Name.Namespace, Text)),
202
(r'(new)(\s+)(' + identifier + r')(\s*)(\()',
203
bygroups(Keyword, Text, Keyword.Type, Text, Operator)),
204
(r'//.*?\n', Comment.Single),
205
(r'/\*.*?\*/', Comment.Multiline),
206
(r'/(\\\\|\\/|[^\n])*/[gisx]*', String.Regex),
207
(r'(\.)(' + identifier + r')', bygroups(Operator, Name.Attribute)),
208
(r'(case|default|for|each|in|while|do|break|return|continue|if|else|'
209
r'throw|try|catch|with|new|typeof|arguments|instanceof|this|'
210
r'switch|import|include|as|is)\b',
212
(r'(class|public|final|internal|native|override|private|protected|'
213
r'static|import|extends|implements|interface|intrinsic|return|super|'
214
r'dynamic|function|const|get|namespace|package|set)\b',
215
Keyword.Declaration),
216
(r'(true|false|null|NaN|Infinity|-Infinity|undefined|void)\b',
218
(r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|'
219
r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|'
220
r'isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|'
221
r'unescape)\b', Name.Function),
223
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
224
(r'0x[0-9a-f]+', Number.Hex),
225
(r'[0-9]+', Number.Integer),
226
(r'"(\\\\|\\"|[^"])*"', String.Double),
227
(r"'(\\\\|\\'|[^'])*'", String.Single),
228
(r'[~\^\*!%&<>\|+=:;,/?\\{}\[\]();.-]+', Operator),
232
(r'(\s*)(\.\.\.)?(' + identifier + r')(\s*)(:)(\s*)(' +
233
identifier + r'|\*)(\s*)',
234
bygroups(Text, Punctuation, Name, Text, Operator, Text,
235
Keyword.Type, Text), 'defval'),
236
(r'\)', Operator, 'type')
239
(r'(\s*)(:)(\s*)(' + identifier + r'|\*)',
240
bygroups(Text, Operator, Text, Keyword.Type), '#pop:2'),
241
(r'\s*', Text, '#pop:2')
244
(r'(=)(\s*)([^(),]+)(\s*)(,?)',
245
bygroups(Operator, Text, using(this), Text, Operator), '#pop'),
246
(r',?', Operator, '#pop')
250
def analyse_text(text):
251
if re.match(r'\w+\s*:\s*\w', text): return 0.3
255
class CssLexer(RegexLexer):
257
For CSS (Cascading Style Sheets).
262
filenames = ['*.css']
263
mimetypes = ['text/css']
271
(r'/\*(?:.|\n)*?\*/', Comment),
272
(r'{', Punctuation, 'content'),
273
(r'\:[a-zA-Z0-9_-]+', Name.Decorator),
274
(r'\.[a-zA-Z0-9_-]+', Name.Class),
275
(r'\#[a-zA-Z0-9_-]+', Name.Function),
276
(r'@[a-zA-Z0-9_-]+', Keyword, 'atrule'),
277
(r'[a-zA-Z0-9_-]+', Name.Tag),
278
(r'[~\^\*!%&\[\]\(\)<>\|+=@:;,./?-]', Operator),
279
(r'"(\\\\|\\"|[^"])*"', String.Double),
280
(r"'(\\\\|\\'|[^'])*'", String.Single)
283
(r'{', Punctuation, 'atcontent'),
284
(r';', Punctuation, '#pop'),
289
(r'}', Punctuation, '#pop:2'),
293
(r'}', Punctuation, '#pop'),
294
(r'url\(.*?\)', String.Other),
295
(r'^@.*?$', Comment.Preproc),
296
(r'(azimuth|background-attachment|background-color|'
297
r'background-image|background-position|background-repeat|'
298
r'background|border-bottom-color|border-bottom-style|'
299
r'border-bottom-width|border-left-color|border-left-style|'
300
r'border-left-width|border-right|border-right-color|'
301
r'border-right-style|border-right-width|border-top-color|'
302
r'border-top-style|border-top-width|border-bottom|'
303
r'border-collapse|border-left|border-width|border-color|'
304
r'border-spacing|border-style|border-top|border|caption-side|'
305
r'clear|clip|color|content|counter-increment|counter-reset|'
306
r'cue-after|cue-before|cue|cursor|direction|display|'
307
r'elevation|empty-cells|float|font-family|font-size|'
308
r'font-size-adjust|font-stretch|font-style|font-variant|'
309
r'font-weight|font|height|letter-spacing|line-height|'
310
r'list-style-type|list-style-image|list-style-position|'
311
r'list-style|margin-bottom|margin-left|margin-right|'
312
r'margin-top|margin|marker-offset|marks|max-height|max-width|'
313
r'min-height|min-width|opacity|orphans|outline|outline-color|'
314
r'outline-style|outline-width|overflow(?:-x|-y|)|padding-bottom|'
315
r'padding-left|padding-right|padding-top|padding|page|'
316
r'page-break-after|page-break-before|page-break-inside|'
317
r'pause-after|pause-before|pause|pitch|pitch-range|'
318
r'play-during|position|quotes|richness|right|size|'
319
r'speak-header|speak-numeral|speak-punctuation|speak|'
320
r'speech-rate|stress|table-layout|text-align|text-decoration|'
321
r'text-indent|text-shadow|text-transform|top|unicode-bidi|'
322
r'vertical-align|visibility|voice-family|volume|white-space|'
323
r'widows|width|word-spacing|z-index|bottom|left|'
324
r'above|absolute|always|armenian|aural|auto|avoid|baseline|'
325
r'behind|below|bidi-override|blink|block|bold|bolder|both|'
326
r'capitalize|center-left|center-right|center|circle|'
327
r'cjk-ideographic|close-quote|collapse|condensed|continuous|'
328
r'crop|crosshair|cross|cursive|dashed|decimal-leading-zero|'
329
r'decimal|default|digits|disc|dotted|double|e-resize|embed|'
330
r'extra-condensed|extra-expanded|expanded|fantasy|far-left|'
331
r'far-right|faster|fast|fixed|georgian|groove|hebrew|help|'
332
r'hidden|hide|higher|high|hiragana-iroha|hiragana|icon|'
333
r'inherit|inline-table|inline|inset|inside|invert|italic|'
334
r'justify|katakana-iroha|katakana|landscape|larger|large|'
335
r'left-side|leftwards|level|lighter|line-through|list-item|'
336
r'loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|'
337
r'lower|low|medium|message-box|middle|mix|monospace|'
338
r'n-resize|narrower|ne-resize|no-close-quote|no-open-quote|'
339
r'no-repeat|none|normal|nowrap|nw-resize|oblique|once|'
340
r'open-quote|outset|outside|overline|pointer|portrait|px|'
341
r'relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|'
342
r'rightwards|s-resize|sans-serif|scroll|se-resize|'
343
r'semi-condensed|semi-expanded|separate|serif|show|silent|'
344
r'slow|slower|small-caps|small-caption|smaller|soft|solid|'
345
r'spell-out|square|static|status-bar|super|sw-resize|'
346
r'table-caption|table-cell|table-column|table-column-group|'
347
r'table-footer-group|table-header-group|table-row|'
348
r'table-row-group|text|text-bottom|text-top|thick|thin|'
349
r'transparent|ultra-condensed|ultra-expanded|underline|'
350
r'upper-alpha|upper-latin|upper-roman|uppercase|url|'
351
r'visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|'
352
r'x-low|x-small|x-soft|xx-large|xx-small|yes)\b', Keyword),
353
(r'(indigo|gold|firebrick|indianred|yellow|darkolivegreen|'
354
r'darkseagreen|mediumvioletred|mediumorchid|chartreuse|'
355
r'mediumslateblue|black|springgreen|crimson|lightsalmon|brown|'
356
r'turquoise|olivedrab|cyan|silver|skyblue|gray|darkturquoise|'
357
r'goldenrod|darkgreen|darkviolet|darkgray|lightpink|teal|'
358
r'darkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|'
359
r'violet|navy|orchid|blue|ghostwhite|honeydew|cornflowerblue|'
360
r'darkblue|darkkhaki|mediumpurple|cornsilk|red|bisque|slategray|'
361
r'darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|'
362
r'gainsboro|mediumturquoise|floralwhite|coral|purple|lightgrey|'
363
r'lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|'
364
r'greenyellow|royalblue|lightseagreen|mistyrose|sienna|'
365
r'lightcoral|orangered|navajowhite|lime|palegreen|burlywood|'
366
r'seashell|mediumspringgreen|fuchsia|papayawhip|blanchedalmond|'
367
r'peru|aquamarine|white|darkslategray|ivory|dodgerblue|'
368
r'lemonchiffon|chocolate|orange|forestgreen|slateblue|olive|'
369
r'mintcream|antiquewhite|darkorange|cadetblue|moccasin|'
370
r'limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|'
371
r'plum|aqua|darkgoldenrod|maroon|sandybrown|magenta|tan|'
372
r'rosybrown|pink|lightblue|palevioletred|mediumseagreen|'
373
r'dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|'
374
r'paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|'
375
r'lightslategray|lawngreen|lightgreen|tomato|hotpink|'
376
r'lightyellow|lavenderblush|linen|mediumaquamarine|green|'
377
r'blueviolet|peachpuff)\b', Name.Builtin),
378
(r'\!important', Comment.Preproc),
379
(r'/\*(?:.|\n)*?\*/', Comment),
380
(r'\#[a-zA-Z0-9]{1,6}', Number),
381
(r'[\.-]?[0-9]*[\.]?[0-9]+(em|px|\%|pt|pc|in|mm|cm|ex)', Number),
382
(r'-?[0-9]+', Number),
383
(r'[~\^\*!%&<>\|+=@:,./?-]+', Operator),
384
(r'[\[\]();]+', Punctuation),
385
(r'"(\\\\|\\"|[^"])*"', String.Double),
386
(r"'(\\\\|\\'|[^'])*'", String.Single),
387
(r'[a-zA-Z][a-zA-Z0-9]+', Name)
392
class ObjectiveJLexer(RegexLexer):
394
For Objective-J source code with preprocessor directives.
396
*New in Pygments 1.3.*
400
aliases = ['objective-j', 'objectivej', 'obj-j', 'objj']
402
mimetypes = ['text/x-objective-j']
404
#: optional Comment or Whitespace
405
_ws = r'(?:\s|//.*?\n|/[*].*?[*]/)*'
407
flags = re.DOTALL | re.MULTILINE
411
include('whitespace'),
413
# function definition
414
(r'^(' + _ws + r'[\+-]' + _ws + r')([\(a-zA-Z_].*?[^\(])(' + _ws + '{)',
415
bygroups(using(this), using(this, state='function_signature'),
419
(r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text),
421
(r'(@class|@protocol)(\s*)', bygroups(Keyword, Text),
422
'forward_classname'),
423
(r'(\s*)(@end)(\s*)', bygroups(Text, Keyword, Text)),
425
include('statements'),
426
('[{\(\)}]', Punctuation),
430
(r'(@import)(\s+)("(\\\\|\\"|[^"])*")',
431
bygroups(Comment.Preproc, Text, String.Double)),
432
(r'(@import)(\s+)(<(\\\\|\\>|[^>])*>)',
433
bygroups(Comment.Preproc, Text, String.Double)),
434
(r'(#(?:include|import))(\s+)("(\\\\|\\"|[^"])*")',
435
bygroups(Comment.Preproc, Text, String.Double)),
436
(r'(#(?:include|import))(\s+)(<(\\\\|\\>|[^>])*>)',
437
bygroups(Comment.Preproc, Text, String.Double)),
439
(r'#if\s+0', Comment.Preproc, 'if0'),
440
(r'#', Comment.Preproc, 'macro'),
444
(r'\\\n', Text), # line continuation
445
(r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
446
(r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
449
'slashstartsregex': [
450
include('whitespace'),
451
(r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
452
r'([gim]+\b|\B)', String.Regex, '#pop'),
453
(r'(?=/)', Text, ('#pop', 'badregex')),
457
('\n', Text, '#pop'),
460
(r'(L|@)?"', String, 'string'),
461
(r"(L|@)?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
463
(r'"(\\\\|\\"|[^"])*"', String.Double),
464
(r"'(\\\\|\\'|[^'])*'", String.Single),
465
(r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
466
(r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
467
(r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
468
(r'0[0-7]+[Ll]?', Number.Oct),
469
(r'\d+[Ll]?', Number.Integer),
471
(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
473
(r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
474
r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?',
475
Operator, 'slashstartsregex'),
476
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
477
(r'[})\].]', Punctuation),
479
(r'(for|in|while|do|break|return|continue|switch|case|default|if|'
480
r'else|throw|try|catch|finally|new|delete|typeof|instanceof|void|'
481
r'prototype|__proto__)\b', Keyword, 'slashstartsregex'),
483
(r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
485
(r'(@selector|@private|@protected|@public|@encode|'
486
r'@synchronized|@try|@throw|@catch|@finally|@end|@property|'
487
r'@synthesize|@dynamic|@for|@accessors|new)\b', Keyword),
489
(r'(int|long|float|short|double|char|unsigned|signed|void|'
490
r'id|BOOL|bool|boolean|IBOutlet|IBAction|SEL|@outlet|@action)\b',
493
(r'(self|super)\b', Name.Builtin),
495
(r'(TRUE|YES|FALSE|NO|Nil|nil|NULL)\b', Keyword.Constant),
496
(r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
497
(r'(ABS|ASIN|ACOS|ATAN|ATAN2|SIN|COS|TAN|EXP|POW|CEIL|FLOOR|ROUND|'
498
r'MIN|MAX|RAND|SQRT|E|LN2|LN10|LOG2E|LOG10E|PI|PI2|PI_2|SQRT1_2|'
499
r'SQRT2)\b', Keyword.Constant),
501
(r'(Array|Boolean|Date|Error|Function|Math|netscape|'
502
r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
503
r'decodeURIComponent|encodeURI|encodeURIComponent|'
504
r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
505
r'window)\b', Name.Builtin),
507
(r'([$a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r')(?=\()',
508
bygroups(Name.Function, using(this))),
510
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name),
513
# interface definition that inherits
514
(r'([a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r':' + _ws +
515
r')([a-zA-Z_][a-zA-Z0-9_]*)?',
516
bygroups(Name.Class, using(this), Name.Class), '#pop'),
517
# interface definition for a category
518
(r'([a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r'\()([a-zA-Z_][a-zA-Z0-9_]*)(\))',
519
bygroups(Name.Class, using(this), Name.Label, Text), '#pop'),
520
# simple interface / implementation
521
(r'([a-zA-Z_][a-zA-Z0-9_]*)', Name.Class, '#pop'),
523
'forward_classname' : [
524
(r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*,\s*)',
525
bygroups(Name.Class, Text), '#push'),
526
(r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*;?)',
527
bygroups(Name.Class, Text), '#pop'),
529
'function_signature': [
530
include('whitespace'),
532
# start of a selector w/ parameters
533
(r'(\(' + _ws + r')' # open paren
534
r'([a-zA-Z_][a-zA-Z0-9_]+)' # return type
535
r'(' + _ws + r'\)' + _ws + r')' # close paren
536
r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name
537
bygroups(using(this), Keyword.Type, using(this),
538
Name.Function), 'function_parameters'),
541
(r'(\(' + _ws + r')' # open paren
542
r'([a-zA-Z_][a-zA-Z0-9_]+)' # return type
543
r'(' + _ws + r'\)' + _ws + r')' # close paren
544
r'([$a-zA-Z_][a-zA-Z0-9_]+)', # function name
545
bygroups(using(this), Keyword.Type, using(this),
546
Name.Function), "#pop"),
548
# no return type given, start of a selector w/ parameters
549
(r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name
550
bygroups (Name.Function), 'function_parameters'),
552
# no return type given, no-param function
553
(r'([$a-zA-Z_][a-zA-Z0-9_]+)', # function name
554
bygroups(Name.Function), "#pop"),
558
'function_parameters': [
559
include('whitespace'),
562
(r'(\(' + _ws + ')' # open paren
564
r'(' + _ws + r'\)' + _ws + r')+' # close paren
565
r'([$a-zA-Z_][a-zA-Z0-9_]+)', # param name
566
bygroups(using(this), Keyword.Type, using(this), Text)),
568
# one piece of a selector name
569
(r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name
572
# smallest possible selector piece
573
(r'(:)', Name.Function),
576
(r'(,' + _ws + r'...)', using(this)),
579
(r'([$a-zA-Z_][a-zA-Z0-9_]+)', Text),
582
(r'([$a-zA-Z_][a-zA-Z0-9_]*)(\()', bygroups(Name.Function,
584
(r'(\))', Punctuation, "#pop"),
587
(r'"', String, '#pop'),
588
(r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
589
(r'[^\\"\n]+', String), # all other characters
590
(r'\\\n', String), # line continuation
591
(r'\\', String), # stray backslash
594
(r'[^/\n]+', Comment.Preproc),
595
(r'/[*](.|\n)*?[*]/', Comment.Multiline),
596
(r'//.*?\n', Comment.Single, '#pop'),
597
(r'/', Comment.Preproc),
598
(r'(?<=\\)\n', Comment.Preproc),
599
(r'\n', Comment.Preproc, '#pop'),
602
(r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
603
(r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
608
def analyse_text(text):
609
if re.search('^\s*@import\s+[<"]', text, re.MULTILINE):
610
# special directive found in most Objective-J files
615
class HtmlLexer(RegexLexer):
617
For HTML 4 and XHTML 1 markup. Nested JavaScript and CSS is highlighted
618
by the appropriate lexer.
623
filenames = ['*.html', '*.htm', '*.xhtml', '*.xslt']
624
mimetypes = ['text/html', 'application/xhtml+xml']
626
flags = re.IGNORECASE | re.DOTALL
630
(r'&\S*?;', Name.Entity),
631
(r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc),
632
('<!--', Comment, 'comment'),
633
(r'<\?.*?\?>', Comment.Preproc),
634
('<![^>]*>', Comment.Preproc),
635
(r'<\s*script\s*', Name.Tag, ('script-content', 'tag')),
636
(r'<\s*style\s*', Name.Tag, ('style-content', 'tag')),
637
(r'<\s*[a-zA-Z0-9:]+', Name.Tag, 'tag'),
638
(r'<\s*/\s*[a-zA-Z0-9:]+\s*>', Name.Tag),
642
('-->', Comment, '#pop'),
647
(r'[a-zA-Z0-9_:-]+\s*=', Name.Attribute, 'attr'),
648
(r'[a-zA-Z0-9_:-]+', Name.Attribute),
649
(r'/?\s*>', Name.Tag, '#pop'),
652
(r'<\s*/\s*script\s*>', Name.Tag, '#pop'),
653
(r'.+?(?=<\s*/\s*script\s*>)', using(JavascriptLexer)),
656
(r'<\s*/\s*style\s*>', Name.Tag, '#pop'),
657
(r'.+?(?=<\s*/\s*style\s*>)', using(CssLexer)),
660
('".*?"', String, '#pop'),
661
("'.*?'", String, '#pop'),
662
(r'[^\s>]+', String, '#pop'),
666
def analyse_text(text):
667
if html_doctype_matches(text):
671
class PhpLexer(RegexLexer):
673
For `PHP <http://www.php.net/>`_ source code.
674
For PHP embedded in HTML, use the `HtmlPhpLexer`.
676
Additional options accepted:
679
If given and ``True`` the lexer starts highlighting with
680
php code (i.e.: no starting ``<?php`` required). The default
682
`funcnamehighlighting`
683
If given and ``True``, highlight builtin function names
686
If given, must be a list of module names whose function names
687
should not be highlighted. By default all modules are highlighted
688
except the special ``'unknown'`` module that includes functions
689
that are known to php but are undocumented.
691
To get a list of allowed modules have a look into the
692
`_phpbuiltins` module:
694
.. sourcecode:: pycon
696
>>> from pygments.lexers._phpbuiltins import MODULES
698
['PHP Options/Info', 'Zip', 'dba', ...]
700
In fact the names of those modules match the module names from
701
the php documentation.
705
aliases = ['php', 'php3', 'php4', 'php5']
706
filenames = ['*.php', '*.php[345]']
707
mimetypes = ['text/x-php']
709
flags = re.IGNORECASE | re.DOTALL | re.MULTILINE
712
(r'<\?(php)?', Comment.Preproc, 'php'),
717
(r'\?>', Comment.Preproc, '#pop'),
718
(r'<<<(\'?)([a-zA-Z_][a-zA-Z0-9_]*)\1\n.*?\n\2\;?\n', String),
720
(r'#.*?\n', Comment.Single),
721
(r'//.*?\n', Comment.Single),
722
# put the empty comment here, it is otherwise seen as
723
# the start of a docstring
724
(r'/\*\*/', Comment.Multiline),
725
(r'/\*\*.*?\*/', String.Doc),
726
(r'/\*.*?\*/', Comment.Multiline),
727
(r'(->|::)(\s*)([a-zA-Z_][a-zA-Z0-9_]*)',
728
bygroups(Operator, Text, Name.Attribute)),
729
(r'[~!%^&*+=|:.<>/?@-]+', Operator),
730
(r'[\[\]{}();,]+', Punctuation),
731
(r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
732
(r'(function)(\s*)(?=\()', bygroups(Keyword, Text)),
733
(r'(function)(\s+)(&?)(\s*)',
734
bygroups(Keyword, Text, Operator, Text), 'functionname'),
735
(r'(const)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)',
736
bygroups(Keyword, Text, Name.Constant)),
737
(r'(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|'
738
r'eval|PHP_OS|break|exit|case|extends|PHP_VERSION|cfunction|'
739
r'FALSE|print|for|require|continue|foreach|require_once|'
740
r'declare|return|default|static|do|switch|die|stdClass|'
741
r'echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|'
742
r'virtual|endfor|include_once|while|endforeach|global|__FILE__|'
743
r'endif|list|__LINE__|endswitch|new|__sleep|endwhile|not|'
744
r'array|__wakeup|E_ALL|NULL|final|php_user_filter|interface|'
745
r'implements|public|private|protected|abstract|clone|try|'
746
r'catch|throw|this|use|namespace)\b', Keyword),
747
('(true|false|null)\b', Keyword.Constant),
748
(r'\$\{\$+[a-zA-Z_][a-zA-Z0-9_]*\}', Name.Variable),
749
(r'\$+[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable),
750
(r'[\\a-zA-Z_][\\a-zA-Z0-9_]*', Name.Other),
751
(r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|"
752
r"0[xX][0-9a-fA-F]+[Ll]?", Number),
753
(r"'([^'\\]*(?:\\.[^'\\]*)*)'", String.Single),
754
(r'`([^`\\]*(?:\\.[^`\\]*)*)`', String.Backtick),
755
(r'"', String.Double, 'string'),
758
(r'[a-zA-Z_][\\a-zA-Z0-9_]*', Name.Class, '#pop')
761
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop')
764
(r'"', String.Double, '#pop'),
765
(r'[^{$"\\]+', String.Double),
766
(r'\\([nrt\"$]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2})', String.Escape),
767
(r'\$[a-zA-Z_][a-zA-Z0-9_]*(\[\S+\]|->[a-zA-Z_][a-zA-Z0-9_]*)?',
769
(r'(\{\$\{)(.*?)(\}\})',
770
bygroups(String.Interpol, using(this, _startinline=True),
773
bygroups(String.Interpol, using(this, _startinline=True),
776
bygroups(String.Interpol, Name.Variable, String.Interpol)),
777
(r'[${\\]+', String.Double)
781
def __init__(self, **options):
782
self.funcnamehighlighting = get_bool_opt(
783
options, 'funcnamehighlighting', True)
784
self.disabledmodules = get_list_opt(
785
options, 'disabledmodules', ['unknown'])
786
self.startinline = get_bool_opt(options, 'startinline', False)
788
# private option argument for the lexer itself
789
if '_startinline' in options:
790
self.startinline = options.pop('_startinline')
792
# collect activated functions in a set
793
self._functions = set()
794
if self.funcnamehighlighting:
795
from pygments.lexers._phpbuiltins import MODULES
796
for key, value in MODULES.iteritems():
797
if key not in self.disabledmodules:
798
self._functions.update(value)
799
RegexLexer.__init__(self, **options)
801
def get_tokens_unprocessed(self, text):
805
for index, token, value in \
806
RegexLexer.get_tokens_unprocessed(self, text, stack):
807
if token is Name.Other:
808
if value in self._functions:
809
yield index, Name.Builtin, value
811
yield index, token, value
813
def analyse_text(text):
815
if re.search(r'<\?(?!xml)', text):
822
class XmlLexer(RegexLexer):
824
Generic lexer for XML (eXtensible Markup Language).
827
flags = re.MULTILINE | re.DOTALL
831
filenames = ['*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl']
832
mimetypes = ['text/xml', 'application/xml', 'image/svg+xml',
833
'application/rss+xml', 'application/atom+xml',
834
'application/xsl+xml', 'application/xslt+xml']
839
(r'&\S*?;', Name.Entity),
840
(r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc),
841
('<!--', Comment, 'comment'),
842
(r'<\?.*?\?>', Comment.Preproc),
843
('<![^>]*>', Comment.Preproc),
844
(r'<\s*[a-zA-Z0-9:._-]+', Name.Tag, 'tag'),
845
(r'<\s*/\s*[a-zA-Z0-9:._-]+\s*>', Name.Tag),
849
('-->', Comment, '#pop'),
854
(r'[a-zA-Z0-9_.:-]+\s*=', Name.Attribute, 'attr'),
855
(r'/?\s*>', Name.Tag, '#pop'),
859
('".*?"', String, '#pop'),
860
("'.*?'", String, '#pop'),
861
(r'[^\s>]+', String, '#pop'),
865
def analyse_text(text):
866
if looks_like_xml(text):
870
class XsltLexer(XmlLexer):
874
*New in Pygments 0.10.*
879
filenames = ['*.xsl', '*.xslt']
881
EXTRA_KEYWORDS = set([
882
'apply-imports', 'apply-templates', 'attribute',
883
'attribute-set', 'call-template', 'choose', 'comment',
884
'copy', 'copy-of', 'decimal-format', 'element', 'fallback',
885
'for-each', 'if', 'import', 'include', 'key', 'message',
886
'namespace-alias', 'number', 'otherwise', 'output', 'param',
887
'preserve-space', 'processing-instruction', 'sort',
888
'strip-space', 'stylesheet', 'template', 'text', 'transform',
889
'value-of', 'variable', 'when', 'with-param'
892
def get_tokens_unprocessed(self, text):
893
for index, token, value in XmlLexer.get_tokens_unprocessed(self, text):
894
m = re.match('</?xsl:([^>]*)/?>?', value)
896
if token is Name.Tag and m and m.group(1) in self.EXTRA_KEYWORDS:
897
yield index, Keyword, value
899
yield index, token, value
901
def analyse_text(text):
902
if looks_like_xml(text) and '<xsl' in text:
906
class MxmlLexer(RegexLexer):
909
Nested AS3 in <script> tags is highlighted by the appropriate lexer.
911
flags = re.MULTILINE | re.DOTALL
914
filenames = ['*.mxml']
915
mimetimes = ['text/xml', 'application/xml']
920
(r'&\S*?;', Name.Entity),
921
(r'(\<\!\[CDATA\[)(.*?)(\]\]\>)',
922
bygroups(String, using(ActionScript3Lexer), String)),
923
('<!--', Comment, 'comment'),
924
(r'<\?.*?\?>', Comment.Preproc),
925
('<![^>]*>', Comment.Preproc),
926
(r'<\s*[a-zA-Z0-9:._-]+', Name.Tag, 'tag'),
927
(r'<\s*/\s*[a-zA-Z0-9:._-]+\s*>', Name.Tag),
931
('-->', Comment, '#pop'),
936
(r'[a-zA-Z0-9_.:-]+\s*=', Name.Attribute, 'attr'),
937
(r'/?\s*>', Name.Tag, '#pop'),
941
('".*?"', String, '#pop'),
942
("'.*?'", String, '#pop'),
943
(r'[^\s>]+', String, '#pop'),
948
class HaxeLexer(RegexLexer):
950
For haXe source code (http://haxe.org/).
954
aliases = ['hx', 'haXe']
956
mimetypes = ['text/haxe']
958
ident = r'(?:[a-zA-Z_][a-zA-Z0-9_]*)'
959
typeid = r'(?:(?:[a-z0-9_\.])*[A-Z_][A-Za-z0-9_]*)'
960
key_prop = r'(?:default|null|never)'
961
key_decl_mod = r'(?:public|private|override|static|inline|extern|dynamic)'
963
flags = re.DOTALL | re.MULTILINE
967
include('whitespace'),
969
(key_decl_mod, Keyword.Declaration),
978
(r'//.*?\n', Comment.Single),
979
(r'/\*.*?\*/', Comment.Multiline),
980
(r'#[^\n]*', Comment.Preproc),
987
(r'\b(if|else|while|do|for|in|break|continue|'
988
r'return|switch|case|try|catch|throw|null|trace|'
989
r'new|this|super|untyped|cast|callback|here)\b',
993
(r'0[xX][0-9a-fA-F]+', Number.Hex),
994
(r'[0-9]+', Number.Integer),
995
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
996
(r"'(\\\\|\\'|[^'])*'", String.Single),
997
(r'"(\\\\|\\"|[^"])*"', String.Double),
998
(r'~/([^\n])*?/[gisx]*', String.Regex),
999
(r'\b(true|false|null)\b', Keyword.Constant),
1002
include('whitespace'),
1005
include('anonfundef'),
1006
include('literals'),
1008
include('codekeywords'),
1009
(r'[();,\[\]]', Punctuation),
1010
(r'(?:=|\+=|-=|\*=|/=|%=|&=|\|=|\^=|<<=|>>=|>>>=|\|\||&&|'
1011
r'\.\.\.|==|!=|>|<|>=|<=|\||&|\^|<<|>>|>>>|\+|\-|\*|/|%|'
1012
r'!|\+\+|\-\-|~|\.|\?|\:)',
1016
(r'}', Punctuation,'#pop'),
1017
(r'{', Punctuation,'#push'),
1020
# Instance/Block level constructs
1022
(r'(\()(' + key_prop + ')(,)(' + key_prop + ')(\))',
1023
bygroups(Punctuation, Keyword.Reserved, Punctuation,
1024
Keyword.Reserved, Punctuation)),
1027
(r'\bnew\b', Keyword, 'typedecl'),
1030
(r'\b(case)(\s+)(' + ident + ')(\s*)(\()',
1031
bygroups(Keyword.Reserved, Text, Name, Text, Punctuation),
1035
(r'\b(var)(\s+)(' + ident + ')',
1036
bygroups(Keyword.Declaration, Text, Name.Variable), 'vardecl'),
1039
include('whitespace'),
1040
include('typelabel'),
1041
(r'=', Operator,'#pop'),
1042
(r';', Punctuation,'#pop'),
1045
(key_decl_mod,Keyword.Declaration),
1046
(r'\b(var)(\s+)(' + ident + ')',
1047
bygroups(Keyword.Declaration, Text, Name.Variable.Instance),
1050
'instancevardecl': [
1052
include('propertydef'),
1056
(r'\bfunction\b', Keyword.Declaration, 'fundecl'),
1059
(key_decl_mod, Keyword.Declaration),
1060
(r'\b(function)(\s+)(' + ident + ')',
1061
bygroups(Keyword.Declaration, Text, Name.Function), 'fundecl'),
1064
include('whitespace'),
1065
include('typelabel'),
1066
include('generictypedecl'),
1067
(r'\(',Punctuation,'funargdecl'),
1068
(r'(?=[a-zA-Z0-9_])',Text,'#pop'),
1069
(r'{',Punctuation,('#pop','codeblock')),
1070
(r';',Punctuation,'#pop'),
1073
include('whitespace'),
1074
(ident, Name.Variable),
1075
include('typelabel'),
1076
include('literals'),
1078
(r',', Punctuation),
1079
(r'\?', Punctuation),
1080
(r'\)', Punctuation, '#pop'),
1084
(r':', Punctuation, 'type'),
1087
include('whitespace'),
1088
(typeid, Name.Class),
1089
(r'<', Punctuation, 'generictypedecl'),
1090
(r'(?=[{}()=,a-z])', Text,'#pop'),
1093
include('whitespace'),
1094
(typeid, Name.Class),
1095
(r'<', Punctuation, 'generictypedecl'),
1096
(r'->', Keyword.Type),
1097
(r'(?=[{}(),;=])', Text, '#pop'),
1099
'generictypedecl': [
1100
include('whitespace'),
1101
(typeid, Name.Class),
1102
(r'<', Punctuation, '#push'),
1103
(r'>', Punctuation, '#pop'),
1104
(r',', Punctuation),
1107
# Top level constructs
1109
(r'(package|import|using)(\s+)([^;]+)(;)',
1110
bygroups(Keyword.Namespace, Text, Name.Namespace,Punctuation)),
1113
(r'typedef', Keyword.Declaration, ('typedefprebody', 'typedecl')),
1116
include('whitespace'),
1117
(r'(=)(\s*)({)', bygroups(Punctuation, Text, Punctuation),
1118
('#pop', 'typedefbody')),
1121
(r'enum', Keyword.Declaration, ('enumdefprebody', 'typedecl')),
1124
include('whitespace'),
1125
(r'{', Punctuation, ('#pop','enumdefbody')),
1128
(r'class', Keyword.Declaration, ('classdefprebody', 'typedecl')),
1130
'classdefprebody': [
1131
include('whitespace'),
1132
(r'(extends|implements)', Keyword.Declaration,'typedecl'),
1133
(r'{', Punctuation, ('#pop', 'classdefbody')),
1136
(r'interface', Keyword.Declaration,
1137
('interfacedefprebody', 'typedecl')),
1139
'interfacedefprebody': [
1140
include('whitespace'),
1141
(r'(extends)', Keyword.Declaration, 'typedecl'),
1142
(r'{', Punctuation, ('#pop', 'classdefbody')),
1146
include('whitespace'),
1147
include('instancevardef'),
1148
include('instancefundef'),
1149
(r'>', Punctuation, 'typedecl'),
1150
(r',', Punctuation),
1151
(r'}', Punctuation, '#pop'),
1154
include('whitespace'),
1155
(ident, Name.Variable.Instance),
1156
(r'\(', Punctuation, 'funargdecl'),
1157
(r';', Punctuation),
1158
(r'}', Punctuation, '#pop'),
1161
include('whitespace'),
1162
include('instancevardef'),
1163
include('instancefundef'),
1164
(r'}', Punctuation, '#pop'),
1165
include('codeblock'),
1169
def analyse_text(text):
1170
if re.match(r'\w+\s*:\s*\w', text): return 0.3
1173
def _indentation(lexer, match, ctx):
1174
indentation = match.group(0)
1175
yield match.start(), Text, indentation
1176
ctx.last_indentation = indentation
1177
ctx.pos = match.end()
1179
if hasattr(ctx, 'block_state') and ctx.block_state and \
1180
indentation.startswith(ctx.block_indentation) and \
1181
indentation != ctx.block_indentation:
1182
ctx.stack.append(ctx.block_state)
1184
ctx.block_state = None
1185
ctx.block_indentation = None
1186
ctx.stack.append('content')
1188
def _starts_block(token, state):
1189
def callback(lexer, match, ctx):
1190
yield match.start(), token, match.group(0)
1192
if hasattr(ctx, 'last_indentation'):
1193
ctx.block_indentation = ctx.last_indentation
1195
ctx.block_indentation = ''
1197
ctx.block_state = state
1198
ctx.pos = match.end()
1203
class HamlLexer(ExtendedRegexLexer):
1207
*New in Pygments 1.3.*
1211
aliases = ['haml', 'HAML']
1212
filenames = ['*.haml']
1213
mimetypes = ['text/x-haml']
1215
flags = re.IGNORECASE
1216
# Haml can include " |\n" anywhere,
1217
# which is ignored and used to wrap long lines.
1218
# To accomodate this, use this custom faux dot instead.
1219
_dot = r'(?: \|\n(?=.* \|)|.)'
1222
(r'[ \t]*\n', Text),
1223
(r'[ \t]*', _indentation),
1227
(r'\.[a-z0-9_:-]+', Name.Class, 'tag'),
1228
(r'\#[a-z0-9_:-]+', Name.Function, 'tag'),
1232
(r'[&!]?==', Punctuation, 'plain'),
1233
(r'([&!]?[=~])(' + _dot + '*\n)',
1234
bygroups(Punctuation, using(RubyLexer)),
1236
(r'', Text, 'plain'),
1241
(r'%[a-z0-9_:-]+', Name.Tag, 'tag'),
1242
(r'!!!' + _dot + '*\n', Name.Namespace, '#pop'),
1243
(r'(/)(\[' + _dot + '*?\])(' + _dot + '*\n)',
1244
bygroups(Comment, Comment.Special, Comment),
1246
(r'/' + _dot + '*\n', _starts_block(Comment, 'html-comment-block'),
1248
(r'-#' + _dot + '*\n', _starts_block(Comment.Preproc,
1249
'haml-comment-block'), '#pop'),
1250
(r'(-)(' + _dot + '*\n)',
1251
bygroups(Punctuation, using(RubyLexer)),
1253
(r':' + _dot + '*\n', _starts_block(Name.Decorator, 'filter-block'),
1255
include('eval-or-plain'),
1260
(r'\{(,\n|' + _dot + ')*?\}', using(RubyLexer)),
1261
(r'\[' + _dot + '*?\]', using(RubyLexer)),
1262
(r'\(', Text, 'html-attributes'),
1263
(r'/[ \t]*\n', Punctuation, '#pop:2'),
1264
(r'[<>]{1,2}(?=[ \t=])', Punctuation),
1265
include('eval-or-plain'),
1269
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text),
1270
(r'(#\{)(' + _dot + '*?)(\})',
1271
bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
1272
(r'\n', Text, 'root'),
1275
'html-attributes': [
1277
(r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'),
1278
(r'[a-z0-9_:-]+', Name.Attribute),
1279
(r'\)', Text, '#pop'),
1282
'html-attribute-value': [
1284
(r'[a-z0-9_]+', Name.Variable, '#pop'),
1285
(r'@[a-z0-9_]+', Name.Variable.Instance, '#pop'),
1286
(r'\$[a-z0-9_]+', Name.Variable.Global, '#pop'),
1287
(r"'(\\\\|\\'|[^'\n])*'", String, '#pop'),
1288
(r'"(\\\\|\\"|[^"\n])*"', String, '#pop'),
1291
'html-comment-block': [
1292
(_dot + '+', Comment),
1293
(r'\n', Text, 'root'),
1296
'haml-comment-block': [
1297
(_dot + '+', Comment.Preproc),
1298
(r'\n', Text, 'root'),
1302
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator),
1303
(r'(#\{)(' + _dot + '*?)(\})',
1304
bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
1305
(r'\n', Text, 'root'),
1310
class SassLexer(ExtendedRegexLexer):
1312
For Sass stylesheets.
1314
*New in Pygments 1.3.*
1318
aliases = ['sass', 'SASS']
1319
filenames = ['*.sass']
1320
mimetypes = ['text/x-sass']
1322
flags = re.IGNORECASE
1325
(r'[ \t]*\n', Text),
1326
(r'[ \t]*', _indentation),
1330
(r'//[^\n]*', _starts_block(Comment.Single, 'single-comment'),
1332
(r'/\*[^\n]*', _starts_block(Comment.Multiline, 'multi-comment'),
1334
(r'@import', Keyword, 'import'),
1335
(r'@for', Keyword, 'for'),
1336
(r'@(debug|if|while)', Keyword, 'script'),
1337
(r'@[a-z0-9_-]+', Keyword, 'selector'),
1338
(r'=[\w-]+', Name.Function, 'script'),
1339
(r'\+[\w-]+', Name.Decorator, 'script'),
1340
(r'(![a-z_]\w*)([ \t]*(?:\|\|)?=)',
1341
bygroups(Name.Variable, Operator), 'script'),
1342
(r':', Name.Attribute, 'old-style-attr'),
1343
(r'(?=[^\s:"\[]+\s*[=:]([ \t]|$))', Name.Attribute, 'new-style-attr'),
1344
(r'', Text, 'selector'),
1348
(r'.+', Comment.Single),
1349
(r'\n', Text, 'root'),
1353
(r'.+', Comment.Multiline),
1354
(r'\n', Text, 'root'),
1359
(r'[^\s]+', String),
1360
(r'\n', Text, 'root'),
1364
(r'(from|to|through)', Operator.Word),
1369
(r'[^\s:="\[]+', Name.Attribute),
1370
(r'#{', String.Interpol, 'interpolation'),
1371
(r'[ \t]*=', Operator, 'script'),
1372
(r'', Text, 'value'),
1376
(r'[^\s:="\[]+', Name.Attribute),
1377
(r'#{', String.Interpol, 'interpolation'),
1378
(r'[ \t]*=', Operator, 'script'),
1379
(r':', Name.Attribute, 'value'),
1384
(r'url\(', String.Other, 'string-url'),
1385
(r'(azimuth|background-attachment|background-color|'
1386
r'background-image|background-position|background-repeat|'
1387
r'background|border-bottom-color|border-bottom-style|'
1388
r'border-bottom-width|border-left-color|border-left-style|'
1389
r'border-left-width|border-right|border-right-color|'
1390
r'border-right-style|border-right-width|border-top-color|'
1391
r'border-top-style|border-top-width|border-bottom|'
1392
r'border-collapse|border-left|border-width|border-color|'
1393
r'border-spacing|border-style|border-top|border|caption-side|'
1394
r'clear|clip|color|content|counter-increment|counter-reset|'
1395
r'cue-after|cue-before|cue|cursor|direction|display|'
1396
r'elevation|empty-cells|float|font-family|font-size|'
1397
r'font-size-adjust|font-stretch|font-style|font-variant|'
1398
r'font-weight|font|height|letter-spacing|line-height|'
1399
r'list-style-type|list-style-image|list-style-position|'
1400
r'list-style|margin-bottom|margin-left|margin-right|'
1401
r'margin-top|margin|marker-offset|marks|max-height|max-width|'
1402
r'min-height|min-width|opacity|orphans|outline|outline-color|'
1403
r'outline-style|outline-width|overflow|padding-bottom|'
1404
r'padding-left|padding-right|padding-top|padding|page|'
1405
r'page-break-after|page-break-before|page-break-inside|'
1406
r'pause-after|pause-before|pause|pitch|pitch-range|'
1407
r'play-during|position|quotes|richness|right|size|'
1408
r'speak-header|speak-numeral|speak-punctuation|speak|'
1409
r'speech-rate|stress|table-layout|text-align|text-decoration|'
1410
r'text-indent|text-shadow|text-transform|top|unicode-bidi|'
1411
r'vertical-align|visibility|voice-family|volume|white-space|'
1412
r'widows|width|word-spacing|z-index|bottom|left|'
1413
r'above|absolute|always|armenian|aural|auto|avoid|baseline|'
1414
r'behind|below|bidi-override|blink|block|bold|bolder|both|'
1415
r'capitalize|center-left|center-right|center|circle|'
1416
r'cjk-ideographic|close-quote|collapse|condensed|continuous|'
1417
r'crop|crosshair|cross|cursive|dashed|decimal-leading-zero|'
1418
r'decimal|default|digits|disc|dotted|double|e-resize|embed|'
1419
r'extra-condensed|extra-expanded|expanded|fantasy|far-left|'
1420
r'far-right|faster|fast|fixed|georgian|groove|hebrew|help|'
1421
r'hidden|hide|higher|high|hiragana-iroha|hiragana|icon|'
1422
r'inherit|inline-table|inline|inset|inside|invert|italic|'
1423
r'justify|katakana-iroha|katakana|landscape|larger|large|'
1424
r'left-side|leftwards|level|lighter|line-through|list-item|'
1425
r'loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|'
1426
r'lower|low|medium|message-box|middle|mix|monospace|'
1427
r'n-resize|narrower|ne-resize|no-close-quote|no-open-quote|'
1428
r'no-repeat|none|normal|nowrap|nw-resize|oblique|once|'
1429
r'open-quote|outset|outside|overline|pointer|portrait|px|'
1430
r'relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|'
1431
r'rightwards|s-resize|sans-serif|scroll|se-resize|'
1432
r'semi-condensed|semi-expanded|separate|serif|show|silent|'
1433
r'slow|slower|small-caps|small-caption|smaller|soft|solid|'
1434
r'spell-out|square|static|status-bar|super|sw-resize|'
1435
r'table-caption|table-cell|table-column|table-column-group|'
1436
r'table-footer-group|table-header-group|table-row|'
1437
r'table-row-group|text|text-bottom|text-top|thick|thin|'
1438
r'transparent|ultra-condensed|ultra-expanded|underline|'
1439
r'upper-alpha|upper-latin|upper-roman|uppercase|url|'
1440
r'visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|'
1441
r'x-low|x-small|x-soft|xx-large|xx-small|yes)\b', Name.Constant),
1442
(r'(indigo|gold|firebrick|indianred|yellow|darkolivegreen|'
1443
r'darkseagreen|mediumvioletred|mediumorchid|chartreuse|'
1444
r'mediumslateblue|black|springgreen|crimson|lightsalmon|brown|'
1445
r'turquoise|olivedrab|cyan|silver|skyblue|gray|darkturquoise|'
1446
r'goldenrod|darkgreen|darkviolet|darkgray|lightpink|teal|'
1447
r'darkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|'
1448
r'violet|navy|orchid|blue|ghostwhite|honeydew|cornflowerblue|'
1449
r'darkblue|darkkhaki|mediumpurple|cornsilk|red|bisque|slategray|'
1450
r'darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|'
1451
r'gainsboro|mediumturquoise|floralwhite|coral|purple|lightgrey|'
1452
r'lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|'
1453
r'greenyellow|royalblue|lightseagreen|mistyrose|sienna|'
1454
r'lightcoral|orangered|navajowhite|lime|palegreen|burlywood|'
1455
r'seashell|mediumspringgreen|fuchsia|papayawhip|blanchedalmond|'
1456
r'peru|aquamarine|white|darkslategray|ivory|dodgerblue|'
1457
r'lemonchiffon|chocolate|orange|forestgreen|slateblue|olive|'
1458
r'mintcream|antiquewhite|darkorange|cadetblue|moccasin|'
1459
r'limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|'
1460
r'plum|aqua|darkgoldenrod|maroon|sandybrown|magenta|tan|'
1461
r'rosybrown|pink|lightblue|palevioletred|mediumseagreen|'
1462
r'dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|'
1463
r'paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|'
1464
r'lightslategray|lawngreen|lightgreen|tomato|hotpink|'
1465
r'lightyellow|lavenderblush|linen|mediumaquamarine|green|'
1466
r'blueviolet|peachpuff)\b', Name.Entity),
1467
(r'\!important', Name.Exception),
1468
(r'/\*', Comment, 'inline-comment'),
1469
(r'\#[a-z0-9]{1,6}', Number.Hex),
1470
(r'(-?\d+)(\%|[a-z]+)?', bygroups(Number.Integer, Keyword.Type)),
1471
(r'(-?\d*\.\d+)(\%|[a-z]+)?', bygroups(Number.Float, Keyword.Type)),
1472
(r'#{', String.Interpol, 'interpolation'),
1473
(r'[~\^\*!&%<>\|+=@:,./?-]+', Operator),
1474
(r'[\[\]();]+', Punctuation),
1475
(r'"', String.Double, 'string-double'),
1476
(r"'", String.Single, 'string-single'),
1477
(r'[a-z][\w-]*', Name),
1478
(r'\n', Text, 'root'),
1483
(r'![\w_]+', Name.Variable),
1484
(r'[+\-*/%=(),!><]', Operator),
1485
(r'"', String.Double, 'string-double'),
1486
(r"'", String.Single, 'string-single'),
1487
(r'\#[a-z0-9]{1,6}', Number.Hex),
1488
(r'(-?\d+)(\%|[a-z]+)?', bygroups(Number.Integer, Keyword.Type)),
1489
(r'(-?\d*\.\d+)(\%|[a-z]+)?', bygroups(Number.Float, Keyword.Type)),
1490
(r'(black|silver|gray|white|maroon|red|purple|fuchsia|green|'
1491
r'lime|olive|yellow|navy|blue|teal|aqua)\b', Name.Builtin),
1492
(r'(true|false)', Name.Pseudo),
1493
(r'(and|or|not)', Operator.Word),
1494
(r'(\\.|[^\s\\+*\/%(),=!])+(?=[ \t]*\()', Name.Function),
1495
(r'(\\.|[^\s\\+*\/%(),=!])+', Name),
1496
(r'\n', Text, 'root'),
1500
(r'\}', String.Interpol, '#pop'),
1506
(r'\:', Name.Decorator, 'pseudo-class'),
1507
(r'\.', Name.Class, 'class'),
1508
(r'\#', Name.Namespace, 'id'),
1509
(r'[a-zA-Z0-9_-]+', Name.Tag),
1510
(r'#\{', String.Interpol, 'interpolation'),
1512
(r'[~\^\*!&\[\]\(\)<>\|+=@:;,./?-]', Operator),
1513
(r'"', String.Double, 'string-double'),
1514
(r"'", String.Single, 'string-single'),
1515
(r'\n', Text, 'root'),
1519
(r'(\\.|#(?=[^\n{])|[^\n"#])+', String.Double),
1520
(r'#\{', String.Interpol, 'interpolation'),
1521
(r'"', String.Double, '#pop'),
1525
(r"(\\.|#(?=[^\n{])|[^\n'#])+", String.Double),
1526
(r'#\{', String.Interpol, 'interpolation'),
1527
(r"'", String.Double, '#pop'),
1531
(r'(\\#|#(?=[^\n{])|[^\n#)])+', String.Other),
1532
(r'#\{', String.Interpol, 'interpolation'),
1533
(r'\)', String.Other, '#pop'),
1537
(r"(\\#|#(?=[^\n{])|\*(?=[^\n/])|[^\n#*])+", Comment),
1538
(r'#\{', String.Interpol, 'interpolation'),
1539
(r"\*/", Comment, '#pop'),
1543
(r'[\w-]+', Name.Decorator),
1544
(r'#\{', String.Interpol, 'interpolation'),
1545
(r'', Text, '#pop'),
1549
(r'[\w-]+', Name.Class),
1550
(r'#\{', String.Interpol, 'interpolation'),
1551
(r'', Text, '#pop'),
1555
(r'[\w-]+', Name.Namespace),
1556
(r'#\{', String.Interpol, 'interpolation'),
1557
(r'', Text, '#pop'),
1562
class CoffeeScriptLexer(RegexLexer):
1564
For `CoffeeScript`_ source code.
1566
.. _CoffeeScript: http://jashkenas.github.com/coffee-script/
1568
*New in Pygments 1.3.*
1571
name = 'CoffeeScript'
1572
aliases = ['coffee-script', 'coffeescript']
1573
filenames = ['*.coffee']
1574
mimetypes = ['text/coffeescript']
1578
'commentsandwhitespace': [
1580
(r'#.*?\n', Comment.Single),
1582
'slashstartsregex': [
1583
include('commentsandwhitespace'),
1584
(r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
1585
r'([gim]+\b|\B)', String.Regex, '#pop'),
1586
(r'(?=/)', Text, ('#pop', 'badregex')),
1587
(r'', Text, '#pop'),
1590
('\n', Text, '#pop'),
1593
(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
1594
include('commentsandwhitespace'),
1595
(r'\+\+|--|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|'
1596
r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*`%&\|\^/])=?',
1597
Operator, 'slashstartsregex'),
1598
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
1599
(r'[})\].]', Punctuation),
1600
(r'(for|in|of|while|break|return|continue|switch|when|then|if|else|'
1601
r'throw|try|catch|finally|new|delete|typeof|instanceof|super|'
1602
r'extends|this)\b', Keyword, 'slashstartsregex'),
1603
(r'(true|false|yes|no|on|off|null|NaN|Infinity|undefined)\b',
1605
(r'(Array|Boolean|Date|Error|Function|Math|netscape|'
1606
r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
1607
r'decodeURIComponent|encodeURI|encodeURIComponent|'
1608
r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
1609
r'window)\b', Name.Builtin),
1610
(r'[$a-zA-Z_][a-zA-Z0-9_\.:]*:\s', Name.Variable,
1611
'slashstartsregex'),
1612
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
1613
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
1614
(r'0x[0-9a-fA-F]+', Number.Hex),
1615
(r'[0-9]+', Number.Integer),
1616
(r'"(\\\\|\\"|[^"])*"', String.Double),
1617
(r"'(\\\\|\\'|[^'])*'", String.Single),