1 # -*- coding: utf-8 -*- |
1 # -*- coding: utf-8 -*- |
2 """ |
2 """ |
3 pygments.lexers.web |
3 pygments.lexers.web |
4 ~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for web-related languages and markup. |
6 Just export previously exported lexers. |
7 |
7 |
8 :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 from __future__ import unicode_literals |
12 from pygments.lexers.html import HtmlLexer, DtdLexer, XmlLexer, XsltLexer, \ |
13 |
13 HamlLexer, ScamlLexer, JadeLexer |
14 import re |
14 from pygments.lexers.css import CssLexer, SassLexer, ScssLexer |
15 import copy |
15 from pygments.lexers.javascript import JavascriptLexer, LiveScriptLexer, \ |
16 |
16 DartLexer, TypeScriptLexer, LassoLexer, ObjectiveJLexer, CoffeeScriptLexer |
17 from pygments.lexer import RegexLexer, ExtendedRegexLexer, bygroups, using, \ |
17 from pygments.lexers.actionscript import ActionScriptLexer, \ |
18 include, this |
18 ActionScript3Lexer, MxmlLexer |
19 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
19 from pygments.lexers.php import PhpLexer |
20 Number, Other, Punctuation, Literal |
20 from pygments.lexers.webmisc import DuelLexer, XQueryLexer, SlimLexer, QmlLexer |
21 from pygments.util import get_bool_opt, get_list_opt, looks_like_xml, \ |
21 from pygments.lexers.data import JsonLexer |
22 html_doctype_matches, unirange |
|
23 from pygments.lexers.agile import RubyLexer |
|
24 from pygments.lexers.compiled import ScalaLexer |
|
25 |
|
26 |
|
27 __all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'JsonLexer', 'CssLexer', |
|
28 'PhpLexer', 'ActionScriptLexer', 'XsltLexer', 'ActionScript3Lexer', |
|
29 'MxmlLexer', 'HaxeLexer', 'HamlLexer', 'SassLexer', 'ScssLexer', |
|
30 'ObjectiveJLexer', 'CoffeeScriptLexer', 'LiveScriptLexer', |
|
31 'DuelLexer', 'ScamlLexer', 'JadeLexer', 'XQueryLexer', |
|
32 'DtdLexer', 'DartLexer', 'LassoLexer', 'QmlLexer', 'TypeScriptLexer'] |
|
33 |
|
34 |
|
35 class JavascriptLexer(RegexLexer): |
|
36 """ |
|
37 For JavaScript source code. |
|
38 """ |
|
39 |
|
40 name = 'JavaScript' |
|
41 aliases = ['js', 'javascript'] |
|
42 filenames = ['*.js', ] |
|
43 mimetypes = ['application/javascript', 'application/x-javascript', |
|
44 'text/x-javascript', 'text/javascript', ] |
|
45 |
|
46 flags = re.DOTALL |
|
47 tokens = { |
|
48 'commentsandwhitespace': [ |
|
49 (r'\s+', Text), |
|
50 (r'<!--', Comment), |
|
51 (r'//.*?\n', Comment.Single), |
|
52 (r'/\*.*?\*/', Comment.Multiline) |
|
53 ], |
|
54 'slashstartsregex': [ |
|
55 include('commentsandwhitespace'), |
|
56 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
57 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
58 (r'(?=/)', Text, ('#pop', 'badregex')), |
|
59 (r'', Text, '#pop') |
|
60 ], |
|
61 'badregex': [ |
|
62 (r'\n', Text, '#pop') |
|
63 ], |
|
64 'root': [ |
|
65 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
66 include('commentsandwhitespace'), |
|
67 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' |
|
68 r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), |
|
69 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
70 (r'[})\].]', Punctuation), |
|
71 (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' |
|
72 r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' |
|
73 r'this)\b', Keyword, 'slashstartsregex'), |
|
74 (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), |
|
75 (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' |
|
76 r'extends|final|float|goto|implements|import|int|interface|long|native|' |
|
77 r'package|private|protected|public|short|static|super|synchronized|throws|' |
|
78 r'transient|volatile)\b', Keyword.Reserved), |
|
79 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), |
|
80 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
81 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
82 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
83 r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' |
|
84 r'window)\b', Name.Builtin), |
|
85 (r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other), |
|
86 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
87 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
88 (r'[0-9]+', Number.Integer), |
|
89 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
90 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
91 ] |
|
92 } |
|
93 |
|
94 |
|
95 class JsonLexer(RegexLexer): |
|
96 """ |
|
97 For JSON data structures. |
|
98 |
|
99 *New in Pygments 1.5.* |
|
100 """ |
|
101 |
|
102 name = 'JSON' |
|
103 aliases = ['json'] |
|
104 filenames = ['*.json'] |
|
105 mimetypes = [ 'application/json', ] |
|
106 |
|
107 # integer part of a number |
|
108 int_part = r'-?(0|[1-9]\d*)' |
|
109 |
|
110 # fractional part of a number |
|
111 frac_part = r'\.\d+' |
|
112 |
|
113 # exponential part of a number |
|
114 exp_part = r'[eE](\+|-)?\d+' |
|
115 |
|
116 |
|
117 flags = re.DOTALL |
|
118 tokens = { |
|
119 'whitespace': [ |
|
120 (r'\s+', Text), |
|
121 ], |
|
122 |
|
123 # represents a simple terminal value |
|
124 'simplevalue': [ |
|
125 (r'(true|false|null)\b', Keyword.Constant), |
|
126 (('%(int_part)s(%(frac_part)s%(exp_part)s|' |
|
127 '%(exp_part)s|%(frac_part)s)') % vars(), |
|
128 Number.Float), |
|
129 (int_part, Number.Integer), |
|
130 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
131 ], |
|
132 |
|
133 |
|
134 # the right hand side of an object, after the attribute name |
|
135 'objectattribute': [ |
|
136 include('value'), |
|
137 (r':', Punctuation), |
|
138 # comma terminates the attribute but expects more |
|
139 (r',', Punctuation, '#pop'), |
|
140 # a closing bracket terminates the entire object, so pop twice |
|
141 (r'}', Punctuation, ('#pop', '#pop')), |
|
142 ], |
|
143 |
|
144 # a json object - { attr, attr, ... } |
|
145 'objectvalue': [ |
|
146 include('whitespace'), |
|
147 (r'"(\\\\|\\"|[^"])*"', Name.Tag, 'objectattribute'), |
|
148 (r'}', Punctuation, '#pop'), |
|
149 ], |
|
150 |
|
151 # json array - [ value, value, ... } |
|
152 'arrayvalue': [ |
|
153 include('whitespace'), |
|
154 include('value'), |
|
155 (r',', Punctuation), |
|
156 (r']', Punctuation, '#pop'), |
|
157 ], |
|
158 |
|
159 # a json value - either a simple value or a complex value (object or array) |
|
160 'value': [ |
|
161 include('whitespace'), |
|
162 include('simplevalue'), |
|
163 (r'{', Punctuation, 'objectvalue'), |
|
164 (r'\[', Punctuation, 'arrayvalue'), |
|
165 ], |
|
166 |
|
167 |
|
168 # the root of a json document whould be a value |
|
169 'root': [ |
|
170 include('value'), |
|
171 ], |
|
172 |
|
173 } |
|
174 |
|
175 JSONLexer = JsonLexer # for backwards compatibility with Pygments 1.5 |
22 JSONLexer = JsonLexer # for backwards compatibility with Pygments 1.5 |
176 |
23 |
177 |
24 __all__ = [] |
178 class ActionScriptLexer(RegexLexer): |
|
179 """ |
|
180 For ActionScript source code. |
|
181 |
|
182 *New in Pygments 0.9.* |
|
183 """ |
|
184 |
|
185 name = 'ActionScript' |
|
186 aliases = ['as', 'actionscript'] |
|
187 filenames = ['*.as'] |
|
188 mimetypes = ['application/x-actionscript3', 'text/x-actionscript3', |
|
189 'text/actionscript3'] |
|
190 |
|
191 flags = re.DOTALL |
|
192 tokens = { |
|
193 'root': [ |
|
194 (r'\s+', Text), |
|
195 (r'//.*?\n', Comment.Single), |
|
196 (r'/\*.*?\*/', Comment.Multiline), |
|
197 (r'/(\\\\|\\/|[^/\n])*/[gim]*', String.Regex), |
|
198 (r'[~\^\*!%&<>\|+=:;,/?\\-]+', Operator), |
|
199 (r'[{}\[\]();.]+', Punctuation), |
|
200 (r'(case|default|for|each|in|while|do|break|return|continue|if|else|' |
|
201 r'throw|try|catch|var|with|new|typeof|arguments|instanceof|this|' |
|
202 r'switch)\b', Keyword), |
|
203 (r'(class|public|final|internal|native|override|private|protected|' |
|
204 r'static|import|extends|implements|interface|intrinsic|return|super|' |
|
205 r'dynamic|function|const|get|namespace|package|set)\b', |
|
206 Keyword.Declaration), |
|
207 (r'(true|false|null|NaN|Infinity|-Infinity|undefined|Void)\b', |
|
208 Keyword.Constant), |
|
209 (r'(Accessibility|AccessibilityProperties|ActionScriptVersion|' |
|
210 r'ActivityEvent|AntiAliasType|ApplicationDomain|AsBroadcaster|Array|' |
|
211 r'AsyncErrorEvent|AVM1Movie|BevelFilter|Bitmap|BitmapData|' |
|
212 r'BitmapDataChannel|BitmapFilter|BitmapFilterQuality|BitmapFilterType|' |
|
213 r'BlendMode|BlurFilter|Boolean|ByteArray|Camera|Capabilities|CapsStyle|' |
|
214 r'Class|Color|ColorMatrixFilter|ColorTransform|ContextMenu|' |
|
215 r'ContextMenuBuiltInItems|ContextMenuEvent|ContextMenuItem|' |
|
216 r'ConvultionFilter|CSMSettings|DataEvent|Date|DefinitionError|' |
|
217 r'DeleteObjectSample|Dictionary|DisplacmentMapFilter|DisplayObject|' |
|
218 r'DisplacmentMapFilterMode|DisplayObjectContainer|DropShadowFilter|' |
|
219 r'Endian|EOFError|Error|ErrorEvent|EvalError|Event|EventDispatcher|' |
|
220 r'EventPhase|ExternalInterface|FileFilter|FileReference|' |
|
221 r'FileReferenceList|FocusDirection|FocusEvent|Font|FontStyle|FontType|' |
|
222 r'FrameLabel|FullScreenEvent|Function|GlowFilter|GradientBevelFilter|' |
|
223 r'GradientGlowFilter|GradientType|Graphics|GridFitType|HTTPStatusEvent|' |
|
224 r'IBitmapDrawable|ID3Info|IDataInput|IDataOutput|IDynamicPropertyOutput' |
|
225 r'IDynamicPropertyWriter|IEventDispatcher|IExternalizable|' |
|
226 r'IllegalOperationError|IME|IMEConversionMode|IMEEvent|int|' |
|
227 r'InteractiveObject|InterpolationMethod|InvalidSWFError|InvokeEvent|' |
|
228 r'IOError|IOErrorEvent|JointStyle|Key|Keyboard|KeyboardEvent|KeyLocation|' |
|
229 r'LineScaleMode|Loader|LoaderContext|LoaderInfo|LoadVars|LocalConnection|' |
|
230 r'Locale|Math|Matrix|MemoryError|Microphone|MorphShape|Mouse|MouseEvent|' |
|
231 r'MovieClip|MovieClipLoader|Namespace|NetConnection|NetStatusEvent|' |
|
232 r'NetStream|NewObjectSample|Number|Object|ObjectEncoding|PixelSnapping|' |
|
233 r'Point|PrintJob|PrintJobOptions|PrintJobOrientation|ProgressEvent|Proxy|' |
|
234 r'QName|RangeError|Rectangle|ReferenceError|RegExp|Responder|Sample|Scene|' |
|
235 r'ScriptTimeoutError|Security|SecurityDomain|SecurityError|' |
|
236 r'SecurityErrorEvent|SecurityPanel|Selection|Shape|SharedObject|' |
|
237 r'SharedObjectFlushStatus|SimpleButton|Socket|Sound|SoundChannel|' |
|
238 r'SoundLoaderContext|SoundMixer|SoundTransform|SpreadMethod|Sprite|' |
|
239 r'StackFrame|StackOverflowError|Stage|StageAlign|StageDisplayState|' |
|
240 r'StageQuality|StageScaleMode|StaticText|StatusEvent|String|StyleSheet|' |
|
241 r'SWFVersion|SyncEvent|SyntaxError|System|TextColorType|TextField|' |
|
242 r'TextFieldAutoSize|TextFieldType|TextFormat|TextFormatAlign|' |
|
243 r'TextLineMetrics|TextRenderer|TextSnapshot|Timer|TimerEvent|Transform|' |
|
244 r'TypeError|uint|URIError|URLLoader|URLLoaderDataFormat|URLRequest|' |
|
245 r'URLRequestHeader|URLRequestMethod|URLStream|URLVariabeles|VerifyError|' |
|
246 r'Video|XML|XMLDocument|XMLList|XMLNode|XMLNodeType|XMLSocket|XMLUI)\b', |
|
247 Name.Builtin), |
|
248 (r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|' |
|
249 r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|' |
|
250 r'isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|' |
|
251 r'unescape)\b',Name.Function), |
|
252 (r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other), |
|
253 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
254 (r'0x[0-9a-f]+', Number.Hex), |
|
255 (r'[0-9]+', Number.Integer), |
|
256 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
257 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
258 ] |
|
259 } |
|
260 |
|
261 |
|
262 class ActionScript3Lexer(RegexLexer): |
|
263 """ |
|
264 For ActionScript 3 source code. |
|
265 |
|
266 *New in Pygments 0.11.* |
|
267 """ |
|
268 |
|
269 name = 'ActionScript 3' |
|
270 aliases = ['as3', 'actionscript3'] |
|
271 filenames = ['*.as'] |
|
272 mimetypes = ['application/x-actionscript', 'text/x-actionscript', |
|
273 'text/actionscript'] |
|
274 |
|
275 identifier = r'[$a-zA-Z_][a-zA-Z0-9_]*' |
|
276 typeidentifier = identifier + '(?:\.<\w+>)?' |
|
277 |
|
278 flags = re.DOTALL | re.MULTILINE |
|
279 tokens = { |
|
280 'root': [ |
|
281 (r'\s+', Text), |
|
282 (r'(function\s+)(' + identifier + r')(\s*)(\()', |
|
283 bygroups(Keyword.Declaration, Name.Function, Text, Operator), |
|
284 'funcparams'), |
|
285 (r'(var|const)(\s+)(' + identifier + r')(\s*)(:)(\s*)(' + |
|
286 typeidentifier + r')', |
|
287 bygroups(Keyword.Declaration, Text, Name, Text, Punctuation, Text, |
|
288 Keyword.Type)), |
|
289 (r'(import|package)(\s+)((?:' + identifier + r'|\.)+)(\s*)', |
|
290 bygroups(Keyword, Text, Name.Namespace, Text)), |
|
291 (r'(new)(\s+)(' + typeidentifier + r')(\s*)(\()', |
|
292 bygroups(Keyword, Text, Keyword.Type, Text, Operator)), |
|
293 (r'//.*?\n', Comment.Single), |
|
294 (r'/\*.*?\*/', Comment.Multiline), |
|
295 (r'/(\\\\|\\/|[^\n])*/[gisx]*', String.Regex), |
|
296 (r'(\.)(' + identifier + r')', bygroups(Operator, Name.Attribute)), |
|
297 (r'(case|default|for|each|in|while|do|break|return|continue|if|else|' |
|
298 r'throw|try|catch|with|new|typeof|arguments|instanceof|this|' |
|
299 r'switch|import|include|as|is)\b', |
|
300 Keyword), |
|
301 (r'(class|public|final|internal|native|override|private|protected|' |
|
302 r'static|import|extends|implements|interface|intrinsic|return|super|' |
|
303 r'dynamic|function|const|get|namespace|package|set)\b', |
|
304 Keyword.Declaration), |
|
305 (r'(true|false|null|NaN|Infinity|-Infinity|undefined|void)\b', |
|
306 Keyword.Constant), |
|
307 (r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|' |
|
308 r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|' |
|
309 r'isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|' |
|
310 r'unescape)\b', Name.Function), |
|
311 (identifier, Name), |
|
312 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
313 (r'0x[0-9a-f]+', Number.Hex), |
|
314 (r'[0-9]+', Number.Integer), |
|
315 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
316 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
317 (r'[~\^\*!%&<>\|+=:;,/?\\{}\[\]().-]+', Operator), |
|
318 ], |
|
319 'funcparams': [ |
|
320 (r'\s+', Text), |
|
321 (r'(\s*)(\.\.\.)?(' + identifier + r')(\s*)(:)(\s*)(' + |
|
322 typeidentifier + r'|\*)(\s*)', |
|
323 bygroups(Text, Punctuation, Name, Text, Operator, Text, |
|
324 Keyword.Type, Text), 'defval'), |
|
325 (r'\)', Operator, 'type') |
|
326 ], |
|
327 'type': [ |
|
328 (r'(\s*)(:)(\s*)(' + typeidentifier + r'|\*)', |
|
329 bygroups(Text, Operator, Text, Keyword.Type), '#pop:2'), |
|
330 (r'\s*', Text, '#pop:2') |
|
331 ], |
|
332 'defval': [ |
|
333 (r'(=)(\s*)([^(),]+)(\s*)(,?)', |
|
334 bygroups(Operator, Text, using(this), Text, Operator), '#pop'), |
|
335 (r',?', Operator, '#pop') |
|
336 ] |
|
337 } |
|
338 |
|
339 def analyse_text(text): |
|
340 if re.match(r'\w+\s*:\s*\w', text): |
|
341 return 0.3 |
|
342 return 0 |
|
343 |
|
344 |
|
345 class CssLexer(RegexLexer): |
|
346 """ |
|
347 For CSS (Cascading Style Sheets). |
|
348 """ |
|
349 |
|
350 name = 'CSS' |
|
351 aliases = ['css'] |
|
352 filenames = ['*.css'] |
|
353 mimetypes = ['text/css'] |
|
354 |
|
355 tokens = { |
|
356 'root': [ |
|
357 include('basics'), |
|
358 ], |
|
359 'basics': [ |
|
360 (r'\s+', Text), |
|
361 (r'/\*(?:.|\n)*?\*/', Comment), |
|
362 (r'{', Punctuation, 'content'), |
|
363 (r'\:[a-zA-Z0-9_-]+', Name.Decorator), |
|
364 (r'\.[a-zA-Z0-9_-]+', Name.Class), |
|
365 (r'\#[a-zA-Z0-9_-]+', Name.Function), |
|
366 (r'@[a-zA-Z0-9_-]+', Keyword, 'atrule'), |
|
367 (r'[a-zA-Z0-9_-]+', Name.Tag), |
|
368 (r'[~\^\*!%&\[\]\(\)<>\|+=@:;,./?-]', Operator), |
|
369 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
370 (r"'(\\\\|\\'|[^'])*'", String.Single) |
|
371 ], |
|
372 'atrule': [ |
|
373 (r'{', Punctuation, 'atcontent'), |
|
374 (r';', Punctuation, '#pop'), |
|
375 include('basics'), |
|
376 ], |
|
377 'atcontent': [ |
|
378 include('basics'), |
|
379 (r'}', Punctuation, '#pop:2'), |
|
380 ], |
|
381 'content': [ |
|
382 (r'\s+', Text), |
|
383 (r'}', Punctuation, '#pop'), |
|
384 (r'url\(.*?\)', String.Other), |
|
385 (r'^@.*?$', Comment.Preproc), |
|
386 (r'(azimuth|background-attachment|background-color|' |
|
387 r'background-image|background-position|background-repeat|' |
|
388 r'background|border-bottom-color|border-bottom-style|' |
|
389 r'border-bottom-width|border-left-color|border-left-style|' |
|
390 r'border-left-width|border-right|border-right-color|' |
|
391 r'border-right-style|border-right-width|border-top-color|' |
|
392 r'border-top-style|border-top-width|border-bottom|' |
|
393 r'border-collapse|border-left|border-width|border-color|' |
|
394 r'border-spacing|border-style|border-top|border|caption-side|' |
|
395 r'clear|clip|color|content|counter-increment|counter-reset|' |
|
396 r'cue-after|cue-before|cue|cursor|direction|display|' |
|
397 r'elevation|empty-cells|float|font-family|font-size|' |
|
398 r'font-size-adjust|font-stretch|font-style|font-variant|' |
|
399 r'font-weight|font|height|letter-spacing|line-height|' |
|
400 r'list-style-type|list-style-image|list-style-position|' |
|
401 r'list-style|margin-bottom|margin-left|margin-right|' |
|
402 r'margin-top|margin|marker-offset|marks|max-height|max-width|' |
|
403 r'min-height|min-width|opacity|orphans|outline|outline-color|' |
|
404 r'outline-style|outline-width|overflow(?:-x|-y)?|padding-bottom|' |
|
405 r'padding-left|padding-right|padding-top|padding|page|' |
|
406 r'page-break-after|page-break-before|page-break-inside|' |
|
407 r'pause-after|pause-before|pause|pitch|pitch-range|' |
|
408 r'play-during|position|quotes|richness|right|size|' |
|
409 r'speak-header|speak-numeral|speak-punctuation|speak|' |
|
410 r'speech-rate|stress|table-layout|text-align|text-decoration|' |
|
411 r'text-indent|text-shadow|text-transform|top|unicode-bidi|' |
|
412 r'vertical-align|visibility|voice-family|volume|white-space|' |
|
413 r'widows|width|word-spacing|z-index|bottom|left|' |
|
414 r'above|absolute|always|armenian|aural|auto|avoid|baseline|' |
|
415 r'behind|below|bidi-override|blink|block|bold|bolder|both|' |
|
416 r'capitalize|center-left|center-right|center|circle|' |
|
417 r'cjk-ideographic|close-quote|collapse|condensed|continuous|' |
|
418 r'crop|crosshair|cross|cursive|dashed|decimal-leading-zero|' |
|
419 r'decimal|default|digits|disc|dotted|double|e-resize|embed|' |
|
420 r'extra-condensed|extra-expanded|expanded|fantasy|far-left|' |
|
421 r'far-right|faster|fast|fixed|georgian|groove|hebrew|help|' |
|
422 r'hidden|hide|higher|high|hiragana-iroha|hiragana|icon|' |
|
423 r'inherit|inline-table|inline|inset|inside|invert|italic|' |
|
424 r'justify|katakana-iroha|katakana|landscape|larger|large|' |
|
425 r'left-side|leftwards|level|lighter|line-through|list-item|' |
|
426 r'loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|' |
|
427 r'lower|low|medium|message-box|middle|mix|monospace|' |
|
428 r'n-resize|narrower|ne-resize|no-close-quote|no-open-quote|' |
|
429 r'no-repeat|none|normal|nowrap|nw-resize|oblique|once|' |
|
430 r'open-quote|outset|outside|overline|pointer|portrait|px|' |
|
431 r'relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|' |
|
432 r'rightwards|s-resize|sans-serif|scroll|se-resize|' |
|
433 r'semi-condensed|semi-expanded|separate|serif|show|silent|' |
|
434 r'slow|slower|small-caps|small-caption|smaller|soft|solid|' |
|
435 r'spell-out|square|static|status-bar|super|sw-resize|' |
|
436 r'table-caption|table-cell|table-column|table-column-group|' |
|
437 r'table-footer-group|table-header-group|table-row|' |
|
438 r'table-row-group|text|text-bottom|text-top|thick|thin|' |
|
439 r'transparent|ultra-condensed|ultra-expanded|underline|' |
|
440 r'upper-alpha|upper-latin|upper-roman|uppercase|url|' |
|
441 r'visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|' |
|
442 r'x-low|x-small|x-soft|xx-large|xx-small|yes)\b', Keyword), |
|
443 (r'(indigo|gold|firebrick|indianred|yellow|darkolivegreen|' |
|
444 r'darkseagreen|mediumvioletred|mediumorchid|chartreuse|' |
|
445 r'mediumslateblue|black|springgreen|crimson|lightsalmon|brown|' |
|
446 r'turquoise|olivedrab|cyan|silver|skyblue|gray|darkturquoise|' |
|
447 r'goldenrod|darkgreen|darkviolet|darkgray|lightpink|teal|' |
|
448 r'darkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|' |
|
449 r'violet|navy|orchid|blue|ghostwhite|honeydew|cornflowerblue|' |
|
450 r'darkblue|darkkhaki|mediumpurple|cornsilk|red|bisque|slategray|' |
|
451 r'darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|' |
|
452 r'gainsboro|mediumturquoise|floralwhite|coral|purple|lightgrey|' |
|
453 r'lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|' |
|
454 r'greenyellow|royalblue|lightseagreen|mistyrose|sienna|' |
|
455 r'lightcoral|orangered|navajowhite|lime|palegreen|burlywood|' |
|
456 r'seashell|mediumspringgreen|fuchsia|papayawhip|blanchedalmond|' |
|
457 r'peru|aquamarine|white|darkslategray|ivory|dodgerblue|' |
|
458 r'lemonchiffon|chocolate|orange|forestgreen|slateblue|olive|' |
|
459 r'mintcream|antiquewhite|darkorange|cadetblue|moccasin|' |
|
460 r'limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|' |
|
461 r'plum|aqua|darkgoldenrod|maroon|sandybrown|magenta|tan|' |
|
462 r'rosybrown|pink|lightblue|palevioletred|mediumseagreen|' |
|
463 r'dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|' |
|
464 r'paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|' |
|
465 r'lightslategray|lawngreen|lightgreen|tomato|hotpink|' |
|
466 r'lightyellow|lavenderblush|linen|mediumaquamarine|green|' |
|
467 r'blueviolet|peachpuff)\b', Name.Builtin), |
|
468 (r'\!important', Comment.Preproc), |
|
469 (r'/\*(?:.|\n)*?\*/', Comment), |
|
470 (r'\#[a-zA-Z0-9]{1,6}', Number), |
|
471 (r'[\.-]?[0-9]*[\.]?[0-9]+(em|px|\%|pt|pc|in|mm|cm|ex|s)\b', Number), |
|
472 (r'-?[0-9]+', Number), |
|
473 (r'[~\^\*!%&<>\|+=@:,./?-]+', Operator), |
|
474 (r'[\[\]();]+', Punctuation), |
|
475 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
476 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
477 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name) |
|
478 ] |
|
479 } |
|
480 |
|
481 |
|
482 class ObjectiveJLexer(RegexLexer): |
|
483 """ |
|
484 For Objective-J source code with preprocessor directives. |
|
485 |
|
486 *New in Pygments 1.3.* |
|
487 """ |
|
488 |
|
489 name = 'Objective-J' |
|
490 aliases = ['objective-j', 'objectivej', 'obj-j', 'objj'] |
|
491 filenames = ['*.j'] |
|
492 mimetypes = ['text/x-objective-j'] |
|
493 |
|
494 #: optional Comment or Whitespace |
|
495 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)*' |
|
496 |
|
497 flags = re.DOTALL | re.MULTILINE |
|
498 |
|
499 tokens = { |
|
500 'root': [ |
|
501 include('whitespace'), |
|
502 |
|
503 # function definition |
|
504 (r'^(' + _ws + r'[\+-]' + _ws + r')([\(a-zA-Z_].*?[^\(])(' + _ws + '{)', |
|
505 bygroups(using(this), using(this, state='function_signature'), |
|
506 using(this))), |
|
507 |
|
508 # class definition |
|
509 (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text), |
|
510 'classname'), |
|
511 (r'(@class|@protocol)(\s*)', bygroups(Keyword, Text), |
|
512 'forward_classname'), |
|
513 (r'(\s*)(@end)(\s*)', bygroups(Text, Keyword, Text)), |
|
514 |
|
515 include('statements'), |
|
516 ('[{\(\)}]', Punctuation), |
|
517 (';', Punctuation), |
|
518 ], |
|
519 'whitespace': [ |
|
520 (r'(@import)(\s+)("(?:\\\\|\\"|[^"])*")', |
|
521 bygroups(Comment.Preproc, Text, String.Double)), |
|
522 (r'(@import)(\s+)(<(?:\\\\|\\>|[^>])*>)', |
|
523 bygroups(Comment.Preproc, Text, String.Double)), |
|
524 (r'(#(?:include|import))(\s+)("(?:\\\\|\\"|[^"])*")', |
|
525 bygroups(Comment.Preproc, Text, String.Double)), |
|
526 (r'(#(?:include|import))(\s+)(<(?:\\\\|\\>|[^>])*>)', |
|
527 bygroups(Comment.Preproc, Text, String.Double)), |
|
528 |
|
529 (r'#if\s+0', Comment.Preproc, 'if0'), |
|
530 (r'#', Comment.Preproc, 'macro'), |
|
531 |
|
532 (r'\n', Text), |
|
533 (r'\s+', Text), |
|
534 (r'\\\n', Text), # line continuation |
|
535 (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single), |
|
536 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), |
|
537 (r'<!--', Comment), |
|
538 ], |
|
539 'slashstartsregex': [ |
|
540 include('whitespace'), |
|
541 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
542 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
543 (r'(?=/)', Text, ('#pop', 'badregex')), |
|
544 (r'', Text, '#pop'), |
|
545 ], |
|
546 'badregex': [ |
|
547 (r'\n', Text, '#pop'), |
|
548 ], |
|
549 'statements': [ |
|
550 (r'(L|@)?"', String, 'string'), |
|
551 (r"(L|@)?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", |
|
552 String.Char), |
|
553 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
554 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
555 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float), |
|
556 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), |
|
557 (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex), |
|
558 (r'0[0-7]+[Ll]?', Number.Oct), |
|
559 (r'\d+[Ll]?', Number.Integer), |
|
560 |
|
561 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
562 |
|
563 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' |
|
564 r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', |
|
565 Operator, 'slashstartsregex'), |
|
566 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
567 (r'[})\].]', Punctuation), |
|
568 |
|
569 (r'(for|in|while|do|break|return|continue|switch|case|default|if|' |
|
570 r'else|throw|try|catch|finally|new|delete|typeof|instanceof|void|' |
|
571 r'prototype|__proto__)\b', Keyword, 'slashstartsregex'), |
|
572 |
|
573 (r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'), |
|
574 |
|
575 (r'(@selector|@private|@protected|@public|@encode|' |
|
576 r'@synchronized|@try|@throw|@catch|@finally|@end|@property|' |
|
577 r'@synthesize|@dynamic|@for|@accessors|new)\b', Keyword), |
|
578 |
|
579 (r'(int|long|float|short|double|char|unsigned|signed|void|' |
|
580 r'id|BOOL|bool|boolean|IBOutlet|IBAction|SEL|@outlet|@action)\b', |
|
581 Keyword.Type), |
|
582 |
|
583 (r'(self|super)\b', Name.Builtin), |
|
584 |
|
585 (r'(TRUE|YES|FALSE|NO|Nil|nil|NULL)\b', Keyword.Constant), |
|
586 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), |
|
587 (r'(ABS|ASIN|ACOS|ATAN|ATAN2|SIN|COS|TAN|EXP|POW|CEIL|FLOOR|ROUND|' |
|
588 r'MIN|MAX|RAND|SQRT|E|LN2|LN10|LOG2E|LOG10E|PI|PI2|PI_2|SQRT1_2|' |
|
589 r'SQRT2)\b', Keyword.Constant), |
|
590 |
|
591 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
592 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
593 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
594 r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' |
|
595 r'window)\b', Name.Builtin), |
|
596 |
|
597 (r'([$a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r')(?=\()', |
|
598 bygroups(Name.Function, using(this))), |
|
599 |
|
600 (r'[$a-zA-Z_][a-zA-Z0-9_]*', Name), |
|
601 ], |
|
602 'classname' : [ |
|
603 # interface definition that inherits |
|
604 (r'([a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r':' + _ws + |
|
605 r')([a-zA-Z_][a-zA-Z0-9_]*)?', |
|
606 bygroups(Name.Class, using(this), Name.Class), '#pop'), |
|
607 # interface definition for a category |
|
608 (r'([a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r'\()([a-zA-Z_][a-zA-Z0-9_]*)(\))', |
|
609 bygroups(Name.Class, using(this), Name.Label, Text), '#pop'), |
|
610 # simple interface / implementation |
|
611 (r'([a-zA-Z_][a-zA-Z0-9_]*)', Name.Class, '#pop'), |
|
612 ], |
|
613 'forward_classname' : [ |
|
614 (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*,\s*)', |
|
615 bygroups(Name.Class, Text), '#push'), |
|
616 (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*;?)', |
|
617 bygroups(Name.Class, Text), '#pop'), |
|
618 ], |
|
619 'function_signature': [ |
|
620 include('whitespace'), |
|
621 |
|
622 # start of a selector w/ parameters |
|
623 (r'(\(' + _ws + r')' # open paren |
|
624 r'([a-zA-Z_][a-zA-Z0-9_]+)' # return type |
|
625 r'(' + _ws + r'\)' + _ws + r')' # close paren |
|
626 r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name |
|
627 bygroups(using(this), Keyword.Type, using(this), |
|
628 Name.Function), 'function_parameters'), |
|
629 |
|
630 # no-param function |
|
631 (r'(\(' + _ws + r')' # open paren |
|
632 r'([a-zA-Z_][a-zA-Z0-9_]+)' # return type |
|
633 r'(' + _ws + r'\)' + _ws + r')' # close paren |
|
634 r'([$a-zA-Z_][a-zA-Z0-9_]+)', # function name |
|
635 bygroups(using(this), Keyword.Type, using(this), |
|
636 Name.Function), "#pop"), |
|
637 |
|
638 # no return type given, start of a selector w/ parameters |
|
639 (r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name |
|
640 bygroups (Name.Function), 'function_parameters'), |
|
641 |
|
642 # no return type given, no-param function |
|
643 (r'([$a-zA-Z_][a-zA-Z0-9_]+)', # function name |
|
644 bygroups(Name.Function), "#pop"), |
|
645 |
|
646 ('', Text, '#pop'), |
|
647 ], |
|
648 'function_parameters': [ |
|
649 include('whitespace'), |
|
650 |
|
651 # parameters |
|
652 (r'(\(' + _ws + ')' # open paren |
|
653 r'([^\)]+)' # type |
|
654 r'(' + _ws + r'\)' + _ws + r')' # close paren |
|
655 r'([$a-zA-Z_][a-zA-Z0-9_]+)', # param name |
|
656 bygroups(using(this), Keyword.Type, using(this), Text)), |
|
657 |
|
658 # one piece of a selector name |
|
659 (r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name |
|
660 Name.Function), |
|
661 |
|
662 # smallest possible selector piece |
|
663 (r'(:)', Name.Function), |
|
664 |
|
665 # var args |
|
666 (r'(,' + _ws + r'\.\.\.)', using(this)), |
|
667 |
|
668 # param name |
|
669 (r'([$a-zA-Z_][a-zA-Z0-9_]+)', Text), |
|
670 ], |
|
671 'expression' : [ |
|
672 (r'([$a-zA-Z_][a-zA-Z0-9_]*)(\()', bygroups(Name.Function, |
|
673 Punctuation)), |
|
674 (r'(\))', Punctuation, "#pop"), |
|
675 ], |
|
676 'string': [ |
|
677 (r'"', String, '#pop'), |
|
678 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), |
|
679 (r'[^\\"\n]+', String), # all other characters |
|
680 (r'\\\n', String), # line continuation |
|
681 (r'\\', String), # stray backslash |
|
682 ], |
|
683 'macro': [ |
|
684 (r'[^/\n]+', Comment.Preproc), |
|
685 (r'/[*](.|\n)*?[*]/', Comment.Multiline), |
|
686 (r'//.*?\n', Comment.Single, '#pop'), |
|
687 (r'/', Comment.Preproc), |
|
688 (r'(?<=\\)\n', Comment.Preproc), |
|
689 (r'\n', Comment.Preproc, '#pop'), |
|
690 ], |
|
691 'if0': [ |
|
692 (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'), |
|
693 (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'), |
|
694 (r'.*?\n', Comment), |
|
695 ] |
|
696 } |
|
697 |
|
698 def analyse_text(text): |
|
699 if re.search('^\s*@import\s+[<"]', text, re.MULTILINE): |
|
700 # special directive found in most Objective-J files |
|
701 return True |
|
702 return False |
|
703 |
|
704 |
|
705 class HtmlLexer(RegexLexer): |
|
706 """ |
|
707 For HTML 4 and XHTML 1 markup. Nested JavaScript and CSS is highlighted |
|
708 by the appropriate lexer. |
|
709 """ |
|
710 |
|
711 name = 'HTML' |
|
712 aliases = ['html'] |
|
713 filenames = ['*.html', '*.htm', '*.xhtml', '*.xslt'] |
|
714 mimetypes = ['text/html', 'application/xhtml+xml'] |
|
715 |
|
716 flags = re.IGNORECASE | re.DOTALL |
|
717 tokens = { |
|
718 'root': [ |
|
719 ('[^<&]+', Text), |
|
720 (r'&\S*?;', Name.Entity), |
|
721 (r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc), |
|
722 ('<!--', Comment, 'comment'), |
|
723 (r'<\?.*?\?>', Comment.Preproc), |
|
724 ('<![^>]*>', Comment.Preproc), |
|
725 (r'<\s*script\s*', Name.Tag, ('script-content', 'tag')), |
|
726 (r'<\s*style\s*', Name.Tag, ('style-content', 'tag')), |
|
727 (r'<\s*[a-zA-Z0-9:]+', Name.Tag, 'tag'), |
|
728 (r'<\s*/\s*[a-zA-Z0-9:]+\s*>', Name.Tag), |
|
729 ], |
|
730 'comment': [ |
|
731 ('[^-]+', Comment), |
|
732 ('-->', Comment, '#pop'), |
|
733 ('-', Comment), |
|
734 ], |
|
735 'tag': [ |
|
736 (r'\s+', Text), |
|
737 (r'[a-zA-Z0-9_:-]+\s*=', Name.Attribute, 'attr'), |
|
738 (r'[a-zA-Z0-9_:-]+', Name.Attribute), |
|
739 (r'/?\s*>', Name.Tag, '#pop'), |
|
740 ], |
|
741 'script-content': [ |
|
742 (r'<\s*/\s*script\s*>', Name.Tag, '#pop'), |
|
743 (r'.+?(?=<\s*/\s*script\s*>)', using(JavascriptLexer)), |
|
744 ], |
|
745 'style-content': [ |
|
746 (r'<\s*/\s*style\s*>', Name.Tag, '#pop'), |
|
747 (r'.+?(?=<\s*/\s*style\s*>)', using(CssLexer)), |
|
748 ], |
|
749 'attr': [ |
|
750 ('".*?"', String, '#pop'), |
|
751 ("'.*?'", String, '#pop'), |
|
752 (r'[^\s>]+', String, '#pop'), |
|
753 ], |
|
754 } |
|
755 |
|
756 def analyse_text(text): |
|
757 if html_doctype_matches(text): |
|
758 return 0.5 |
|
759 |
|
760 |
|
761 class PhpLexer(RegexLexer): |
|
762 """ |
|
763 For `PHP <http://www.php.net/>`_ source code. |
|
764 For PHP embedded in HTML, use the `HtmlPhpLexer`. |
|
765 |
|
766 Additional options accepted: |
|
767 |
|
768 `startinline` |
|
769 If given and ``True`` the lexer starts highlighting with |
|
770 php code (i.e.: no starting ``<?php`` required). The default |
|
771 is ``False``. |
|
772 `funcnamehighlighting` |
|
773 If given and ``True``, highlight builtin function names |
|
774 (default: ``True``). |
|
775 `disabledmodules` |
|
776 If given, must be a list of module names whose function names |
|
777 should not be highlighted. By default all modules are highlighted |
|
778 except the special ``'unknown'`` module that includes functions |
|
779 that are known to php but are undocumented. |
|
780 |
|
781 To get a list of allowed modules have a look into the |
|
782 `_phpbuiltins` module: |
|
783 |
|
784 .. sourcecode:: pycon |
|
785 |
|
786 >>> from pygments.lexers._phpbuiltins import MODULES |
|
787 >>> MODULES.keys() |
|
788 ['PHP Options/Info', 'Zip', 'dba', ...] |
|
789 |
|
790 In fact the names of those modules match the module names from |
|
791 the php documentation. |
|
792 """ |
|
793 |
|
794 name = 'PHP' |
|
795 aliases = ['php', 'php3', 'php4', 'php5'] |
|
796 filenames = ['*.php', '*.php[345]', '*.inc'] |
|
797 mimetypes = ['text/x-php'] |
|
798 |
|
799 flags = re.IGNORECASE | re.DOTALL | re.MULTILINE |
|
800 tokens = { |
|
801 'root': [ |
|
802 (r'<\?(php)?', Comment.Preproc, 'php'), |
|
803 (r'[^<]+', Other), |
|
804 (r'<', Other) |
|
805 ], |
|
806 'php': [ |
|
807 (r'\?>', Comment.Preproc, '#pop'), |
|
808 (r'<<<(\'?)([a-zA-Z_][a-zA-Z0-9_]*)\1\n.*?\n\2\;?\n', String), |
|
809 (r'\s+', Text), |
|
810 (r'#.*?\n', Comment.Single), |
|
811 (r'//.*?\n', Comment.Single), |
|
812 # put the empty comment here, it is otherwise seen as |
|
813 # the start of a docstring |
|
814 (r'/\*\*/', Comment.Multiline), |
|
815 (r'/\*\*.*?\*/', String.Doc), |
|
816 (r'/\*.*?\*/', Comment.Multiline), |
|
817 (r'(->|::)(\s*)([a-zA-Z_][a-zA-Z0-9_]*)', |
|
818 bygroups(Operator, Text, Name.Attribute)), |
|
819 (r'[~!%^&*+=|:.<>/?@-]+', Operator), |
|
820 (r'[\[\]{}();,]+', Punctuation), |
|
821 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), |
|
822 (r'(function)(\s*)(?=\()', bygroups(Keyword, Text)), |
|
823 (r'(function)(\s+)(&?)(\s*)', |
|
824 bygroups(Keyword, Text, Operator, Text), 'functionname'), |
|
825 (r'(const)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)', |
|
826 bygroups(Keyword, Text, Name.Constant)), |
|
827 (r'(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|' |
|
828 r'eval|PHP_OS|break|exit|case|extends|PHP_VERSION|cfunction|' |
|
829 r'FALSE|print|for|require|continue|foreach|require_once|' |
|
830 r'declare|return|default|static|do|switch|die|stdClass|' |
|
831 r'echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|' |
|
832 r'virtual|endfor|include_once|while|endforeach|global|__FILE__|' |
|
833 r'endif|list|__LINE__|endswitch|new|__sleep|endwhile|not|' |
|
834 r'array|__wakeup|E_ALL|NULL|final|php_user_filter|interface|' |
|
835 r'implements|public|private|protected|abstract|clone|try|' |
|
836 r'catch|throw|this|use|namespace|trait)\b', Keyword), |
|
837 (r'(true|false|null)\b', Keyword.Constant), |
|
838 (r'\$\{\$+[a-zA-Z_][a-zA-Z0-9_]*\}', Name.Variable), |
|
839 (r'\$+[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable), |
|
840 (r'[\\a-zA-Z_][\\a-zA-Z0-9_]*', Name.Other), |
|
841 (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float), |
|
842 (r'\d+[eE][+-]?[0-9]+', Number.Float), |
|
843 (r'0[0-7]+', Number.Oct), |
|
844 (r'0[xX][a-fA-F0-9]+', Number.Hex), |
|
845 (r'\d+', Number.Integer), |
|
846 (r"'([^'\\]*(?:\\.[^'\\]*)*)'", String.Single), |
|
847 (r'`([^`\\]*(?:\\.[^`\\]*)*)`', String.Backtick), |
|
848 (r'"', String.Double, 'string'), |
|
849 ], |
|
850 'classname': [ |
|
851 (r'[a-zA-Z_][\\a-zA-Z0-9_]*', Name.Class, '#pop') |
|
852 ], |
|
853 'functionname': [ |
|
854 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop') |
|
855 ], |
|
856 'string': [ |
|
857 (r'"', String.Double, '#pop'), |
|
858 (r'[^{$"\\]+', String.Double), |
|
859 (r'\\([nrt\"$\\]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2})', String.Escape), |
|
860 (r'\$[a-zA-Z_][a-zA-Z0-9_]*(\[\S+\]|->[a-zA-Z_][a-zA-Z0-9_]*)?', |
|
861 String.Interpol), |
|
862 (r'(\{\$\{)(.*?)(\}\})', |
|
863 bygroups(String.Interpol, using(this, _startinline=True), |
|
864 String.Interpol)), |
|
865 (r'(\{)(\$.*?)(\})', |
|
866 bygroups(String.Interpol, using(this, _startinline=True), |
|
867 String.Interpol)), |
|
868 (r'(\$\{)(\S+)(\})', |
|
869 bygroups(String.Interpol, Name.Variable, String.Interpol)), |
|
870 (r'[${\\]+', String.Double) |
|
871 ], |
|
872 } |
|
873 |
|
874 def __init__(self, **options): |
|
875 self.funcnamehighlighting = get_bool_opt( |
|
876 options, 'funcnamehighlighting', True) |
|
877 self.disabledmodules = get_list_opt( |
|
878 options, 'disabledmodules', ['unknown']) |
|
879 self.startinline = get_bool_opt(options, 'startinline', False) |
|
880 |
|
881 # private option argument for the lexer itself |
|
882 if '_startinline' in options: |
|
883 self.startinline = options.pop('_startinline') |
|
884 |
|
885 # collect activated functions in a set |
|
886 self._functions = set() |
|
887 if self.funcnamehighlighting: |
|
888 from pygments.lexers._phpbuiltins import MODULES |
|
889 for key, value in MODULES.items(): |
|
890 if key not in self.disabledmodules: |
|
891 self._functions.update(value) |
|
892 RegexLexer.__init__(self, **options) |
|
893 |
|
894 def get_tokens_unprocessed(self, text): |
|
895 stack = ['root'] |
|
896 if self.startinline: |
|
897 stack.append('php') |
|
898 for index, token, value in \ |
|
899 RegexLexer.get_tokens_unprocessed(self, text, stack): |
|
900 if token is Name.Other: |
|
901 if value in self._functions: |
|
902 yield index, Name.Builtin, value |
|
903 continue |
|
904 yield index, token, value |
|
905 |
|
906 def analyse_text(text): |
|
907 rv = 0.0 |
|
908 if re.search(r'<\?(?!xml)', text): |
|
909 rv += 0.3 |
|
910 if '?>' in text: |
|
911 rv += 0.1 |
|
912 return rv |
|
913 |
|
914 |
|
915 class DtdLexer(RegexLexer): |
|
916 """ |
|
917 A lexer for DTDs (Document Type Definitions). |
|
918 |
|
919 *New in Pygments 1.5.* |
|
920 """ |
|
921 |
|
922 flags = re.MULTILINE | re.DOTALL |
|
923 |
|
924 name = 'DTD' |
|
925 aliases = ['dtd'] |
|
926 filenames = ['*.dtd'] |
|
927 mimetypes = ['application/xml-dtd'] |
|
928 |
|
929 tokens = { |
|
930 'root': [ |
|
931 include('common'), |
|
932 |
|
933 (r'(<!ELEMENT)(\s+)(\S+)', |
|
934 bygroups(Keyword, Text, Name.Tag), 'element'), |
|
935 (r'(<!ATTLIST)(\s+)(\S+)', |
|
936 bygroups(Keyword, Text, Name.Tag), 'attlist'), |
|
937 (r'(<!ENTITY)(\s+)(\S+)', |
|
938 bygroups(Keyword, Text, Name.Entity), 'entity'), |
|
939 (r'(<!NOTATION)(\s+)(\S+)', |
|
940 bygroups(Keyword, Text, Name.Tag), 'notation'), |
|
941 (r'(<!\[)([^\[\s]+)(\s*)(\[)', # conditional sections |
|
942 bygroups(Keyword, Name.Entity, Text, Keyword)), |
|
943 |
|
944 (r'(<!DOCTYPE)(\s+)([^>\s]+)', |
|
945 bygroups(Keyword, Text, Name.Tag)), |
|
946 (r'PUBLIC|SYSTEM', Keyword.Constant), |
|
947 (r'[\[\]>]', Keyword), |
|
948 ], |
|
949 |
|
950 'common': [ |
|
951 (r'\s+', Text), |
|
952 (r'(%|&)[^;]*;', Name.Entity), |
|
953 ('<!--', Comment, 'comment'), |
|
954 (r'[(|)*,?+]', Operator), |
|
955 (r'"[^"]*"', String.Double), |
|
956 (r'\'[^\']*\'', String.Single), |
|
957 ], |
|
958 |
|
959 'comment': [ |
|
960 ('[^-]+', Comment), |
|
961 ('-->', Comment, '#pop'), |
|
962 ('-', Comment), |
|
963 ], |
|
964 |
|
965 'element': [ |
|
966 include('common'), |
|
967 (r'EMPTY|ANY|#PCDATA', Keyword.Constant), |
|
968 (r'[^>\s\|()?+*,]+', Name.Tag), |
|
969 (r'>', Keyword, '#pop'), |
|
970 ], |
|
971 |
|
972 'attlist': [ |
|
973 include('common'), |
|
974 (r'CDATA|IDREFS|IDREF|ID|NMTOKENS|NMTOKEN|ENTITIES|ENTITY|NOTATION', |
|
975 Keyword.Constant), |
|
976 (r'#REQUIRED|#IMPLIED|#FIXED', Keyword.Constant), |
|
977 (r'xml:space|xml:lang', Keyword.Reserved), |
|
978 (r'[^>\s\|()?+*,]+', Name.Attribute), |
|
979 (r'>', Keyword, '#pop'), |
|
980 ], |
|
981 |
|
982 'entity': [ |
|
983 include('common'), |
|
984 (r'SYSTEM|PUBLIC|NDATA', Keyword.Constant), |
|
985 (r'[^>\s\|()?+*,]+', Name.Entity), |
|
986 (r'>', Keyword, '#pop'), |
|
987 ], |
|
988 |
|
989 'notation': [ |
|
990 include('common'), |
|
991 (r'SYSTEM|PUBLIC', Keyword.Constant), |
|
992 (r'[^>\s\|()?+*,]+', Name.Attribute), |
|
993 (r'>', Keyword, '#pop'), |
|
994 ], |
|
995 } |
|
996 |
|
997 def analyse_text(text): |
|
998 if not looks_like_xml(text) and \ |
|
999 ('<!ELEMENT' in text or '<!ATTLIST' in text or '<!ENTITY' in text): |
|
1000 return 0.8 |
|
1001 |
|
1002 class XmlLexer(RegexLexer): |
|
1003 """ |
|
1004 Generic lexer for XML (eXtensible Markup Language). |
|
1005 """ |
|
1006 |
|
1007 flags = re.MULTILINE | re.DOTALL | re.UNICODE |
|
1008 |
|
1009 name = 'XML' |
|
1010 aliases = ['xml'] |
|
1011 filenames = ['*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl'] |
|
1012 mimetypes = ['text/xml', 'application/xml', 'image/svg+xml', |
|
1013 'application/rss+xml', 'application/atom+xml'] |
|
1014 |
|
1015 tokens = { |
|
1016 'root': [ |
|
1017 ('[^<&]+', Text), |
|
1018 (r'&\S*?;', Name.Entity), |
|
1019 (r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc), |
|
1020 ('<!--', Comment, 'comment'), |
|
1021 (r'<\?.*?\?>', Comment.Preproc), |
|
1022 ('<![^>]*>', Comment.Preproc), |
|
1023 (r'<\s*[\w:.-]+', Name.Tag, 'tag'), |
|
1024 (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag), |
|
1025 ], |
|
1026 'comment': [ |
|
1027 ('[^-]+', Comment), |
|
1028 ('-->', Comment, '#pop'), |
|
1029 ('-', Comment), |
|
1030 ], |
|
1031 'tag': [ |
|
1032 (r'\s+', Text), |
|
1033 (r'[\w.:-]+\s*=', Name.Attribute, 'attr'), |
|
1034 (r'/?\s*>', Name.Tag, '#pop'), |
|
1035 ], |
|
1036 'attr': [ |
|
1037 ('\s+', Text), |
|
1038 ('".*?"', String, '#pop'), |
|
1039 ("'.*?'", String, '#pop'), |
|
1040 (r'[^\s>]+', String, '#pop'), |
|
1041 ], |
|
1042 } |
|
1043 |
|
1044 def analyse_text(text): |
|
1045 if looks_like_xml(text): |
|
1046 return 0.5 |
|
1047 |
|
1048 |
|
1049 class XsltLexer(XmlLexer): |
|
1050 ''' |
|
1051 A lexer for XSLT. |
|
1052 |
|
1053 *New in Pygments 0.10.* |
|
1054 ''' |
|
1055 |
|
1056 name = 'XSLT' |
|
1057 aliases = ['xslt'] |
|
1058 filenames = ['*.xsl', '*.xslt', '*.xpl'] # xpl is XProc |
|
1059 mimetypes = ['application/xsl+xml', 'application/xslt+xml'] |
|
1060 |
|
1061 EXTRA_KEYWORDS = set([ |
|
1062 'apply-imports', 'apply-templates', 'attribute', |
|
1063 'attribute-set', 'call-template', 'choose', 'comment', |
|
1064 'copy', 'copy-of', 'decimal-format', 'element', 'fallback', |
|
1065 'for-each', 'if', 'import', 'include', 'key', 'message', |
|
1066 'namespace-alias', 'number', 'otherwise', 'output', 'param', |
|
1067 'preserve-space', 'processing-instruction', 'sort', |
|
1068 'strip-space', 'stylesheet', 'template', 'text', 'transform', |
|
1069 'value-of', 'variable', 'when', 'with-param' |
|
1070 ]) |
|
1071 |
|
1072 def get_tokens_unprocessed(self, text): |
|
1073 for index, token, value in XmlLexer.get_tokens_unprocessed(self, text): |
|
1074 m = re.match('</?xsl:([^>]*)/?>?', value) |
|
1075 |
|
1076 if token is Name.Tag and m and m.group(1) in self.EXTRA_KEYWORDS: |
|
1077 yield index, Keyword, value |
|
1078 else: |
|
1079 yield index, token, value |
|
1080 |
|
1081 def analyse_text(text): |
|
1082 if looks_like_xml(text) and '<xsl' in text: |
|
1083 return 0.8 |
|
1084 |
|
1085 |
|
1086 class MxmlLexer(RegexLexer): |
|
1087 """ |
|
1088 For MXML markup. |
|
1089 Nested AS3 in <script> tags is highlighted by the appropriate lexer. |
|
1090 |
|
1091 *New in Pygments 1.1.* |
|
1092 """ |
|
1093 flags = re.MULTILINE | re.DOTALL |
|
1094 name = 'MXML' |
|
1095 aliases = ['mxml'] |
|
1096 filenames = ['*.mxml'] |
|
1097 mimetimes = ['text/xml', 'application/xml'] |
|
1098 |
|
1099 tokens = { |
|
1100 'root': [ |
|
1101 ('[^<&]+', Text), |
|
1102 (r'&\S*?;', Name.Entity), |
|
1103 (r'(\<\!\[CDATA\[)(.*?)(\]\]\>)', |
|
1104 bygroups(String, using(ActionScript3Lexer), String)), |
|
1105 ('<!--', Comment, 'comment'), |
|
1106 (r'<\?.*?\?>', Comment.Preproc), |
|
1107 ('<![^>]*>', Comment.Preproc), |
|
1108 (r'<\s*[a-zA-Z0-9:._-]+', Name.Tag, 'tag'), |
|
1109 (r'<\s*/\s*[a-zA-Z0-9:._-]+\s*>', Name.Tag), |
|
1110 ], |
|
1111 'comment': [ |
|
1112 ('[^-]+', Comment), |
|
1113 ('-->', Comment, '#pop'), |
|
1114 ('-', Comment), |
|
1115 ], |
|
1116 'tag': [ |
|
1117 (r'\s+', Text), |
|
1118 (r'[a-zA-Z0-9_.:-]+\s*=', Name.Attribute, 'attr'), |
|
1119 (r'/?\s*>', Name.Tag, '#pop'), |
|
1120 ], |
|
1121 'attr': [ |
|
1122 ('\s+', Text), |
|
1123 ('".*?"', String, '#pop'), |
|
1124 ("'.*?'", String, '#pop'), |
|
1125 (r'[^\s>]+', String, '#pop'), |
|
1126 ], |
|
1127 } |
|
1128 |
|
1129 |
|
1130 class HaxeLexer(RegexLexer): |
|
1131 """ |
|
1132 For haXe source code (http://haxe.org/). |
|
1133 |
|
1134 *New in Pygments 1.3.* |
|
1135 """ |
|
1136 |
|
1137 name = 'haXe' |
|
1138 aliases = ['hx', 'haXe'] |
|
1139 filenames = ['*.hx'] |
|
1140 mimetypes = ['text/haxe'] |
|
1141 |
|
1142 ident = r'(?:[a-zA-Z_][a-zA-Z0-9_]*)' |
|
1143 typeid = r'(?:(?:[a-z0-9_\.])*[A-Z_][A-Za-z0-9_]*)' |
|
1144 key_prop = r'(?:default|null|never)' |
|
1145 key_decl_mod = r'(?:public|private|override|static|inline|extern|dynamic)' |
|
1146 |
|
1147 flags = re.DOTALL | re.MULTILINE |
|
1148 |
|
1149 tokens = { |
|
1150 'root': [ |
|
1151 include('whitespace'), |
|
1152 include('comments'), |
|
1153 (key_decl_mod, Keyword.Declaration), |
|
1154 include('enumdef'), |
|
1155 include('typedef'), |
|
1156 include('classdef'), |
|
1157 include('imports'), |
|
1158 ], |
|
1159 |
|
1160 # General constructs |
|
1161 'comments': [ |
|
1162 (r'//.*?\n', Comment.Single), |
|
1163 (r'/\*.*?\*/', Comment.Multiline), |
|
1164 (r'#[^\n]*', Comment.Preproc), |
|
1165 ], |
|
1166 'whitespace': [ |
|
1167 include('comments'), |
|
1168 (r'\s+', Text), |
|
1169 ], |
|
1170 'codekeywords': [ |
|
1171 (r'\b(if|else|while|do|for|in|break|continue|' |
|
1172 r'return|switch|case|try|catch|throw|null|trace|' |
|
1173 r'new|this|super|untyped|cast|callback|here)\b', |
|
1174 Keyword.Reserved), |
|
1175 ], |
|
1176 'literals': [ |
|
1177 (r'0[xX][0-9a-fA-F]+', Number.Hex), |
|
1178 (r'[0-9]+', Number.Integer), |
|
1179 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
1180 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
1181 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
1182 (r'~/([^\n])*?/[gisx]*', String.Regex), |
|
1183 (r'\b(true|false|null)\b', Keyword.Constant), |
|
1184 ], |
|
1185 'codeblock': [ |
|
1186 include('whitespace'), |
|
1187 include('new'), |
|
1188 include('case'), |
|
1189 include('anonfundef'), |
|
1190 include('literals'), |
|
1191 include('vardef'), |
|
1192 include('codekeywords'), |
|
1193 (r'[();,\[\]]', Punctuation), |
|
1194 (r'(?:=|\+=|-=|\*=|/=|%=|&=|\|=|\^=|<<=|>>=|>>>=|\|\||&&|' |
|
1195 r'\.\.\.|==|!=|>|<|>=|<=|\||&|\^|<<|>>>|>>|\+|\-|\*|/|%|' |
|
1196 r'!|\+\+|\-\-|~|\.|\?|\:)', |
|
1197 Operator), |
|
1198 (ident, Name), |
|
1199 |
|
1200 (r'}', Punctuation,'#pop'), |
|
1201 (r'{', Punctuation,'#push'), |
|
1202 ], |
|
1203 |
|
1204 # Instance/Block level constructs |
|
1205 'propertydef': [ |
|
1206 (r'(\()(' + key_prop + ')(,)(' + key_prop + ')(\))', |
|
1207 bygroups(Punctuation, Keyword.Reserved, Punctuation, |
|
1208 Keyword.Reserved, Punctuation)), |
|
1209 ], |
|
1210 'new': [ |
|
1211 (r'\bnew\b', Keyword, 'typedecl'), |
|
1212 ], |
|
1213 'case': [ |
|
1214 (r'\b(case)(\s+)(' + ident + ')(\s*)(\()', |
|
1215 bygroups(Keyword.Reserved, Text, Name, Text, Punctuation), |
|
1216 'funargdecl'), |
|
1217 ], |
|
1218 'vardef': [ |
|
1219 (r'\b(var)(\s+)(' + ident + ')', |
|
1220 bygroups(Keyword.Declaration, Text, Name.Variable), 'vardecl'), |
|
1221 ], |
|
1222 'vardecl': [ |
|
1223 include('whitespace'), |
|
1224 include('typelabel'), |
|
1225 (r'=', Operator,'#pop'), |
|
1226 (r';', Punctuation,'#pop'), |
|
1227 ], |
|
1228 'instancevardef': [ |
|
1229 (key_decl_mod,Keyword.Declaration), |
|
1230 (r'\b(var)(\s+)(' + ident + ')', |
|
1231 bygroups(Keyword.Declaration, Text, Name.Variable.Instance), |
|
1232 'instancevardecl'), |
|
1233 ], |
|
1234 'instancevardecl': [ |
|
1235 include('vardecl'), |
|
1236 include('propertydef'), |
|
1237 ], |
|
1238 |
|
1239 'anonfundef': [ |
|
1240 (r'\bfunction\b', Keyword.Declaration, 'fundecl'), |
|
1241 ], |
|
1242 'instancefundef': [ |
|
1243 (key_decl_mod, Keyword.Declaration), |
|
1244 (r'\b(function)(\s+)(' + ident + ')', |
|
1245 bygroups(Keyword.Declaration, Text, Name.Function), 'fundecl'), |
|
1246 ], |
|
1247 'fundecl': [ |
|
1248 include('whitespace'), |
|
1249 include('typelabel'), |
|
1250 include('generictypedecl'), |
|
1251 (r'\(',Punctuation,'funargdecl'), |
|
1252 (r'(?=[a-zA-Z0-9_])',Text,'#pop'), |
|
1253 (r'{',Punctuation,('#pop','codeblock')), |
|
1254 (r';',Punctuation,'#pop'), |
|
1255 ], |
|
1256 'funargdecl': [ |
|
1257 include('whitespace'), |
|
1258 (ident, Name.Variable), |
|
1259 include('typelabel'), |
|
1260 include('literals'), |
|
1261 (r'=', Operator), |
|
1262 (r',', Punctuation), |
|
1263 (r'\?', Punctuation), |
|
1264 (r'\)', Punctuation, '#pop'), |
|
1265 ], |
|
1266 |
|
1267 'typelabel': [ |
|
1268 (r':', Punctuation, 'type'), |
|
1269 ], |
|
1270 'typedecl': [ |
|
1271 include('whitespace'), |
|
1272 (typeid, Name.Class), |
|
1273 (r'<', Punctuation, 'generictypedecl'), |
|
1274 (r'(?=[{}()=,a-z])', Text,'#pop'), |
|
1275 ], |
|
1276 'type': [ |
|
1277 include('whitespace'), |
|
1278 (typeid, Name.Class), |
|
1279 (r'<', Punctuation, 'generictypedecl'), |
|
1280 (r'->', Keyword.Type), |
|
1281 (r'(?=[{}(),;=])', Text, '#pop'), |
|
1282 ], |
|
1283 'generictypedecl': [ |
|
1284 include('whitespace'), |
|
1285 (typeid, Name.Class), |
|
1286 (r'<', Punctuation, '#push'), |
|
1287 (r'>', Punctuation, '#pop'), |
|
1288 (r',', Punctuation), |
|
1289 ], |
|
1290 |
|
1291 # Top level constructs |
|
1292 'imports': [ |
|
1293 (r'(package|import|using)(\s+)([^;]+)(;)', |
|
1294 bygroups(Keyword.Namespace, Text, Name.Namespace,Punctuation)), |
|
1295 ], |
|
1296 'typedef': [ |
|
1297 (r'typedef', Keyword.Declaration, ('typedefprebody', 'typedecl')), |
|
1298 ], |
|
1299 'typedefprebody': [ |
|
1300 include('whitespace'), |
|
1301 (r'(=)(\s*)({)', bygroups(Punctuation, Text, Punctuation), |
|
1302 ('#pop', 'typedefbody')), |
|
1303 ], |
|
1304 'enumdef': [ |
|
1305 (r'enum', Keyword.Declaration, ('enumdefprebody', 'typedecl')), |
|
1306 ], |
|
1307 'enumdefprebody': [ |
|
1308 include('whitespace'), |
|
1309 (r'{', Punctuation, ('#pop','enumdefbody')), |
|
1310 ], |
|
1311 'classdef': [ |
|
1312 (r'class', Keyword.Declaration, ('classdefprebody', 'typedecl')), |
|
1313 ], |
|
1314 'classdefprebody': [ |
|
1315 include('whitespace'), |
|
1316 (r'(extends|implements)', Keyword.Declaration,'typedecl'), |
|
1317 (r'{', Punctuation, ('#pop', 'classdefbody')), |
|
1318 ], |
|
1319 'interfacedef': [ |
|
1320 (r'interface', Keyword.Declaration, |
|
1321 ('interfacedefprebody', 'typedecl')), |
|
1322 ], |
|
1323 'interfacedefprebody': [ |
|
1324 include('whitespace'), |
|
1325 (r'(extends)', Keyword.Declaration, 'typedecl'), |
|
1326 (r'{', Punctuation, ('#pop', 'classdefbody')), |
|
1327 ], |
|
1328 |
|
1329 'typedefbody': [ |
|
1330 include('whitespace'), |
|
1331 include('instancevardef'), |
|
1332 include('instancefundef'), |
|
1333 (r'>', Punctuation, 'typedecl'), |
|
1334 (r',', Punctuation), |
|
1335 (r'}', Punctuation, '#pop'), |
|
1336 ], |
|
1337 'enumdefbody': [ |
|
1338 include('whitespace'), |
|
1339 (ident, Name.Variable.Instance), |
|
1340 (r'\(', Punctuation, 'funargdecl'), |
|
1341 (r';', Punctuation), |
|
1342 (r'}', Punctuation, '#pop'), |
|
1343 ], |
|
1344 'classdefbody': [ |
|
1345 include('whitespace'), |
|
1346 include('instancevardef'), |
|
1347 include('instancefundef'), |
|
1348 (r'}', Punctuation, '#pop'), |
|
1349 include('codeblock'), |
|
1350 ], |
|
1351 } |
|
1352 |
|
1353 def analyse_text(text): |
|
1354 if re.match(r'\w+\s*:\s*\w', text): return 0.3 |
|
1355 |
|
1356 |
|
1357 def _indentation(lexer, match, ctx): |
|
1358 indentation = match.group(0) |
|
1359 yield match.start(), Text, indentation |
|
1360 ctx.last_indentation = indentation |
|
1361 ctx.pos = match.end() |
|
1362 |
|
1363 if hasattr(ctx, 'block_state') and ctx.block_state and \ |
|
1364 indentation.startswith(ctx.block_indentation) and \ |
|
1365 indentation != ctx.block_indentation: |
|
1366 ctx.stack.append(ctx.block_state) |
|
1367 else: |
|
1368 ctx.block_state = None |
|
1369 ctx.block_indentation = None |
|
1370 ctx.stack.append('content') |
|
1371 |
|
1372 def _starts_block(token, state): |
|
1373 def callback(lexer, match, ctx): |
|
1374 yield match.start(), token, match.group(0) |
|
1375 |
|
1376 if hasattr(ctx, 'last_indentation'): |
|
1377 ctx.block_indentation = ctx.last_indentation |
|
1378 else: |
|
1379 ctx.block_indentation = '' |
|
1380 |
|
1381 ctx.block_state = state |
|
1382 ctx.pos = match.end() |
|
1383 |
|
1384 return callback |
|
1385 |
|
1386 |
|
1387 class HamlLexer(ExtendedRegexLexer): |
|
1388 """ |
|
1389 For Haml markup. |
|
1390 |
|
1391 *New in Pygments 1.3.* |
|
1392 """ |
|
1393 |
|
1394 name = 'Haml' |
|
1395 aliases = ['haml', 'HAML'] |
|
1396 filenames = ['*.haml'] |
|
1397 mimetypes = ['text/x-haml'] |
|
1398 |
|
1399 flags = re.IGNORECASE |
|
1400 # Haml can include " |\n" anywhere, |
|
1401 # which is ignored and used to wrap long lines. |
|
1402 # To accomodate this, use this custom faux dot instead. |
|
1403 _dot = r'(?: \|\n(?=.* \|)|.)' |
|
1404 |
|
1405 # In certain places, a comma at the end of the line |
|
1406 # allows line wrapping as well. |
|
1407 _comma_dot = r'(?:,\s*\n|' + _dot + ')' |
|
1408 tokens = { |
|
1409 'root': [ |
|
1410 (r'[ \t]*\n', Text), |
|
1411 (r'[ \t]*', _indentation), |
|
1412 ], |
|
1413 |
|
1414 'css': [ |
|
1415 (r'\.[a-z0-9_:-]+', Name.Class, 'tag'), |
|
1416 (r'\#[a-z0-9_:-]+', Name.Function, 'tag'), |
|
1417 ], |
|
1418 |
|
1419 'eval-or-plain': [ |
|
1420 (r'[&!]?==', Punctuation, 'plain'), |
|
1421 (r'([&!]?[=~])(' + _comma_dot + r'*\n)', |
|
1422 bygroups(Punctuation, using(RubyLexer)), |
|
1423 'root'), |
|
1424 (r'', Text, 'plain'), |
|
1425 ], |
|
1426 |
|
1427 'content': [ |
|
1428 include('css'), |
|
1429 (r'%[a-z0-9_:-]+', Name.Tag, 'tag'), |
|
1430 (r'!!!' + _dot + r'*\n', Name.Namespace, '#pop'), |
|
1431 (r'(/)(\[' + _dot + '*?\])(' + _dot + r'*\n)', |
|
1432 bygroups(Comment, Comment.Special, Comment), |
|
1433 '#pop'), |
|
1434 (r'/' + _dot + r'*\n', _starts_block(Comment, 'html-comment-block'), |
|
1435 '#pop'), |
|
1436 (r'-#' + _dot + r'*\n', _starts_block(Comment.Preproc, |
|
1437 'haml-comment-block'), '#pop'), |
|
1438 (r'(-)(' + _comma_dot + r'*\n)', |
|
1439 bygroups(Punctuation, using(RubyLexer)), |
|
1440 '#pop'), |
|
1441 (r':' + _dot + r'*\n', _starts_block(Name.Decorator, 'filter-block'), |
|
1442 '#pop'), |
|
1443 include('eval-or-plain'), |
|
1444 ], |
|
1445 |
|
1446 'tag': [ |
|
1447 include('css'), |
|
1448 (r'\{(,\n|' + _dot + ')*?\}', using(RubyLexer)), |
|
1449 (r'\[' + _dot + '*?\]', using(RubyLexer)), |
|
1450 (r'\(', Text, 'html-attributes'), |
|
1451 (r'/[ \t]*\n', Punctuation, '#pop:2'), |
|
1452 (r'[<>]{1,2}(?=[ \t=])', Punctuation), |
|
1453 include('eval-or-plain'), |
|
1454 ], |
|
1455 |
|
1456 'plain': [ |
|
1457 (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text), |
|
1458 (r'(#\{)(' + _dot + '*?)(\})', |
|
1459 bygroups(String.Interpol, using(RubyLexer), String.Interpol)), |
|
1460 (r'\n', Text, 'root'), |
|
1461 ], |
|
1462 |
|
1463 'html-attributes': [ |
|
1464 (r'\s+', Text), |
|
1465 (r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'), |
|
1466 (r'[a-z0-9_:-]+', Name.Attribute), |
|
1467 (r'\)', Text, '#pop'), |
|
1468 ], |
|
1469 |
|
1470 'html-attribute-value': [ |
|
1471 (r'[ \t]+', Text), |
|
1472 (r'[a-z0-9_]+', Name.Variable, '#pop'), |
|
1473 (r'@[a-z0-9_]+', Name.Variable.Instance, '#pop'), |
|
1474 (r'\$[a-z0-9_]+', Name.Variable.Global, '#pop'), |
|
1475 (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'), |
|
1476 (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'), |
|
1477 ], |
|
1478 |
|
1479 'html-comment-block': [ |
|
1480 (_dot + '+', Comment), |
|
1481 (r'\n', Text, 'root'), |
|
1482 ], |
|
1483 |
|
1484 'haml-comment-block': [ |
|
1485 (_dot + '+', Comment.Preproc), |
|
1486 (r'\n', Text, 'root'), |
|
1487 ], |
|
1488 |
|
1489 'filter-block': [ |
|
1490 (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator), |
|
1491 (r'(#\{)(' + _dot + '*?)(\})', |
|
1492 bygroups(String.Interpol, using(RubyLexer), String.Interpol)), |
|
1493 (r'\n', Text, 'root'), |
|
1494 ], |
|
1495 } |
|
1496 |
|
1497 |
|
1498 common_sass_tokens = { |
|
1499 'value': [ |
|
1500 (r'[ \t]+', Text), |
|
1501 (r'[!$][\w-]+', Name.Variable), |
|
1502 (r'url\(', String.Other, 'string-url'), |
|
1503 (r'[a-z_-][\w-]*(?=\()', Name.Function), |
|
1504 (r'(azimuth|background-attachment|background-color|' |
|
1505 r'background-image|background-position|background-repeat|' |
|
1506 r'background|border-bottom-color|border-bottom-style|' |
|
1507 r'border-bottom-width|border-left-color|border-left-style|' |
|
1508 r'border-left-width|border-right|border-right-color|' |
|
1509 r'border-right-style|border-right-width|border-top-color|' |
|
1510 r'border-top-style|border-top-width|border-bottom|' |
|
1511 r'border-collapse|border-left|border-width|border-color|' |
|
1512 r'border-spacing|border-style|border-top|border|caption-side|' |
|
1513 r'clear|clip|color|content|counter-increment|counter-reset|' |
|
1514 r'cue-after|cue-before|cue|cursor|direction|display|' |
|
1515 r'elevation|empty-cells|float|font-family|font-size|' |
|
1516 r'font-size-adjust|font-stretch|font-style|font-variant|' |
|
1517 r'font-weight|font|height|letter-spacing|line-height|' |
|
1518 r'list-style-type|list-style-image|list-style-position|' |
|
1519 r'list-style|margin-bottom|margin-left|margin-right|' |
|
1520 r'margin-top|margin|marker-offset|marks|max-height|max-width|' |
|
1521 r'min-height|min-width|opacity|orphans|outline|outline-color|' |
|
1522 r'outline-style|outline-width|overflow|padding-bottom|' |
|
1523 r'padding-left|padding-right|padding-top|padding|page|' |
|
1524 r'page-break-after|page-break-before|page-break-inside|' |
|
1525 r'pause-after|pause-before|pause|pitch|pitch-range|' |
|
1526 r'play-during|position|quotes|richness|right|size|' |
|
1527 r'speak-header|speak-numeral|speak-punctuation|speak|' |
|
1528 r'speech-rate|stress|table-layout|text-align|text-decoration|' |
|
1529 r'text-indent|text-shadow|text-transform|top|unicode-bidi|' |
|
1530 r'vertical-align|visibility|voice-family|volume|white-space|' |
|
1531 r'widows|width|word-spacing|z-index|bottom|left|' |
|
1532 r'above|absolute|always|armenian|aural|auto|avoid|baseline|' |
|
1533 r'behind|below|bidi-override|blink|block|bold|bolder|both|' |
|
1534 r'capitalize|center-left|center-right|center|circle|' |
|
1535 r'cjk-ideographic|close-quote|collapse|condensed|continuous|' |
|
1536 r'crop|crosshair|cross|cursive|dashed|decimal-leading-zero|' |
|
1537 r'decimal|default|digits|disc|dotted|double|e-resize|embed|' |
|
1538 r'extra-condensed|extra-expanded|expanded|fantasy|far-left|' |
|
1539 r'far-right|faster|fast|fixed|georgian|groove|hebrew|help|' |
|
1540 r'hidden|hide|higher|high|hiragana-iroha|hiragana|icon|' |
|
1541 r'inherit|inline-table|inline|inset|inside|invert|italic|' |
|
1542 r'justify|katakana-iroha|katakana|landscape|larger|large|' |
|
1543 r'left-side|leftwards|level|lighter|line-through|list-item|' |
|
1544 r'loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|' |
|
1545 r'lower|low|medium|message-box|middle|mix|monospace|' |
|
1546 r'n-resize|narrower|ne-resize|no-close-quote|no-open-quote|' |
|
1547 r'no-repeat|none|normal|nowrap|nw-resize|oblique|once|' |
|
1548 r'open-quote|outset|outside|overline|pointer|portrait|px|' |
|
1549 r'relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|' |
|
1550 r'rightwards|s-resize|sans-serif|scroll|se-resize|' |
|
1551 r'semi-condensed|semi-expanded|separate|serif|show|silent|' |
|
1552 r'slow|slower|small-caps|small-caption|smaller|soft|solid|' |
|
1553 r'spell-out|square|static|status-bar|super|sw-resize|' |
|
1554 r'table-caption|table-cell|table-column|table-column-group|' |
|
1555 r'table-footer-group|table-header-group|table-row|' |
|
1556 r'table-row-group|text|text-bottom|text-top|thick|thin|' |
|
1557 r'transparent|ultra-condensed|ultra-expanded|underline|' |
|
1558 r'upper-alpha|upper-latin|upper-roman|uppercase|url|' |
|
1559 r'visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|' |
|
1560 r'x-low|x-small|x-soft|xx-large|xx-small|yes)\b', Name.Constant), |
|
1561 (r'(indigo|gold|firebrick|indianred|darkolivegreen|' |
|
1562 r'darkseagreen|mediumvioletred|mediumorchid|chartreuse|' |
|
1563 r'mediumslateblue|springgreen|crimson|lightsalmon|brown|' |
|
1564 r'turquoise|olivedrab|cyan|skyblue|darkturquoise|' |
|
1565 r'goldenrod|darkgreen|darkviolet|darkgray|lightpink|' |
|
1566 r'darkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|' |
|
1567 r'violet|orchid|ghostwhite|honeydew|cornflowerblue|' |
|
1568 r'darkblue|darkkhaki|mediumpurple|cornsilk|bisque|slategray|' |
|
1569 r'darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|' |
|
1570 r'gainsboro|mediumturquoise|floralwhite|coral|lightgrey|' |
|
1571 r'lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|' |
|
1572 r'greenyellow|royalblue|lightseagreen|mistyrose|sienna|' |
|
1573 r'lightcoral|orangered|navajowhite|palegreen|burlywood|' |
|
1574 r'seashell|mediumspringgreen|papayawhip|blanchedalmond|' |
|
1575 r'peru|aquamarine|darkslategray|ivory|dodgerblue|' |
|
1576 r'lemonchiffon|chocolate|orange|forestgreen|slateblue|' |
|
1577 r'mintcream|antiquewhite|darkorange|cadetblue|moccasin|' |
|
1578 r'limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|' |
|
1579 r'plum|darkgoldenrod|sandybrown|magenta|tan|' |
|
1580 r'rosybrown|pink|lightblue|palevioletred|mediumseagreen|' |
|
1581 r'dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|' |
|
1582 r'paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|' |
|
1583 r'lightslategray|lawngreen|lightgreen|tomato|hotpink|' |
|
1584 r'lightyellow|lavenderblush|linen|mediumaquamarine|' |
|
1585 r'blueviolet|peachpuff)\b', Name.Entity), |
|
1586 (r'(black|silver|gray|white|maroon|red|purple|fuchsia|green|' |
|
1587 r'lime|olive|yellow|navy|blue|teal|aqua)\b', Name.Builtin), |
|
1588 (r'\!(important|default)', Name.Exception), |
|
1589 (r'(true|false)', Name.Pseudo), |
|
1590 (r'(and|or|not)', Operator.Word), |
|
1591 (r'/\*', Comment.Multiline, 'inline-comment'), |
|
1592 (r'//[^\n]*', Comment.Single), |
|
1593 (r'\#[a-z0-9]{1,6}', Number.Hex), |
|
1594 (r'(-?\d+)(\%|[a-z]+)?', bygroups(Number.Integer, Keyword.Type)), |
|
1595 (r'(-?\d*\.\d+)(\%|[a-z]+)?', bygroups(Number.Float, Keyword.Type)), |
|
1596 (r'#{', String.Interpol, 'interpolation'), |
|
1597 (r'[~\^\*!&%<>\|+=@:,./?-]+', Operator), |
|
1598 (r'[\[\]()]+', Punctuation), |
|
1599 (r'"', String.Double, 'string-double'), |
|
1600 (r"'", String.Single, 'string-single'), |
|
1601 (r'[a-z_-][\w-]*', Name), |
|
1602 ], |
|
1603 |
|
1604 'interpolation': [ |
|
1605 (r'\}', String.Interpol, '#pop'), |
|
1606 include('value'), |
|
1607 ], |
|
1608 |
|
1609 'selector': [ |
|
1610 (r'[ \t]+', Text), |
|
1611 (r'\:', Name.Decorator, 'pseudo-class'), |
|
1612 (r'\.', Name.Class, 'class'), |
|
1613 (r'\#', Name.Namespace, 'id'), |
|
1614 (r'[a-zA-Z0-9_-]+', Name.Tag), |
|
1615 (r'#\{', String.Interpol, 'interpolation'), |
|
1616 (r'&', Keyword), |
|
1617 (r'[~\^\*!&\[\]\(\)<>\|+=@:;,./?-]', Operator), |
|
1618 (r'"', String.Double, 'string-double'), |
|
1619 (r"'", String.Single, 'string-single'), |
|
1620 ], |
|
1621 |
|
1622 'string-double': [ |
|
1623 (r'(\\.|#(?=[^\n{])|[^\n"#])+', String.Double), |
|
1624 (r'#\{', String.Interpol, 'interpolation'), |
|
1625 (r'"', String.Double, '#pop'), |
|
1626 ], |
|
1627 |
|
1628 'string-single': [ |
|
1629 (r"(\\.|#(?=[^\n{])|[^\n'#])+", String.Double), |
|
1630 (r'#\{', String.Interpol, 'interpolation'), |
|
1631 (r"'", String.Double, '#pop'), |
|
1632 ], |
|
1633 |
|
1634 'string-url': [ |
|
1635 (r'(\\#|#(?=[^\n{])|[^\n#)])+', String.Other), |
|
1636 (r'#\{', String.Interpol, 'interpolation'), |
|
1637 (r'\)', String.Other, '#pop'), |
|
1638 ], |
|
1639 |
|
1640 'pseudo-class': [ |
|
1641 (r'[\w-]+', Name.Decorator), |
|
1642 (r'#\{', String.Interpol, 'interpolation'), |
|
1643 (r'', Text, '#pop'), |
|
1644 ], |
|
1645 |
|
1646 'class': [ |
|
1647 (r'[\w-]+', Name.Class), |
|
1648 (r'#\{', String.Interpol, 'interpolation'), |
|
1649 (r'', Text, '#pop'), |
|
1650 ], |
|
1651 |
|
1652 'id': [ |
|
1653 (r'[\w-]+', Name.Namespace), |
|
1654 (r'#\{', String.Interpol, 'interpolation'), |
|
1655 (r'', Text, '#pop'), |
|
1656 ], |
|
1657 |
|
1658 'for': [ |
|
1659 (r'(from|to|through)', Operator.Word), |
|
1660 include('value'), |
|
1661 ], |
|
1662 } |
|
1663 |
|
1664 class SassLexer(ExtendedRegexLexer): |
|
1665 """ |
|
1666 For Sass stylesheets. |
|
1667 |
|
1668 *New in Pygments 1.3.* |
|
1669 """ |
|
1670 |
|
1671 name = 'Sass' |
|
1672 aliases = ['sass', 'SASS'] |
|
1673 filenames = ['*.sass'] |
|
1674 mimetypes = ['text/x-sass'] |
|
1675 |
|
1676 flags = re.IGNORECASE |
|
1677 tokens = { |
|
1678 'root': [ |
|
1679 (r'[ \t]*\n', Text), |
|
1680 (r'[ \t]*', _indentation), |
|
1681 ], |
|
1682 |
|
1683 'content': [ |
|
1684 (r'//[^\n]*', _starts_block(Comment.Single, 'single-comment'), |
|
1685 'root'), |
|
1686 (r'/\*[^\n]*', _starts_block(Comment.Multiline, 'multi-comment'), |
|
1687 'root'), |
|
1688 (r'@import', Keyword, 'import'), |
|
1689 (r'@for', Keyword, 'for'), |
|
1690 (r'@(debug|warn|if|while)', Keyword, 'value'), |
|
1691 (r'(@mixin)( [\w-]+)', bygroups(Keyword, Name.Function), 'value'), |
|
1692 (r'(@include)( [\w-]+)', bygroups(Keyword, Name.Decorator), 'value'), |
|
1693 (r'@extend', Keyword, 'selector'), |
|
1694 (r'@[a-z0-9_-]+', Keyword, 'selector'), |
|
1695 (r'=[\w-]+', Name.Function, 'value'), |
|
1696 (r'\+[\w-]+', Name.Decorator, 'value'), |
|
1697 (r'([!$][\w-]\w*)([ \t]*(?:(?:\|\|)?=|:))', |
|
1698 bygroups(Name.Variable, Operator), 'value'), |
|
1699 (r':', Name.Attribute, 'old-style-attr'), |
|
1700 (r'(?=.+?[=:]([^a-z]|$))', Name.Attribute, 'new-style-attr'), |
|
1701 (r'', Text, 'selector'), |
|
1702 ], |
|
1703 |
|
1704 'single-comment': [ |
|
1705 (r'.+', Comment.Single), |
|
1706 (r'\n', Text, 'root'), |
|
1707 ], |
|
1708 |
|
1709 'multi-comment': [ |
|
1710 (r'.+', Comment.Multiline), |
|
1711 (r'\n', Text, 'root'), |
|
1712 ], |
|
1713 |
|
1714 'import': [ |
|
1715 (r'[ \t]+', Text), |
|
1716 (r'\S+', String), |
|
1717 (r'\n', Text, 'root'), |
|
1718 ], |
|
1719 |
|
1720 'old-style-attr': [ |
|
1721 (r'[^\s:="\[]+', Name.Attribute), |
|
1722 (r'#{', String.Interpol, 'interpolation'), |
|
1723 (r'[ \t]*=', Operator, 'value'), |
|
1724 (r'', Text, 'value'), |
|
1725 ], |
|
1726 |
|
1727 'new-style-attr': [ |
|
1728 (r'[^\s:="\[]+', Name.Attribute), |
|
1729 (r'#{', String.Interpol, 'interpolation'), |
|
1730 (r'[ \t]*[=:]', Operator, 'value'), |
|
1731 ], |
|
1732 |
|
1733 'inline-comment': [ |
|
1734 (r"(\\#|#(?=[^\n{])|\*(?=[^\n/])|[^\n#*])+", Comment.Multiline), |
|
1735 (r'#\{', String.Interpol, 'interpolation'), |
|
1736 (r"\*/", Comment, '#pop'), |
|
1737 ], |
|
1738 } |
|
1739 for group, common in common_sass_tokens.items(): |
|
1740 tokens[group] = copy.copy(common) |
|
1741 tokens['value'].append((r'\n', Text, 'root')) |
|
1742 tokens['selector'].append((r'\n', Text, 'root')) |
|
1743 |
|
1744 |
|
1745 class ScssLexer(RegexLexer): |
|
1746 """ |
|
1747 For SCSS stylesheets. |
|
1748 """ |
|
1749 |
|
1750 name = 'SCSS' |
|
1751 aliases = ['scss'] |
|
1752 filenames = ['*.scss'] |
|
1753 mimetypes = ['text/x-scss'] |
|
1754 |
|
1755 flags = re.IGNORECASE | re.DOTALL |
|
1756 tokens = { |
|
1757 'root': [ |
|
1758 (r'\s+', Text), |
|
1759 (r'//.*?\n', Comment.Single), |
|
1760 (r'/\*.*?\*/', Comment.Multiline), |
|
1761 (r'@import', Keyword, 'value'), |
|
1762 (r'@for', Keyword, 'for'), |
|
1763 (r'@(debug|warn|if|while)', Keyword, 'value'), |
|
1764 (r'(@mixin)( [\w-]+)', bygroups(Keyword, Name.Function), 'value'), |
|
1765 (r'(@include)( [\w-]+)', bygroups(Keyword, Name.Decorator), 'value'), |
|
1766 (r'@extend', Keyword, 'selector'), |
|
1767 (r'@[a-z0-9_-]+', Keyword, 'selector'), |
|
1768 (r'(\$[\w-]*\w)([ \t]*:)', bygroups(Name.Variable, Operator), 'value'), |
|
1769 (r'(?=[^;{}][;}])', Name.Attribute, 'attr'), |
|
1770 (r'(?=[^;{}:]+:[^a-z])', Name.Attribute, 'attr'), |
|
1771 (r'', Text, 'selector'), |
|
1772 ], |
|
1773 |
|
1774 'attr': [ |
|
1775 (r'[^\s:="\[]+', Name.Attribute), |
|
1776 (r'#{', String.Interpol, 'interpolation'), |
|
1777 (r'[ \t]*:', Operator, 'value'), |
|
1778 ], |
|
1779 |
|
1780 'inline-comment': [ |
|
1781 (r"(\\#|#(?=[^{])|\*(?=[^/])|[^#*])+", Comment.Multiline), |
|
1782 (r'#\{', String.Interpol, 'interpolation'), |
|
1783 (r"\*/", Comment, '#pop'), |
|
1784 ], |
|
1785 } |
|
1786 for group, common in common_sass_tokens.items(): |
|
1787 tokens[group] = copy.copy(common) |
|
1788 tokens['value'].extend([(r'\n', Text), (r'[;{}]', Punctuation, 'root')]) |
|
1789 tokens['selector'].extend([(r'\n', Text), (r'[;{}]', Punctuation, 'root')]) |
|
1790 |
|
1791 |
|
1792 class CoffeeScriptLexer(RegexLexer): |
|
1793 """ |
|
1794 For `CoffeeScript`_ source code. |
|
1795 |
|
1796 .. _CoffeeScript: http://coffeescript.org |
|
1797 |
|
1798 *New in Pygments 1.3.* |
|
1799 """ |
|
1800 |
|
1801 name = 'CoffeeScript' |
|
1802 aliases = ['coffee-script', 'coffeescript'] |
|
1803 filenames = ['*.coffee'] |
|
1804 mimetypes = ['text/coffeescript'] |
|
1805 |
|
1806 flags = re.DOTALL |
|
1807 tokens = { |
|
1808 'commentsandwhitespace': [ |
|
1809 (r'\s+', Text), |
|
1810 (r'###[^#].*?###', Comment.Multiline), |
|
1811 (r'#(?!##[^#]).*?\n', Comment.Single), |
|
1812 ], |
|
1813 'multilineregex': [ |
|
1814 (r'[^/#]+', String.Regex), |
|
1815 (r'///([gim]+\b|\B)', String.Regex, '#pop'), |
|
1816 (r'#{', String.Interpol, 'interpoling_string'), |
|
1817 (r'[/#]', String.Regex), |
|
1818 ], |
|
1819 'slashstartsregex': [ |
|
1820 include('commentsandwhitespace'), |
|
1821 (r'///', String.Regex, ('#pop', 'multilineregex')), |
|
1822 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
1823 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
1824 (r'', Text, '#pop'), |
|
1825 ], |
|
1826 'root': [ |
|
1827 # this next expr leads to infinite loops root -> slashstartsregex |
|
1828 #(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
1829 include('commentsandwhitespace'), |
|
1830 (r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|' |
|
1831 r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|' |
|
1832 r'=(?!>)|-(?!>)|[<>+*`%&\|\^/])=?', |
|
1833 Operator, 'slashstartsregex'), |
|
1834 (r'(?:\([^()]+\))?\s*[=-]>', Name.Function), |
|
1835 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
1836 (r'[})\].]', Punctuation), |
|
1837 (r'(?<![\.\$])(for|own|in|of|while|until|' |
|
1838 r'loop|break|return|continue|' |
|
1839 r'switch|when|then|if|unless|else|' |
|
1840 r'throw|try|catch|finally|new|delete|typeof|instanceof|super|' |
|
1841 r'extends|this|class|by)\b', Keyword, 'slashstartsregex'), |
|
1842 (r'(?<![\.\$])(true|false|yes|no|on|off|null|' |
|
1843 r'NaN|Infinity|undefined)\b', |
|
1844 Keyword.Constant), |
|
1845 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
1846 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
1847 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
1848 r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b', |
|
1849 Name.Builtin), |
|
1850 (r'[$a-zA-Z_][a-zA-Z0-9_\.:\$]*\s*[:=]\s', Name.Variable, |
|
1851 'slashstartsregex'), |
|
1852 (r'@[$a-zA-Z_][a-zA-Z0-9_\.:\$]*\s*[:=]\s', Name.Variable.Instance, |
|
1853 'slashstartsregex'), |
|
1854 (r'@', Name.Other, 'slashstartsregex'), |
|
1855 (r'@?[$a-zA-Z_][a-zA-Z0-9_\$]*', Name.Other, 'slashstartsregex'), |
|
1856 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
1857 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
1858 (r'[0-9]+', Number.Integer), |
|
1859 ('"""', String, 'tdqs'), |
|
1860 ("'''", String, 'tsqs'), |
|
1861 ('"', String, 'dqs'), |
|
1862 ("'", String, 'sqs'), |
|
1863 ], |
|
1864 'strings': [ |
|
1865 (r'[^#\\\'"]+', String), |
|
1866 # note that all coffee script strings are multi-line. |
|
1867 # hashmarks, quotes and backslashes must be parsed one at a time |
|
1868 ], |
|
1869 'interpoling_string' : [ |
|
1870 (r'}', String.Interpol, "#pop"), |
|
1871 include('root') |
|
1872 ], |
|
1873 'dqs': [ |
|
1874 (r'"', String, '#pop'), |
|
1875 (r'\\.|\'', String), # double-quoted string don't need ' escapes |
|
1876 (r'#{', String.Interpol, "interpoling_string"), |
|
1877 include('strings') |
|
1878 ], |
|
1879 'sqs': [ |
|
1880 (r"'", String, '#pop'), |
|
1881 (r'#|\\.|"', String), # single quoted strings don't need " escapses |
|
1882 include('strings') |
|
1883 ], |
|
1884 'tdqs': [ |
|
1885 (r'"""', String, '#pop'), |
|
1886 (r'\\.|\'|"', String), # no need to escape quotes in triple-string |
|
1887 (r'#{', String.Interpol, "interpoling_string"), |
|
1888 include('strings'), |
|
1889 ], |
|
1890 'tsqs': [ |
|
1891 (r"'''", String, '#pop'), |
|
1892 (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings |
|
1893 include('strings') |
|
1894 ], |
|
1895 } |
|
1896 |
|
1897 |
|
1898 class LiveScriptLexer(RegexLexer): |
|
1899 """ |
|
1900 For `LiveScript`_ source code. |
|
1901 |
|
1902 .. _LiveScript: http://gkz.github.com/LiveScript/ |
|
1903 |
|
1904 New in Pygments 1.6. |
|
1905 """ |
|
1906 |
|
1907 name = 'LiveScript' |
|
1908 aliases = ['live-script', 'livescript'] |
|
1909 filenames = ['*.ls'] |
|
1910 mimetypes = ['text/livescript'] |
|
1911 |
|
1912 flags = re.DOTALL |
|
1913 tokens = { |
|
1914 'commentsandwhitespace': [ |
|
1915 (r'\s+', Text), |
|
1916 (r'/\*.*?\*/', Comment.Multiline), |
|
1917 (r'#.*?\n', Comment.Single), |
|
1918 ], |
|
1919 'multilineregex': [ |
|
1920 include('commentsandwhitespace'), |
|
1921 (r'//([gim]+\b|\B)', String.Regex, '#pop'), |
|
1922 (r'/', String.Regex), |
|
1923 (r'[^/#]+', String.Regex) |
|
1924 ], |
|
1925 'slashstartsregex': [ |
|
1926 include('commentsandwhitespace'), |
|
1927 (r'//', String.Regex, ('#pop', 'multilineregex')), |
|
1928 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
1929 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
1930 (r'', Text, '#pop'), |
|
1931 ], |
|
1932 'root': [ |
|
1933 # this next expr leads to infinite loops root -> slashstartsregex |
|
1934 #(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
1935 include('commentsandwhitespace'), |
|
1936 (r'(?:\([^()]+\))?[ ]*[~-]{1,2}>|' |
|
1937 r'(?:\(?[^()\n]+\)?)?[ ]*<[~-]{1,2}', Name.Function), |
|
1938 (r'\+\+|&&|(?<![\.\$])\b(?:and|x?or|is|isnt|not)\b|\?|:|=|' |
|
1939 r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|' |
|
1940 r'~(?!\~?>)|-(?!\-?>)|<(?!\[)|(?<!\])>|' |
|
1941 r'[+*`%&\|\^/])=?', |
|
1942 Operator, 'slashstartsregex'), |
|
1943 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
1944 (r'[})\].]', Punctuation), |
|
1945 (r'(?<![\.\$])(for|own|in|of|while|until|loop|break|' |
|
1946 r'return|continue|switch|when|then|if|unless|else|' |
|
1947 r'throw|try|catch|finally|new|delete|typeof|instanceof|super|' |
|
1948 r'extends|this|class|by|const|var|to|til)\b', Keyword, |
|
1949 'slashstartsregex'), |
|
1950 (r'(?<![\.\$])(true|false|yes|no|on|off|' |
|
1951 r'null|NaN|Infinity|undefined|void)\b', |
|
1952 Keyword.Constant), |
|
1953 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
1954 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
1955 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
1956 r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b', |
|
1957 Name.Builtin), |
|
1958 (r'[$a-zA-Z_][a-zA-Z0-9_\.\-:\$]*\s*[:=]\s', Name.Variable, |
|
1959 'slashstartsregex'), |
|
1960 (r'@[$a-zA-Z_][a-zA-Z0-9_\.\-:\$]*\s*[:=]\s', Name.Variable.Instance, |
|
1961 'slashstartsregex'), |
|
1962 (r'@', Name.Other, 'slashstartsregex'), |
|
1963 (r'@?[$a-zA-Z_][a-zA-Z0-9_\-]*', Name.Other, 'slashstartsregex'), |
|
1964 (r'[0-9]+\.[0-9]+([eE][0-9]+)?[fd]?(?:[a-zA-Z_]+)?', Number.Float), |
|
1965 (r'[0-9]+(~[0-9a-z]+)?(?:[a-zA-Z_]+)?', Number.Integer), |
|
1966 ('"""', String, 'tdqs'), |
|
1967 ("'''", String, 'tsqs'), |
|
1968 ('"', String, 'dqs'), |
|
1969 ("'", String, 'sqs'), |
|
1970 (r'\\[\w$-]+', String), |
|
1971 (r'<\[.*\]>', String), |
|
1972 ], |
|
1973 'strings': [ |
|
1974 (r'[^#\\\'"]+', String), |
|
1975 # note that all coffee script strings are multi-line. |
|
1976 # hashmarks, quotes and backslashes must be parsed one at a time |
|
1977 ], |
|
1978 'interpoling_string' : [ |
|
1979 (r'}', String.Interpol, "#pop"), |
|
1980 include('root') |
|
1981 ], |
|
1982 'dqs': [ |
|
1983 (r'"', String, '#pop'), |
|
1984 (r'\\.|\'', String), # double-quoted string don't need ' escapes |
|
1985 (r'#{', String.Interpol, "interpoling_string"), |
|
1986 (r'#', String), |
|
1987 include('strings') |
|
1988 ], |
|
1989 'sqs': [ |
|
1990 (r"'", String, '#pop'), |
|
1991 (r'#|\\.|"', String), # single quoted strings don't need " escapses |
|
1992 include('strings') |
|
1993 ], |
|
1994 'tdqs': [ |
|
1995 (r'"""', String, '#pop'), |
|
1996 (r'\\.|\'|"', String), # no need to escape quotes in triple-string |
|
1997 (r'#{', String.Interpol, "interpoling_string"), |
|
1998 (r'#', String), |
|
1999 include('strings'), |
|
2000 ], |
|
2001 'tsqs': [ |
|
2002 (r"'''", String, '#pop'), |
|
2003 (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings |
|
2004 include('strings') |
|
2005 ], |
|
2006 } |
|
2007 |
|
2008 |
|
2009 class DuelLexer(RegexLexer): |
|
2010 """ |
|
2011 Lexer for Duel Views Engine (formerly JBST) markup with JavaScript code blocks. |
|
2012 See http://duelengine.org/. |
|
2013 See http://jsonml.org/jbst/. |
|
2014 |
|
2015 *New in Pygments 1.4.* |
|
2016 """ |
|
2017 |
|
2018 name = 'Duel' |
|
2019 aliases = ['duel', 'Duel Engine', 'Duel View', 'JBST', 'jbst', 'JsonML+BST'] |
|
2020 filenames = ['*.duel','*.jbst'] |
|
2021 mimetypes = ['text/x-duel','text/x-jbst'] |
|
2022 |
|
2023 flags = re.DOTALL |
|
2024 |
|
2025 tokens = { |
|
2026 'root': [ |
|
2027 (r'(<%[@=#!:]?)(.*?)(%>)', |
|
2028 bygroups(Name.Tag, using(JavascriptLexer), Name.Tag)), |
|
2029 (r'(<%\$)(.*?)(:)(.*?)(%>)', |
|
2030 bygroups(Name.Tag, Name.Function, Punctuation, String, Name.Tag)), |
|
2031 (r'(<%--)(.*?)(--%>)', |
|
2032 bygroups(Name.Tag, Comment.Multiline, Name.Tag)), |
|
2033 (r'(<script.*?>)(.*?)(</script>)', |
|
2034 bygroups(using(HtmlLexer), |
|
2035 using(JavascriptLexer), using(HtmlLexer))), |
|
2036 (r'(.+?)(?=<)', using(HtmlLexer)), |
|
2037 (r'.+', using(HtmlLexer)), |
|
2038 ], |
|
2039 } |
|
2040 |
|
2041 |
|
2042 class ScamlLexer(ExtendedRegexLexer): |
|
2043 """ |
|
2044 For `Scaml markup <http://scalate.fusesource.org/>`_. Scaml is Haml for Scala. |
|
2045 |
|
2046 *New in Pygments 1.4.* |
|
2047 """ |
|
2048 |
|
2049 name = 'Scaml' |
|
2050 aliases = ['scaml', 'SCAML'] |
|
2051 filenames = ['*.scaml'] |
|
2052 mimetypes = ['text/x-scaml'] |
|
2053 |
|
2054 flags = re.IGNORECASE |
|
2055 # Scaml does not yet support the " |\n" notation to |
|
2056 # wrap long lines. Once it does, use the custom faux |
|
2057 # dot instead. |
|
2058 # _dot = r'(?: \|\n(?=.* \|)|.)' |
|
2059 _dot = r'.' |
|
2060 |
|
2061 tokens = { |
|
2062 'root': [ |
|
2063 (r'[ \t]*\n', Text), |
|
2064 (r'[ \t]*', _indentation), |
|
2065 ], |
|
2066 |
|
2067 'css': [ |
|
2068 (r'\.[a-z0-9_:-]+', Name.Class, 'tag'), |
|
2069 (r'\#[a-z0-9_:-]+', Name.Function, 'tag'), |
|
2070 ], |
|
2071 |
|
2072 'eval-or-plain': [ |
|
2073 (r'[&!]?==', Punctuation, 'plain'), |
|
2074 (r'([&!]?[=~])(' + _dot + r'*\n)', |
|
2075 bygroups(Punctuation, using(ScalaLexer)), |
|
2076 'root'), |
|
2077 (r'', Text, 'plain'), |
|
2078 ], |
|
2079 |
|
2080 'content': [ |
|
2081 include('css'), |
|
2082 (r'%[a-z0-9_:-]+', Name.Tag, 'tag'), |
|
2083 (r'!!!' + _dot + r'*\n', Name.Namespace, '#pop'), |
|
2084 (r'(/)(\[' + _dot + '*?\])(' + _dot + r'*\n)', |
|
2085 bygroups(Comment, Comment.Special, Comment), |
|
2086 '#pop'), |
|
2087 (r'/' + _dot + r'*\n', _starts_block(Comment, 'html-comment-block'), |
|
2088 '#pop'), |
|
2089 (r'-#' + _dot + r'*\n', _starts_block(Comment.Preproc, |
|
2090 'scaml-comment-block'), '#pop'), |
|
2091 (r'(-@\s*)(import)?(' + _dot + r'*\n)', |
|
2092 bygroups(Punctuation, Keyword, using(ScalaLexer)), |
|
2093 '#pop'), |
|
2094 (r'(-)(' + _dot + r'*\n)', |
|
2095 bygroups(Punctuation, using(ScalaLexer)), |
|
2096 '#pop'), |
|
2097 (r':' + _dot + r'*\n', _starts_block(Name.Decorator, 'filter-block'), |
|
2098 '#pop'), |
|
2099 include('eval-or-plain'), |
|
2100 ], |
|
2101 |
|
2102 'tag': [ |
|
2103 include('css'), |
|
2104 (r'\{(,\n|' + _dot + ')*?\}', using(ScalaLexer)), |
|
2105 (r'\[' + _dot + '*?\]', using(ScalaLexer)), |
|
2106 (r'\(', Text, 'html-attributes'), |
|
2107 (r'/[ \t]*\n', Punctuation, '#pop:2'), |
|
2108 (r'[<>]{1,2}(?=[ \t=])', Punctuation), |
|
2109 include('eval-or-plain'), |
|
2110 ], |
|
2111 |
|
2112 'plain': [ |
|
2113 (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text), |
|
2114 (r'(#\{)(' + _dot + '*?)(\})', |
|
2115 bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), |
|
2116 (r'\n', Text, 'root'), |
|
2117 ], |
|
2118 |
|
2119 'html-attributes': [ |
|
2120 (r'\s+', Text), |
|
2121 (r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'), |
|
2122 (r'[a-z0-9_:-]+', Name.Attribute), |
|
2123 (r'\)', Text, '#pop'), |
|
2124 ], |
|
2125 |
|
2126 'html-attribute-value': [ |
|
2127 (r'[ \t]+', Text), |
|
2128 (r'[a-z0-9_]+', Name.Variable, '#pop'), |
|
2129 (r'@[a-z0-9_]+', Name.Variable.Instance, '#pop'), |
|
2130 (r'\$[a-z0-9_]+', Name.Variable.Global, '#pop'), |
|
2131 (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'), |
|
2132 (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'), |
|
2133 ], |
|
2134 |
|
2135 'html-comment-block': [ |
|
2136 (_dot + '+', Comment), |
|
2137 (r'\n', Text, 'root'), |
|
2138 ], |
|
2139 |
|
2140 'scaml-comment-block': [ |
|
2141 (_dot + '+', Comment.Preproc), |
|
2142 (r'\n', Text, 'root'), |
|
2143 ], |
|
2144 |
|
2145 'filter-block': [ |
|
2146 (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator), |
|
2147 (r'(#\{)(' + _dot + '*?)(\})', |
|
2148 bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), |
|
2149 (r'\n', Text, 'root'), |
|
2150 ], |
|
2151 } |
|
2152 |
|
2153 |
|
2154 class JadeLexer(ExtendedRegexLexer): |
|
2155 """ |
|
2156 For Jade markup. |
|
2157 Jade is a variant of Scaml, see: |
|
2158 http://scalate.fusesource.org/documentation/scaml-reference.html |
|
2159 |
|
2160 *New in Pygments 1.4.* |
|
2161 """ |
|
2162 |
|
2163 name = 'Jade' |
|
2164 aliases = ['jade', 'JADE'] |
|
2165 filenames = ['*.jade'] |
|
2166 mimetypes = ['text/x-jade'] |
|
2167 |
|
2168 flags = re.IGNORECASE |
|
2169 _dot = r'.' |
|
2170 |
|
2171 tokens = { |
|
2172 'root': [ |
|
2173 (r'[ \t]*\n', Text), |
|
2174 (r'[ \t]*', _indentation), |
|
2175 ], |
|
2176 |
|
2177 'css': [ |
|
2178 (r'\.[a-z0-9_:-]+', Name.Class, 'tag'), |
|
2179 (r'\#[a-z0-9_:-]+', Name.Function, 'tag'), |
|
2180 ], |
|
2181 |
|
2182 'eval-or-plain': [ |
|
2183 (r'[&!]?==', Punctuation, 'plain'), |
|
2184 (r'([&!]?[=~])(' + _dot + r'*\n)', |
|
2185 bygroups(Punctuation, using(ScalaLexer)), 'root'), |
|
2186 (r'', Text, 'plain'), |
|
2187 ], |
|
2188 |
|
2189 'content': [ |
|
2190 include('css'), |
|
2191 (r'!!!' + _dot + r'*\n', Name.Namespace, '#pop'), |
|
2192 (r'(/)(\[' + _dot + '*?\])(' + _dot + r'*\n)', |
|
2193 bygroups(Comment, Comment.Special, Comment), |
|
2194 '#pop'), |
|
2195 (r'/' + _dot + r'*\n', _starts_block(Comment, 'html-comment-block'), |
|
2196 '#pop'), |
|
2197 (r'-#' + _dot + r'*\n', _starts_block(Comment.Preproc, |
|
2198 'scaml-comment-block'), '#pop'), |
|
2199 (r'(-@\s*)(import)?(' + _dot + r'*\n)', |
|
2200 bygroups(Punctuation, Keyword, using(ScalaLexer)), |
|
2201 '#pop'), |
|
2202 (r'(-)(' + _dot + r'*\n)', |
|
2203 bygroups(Punctuation, using(ScalaLexer)), |
|
2204 '#pop'), |
|
2205 (r':' + _dot + r'*\n', _starts_block(Name.Decorator, 'filter-block'), |
|
2206 '#pop'), |
|
2207 (r'[a-z0-9_:-]+', Name.Tag, 'tag'), |
|
2208 (r'\|', Text, 'eval-or-plain'), |
|
2209 ], |
|
2210 |
|
2211 'tag': [ |
|
2212 include('css'), |
|
2213 (r'\{(,\n|' + _dot + ')*?\}', using(ScalaLexer)), |
|
2214 (r'\[' + _dot + '*?\]', using(ScalaLexer)), |
|
2215 (r'\(', Text, 'html-attributes'), |
|
2216 (r'/[ \t]*\n', Punctuation, '#pop:2'), |
|
2217 (r'[<>]{1,2}(?=[ \t=])', Punctuation), |
|
2218 include('eval-or-plain'), |
|
2219 ], |
|
2220 |
|
2221 'plain': [ |
|
2222 (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text), |
|
2223 (r'(#\{)(' + _dot + '*?)(\})', |
|
2224 bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), |
|
2225 (r'\n', Text, 'root'), |
|
2226 ], |
|
2227 |
|
2228 'html-attributes': [ |
|
2229 (r'\s+', Text), |
|
2230 (r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'), |
|
2231 (r'[a-z0-9_:-]+', Name.Attribute), |
|
2232 (r'\)', Text, '#pop'), |
|
2233 ], |
|
2234 |
|
2235 'html-attribute-value': [ |
|
2236 (r'[ \t]+', Text), |
|
2237 (r'[a-z0-9_]+', Name.Variable, '#pop'), |
|
2238 (r'@[a-z0-9_]+', Name.Variable.Instance, '#pop'), |
|
2239 (r'\$[a-z0-9_]+', Name.Variable.Global, '#pop'), |
|
2240 (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'), |
|
2241 (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'), |
|
2242 ], |
|
2243 |
|
2244 'html-comment-block': [ |
|
2245 (_dot + '+', Comment), |
|
2246 (r'\n', Text, 'root'), |
|
2247 ], |
|
2248 |
|
2249 'scaml-comment-block': [ |
|
2250 (_dot + '+', Comment.Preproc), |
|
2251 (r'\n', Text, 'root'), |
|
2252 ], |
|
2253 |
|
2254 'filter-block': [ |
|
2255 (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator), |
|
2256 (r'(#\{)(' + _dot + '*?)(\})', |
|
2257 bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), |
|
2258 (r'\n', Text, 'root'), |
|
2259 ], |
|
2260 } |
|
2261 |
|
2262 |
|
2263 class XQueryLexer(ExtendedRegexLexer): |
|
2264 """ |
|
2265 An XQuery lexer, parsing a stream and outputting the tokens needed to |
|
2266 highlight xquery code. |
|
2267 |
|
2268 *New in Pygments 1.4.* |
|
2269 """ |
|
2270 name = 'XQuery' |
|
2271 aliases = ['xquery', 'xqy', 'xq', 'xql', 'xqm'] |
|
2272 filenames = ['*.xqy', '*.xquery', '*.xq', '*.xql', '*.xqm'] |
|
2273 mimetypes = ['text/xquery', 'application/xquery'] |
|
2274 |
|
2275 xquery_parse_state = [] |
|
2276 |
|
2277 # FIX UNICODE LATER |
|
2278 #ncnamestartchar = ( |
|
2279 # ur"[A-Z]|_|[a-z]|[\u00C0-\u00D6]|[\u00D8-\u00F6]|[\u00F8-\u02FF]|" |
|
2280 # ur"[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|" |
|
2281 # ur"[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]|" |
|
2282 # ur"[\u10000-\uEFFFF]" |
|
2283 #) |
|
2284 ncnamestartchar = r"(?:[A-Z]|_|[a-z])" |
|
2285 # FIX UNICODE LATER |
|
2286 #ncnamechar = ncnamestartchar + (ur"|-|\.|[0-9]|\u00B7|[\u0300-\u036F]|" |
|
2287 # ur"[\u203F-\u2040]") |
|
2288 ncnamechar = r"(?:" + ncnamestartchar + r"|-|\.|[0-9])" |
|
2289 ncname = "(?:%s+%s*)" % (ncnamestartchar, ncnamechar) |
|
2290 pitarget_namestartchar = r"(?:[A-KN-WY-Z]|_|:|[a-kn-wy-z])" |
|
2291 pitarget_namechar = r"(?:" + pitarget_namestartchar + r"|-|\.|[0-9])" |
|
2292 pitarget = "%s+%s*" % (pitarget_namestartchar, pitarget_namechar) |
|
2293 prefixedname = "%s:%s" % (ncname, ncname) |
|
2294 unprefixedname = ncname |
|
2295 qname = "(?:%s|%s)" % (prefixedname, unprefixedname) |
|
2296 |
|
2297 entityref = r'(?:&(?:lt|gt|amp|quot|apos|nbsp);)' |
|
2298 charref = r'(?:&#[0-9]+;|&#x[0-9a-fA-F]+;)' |
|
2299 |
|
2300 stringdouble = r'(?:"(?:' + entityref + r'|' + charref + r'|""|[^&"])*")' |
|
2301 stringsingle = r"(?:'(?:" + entityref + r"|" + charref + r"|''|[^&'])*')" |
|
2302 |
|
2303 # FIX UNICODE LATER |
|
2304 #elementcontentchar = (ur'\t|\r|\n|[\u0020-\u0025]|[\u0028-\u003b]|' |
|
2305 # ur'[\u003d-\u007a]|\u007c|[\u007e-\u007F]') |
|
2306 elementcontentchar = r'[A-Za-z]|\s|\d|[!"#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_\'`\|~]' |
|
2307 #quotattrcontentchar = (ur'\t|\r|\n|[\u0020-\u0021]|[\u0023-\u0025]|' |
|
2308 # ur'[\u0027-\u003b]|[\u003d-\u007a]|\u007c|[\u007e-\u007F]') |
|
2309 quotattrcontentchar = r'[A-Za-z]|\s|\d|[!#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_\'`\|~]' |
|
2310 #aposattrcontentchar = (ur'\t|\r|\n|[\u0020-\u0025]|[\u0028-\u003b]|' |
|
2311 # ur'[\u003d-\u007a]|\u007c|[\u007e-\u007F]') |
|
2312 aposattrcontentchar = r'[A-Za-z]|\s|\d|[!"#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_`\|~]' |
|
2313 |
|
2314 |
|
2315 # CHAR elements - fix the above elementcontentchar, quotattrcontentchar, |
|
2316 # aposattrcontentchar |
|
2317 #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] |
|
2318 |
|
2319 flags = re.DOTALL | re.MULTILINE | re.UNICODE |
|
2320 |
|
2321 def punctuation_root_callback(lexer, match, ctx): |
|
2322 yield match.start(), Punctuation, match.group(1) |
|
2323 # transition to root always - don't pop off stack |
|
2324 ctx.stack = ['root'] |
|
2325 ctx.pos = match.end() |
|
2326 |
|
2327 def operator_root_callback(lexer, match, ctx): |
|
2328 yield match.start(), Operator, match.group(1) |
|
2329 # transition to root always - don't pop off stack |
|
2330 ctx.stack = ['root'] |
|
2331 ctx.pos = match.end() |
|
2332 |
|
2333 def popstate_tag_callback(lexer, match, ctx): |
|
2334 yield match.start(), Name.Tag, match.group(1) |
|
2335 ctx.stack.append(lexer.xquery_parse_state.pop()) |
|
2336 ctx.pos = match.end() |
|
2337 |
|
2338 def popstate_xmlcomment_callback(lexer, match, ctx): |
|
2339 yield match.start(), String.Doc, match.group(1) |
|
2340 ctx.stack.append(lexer.xquery_parse_state.pop()) |
|
2341 ctx.pos = match.end() |
|
2342 |
|
2343 def popstate_kindtest_callback(lexer, match, ctx): |
|
2344 yield match.start(), Punctuation, match.group(1) |
|
2345 next_state = lexer.xquery_parse_state.pop() |
|
2346 if next_state == 'occurrenceindicator': |
|
2347 if re.match("[?*+]+", match.group(2)): |
|
2348 yield match.start(), Punctuation, match.group(2) |
|
2349 ctx.stack.append('operator') |
|
2350 ctx.pos = match.end() |
|
2351 else: |
|
2352 ctx.stack.append('operator') |
|
2353 ctx.pos = match.end(1) |
|
2354 else: |
|
2355 ctx.stack.append(next_state) |
|
2356 ctx.pos = match.end(1) |
|
2357 |
|
2358 def popstate_callback(lexer, match, ctx): |
|
2359 yield match.start(), Punctuation, match.group(1) |
|
2360 # if we have run out of our state stack, pop whatever is on the pygments |
|
2361 # state stack |
|
2362 if len(lexer.xquery_parse_state) == 0: |
|
2363 ctx.stack.pop() |
|
2364 elif len(ctx.stack) > 1: |
|
2365 ctx.stack.append(lexer.xquery_parse_state.pop()) |
|
2366 else: |
|
2367 # i don't know if i'll need this, but in case, default back to root |
|
2368 ctx.stack = ['root'] |
|
2369 ctx.pos = match.end() |
|
2370 |
|
2371 def pushstate_element_content_starttag_callback(lexer, match, ctx): |
|
2372 yield match.start(), Name.Tag, match.group(1) |
|
2373 lexer.xquery_parse_state.append('element_content') |
|
2374 ctx.stack.append('start_tag') |
|
2375 ctx.pos = match.end() |
|
2376 |
|
2377 def pushstate_cdata_section_callback(lexer, match, ctx): |
|
2378 yield match.start(), String.Doc, match.group(1) |
|
2379 ctx.stack.append('cdata_section') |
|
2380 lexer.xquery_parse_state.append(ctx.state.pop) |
|
2381 ctx.pos = match.end() |
|
2382 |
|
2383 def pushstate_starttag_callback(lexer, match, ctx): |
|
2384 yield match.start(), Name.Tag, match.group(1) |
|
2385 lexer.xquery_parse_state.append(ctx.state.pop) |
|
2386 ctx.stack.append('start_tag') |
|
2387 ctx.pos = match.end() |
|
2388 |
|
2389 def pushstate_operator_order_callback(lexer, match, ctx): |
|
2390 yield match.start(), Keyword, match.group(1) |
|
2391 yield match.start(), Text, match.group(2) |
|
2392 yield match.start(), Punctuation, match.group(3) |
|
2393 ctx.stack = ['root'] |
|
2394 lexer.xquery_parse_state.append('operator') |
|
2395 ctx.pos = match.end() |
|
2396 |
|
2397 def pushstate_operator_root_validate(lexer, match, ctx): |
|
2398 yield match.start(), Keyword, match.group(1) |
|
2399 yield match.start(), Text, match.group(2) |
|
2400 yield match.start(), Punctuation, match.group(3) |
|
2401 ctx.stack = ['root'] |
|
2402 lexer.xquery_parse_state.append('operator') |
|
2403 ctx.pos = match.end() |
|
2404 |
|
2405 def pushstate_operator_root_validate_withmode(lexer, match, ctx): |
|
2406 yield match.start(), Keyword, match.group(1) |
|
2407 yield match.start(), Text, match.group(2) |
|
2408 yield match.start(), Keyword, match.group(3) |
|
2409 ctx.stack = ['root'] |
|
2410 lexer.xquery_parse_state.append('operator') |
|
2411 ctx.pos = match.end() |
|
2412 |
|
2413 def pushstate_operator_processing_instruction_callback(lexer, match, ctx): |
|
2414 yield match.start(), String.Doc, match.group(1) |
|
2415 ctx.stack.append('processing_instruction') |
|
2416 lexer.xquery_parse_state.append('operator') |
|
2417 ctx.pos = match.end() |
|
2418 |
|
2419 def pushstate_element_content_processing_instruction_callback(lexer, match, ctx): |
|
2420 yield match.start(), String.Doc, match.group(1) |
|
2421 ctx.stack.append('processing_instruction') |
|
2422 lexer.xquery_parse_state.append('element_content') |
|
2423 ctx.pos = match.end() |
|
2424 |
|
2425 def pushstate_element_content_cdata_section_callback(lexer, match, ctx): |
|
2426 yield match.start(), String.Doc, match.group(1) |
|
2427 ctx.stack.append('cdata_section') |
|
2428 lexer.xquery_parse_state.append('element_content') |
|
2429 ctx.pos = match.end() |
|
2430 |
|
2431 def pushstate_operator_cdata_section_callback(lexer, match, ctx): |
|
2432 yield match.start(), String.Doc, match.group(1) |
|
2433 ctx.stack.append('cdata_section') |
|
2434 lexer.xquery_parse_state.append('operator') |
|
2435 ctx.pos = match.end() |
|
2436 |
|
2437 def pushstate_element_content_xmlcomment_callback(lexer, match, ctx): |
|
2438 yield match.start(), String.Doc, match.group(1) |
|
2439 ctx.stack.append('xml_comment') |
|
2440 lexer.xquery_parse_state.append('element_content') |
|
2441 ctx.pos = match.end() |
|
2442 |
|
2443 def pushstate_operator_xmlcomment_callback(lexer, match, ctx): |
|
2444 yield match.start(), String.Doc, match.group(1) |
|
2445 ctx.stack.append('xml_comment') |
|
2446 lexer.xquery_parse_state.append('operator') |
|
2447 ctx.pos = match.end() |
|
2448 |
|
2449 def pushstate_kindtest_callback(lexer, match, ctx): |
|
2450 yield match.start(), Keyword, match.group(1) |
|
2451 yield match.start(), Text, match.group(2) |
|
2452 yield match.start(), Punctuation, match.group(3) |
|
2453 lexer.xquery_parse_state.append('kindtest') |
|
2454 ctx.stack.append('kindtest') |
|
2455 ctx.pos = match.end() |
|
2456 |
|
2457 def pushstate_operator_kindtestforpi_callback(lexer, match, ctx): |
|
2458 yield match.start(), Keyword, match.group(1) |
|
2459 yield match.start(), Text, match.group(2) |
|
2460 yield match.start(), Punctuation, match.group(3) |
|
2461 lexer.xquery_parse_state.append('operator') |
|
2462 ctx.stack.append('kindtestforpi') |
|
2463 ctx.pos = match.end() |
|
2464 |
|
2465 def pushstate_operator_kindtest_callback(lexer, match, ctx): |
|
2466 yield match.start(), Keyword, match.group(1) |
|
2467 yield match.start(), Text, match.group(2) |
|
2468 yield match.start(), Punctuation, match.group(3) |
|
2469 lexer.xquery_parse_state.append('operator') |
|
2470 ctx.stack.append('kindtest') |
|
2471 ctx.pos = match.end() |
|
2472 |
|
2473 def pushstate_occurrenceindicator_kindtest_callback(lexer, match, ctx): |
|
2474 yield match.start(), Name.Tag, match.group(1) |
|
2475 yield match.start(), Text, match.group(2) |
|
2476 yield match.start(), Punctuation, match.group(3) |
|
2477 lexer.xquery_parse_state.append('occurrenceindicator') |
|
2478 ctx.stack.append('kindtest') |
|
2479 ctx.pos = match.end() |
|
2480 |
|
2481 def pushstate_operator_starttag_callback(lexer, match, ctx): |
|
2482 yield match.start(), Name.Tag, match.group(1) |
|
2483 lexer.xquery_parse_state.append('operator') |
|
2484 ctx.stack.append('start_tag') |
|
2485 ctx.pos = match.end() |
|
2486 |
|
2487 def pushstate_operator_root_callback(lexer, match, ctx): |
|
2488 yield match.start(), Punctuation, match.group(1) |
|
2489 lexer.xquery_parse_state.append('operator') |
|
2490 ctx.stack = ['root']#.append('root') |
|
2491 ctx.pos = match.end() |
|
2492 |
|
2493 def pushstate_operator_root_construct_callback(lexer, match, ctx): |
|
2494 yield match.start(), Keyword, match.group(1) |
|
2495 yield match.start(), Text, match.group(2) |
|
2496 yield match.start(), Punctuation, match.group(3) |
|
2497 lexer.xquery_parse_state.append('operator') |
|
2498 ctx.stack = ['root'] |
|
2499 ctx.pos = match.end() |
|
2500 |
|
2501 def pushstate_root_callback(lexer, match, ctx): |
|
2502 yield match.start(), Punctuation, match.group(1) |
|
2503 cur_state = ctx.stack.pop() |
|
2504 lexer.xquery_parse_state.append(cur_state) |
|
2505 ctx.stack = ['root']#.append('root') |
|
2506 ctx.pos = match.end() |
|
2507 |
|
2508 def pushstate_operator_attribute_callback(lexer, match, ctx): |
|
2509 yield match.start(), Name.Attribute, match.group(1) |
|
2510 ctx.stack.append('operator') |
|
2511 ctx.pos = match.end() |
|
2512 |
|
2513 def pushstate_operator_callback(lexer, match, ctx): |
|
2514 yield match.start(), Keyword, match.group(1) |
|
2515 yield match.start(), Text, match.group(2) |
|
2516 yield match.start(), Punctuation, match.group(3) |
|
2517 lexer.xquery_parse_state.append('operator') |
|
2518 ctx.pos = match.end() |
|
2519 |
|
2520 tokens = { |
|
2521 'comment': [ |
|
2522 # xquery comments |
|
2523 (r'(:\))', Comment, '#pop'), |
|
2524 (r'(\(:)', Comment, '#push'), |
|
2525 (r'[^:)]', Comment), |
|
2526 (r'([^:)]|:|\))', Comment), |
|
2527 ], |
|
2528 'whitespace': [ |
|
2529 (r'\s+', Text), |
|
2530 ], |
|
2531 'operator': [ |
|
2532 include('whitespace'), |
|
2533 (r'(\})', popstate_callback), |
|
2534 (r'\(:', Comment, 'comment'), |
|
2535 |
|
2536 (r'(\{)', pushstate_root_callback), |
|
2537 (r'then|else|external|at|div|except', Keyword, 'root'), |
|
2538 (r'order by', Keyword, 'root'), |
|
2539 (r'is|mod|order\s+by|stable\s+order\s+by', Keyword, 'root'), |
|
2540 (r'and|or', Operator.Word, 'root'), |
|
2541 (r'(eq|ge|gt|le|lt|ne|idiv|intersect|in)(?=\b)', |
|
2542 Operator.Word, 'root'), |
|
2543 (r'return|satisfies|to|union|where|preserve\s+strip', |
|
2544 Keyword, 'root'), |
|
2545 (r'(>=|>>|>|<=|<<|<|-|\*|!=|\+|\||:=|=)', |
|
2546 operator_root_callback), |
|
2547 (r'(::|;|\[|//|/|,)', |
|
2548 punctuation_root_callback), |
|
2549 (r'(castable|cast)(\s+)(as)\b', |
|
2550 bygroups(Keyword, Text, Keyword), 'singletype'), |
|
2551 (r'(instance)(\s+)(of)\b', |
|
2552 bygroups(Keyword, Text, Keyword), 'itemtype'), |
|
2553 (r'(treat)(\s+)(as)\b', |
|
2554 bygroups(Keyword, Text, Keyword), 'itemtype'), |
|
2555 (r'(case|as)\b', Keyword, 'itemtype'), |
|
2556 (r'(\))(\s*)(as)', |
|
2557 bygroups(Punctuation, Text, Keyword), 'itemtype'), |
|
2558 (r'\$', Name.Variable, 'varname'), |
|
2559 (r'(for|let)(\s+)(\$)', |
|
2560 bygroups(Keyword, Text, Name.Variable), 'varname'), |
|
2561 #(r'\)|\?|\]', Punctuation, '#push'), |
|
2562 (r'\)|\?|\]', Punctuation), |
|
2563 (r'(empty)(\s+)(greatest|least)', bygroups(Keyword, Text, Keyword)), |
|
2564 (r'ascending|descending|default', Keyword, '#push'), |
|
2565 (r'external', Keyword), |
|
2566 (r'collation', Keyword, 'uritooperator'), |
|
2567 # finally catch all string literals and stay in operator state |
|
2568 (stringdouble, String.Double), |
|
2569 (stringsingle, String.Single), |
|
2570 |
|
2571 (r'(catch)(\s*)', bygroups(Keyword, Text), 'root'), |
|
2572 ], |
|
2573 'uritooperator': [ |
|
2574 (stringdouble, String.Double, '#pop'), |
|
2575 (stringsingle, String.Single, '#pop'), |
|
2576 ], |
|
2577 'namespacedecl': [ |
|
2578 include('whitespace'), |
|
2579 (r'\(:', Comment, 'comment'), |
|
2580 (r'(at)(\s+)('+stringdouble+')', bygroups(Keyword, Text, String.Double)), |
|
2581 (r"(at)(\s+)("+stringsingle+')', bygroups(Keyword, Text, String.Single)), |
|
2582 (stringdouble, String.Double), |
|
2583 (stringsingle, String.Single), |
|
2584 (r',', Punctuation), |
|
2585 (r'=', Operator), |
|
2586 (r';', Punctuation, 'root'), |
|
2587 (ncname, Name.Namespace), |
|
2588 ], |
|
2589 'namespacekeyword': [ |
|
2590 include('whitespace'), |
|
2591 (r'\(:', Comment, 'comment'), |
|
2592 (stringdouble, String.Double, 'namespacedecl'), |
|
2593 (stringsingle, String.Single, 'namespacedecl'), |
|
2594 (r'inherit|no-inherit', Keyword, 'root'), |
|
2595 (r'namespace', Keyword, 'namespacedecl'), |
|
2596 (r'(default)(\s+)(element)', bygroups(Keyword, Text, Keyword)), |
|
2597 (r'preserve|no-preserve', Keyword), |
|
2598 (r',', Punctuation), |
|
2599 ], |
|
2600 'varname': [ |
|
2601 (r'\(:', Comment, 'comment'), |
|
2602 (qname, Name.Variable, 'operator'), |
|
2603 ], |
|
2604 'singletype': [ |
|
2605 (r'\(:', Comment, 'comment'), |
|
2606 (ncname + r'(:\*)', Name.Variable, 'operator'), |
|
2607 (qname, Name.Variable, 'operator'), |
|
2608 ], |
|
2609 'itemtype': [ |
|
2610 include('whitespace'), |
|
2611 (r'\(:', Comment, 'comment'), |
|
2612 (r'\$', Punctuation, 'varname'), |
|
2613 (r'(void)(\s*)(\()(\s*)(\))', |
|
2614 bygroups(Keyword, Text, Punctuation, Text, Punctuation), 'operator'), |
|
2615 (r'(element|attribute|schema-element|schema-attribute|comment|text|' |
|
2616 r'node|binary|document-node|empty-sequence)(\s*)(\()', |
|
2617 pushstate_occurrenceindicator_kindtest_callback), |
|
2618 # Marklogic specific type? |
|
2619 (r'(processing-instruction)(\s*)(\()', |
|
2620 bygroups(Keyword, Text, Punctuation), |
|
2621 ('occurrenceindicator', 'kindtestforpi')), |
|
2622 (r'(item)(\s*)(\()(\s*)(\))(?=[*+?])', |
|
2623 bygroups(Keyword, Text, Punctuation, Text, Punctuation), |
|
2624 'occurrenceindicator'), |
|
2625 (r'\(\#', Punctuation, 'pragma'), |
|
2626 (r';', Punctuation, '#pop'), |
|
2627 (r'then|else', Keyword, '#pop'), |
|
2628 (r'(at)(\s+)(' + stringdouble + ')', |
|
2629 bygroups(Keyword, Text, String.Double), 'namespacedecl'), |
|
2630 (r'(at)(\s+)(' + stringsingle + ')', |
|
2631 bygroups(Keyword, Text, String.Single), 'namespacedecl'), |
|
2632 (r'except|intersect|in|is|return|satisfies|to|union|where', |
|
2633 Keyword, 'root'), |
|
2634 (r'and|div|eq|ge|gt|le|lt|ne|idiv|mod|or', Operator.Word, 'root'), |
|
2635 (r':=|=|,|>=|>>|>|\[|\(|<=|<<|<|-|!=|\|', Operator, 'root'), |
|
2636 (r'external|at', Keyword, 'root'), |
|
2637 (r'(stable)(\s+)(order)(\s+)(by)', |
|
2638 bygroups(Keyword, Text, Keyword, Text, Keyword), 'root'), |
|
2639 (r'(castable|cast)(\s+)(as)', |
|
2640 bygroups(Keyword, Text, Keyword), 'singletype'), |
|
2641 (r'(treat)(\s+)(as)', bygroups(Keyword, Text, Keyword)), |
|
2642 (r'(instance)(\s+)(of)', bygroups(Keyword, Text, Keyword)), |
|
2643 (r'case|as', Keyword, 'itemtype'), |
|
2644 (r'(\))(\s*)(as)', bygroups(Operator, Text, Keyword), 'itemtype'), |
|
2645 (ncname + r':\*', Keyword.Type, 'operator'), |
|
2646 (qname, Keyword.Type, 'occurrenceindicator'), |
|
2647 ], |
|
2648 'kindtest': [ |
|
2649 (r'\(:', Comment, 'comment'), |
|
2650 (r'{', Punctuation, 'root'), |
|
2651 (r'(\))([*+?]?)', popstate_kindtest_callback), |
|
2652 (r'\*', Name, 'closekindtest'), |
|
2653 (qname, Name, 'closekindtest'), |
|
2654 (r'(element|schema-element)(\s*)(\()', pushstate_kindtest_callback), |
|
2655 ], |
|
2656 'kindtestforpi': [ |
|
2657 (r'\(:', Comment, 'comment'), |
|
2658 (r'\)', Punctuation, '#pop'), |
|
2659 (ncname, Name.Variable), |
|
2660 (stringdouble, String.Double), |
|
2661 (stringsingle, String.Single), |
|
2662 ], |
|
2663 'closekindtest': [ |
|
2664 (r'\(:', Comment, 'comment'), |
|
2665 (r'(\))', popstate_callback), |
|
2666 (r',', Punctuation), |
|
2667 (r'(\{)', pushstate_operator_root_callback), |
|
2668 (r'\?', Punctuation), |
|
2669 ], |
|
2670 'xml_comment': [ |
|
2671 (r'(-->)', popstate_xmlcomment_callback), |
|
2672 (r'[^-]{1,2}', Literal), |
|
2673 (r'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + |
|
2674 unirange(0x10000, 0x10ffff), Literal), |
|
2675 ], |
|
2676 'processing_instruction': [ |
|
2677 (r'\s+', Text, 'processing_instruction_content'), |
|
2678 (r'\?>', String.Doc, '#pop'), |
|
2679 (pitarget, Name), |
|
2680 ], |
|
2681 'processing_instruction_content': [ |
|
2682 (r'\?>', String.Doc, '#pop'), |
|
2683 (r'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + |
|
2684 unirange(0x10000, 0x10ffff), Literal), |
|
2685 ], |
|
2686 'cdata_section': [ |
|
2687 (r']]>', String.Doc, '#pop'), |
|
2688 (r'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + |
|
2689 unirange(0x10000, 0x10ffff), Literal), |
|
2690 ], |
|
2691 'start_tag': [ |
|
2692 include('whitespace'), |
|
2693 (r'(/>)', popstate_tag_callback), |
|
2694 (r'>', Name.Tag, 'element_content'), |
|
2695 (r'"', Punctuation, 'quot_attribute_content'), |
|
2696 (r"'", Punctuation, 'apos_attribute_content'), |
|
2697 (r'=', Operator), |
|
2698 (qname, Name.Tag), |
|
2699 ], |
|
2700 'quot_attribute_content': [ |
|
2701 (r'"', Punctuation, 'start_tag'), |
|
2702 (r'(\{)', pushstate_root_callback), |
|
2703 (r'""', Name.Attribute), |
|
2704 (quotattrcontentchar, Name.Attribute), |
|
2705 (entityref, Name.Attribute), |
|
2706 (charref, Name.Attribute), |
|
2707 (r'\{\{|\}\}', Name.Attribute), |
|
2708 ], |
|
2709 'apos_attribute_content': [ |
|
2710 (r"'", Punctuation, 'start_tag'), |
|
2711 (r'\{', Punctuation, 'root'), |
|
2712 (r"''", Name.Attribute), |
|
2713 (aposattrcontentchar, Name.Attribute), |
|
2714 (entityref, Name.Attribute), |
|
2715 (charref, Name.Attribute), |
|
2716 (r'\{\{|\}\}', Name.Attribute), |
|
2717 ], |
|
2718 'element_content': [ |
|
2719 (r'</', Name.Tag, 'end_tag'), |
|
2720 (r'(\{)', pushstate_root_callback), |
|
2721 (r'(<!--)', pushstate_element_content_xmlcomment_callback), |
|
2722 (r'(<\?)', pushstate_element_content_processing_instruction_callback), |
|
2723 (r'(<!\[CDATA\[)', pushstate_element_content_cdata_section_callback), |
|
2724 (r'(<)', pushstate_element_content_starttag_callback), |
|
2725 (elementcontentchar, Literal), |
|
2726 (entityref, Literal), |
|
2727 (charref, Literal), |
|
2728 (r'\{\{|\}\}', Literal), |
|
2729 ], |
|
2730 'end_tag': [ |
|
2731 include('whitespace'), |
|
2732 (r'(>)', popstate_tag_callback), |
|
2733 (qname, Name.Tag), |
|
2734 ], |
|
2735 'xmlspace_decl': [ |
|
2736 (r'\(:', Comment, 'comment'), |
|
2737 (r'preserve|strip', Keyword, '#pop'), |
|
2738 ], |
|
2739 'declareordering': [ |
|
2740 (r'\(:', Comment, 'comment'), |
|
2741 include('whitespace'), |
|
2742 (r'ordered|unordered', Keyword, '#pop'), |
|
2743 ], |
|
2744 'xqueryversion': [ |
|
2745 include('whitespace'), |
|
2746 (r'\(:', Comment, 'comment'), |
|
2747 (stringdouble, String.Double), |
|
2748 (stringsingle, String.Single), |
|
2749 (r'encoding', Keyword), |
|
2750 (r';', Punctuation, '#pop'), |
|
2751 ], |
|
2752 'pragma': [ |
|
2753 (qname, Name.Variable, 'pragmacontents'), |
|
2754 ], |
|
2755 'pragmacontents': [ |
|
2756 (r'#\)', Punctuation, 'operator'), |
|
2757 (r'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + |
|
2758 unirange(0x10000, 0x10ffff), Literal), |
|
2759 (r'(\s+)', Text), |
|
2760 ], |
|
2761 'occurrenceindicator': [ |
|
2762 include('whitespace'), |
|
2763 (r'\(:', Comment, 'comment'), |
|
2764 (r'\*|\?|\+', Operator, 'operator'), |
|
2765 (r':=', Operator, 'root'), |
|
2766 (r'', Text, 'operator'), |
|
2767 ], |
|
2768 'option': [ |
|
2769 include('whitespace'), |
|
2770 (qname, Name.Variable, '#pop'), |
|
2771 ], |
|
2772 'qname_braren': [ |
|
2773 include('whitespace'), |
|
2774 (r'(\{)', pushstate_operator_root_callback), |
|
2775 (r'(\()', Punctuation, 'root'), |
|
2776 ], |
|
2777 'element_qname': [ |
|
2778 (qname, Name.Variable, 'root'), |
|
2779 ], |
|
2780 'attribute_qname': [ |
|
2781 (qname, Name.Variable, 'root'), |
|
2782 ], |
|
2783 'root': [ |
|
2784 include('whitespace'), |
|
2785 (r'\(:', Comment, 'comment'), |
|
2786 |
|
2787 # handle operator state |
|
2788 # order on numbers matters - handle most complex first |
|
2789 (r'\d+(\.\d*)?[eE][\+\-]?\d+', Number.Double, 'operator'), |
|
2790 (r'(\.\d+)[eE][\+\-]?\d+', Number.Double, 'operator'), |
|
2791 (r'(\.\d+|\d+\.\d*)', Number, 'operator'), |
|
2792 (r'(\d+)', Number.Integer, 'operator'), |
|
2793 (r'(\.\.|\.|\))', Punctuation, 'operator'), |
|
2794 (r'(declare)(\s+)(construction)', |
|
2795 bygroups(Keyword, Text, Keyword), 'operator'), |
|
2796 (r'(declare)(\s+)(default)(\s+)(order)', |
|
2797 bygroups(Keyword, Text, Keyword, Text, Keyword), 'operator'), |
|
2798 (ncname + ':\*', Name, 'operator'), |
|
2799 ('\*:'+ncname, Name.Tag, 'operator'), |
|
2800 ('\*', Name.Tag, 'operator'), |
|
2801 (stringdouble, String.Double, 'operator'), |
|
2802 (stringsingle, String.Single, 'operator'), |
|
2803 |
|
2804 (r'(\})', popstate_callback), |
|
2805 |
|
2806 #NAMESPACE DECL |
|
2807 (r'(declare)(\s+)(default)(\s+)(collation)', |
|
2808 bygroups(Keyword, Text, Keyword, Text, Keyword)), |
|
2809 (r'(module|declare)(\s+)(namespace)', |
|
2810 bygroups(Keyword, Text, Keyword), 'namespacedecl'), |
|
2811 (r'(declare)(\s+)(base-uri)', |
|
2812 bygroups(Keyword, Text, Keyword), 'namespacedecl'), |
|
2813 |
|
2814 #NAMESPACE KEYWORD |
|
2815 (r'(declare)(\s+)(default)(\s+)(element|function)', |
|
2816 bygroups(Keyword, Text, Keyword, Text, Keyword), 'namespacekeyword'), |
|
2817 (r'(import)(\s+)(schema|module)', |
|
2818 bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'namespacekeyword'), |
|
2819 (r'(declare)(\s+)(copy-namespaces)', |
|
2820 bygroups(Keyword, Text, Keyword), 'namespacekeyword'), |
|
2821 |
|
2822 #VARNAMEs |
|
2823 (r'(for|let|some|every)(\s+)(\$)', |
|
2824 bygroups(Keyword, Text, Name.Variable), 'varname'), |
|
2825 (r'\$', Name.Variable, 'varname'), |
|
2826 (r'(declare)(\s+)(variable)(\s+)(\$)', |
|
2827 bygroups(Keyword, Text, Keyword, Text, Name.Variable), 'varname'), |
|
2828 |
|
2829 #ITEMTYPE |
|
2830 (r'(\))(\s+)(as)', bygroups(Operator, Text, Keyword), 'itemtype'), |
|
2831 |
|
2832 (r'(element|attribute|schema-element|schema-attribute|comment|' |
|
2833 r'text|node|document-node|empty-sequence)(\s+)(\()', |
|
2834 pushstate_operator_kindtest_callback), |
|
2835 |
|
2836 (r'(processing-instruction)(\s+)(\()', |
|
2837 pushstate_operator_kindtestforpi_callback), |
|
2838 |
|
2839 (r'(<!--)', pushstate_operator_xmlcomment_callback), |
|
2840 |
|
2841 (r'(<\?)', pushstate_operator_processing_instruction_callback), |
|
2842 |
|
2843 (r'(<!\[CDATA\[)', pushstate_operator_cdata_section_callback), |
|
2844 |
|
2845 # (r'</', Name.Tag, 'end_tag'), |
|
2846 (r'(<)', pushstate_operator_starttag_callback), |
|
2847 |
|
2848 (r'(declare)(\s+)(boundary-space)', |
|
2849 bygroups(Keyword, Text, Keyword), 'xmlspace_decl'), |
|
2850 |
|
2851 (r'(validate)(\s+)(lax|strict)', |
|
2852 pushstate_operator_root_validate_withmode), |
|
2853 (r'(validate)(\s*)(\{)', pushstate_operator_root_validate), |
|
2854 (r'(typeswitch)(\s*)(\()', bygroups(Keyword, Text, Punctuation)), |
|
2855 (r'(element|attribute)(\s*)(\{)', |
|
2856 pushstate_operator_root_construct_callback), |
|
2857 |
|
2858 (r'(document|text|processing-instruction|comment)(\s*)(\{)', |
|
2859 pushstate_operator_root_construct_callback), |
|
2860 #ATTRIBUTE |
|
2861 (r'(attribute)(\s+)(?=' + qname + r')', |
|
2862 bygroups(Keyword, Text), 'attribute_qname'), |
|
2863 #ELEMENT |
|
2864 (r'(element)(\s+)(?=' +qname+ r')', |
|
2865 bygroups(Keyword, Text), 'element_qname'), |
|
2866 #PROCESSING_INSTRUCTION |
|
2867 (r'(processing-instruction)(\s+)(' + ncname + r')(\s*)(\{)', |
|
2868 bygroups(Keyword, Text, Name.Variable, Text, Punctuation), |
|
2869 'operator'), |
|
2870 |
|
2871 (r'(declare|define)(\s+)(function)', |
|
2872 bygroups(Keyword, Text, Keyword)), |
|
2873 |
|
2874 (r'(\{)', pushstate_operator_root_callback), |
|
2875 |
|
2876 (r'(unordered|ordered)(\s*)(\{)', |
|
2877 pushstate_operator_order_callback), |
|
2878 |
|
2879 (r'(declare)(\s+)(ordering)', |
|
2880 bygroups(Keyword, Text, Keyword), 'declareordering'), |
|
2881 |
|
2882 (r'(xquery)(\s+)(version)', |
|
2883 bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'xqueryversion'), |
|
2884 |
|
2885 (r'(\(#)', Punctuation, 'pragma'), |
|
2886 |
|
2887 # sometimes return can occur in root state |
|
2888 (r'return', Keyword), |
|
2889 |
|
2890 (r'(declare)(\s+)(option)', bygroups(Keyword, Text, Keyword), |
|
2891 'option'), |
|
2892 |
|
2893 #URI LITERALS - single and double quoted |
|
2894 (r'(at)(\s+)('+stringdouble+')', String.Double, 'namespacedecl'), |
|
2895 (r'(at)(\s+)('+stringsingle+')', String.Single, 'namespacedecl'), |
|
2896 |
|
2897 (r'(ancestor-or-self|ancestor|attribute|child|descendant-or-self)(::)', |
|
2898 bygroups(Keyword, Punctuation)), |
|
2899 (r'(descendant|following-sibling|following|parent|preceding-sibling' |
|
2900 r'|preceding|self)(::)', bygroups(Keyword, Punctuation)), |
|
2901 |
|
2902 (r'(if)(\s*)(\()', bygroups(Keyword, Text, Punctuation)), |
|
2903 |
|
2904 (r'then|else', Keyword), |
|
2905 |
|
2906 # ML specific |
|
2907 (r'(try)(\s*)', bygroups(Keyword, Text), 'root'), |
|
2908 (r'(catch)(\s*)(\()(\$)', |
|
2909 bygroups(Keyword, Text, Punctuation, Name.Variable), 'varname'), |
|
2910 |
|
2911 (r'(@'+qname+')', Name.Attribute), |
|
2912 (r'(@'+ncname+')', Name.Attribute), |
|
2913 (r'@\*:'+ncname, Name.Attribute), |
|
2914 (r'(@)', Name.Attribute), |
|
2915 |
|
2916 (r'//|/|\+|-|;|,|\(|\)', Punctuation), |
|
2917 |
|
2918 # STANDALONE QNAMES |
|
2919 (qname + r'(?=\s*{)', Name.Tag, 'qname_braren'), |
|
2920 (qname + r'(?=\s*\([^:])', Name.Function, 'qname_braren'), |
|
2921 (qname, Name.Tag, 'operator'), |
|
2922 ] |
|
2923 } |
|
2924 |
|
2925 |
|
2926 class DartLexer(RegexLexer): |
|
2927 """ |
|
2928 For `Dart <http://dartlang.org/>`_ source code. |
|
2929 |
|
2930 *New in Pygments 1.5.* |
|
2931 """ |
|
2932 |
|
2933 name = 'Dart' |
|
2934 aliases = ['dart'] |
|
2935 filenames = ['*.dart'] |
|
2936 mimetypes = ['text/x-dart'] |
|
2937 |
|
2938 flags = re.MULTILINE | re.DOTALL |
|
2939 |
|
2940 tokens = { |
|
2941 'root': [ |
|
2942 include('string_literal'), |
|
2943 (r'#!(.*?)$', Comment.Preproc), |
|
2944 (r'\b(import|export)\b', Keyword, 'import_decl'), |
|
2945 (r'\b(library|source|part of|part)\b', Keyword), |
|
2946 (r'[^\S\n]+', Text), |
|
2947 (r'//.*?\n', Comment.Single), |
|
2948 (r'/\*.*?\*/', Comment.Multiline), |
|
2949 (r'\b(class)\b(\s+)', |
|
2950 bygroups(Keyword.Declaration, Text), 'class'), |
|
2951 (r'\b(assert|break|case|catch|continue|default|do|else|finally|for|' |
|
2952 r'if|in|is|new|return|super|switch|this|throw|try|while)\b', |
|
2953 Keyword), |
|
2954 (r'\b(abstract|const|extends|factory|final|get|implements|' |
|
2955 r'native|operator|set|static|typedef|var)\b', Keyword.Declaration), |
|
2956 (r'\b(bool|double|Dynamic|int|num|Object|String|void)\b', Keyword.Type), |
|
2957 (r'\b(false|null|true)\b', Keyword.Constant), |
|
2958 (r'[~!%^&*+=|?:<>/-]|as', Operator), |
|
2959 (r'[a-zA-Z_$][a-zA-Z0-9_]*:', Name.Label), |
|
2960 (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name), |
|
2961 (r'[(){}\[\],.;]', Punctuation), |
|
2962 (r'0[xX][0-9a-fA-F]+', Number.Hex), |
|
2963 # DIGIT+ (‘.’ DIGIT*)? EXPONENT? |
|
2964 (r'\d+(\.\d*)?([eE][+-]?\d+)?', Number), |
|
2965 (r'\.\d+([eE][+-]?\d+)?', Number), # ‘.’ DIGIT+ EXPONENT? |
|
2966 (r'\n', Text) |
|
2967 # pseudo-keyword negate intentionally left out |
|
2968 ], |
|
2969 'class': [ |
|
2970 (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name.Class, '#pop') |
|
2971 ], |
|
2972 'import_decl': [ |
|
2973 include('string_literal'), |
|
2974 (r'\s+', Text), |
|
2975 (r'\b(as|show|hide)\b', Keyword), |
|
2976 (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name), |
|
2977 (r'\,', Punctuation), |
|
2978 (r'\;', Punctuation, '#pop') |
|
2979 ], |
|
2980 'string_literal': [ |
|
2981 # Raw strings. |
|
2982 (r'r"""([\s|\S]*?)"""', String.Double), |
|
2983 (r"r'''([\s|\S]*?)'''", String.Single), |
|
2984 (r'r"(.*?)"', String.Double), |
|
2985 (r"r'(.*?)'", String.Single), |
|
2986 # Normal Strings. |
|
2987 (r'"""', String.Double, 'string_double_multiline'), |
|
2988 (r"'''", String.Single, 'string_single_multiline'), |
|
2989 (r'"', String.Double, 'string_double'), |
|
2990 (r"'", String.Single, 'string_single') |
|
2991 ], |
|
2992 'string_common': [ |
|
2993 (r"\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\{[0-9A-Fa-f]*\}|[a-z\'\"$\\])", |
|
2994 String.Escape), |
|
2995 (r'(\$)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(String.Interpol, Name)), |
|
2996 (r'(\$\{)(.*?)(\})', |
|
2997 bygroups(String.Interpol, using(this), String.Interpol)) |
|
2998 ], |
|
2999 'string_double': [ |
|
3000 (r'"', String.Double, '#pop'), |
|
3001 (r'[^\"$\\\n]+', String.Double), |
|
3002 include('string_common'), |
|
3003 (r'\$+', String.Double) |
|
3004 ], |
|
3005 'string_double_multiline': [ |
|
3006 (r'"""', String.Double, '#pop'), |
|
3007 (r'[^\"$\\]+', String.Double), |
|
3008 include('string_common'), |
|
3009 (r'(\$|\")+', String.Double) |
|
3010 ], |
|
3011 'string_single': [ |
|
3012 (r"'", String.Single, '#pop'), |
|
3013 (r"[^\'$\\\n]+", String.Single), |
|
3014 include('string_common'), |
|
3015 (r'\$+', String.Single) |
|
3016 ], |
|
3017 'string_single_multiline': [ |
|
3018 (r"'''", String.Single, '#pop'), |
|
3019 (r'[^\'$\\]+', String.Single), |
|
3020 include('string_common'), |
|
3021 (r'(\$|\')+', String.Single) |
|
3022 ] |
|
3023 } |
|
3024 |
|
3025 |
|
3026 class TypeScriptLexer(RegexLexer): |
|
3027 """ |
|
3028 For `TypeScript <http://www.python.org>`_ source code. |
|
3029 |
|
3030 *New in Pygments 1.6.* |
|
3031 """ |
|
3032 |
|
3033 name = 'TypeScript' |
|
3034 aliases = ['ts'] |
|
3035 filenames = ['*.ts'] |
|
3036 mimetypes = ['text/x-typescript'] |
|
3037 |
|
3038 flags = re.DOTALL |
|
3039 tokens = { |
|
3040 'commentsandwhitespace': [ |
|
3041 (r'\s+', Text), |
|
3042 (r'<!--', Comment), |
|
3043 (r'//.*?\n', Comment.Single), |
|
3044 (r'/\*.*?\*/', Comment.Multiline) |
|
3045 ], |
|
3046 'slashstartsregex': [ |
|
3047 include('commentsandwhitespace'), |
|
3048 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
3049 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
3050 (r'(?=/)', Text, ('#pop', 'badregex')), |
|
3051 (r'', Text, '#pop') |
|
3052 ], |
|
3053 'badregex': [ |
|
3054 (r'\n', Text, '#pop') |
|
3055 ], |
|
3056 'root': [ |
|
3057 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
3058 include('commentsandwhitespace'), |
|
3059 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' |
|
3060 r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), |
|
3061 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
3062 (r'[})\].]', Punctuation), |
|
3063 (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' |
|
3064 r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' |
|
3065 r'this)\b', Keyword, 'slashstartsregex'), |
|
3066 (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), |
|
3067 (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' |
|
3068 r'extends|final|float|goto|implements|import|int|interface|long|native|' |
|
3069 r'package|private|protected|public|short|static|super|synchronized|throws|' |
|
3070 r'transient|volatile)\b', Keyword.Reserved), |
|
3071 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), |
|
3072 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
3073 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
3074 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
3075 r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' |
|
3076 r'window)\b', Name.Builtin), |
|
3077 # Match stuff like: module name {...} |
|
3078 (r'\b(module)(\s*)(\s*[a-zA-Z0-9_?.$][\w?.$]*)(\s*)', |
|
3079 bygroups(Keyword.Reserved, Text, Name.Other, Text), 'slashstartsregex'), |
|
3080 # Match variable type keywords |
|
3081 (r'\b(string|bool|number)\b', Keyword.Type), |
|
3082 # Match stuff like: constructor |
|
3083 (r'\b(constructor|declare|interface|as|AS)\b', Keyword.Reserved), |
|
3084 # Match stuff like: super(argument, list) |
|
3085 (r'(super)(\s*)(\([a-zA-Z0-9,_?.$\s]+\s*\))', |
|
3086 bygroups(Keyword.Reserved, Text), 'slashstartsregex'), |
|
3087 # Match stuff like: function() {...} |
|
3088 (r'([a-zA-Z_?.$][\w?.$]*)\(\) \{', Name.Other, 'slashstartsregex'), |
|
3089 # Match stuff like: (function: return type) |
|
3090 (r'([a-zA-Z0-9_?.$][\w?.$]*)(\s*:\s*)([a-zA-Z0-9_?.$][\w?.$]*)', |
|
3091 bygroups(Name.Other, Text, Keyword.Type)), |
|
3092 (r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other), |
|
3093 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
3094 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
3095 (r'[0-9]+', Number.Integer), |
|
3096 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
3097 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
3098 ] |
|
3099 } |
|
3100 |
|
3101 |
|
3102 class LassoLexer(RegexLexer): |
|
3103 """ |
|
3104 For `Lasso <http://www.lassosoft.com/>`_ source code, covering both Lasso 9 |
|
3105 syntax and LassoScript for Lasso 8.6 and earlier. For Lasso embedded in |
|
3106 HTML, use the `LassoHtmlLexer`. |
|
3107 |
|
3108 Additional options accepted: |
|
3109 |
|
3110 `builtinshighlighting` |
|
3111 If given and ``True``, highlight builtin tags, types, traits, and |
|
3112 methods (default: ``True``). |
|
3113 `requiredelimiters` |
|
3114 If given and ``True``, only highlight code between delimiters as Lasso |
|
3115 (default: ``False``). |
|
3116 |
|
3117 *New in Pygments 1.6.* |
|
3118 """ |
|
3119 |
|
3120 name = 'Lasso' |
|
3121 aliases = ['lasso', 'lassoscript'] |
|
3122 filenames = ['*.lasso', '*.lasso[89]'] |
|
3123 alias_filenames = ['*.incl', '*.inc', '*.las'] |
|
3124 mimetypes = ['text/x-lasso'] |
|
3125 flags = re.IGNORECASE | re.DOTALL | re.MULTILINE |
|
3126 |
|
3127 tokens = { |
|
3128 'root': [ |
|
3129 (r'^#!.+lasso9\b', Comment.Preproc, 'lasso'), |
|
3130 (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), |
|
3131 (r'\[noprocess\]', Comment.Preproc, ('delimiters', 'noprocess')), |
|
3132 (r'\[', Comment.Preproc, ('delimiters', 'squarebrackets')), |
|
3133 (r'<\?(LassoScript|lasso|=)', Comment.Preproc, |
|
3134 ('delimiters', 'anglebrackets')), |
|
3135 (r'<', Other, 'delimiters'), |
|
3136 (r'\s+', Other), |
|
3137 (r'', Other, ('delimiters', 'lassofile')), |
|
3138 ], |
|
3139 'delimiters': [ |
|
3140 (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), |
|
3141 (r'\[noprocess\]', Comment.Preproc, 'noprocess'), |
|
3142 (r'\[', Comment.Preproc, 'squarebrackets'), |
|
3143 (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), |
|
3144 (r'<', Other), |
|
3145 (r'[^[<]+', Other), |
|
3146 ], |
|
3147 'nosquarebrackets': [ |
|
3148 (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), |
|
3149 (r'<', Other), |
|
3150 (r'[^<]+', Other), |
|
3151 ], |
|
3152 'noprocess': [ |
|
3153 (r'\[/noprocess\]', Comment.Preproc, '#pop'), |
|
3154 (r'\[', Other), |
|
3155 (r'[^[]', Other), |
|
3156 ], |
|
3157 'squarebrackets': [ |
|
3158 (r'\]', Comment.Preproc, '#pop'), |
|
3159 include('lasso'), |
|
3160 ], |
|
3161 'anglebrackets': [ |
|
3162 (r'\?>', Comment.Preproc, '#pop'), |
|
3163 include('lasso'), |
|
3164 ], |
|
3165 'lassofile': [ |
|
3166 (r'\]', Comment.Preproc, '#pop'), |
|
3167 (r'\?>', Comment.Preproc, '#pop'), |
|
3168 include('lasso'), |
|
3169 ], |
|
3170 'whitespacecomments': [ |
|
3171 (r'\s+', Text), |
|
3172 (r'//.*?\n', Comment.Single), |
|
3173 (r'/\*\*!.*?\*/', String.Doc), |
|
3174 (r'/\*.*?\*/', Comment.Multiline), |
|
3175 ], |
|
3176 'lasso': [ |
|
3177 # whitespace/comments |
|
3178 include('whitespacecomments'), |
|
3179 |
|
3180 # literals |
|
3181 (r'\d*\.\d+(e[+-]?\d+)?', Number.Float), |
|
3182 (r'0x[\da-f]+', Number.Hex), |
|
3183 (r'\d+', Number.Integer), |
|
3184 (r'([+-]?)(infinity|NaN)\b', bygroups(Operator, Number)), |
|
3185 (r"'", String.Single, 'singlestring'), |
|
3186 (r'"', String.Double, 'doublestring'), |
|
3187 (r'`[^`]*`', String.Backtick), |
|
3188 |
|
3189 # names |
|
3190 (r'\$[a-z_][\w.]*', Name.Variable), |
|
3191 (r'#[a-z_][\w.]*|#\d+', Name.Variable.Instance), |
|
3192 (r"(\.)('[a-z_][\w.]*')", |
|
3193 bygroups(Name.Builtin.Pseudo, Name.Variable.Class)), |
|
3194 (r"(self)(->)('[a-z_][\w.]*')", |
|
3195 bygroups(Name.Builtin.Pseudo, Operator, Name.Variable.Class)), |
|
3196 (r'(\.\.?)([a-z_][\w.]*)', |
|
3197 bygroups(Name.Builtin.Pseudo, Name.Other)), |
|
3198 (r'(self|inherited|global|void)\b', Name.Builtin.Pseudo), |
|
3199 (r'-[a-z_][\w.]*', Name.Attribute), |
|
3200 (r'(::\s*)([a-z_][\w.]*)', bygroups(Punctuation, Name.Label)), |
|
3201 (r'(error_(code|msg)_\w+|Error_AddError|Error_ColumnRestriction|' |
|
3202 r'Error_DatabaseConnectionUnavailable|Error_DatabaseTimeout|' |
|
3203 r'Error_DeleteError|Error_FieldRestriction|Error_FileNotFound|' |
|
3204 r'Error_InvalidDatabase|Error_InvalidPassword|' |
|
3205 r'Error_InvalidUsername|Error_ModuleNotFound|' |
|
3206 r'Error_NoError|Error_NoPermission|Error_OutOfMemory|' |
|
3207 r'Error_ReqColumnMissing|Error_ReqFieldMissing|' |
|
3208 r'Error_RequiredColumnMissing|Error_RequiredFieldMissing|' |
|
3209 r'Error_UpdateError)\b', Name.Exception), |
|
3210 |
|
3211 # definitions |
|
3212 (r'(define)(\s+)([a-z_][\w.]*)(\s*)(=>)(\s*)(type|trait|thread)\b', |
|
3213 bygroups(Keyword.Declaration, Text, Name.Class, Text, Operator, |
|
3214 Text, Keyword)), |
|
3215 (r'(define)(\s+)([a-z_][\w.]*)(->)([a-z_][\w.]*=?|[-+*/%<>]|==)', |
|
3216 bygroups(Keyword.Declaration, Text, Name.Class, Operator, |
|
3217 Name.Function), 'signature'), |
|
3218 (r'(define)(\s+)([a-z_][\w.]*)', |
|
3219 bygroups(Keyword.Declaration, Text, Name.Function), |
|
3220 'signature'), |
|
3221 (r'(public|protected|private|provide)(\s+)(([a-z_][\w.]*=?|' |
|
3222 r'[-+*/%<>]|==)(?=\s*\())', bygroups(Keyword, Text, Name.Function), |
|
3223 'signature'), |
|
3224 (r'(public|protected|private)(\s+)([a-z_][\w.]*)', |
|
3225 bygroups(Keyword, Text, Name.Function)), |
|
3226 |
|
3227 # keywords |
|
3228 (r'(true|false|none|minimal|full|all)\b', Keyword.Constant), |
|
3229 (r'(local|var|variable|data)\b', Keyword.Declaration), |
|
3230 (r'(array|date|decimal|duration|integer|map|pair|string|tag|xml|' |
|
3231 r'null)\b', Keyword.Type), |
|
3232 (r'([a-z_][\w.]*)(\s+)(in)\b', bygroups(Name, Text, Keyword)), |
|
3233 (r'(let|into)(\s+)([a-z_][\w.]*)', bygroups(Keyword, Text, Name)), |
|
3234 (r'require\b', Keyword, 'requiresection'), |
|
3235 (r'(/?)(Namespace_Using)\b', |
|
3236 bygroups(Punctuation, Keyword.Namespace)), |
|
3237 (r'(/?)(Cache|Database_Names|Database_SchemaNames|' |
|
3238 r'Database_TableNames|Define_Tag|Define_Type|Email_Batch|' |
|
3239 r'Encode_Set|HTML_Comment|Handle|Handle_Error|Header|If|Inline|' |
|
3240 r'Iterate|LJAX_Target|Link|Link_CurrentAction|Link_CurrentGroup|' |
|
3241 r'Link_CurrentRecord|Link_Detail|Link_FirstGroup|' |
|
3242 r'Link_FirstRecord|Link_LastGroup|Link_LastRecord|Link_NextGroup|' |
|
3243 r'Link_NextRecord|Link_PrevGroup|Link_PrevRecord|Log|Loop|' |
|
3244 r'NoProcess|Output_None|Portal|Private|Protect|Records|Referer|' |
|
3245 r'Referrer|Repeating|ResultSet|Rows|Search_Args|Search_Arguments|' |
|
3246 r'Select|Sort_Args|Sort_Arguments|Thread_Atomic|Value_List|While|' |
|
3247 r'Abort|Case|Else|If_Empty|If_False|If_Null|If_True|Loop_Abort|' |
|
3248 r'Loop_Continue|Loop_Count|Params|Params_Up|Return|Return_Value|' |
|
3249 r'Run_Children|SOAP_DefineTag|SOAP_LastRequest|SOAP_LastResponse|' |
|
3250 r'Tag_Name|ascending|average|by|define|descending|do|equals|' |
|
3251 r'frozen|group|handle_failure|import|in|into|join|let|match|max|' |
|
3252 r'min|on|order|parent|protected|provide|public|require|skip|' |
|
3253 r'split_thread|sum|take|thread|to|trait|type|where|with|yield)\b', |
|
3254 bygroups(Punctuation, Keyword)), |
|
3255 |
|
3256 # other |
|
3257 (r'(([a-z_][\w.]*=?|[-+*/%<>]|==)(?=\s*\([^)]*\)\s*=>))', |
|
3258 Name.Function, 'signature'), |
|
3259 (r'(and|or|not)\b', Operator.Word), |
|
3260 (r'([a-z_][\w.]*)(\s*)(::\s*)([a-z_][\w.]*)(\s*)(=)', |
|
3261 bygroups(Name, Text, Punctuation, Name.Label, Text, Operator)), |
|
3262 (r'((?<!->)[a-z_][\w.]*)(\s*)(=(?!=))', |
|
3263 bygroups(Name, Text, Operator)), |
|
3264 (r'(/?)([\w.]+)', bygroups(Punctuation, Name.Other)), |
|
3265 (r'(=)(bw|ew|cn|lte?|gte?|n?eq|ft|n?rx)\b', |
|
3266 bygroups(Operator, Operator.Word)), |
|
3267 (r':=|[-+*/%=<>&|!?\\]+', Operator), |
|
3268 (r'[{}():;,@^]', Punctuation), |
|
3269 ], |
|
3270 'singlestring': [ |
|
3271 (r"'", String.Single, '#pop'), |
|
3272 (r"[^'\\]+", String.Single), |
|
3273 include('escape'), |
|
3274 (r"\\+", String.Single), |
|
3275 ], |
|
3276 'doublestring': [ |
|
3277 (r'"', String.Double, '#pop'), |
|
3278 (r'[^"\\]+', String.Double), |
|
3279 include('escape'), |
|
3280 (r'\\+', String.Double), |
|
3281 ], |
|
3282 'escape': [ |
|
3283 (r'\\(U[\da-f]{8}|u[\da-f]{4}|x[\da-f]{1,2}|[0-7]{1,3}|:[^:]+:|' |
|
3284 r'[abefnrtv?\"\'\\]|$)', String.Escape), |
|
3285 ], |
|
3286 'signature': [ |
|
3287 (r'=>', Operator, '#pop'), |
|
3288 (r'\)', Punctuation, '#pop'), |
|
3289 (r'[(,]', Punctuation, 'parameter'), |
|
3290 include('lasso'), |
|
3291 ], |
|
3292 'parameter': [ |
|
3293 (r'\)', Punctuation, '#pop'), |
|
3294 (r'-?[a-z_][\w.]*', Name.Attribute, '#pop'), |
|
3295 (r'\.\.\.', Name.Builtin.Pseudo), |
|
3296 include('lasso'), |
|
3297 ], |
|
3298 'requiresection': [ |
|
3299 (r'(([a-z_][\w.]*=?|[-+*/%<>]|==)(?=\s*\())', Name, 'requiresignature'), |
|
3300 (r'(([a-z_][\w.]*=?|[-+*/%<>]|==)(?=(\s*::\s*[\w.]+)?\s*,))', Name), |
|
3301 (r'[a-z_][\w.]*=?|[-+*/%<>]|==', Name, '#pop'), |
|
3302 (r'(::\s*)([a-z_][\w.]*)', bygroups(Punctuation, Name.Label)), |
|
3303 (r',', Punctuation), |
|
3304 include('whitespacecomments'), |
|
3305 ], |
|
3306 'requiresignature': [ |
|
3307 (r'(\)(?=(\s*::\s*[\w.]+)?\s*,))', Punctuation, '#pop'), |
|
3308 (r'\)', Punctuation, '#pop:2'), |
|
3309 (r'-?[a-z_][\w.]*', Name.Attribute), |
|
3310 (r'(::\s*)([a-z_][\w.]*)', bygroups(Punctuation, Name.Label)), |
|
3311 (r'\.\.\.', Name.Builtin.Pseudo), |
|
3312 (r'[(,]', Punctuation), |
|
3313 include('whitespacecomments'), |
|
3314 ], |
|
3315 } |
|
3316 |
|
3317 def __init__(self, **options): |
|
3318 self.builtinshighlighting = get_bool_opt( |
|
3319 options, 'builtinshighlighting', True) |
|
3320 self.requiredelimiters = get_bool_opt( |
|
3321 options, 'requiredelimiters', False) |
|
3322 |
|
3323 self._builtins = set() |
|
3324 if self.builtinshighlighting: |
|
3325 from pygments.lexers._lassobuiltins import BUILTINS |
|
3326 for key, value in BUILTINS.items(): |
|
3327 self._builtins.update(value) |
|
3328 RegexLexer.__init__(self, **options) |
|
3329 |
|
3330 def get_tokens_unprocessed(self, text): |
|
3331 stack = ['root'] |
|
3332 if self.requiredelimiters: |
|
3333 stack.append('delimiters') |
|
3334 for index, token, value in \ |
|
3335 RegexLexer.get_tokens_unprocessed(self, text, stack): |
|
3336 if token is Name.Other: |
|
3337 if value.lower() in self._builtins: |
|
3338 yield index, Name.Builtin, value |
|
3339 continue |
|
3340 yield index, token, value |
|
3341 |
|
3342 def analyse_text(text): |
|
3343 rv = 0.0 |
|
3344 if 'bin/lasso9' in text: |
|
3345 rv += 0.8 |
|
3346 if re.search(r'<\?(=|lasso)', text, re.I): |
|
3347 rv += 0.4 |
|
3348 if re.search(r'local\(', text, re.I): |
|
3349 rv += 0.4 |
|
3350 if re.search(r'\[\n|\?>', text): |
|
3351 rv += 0.4 |
|
3352 return rv |
|
3353 |
|
3354 |
|
3355 class QmlLexer(RegexLexer): |
|
3356 """ |
|
3357 For QML files. See http://doc.qt.digia.com/4.7/qdeclarativeintroduction.html. |
|
3358 |
|
3359 *New in Pygments 1.6.* |
|
3360 """ |
|
3361 |
|
3362 # QML is based on javascript, so much of this is taken from the |
|
3363 # JavascriptLexer above. |
|
3364 |
|
3365 name = 'QML' |
|
3366 aliases = ['qml', 'Qt Meta Language', 'Qt modeling Language'] |
|
3367 filenames = ['*.qml',] |
|
3368 mimetypes = [ 'application/x-qml',] |
|
3369 |
|
3370 |
|
3371 # pasted from JavascriptLexer, with some additions |
|
3372 flags = re.DOTALL |
|
3373 tokens = { |
|
3374 'commentsandwhitespace': [ |
|
3375 (r'\s+', Text), |
|
3376 (r'<!--', Comment), |
|
3377 (r'//.*?\n', Comment.Single), |
|
3378 (r'/\*.*?\*/', Comment.Multiline) |
|
3379 ], |
|
3380 'slashstartsregex': [ |
|
3381 include('commentsandwhitespace'), |
|
3382 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
3383 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
3384 (r'(?=/)', Text, ('#pop', 'badregex')), |
|
3385 (r'', Text, '#pop') |
|
3386 ], |
|
3387 'badregex': [ |
|
3388 (r'\n', Text, '#pop') |
|
3389 ], |
|
3390 'root' : [ |
|
3391 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
3392 include('commentsandwhitespace'), |
|
3393 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' |
|
3394 r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), |
|
3395 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
3396 (r'[})\].]', Punctuation), |
|
3397 |
|
3398 # QML insertions |
|
3399 (r'\bid\s*:\s*[A-Za-z][_A-Za-z.0-9]*',Keyword.Declaration, |
|
3400 'slashstartsregex'), |
|
3401 (r'\b[A-Za-z][_A-Za-z.0-9]*\s*:',Keyword, 'slashstartsregex'), |
|
3402 |
|
3403 # the rest from JavascriptLexer |
|
3404 (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' |
|
3405 r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' |
|
3406 r'this)\b', Keyword, 'slashstartsregex'), |
|
3407 (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), |
|
3408 (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' |
|
3409 r'extends|final|float|goto|implements|import|int|interface|long|native|' |
|
3410 r'package|private|protected|public|short|static|super|synchronized|throws|' |
|
3411 r'transient|volatile)\b', Keyword.Reserved), |
|
3412 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), |
|
3413 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
3414 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
3415 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
3416 r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' |
|
3417 r'window)\b', Name.Builtin), |
|
3418 (r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other), |
|
3419 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
3420 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
3421 (r'[0-9]+', Number.Integer), |
|
3422 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
3423 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
3424 ] |
|
3425 } |
|