pygmentize 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/lib/pygments.rb +23 -0
- data/pygmentize.gemspec +11 -0
- data/test/pygments.rb +19 -0
- data/vendor/pygmentize.py +7 -0
- data/vendor/pygments/AUTHORS +73 -0
- data/vendor/pygments/LICENSE +25 -0
- data/vendor/pygments/__init__.py +91 -0
- data/vendor/pygments/__init__.pyc +0 -0
- data/vendor/pygments/cmdline.py +430 -0
- data/vendor/pygments/cmdline.pyc +0 -0
- data/vendor/pygments/console.py +74 -0
- data/vendor/pygments/console.pyc +0 -0
- data/vendor/pygments/filter.py +74 -0
- data/vendor/pygments/filter.pyc +0 -0
- data/vendor/pygments/filters/__init__.py +357 -0
- data/vendor/pygments/filters/__init__.pyc +0 -0
- data/vendor/pygments/formatter.py +92 -0
- data/vendor/pygments/formatter.pyc +0 -0
- data/vendor/pygments/formatters/__init__.py +68 -0
- data/vendor/pygments/formatters/__init__.pyc +0 -0
- data/vendor/pygments/formatters/_mapping.py +92 -0
- data/vendor/pygments/formatters/_mapping.pyc +0 -0
- data/vendor/pygments/formatters/bbcode.py +109 -0
- data/vendor/pygments/formatters/bbcode.pyc +0 -0
- data/vendor/pygments/formatters/html.py +723 -0
- data/vendor/pygments/formatters/html.pyc +0 -0
- data/vendor/pygments/formatters/img.py +553 -0
- data/vendor/pygments/formatters/img.pyc +0 -0
- data/vendor/pygments/formatters/latex.py +354 -0
- data/vendor/pygments/formatters/latex.pyc +0 -0
- data/vendor/pygments/formatters/other.py +117 -0
- data/vendor/pygments/formatters/other.pyc +0 -0
- data/vendor/pygments/formatters/rtf.py +136 -0
- data/vendor/pygments/formatters/rtf.pyc +0 -0
- data/vendor/pygments/formatters/svg.py +154 -0
- data/vendor/pygments/formatters/svg.pyc +0 -0
- data/vendor/pygments/formatters/terminal.py +109 -0
- data/vendor/pygments/formatters/terminal.pyc +0 -0
- data/vendor/pygments/formatters/terminal256.py +219 -0
- data/vendor/pygments/formatters/terminal256.pyc +0 -0
- data/vendor/pygments/lexer.py +660 -0
- data/vendor/pygments/lexer.pyc +0 -0
- data/vendor/pygments/lexers/__init__.py +226 -0
- data/vendor/pygments/lexers/__init__.pyc +0 -0
- data/vendor/pygments/lexers/_asybuiltins.py +1645 -0
- data/vendor/pygments/lexers/_clbuiltins.py +232 -0
- data/vendor/pygments/lexers/_luabuiltins.py +256 -0
- data/vendor/pygments/lexers/_mapping.py +234 -0
- data/vendor/pygments/lexers/_mapping.pyc +0 -0
- data/vendor/pygments/lexers/_phpbuiltins.py +3389 -0
- data/vendor/pygments/lexers/_vimbuiltins.py +3 -0
- data/vendor/pygments/lexers/agile.py +1485 -0
- data/vendor/pygments/lexers/agile.pyc +0 -0
- data/vendor/pygments/lexers/asm.py +353 -0
- data/vendor/pygments/lexers/compiled.py +2365 -0
- data/vendor/pygments/lexers/dotnet.py +355 -0
- data/vendor/pygments/lexers/functional.py +756 -0
- data/vendor/pygments/lexers/functional.pyc +0 -0
- data/vendor/pygments/lexers/math.py +461 -0
- data/vendor/pygments/lexers/other.py +2297 -0
- data/vendor/pygments/lexers/parsers.py +695 -0
- data/vendor/pygments/lexers/special.py +100 -0
- data/vendor/pygments/lexers/special.pyc +0 -0
- data/vendor/pygments/lexers/templates.py +1387 -0
- data/vendor/pygments/lexers/text.py +1586 -0
- data/vendor/pygments/lexers/web.py +1619 -0
- data/vendor/pygments/lexers/web.pyc +0 -0
- data/vendor/pygments/plugin.py +74 -0
- data/vendor/pygments/plugin.pyc +0 -0
- data/vendor/pygments/scanner.py +104 -0
- data/vendor/pygments/style.py +117 -0
- data/vendor/pygments/style.pyc +0 -0
- data/vendor/pygments/styles/__init__.py +68 -0
- data/vendor/pygments/styles/__init__.pyc +0 -0
- data/vendor/pygments/styles/autumn.py +65 -0
- data/vendor/pygments/styles/borland.py +51 -0
- data/vendor/pygments/styles/bw.py +49 -0
- data/vendor/pygments/styles/colorful.py +81 -0
- data/vendor/pygments/styles/default.py +73 -0
- data/vendor/pygments/styles/default.pyc +0 -0
- data/vendor/pygments/styles/emacs.py +72 -0
- data/vendor/pygments/styles/friendly.py +72 -0
- data/vendor/pygments/styles/fruity.py +43 -0
- data/vendor/pygments/styles/manni.py +75 -0
- data/vendor/pygments/styles/monokai.py +106 -0
- data/vendor/pygments/styles/murphy.py +80 -0
- data/vendor/pygments/styles/native.py +65 -0
- data/vendor/pygments/styles/pastie.py +75 -0
- data/vendor/pygments/styles/perldoc.py +69 -0
- data/vendor/pygments/styles/tango.py +141 -0
- data/vendor/pygments/styles/trac.py +63 -0
- data/vendor/pygments/styles/vim.py +63 -0
- data/vendor/pygments/styles/vs.py +38 -0
- data/vendor/pygments/token.py +198 -0
- data/vendor/pygments/token.pyc +0 -0
- data/vendor/pygments/unistring.py +130 -0
- data/vendor/pygments/unistring.pyc +0 -0
- data/vendor/pygments/util.py +226 -0
- data/vendor/pygments/util.pyc +0 -0
- metadata +166 -0
@@ -0,0 +1,1619 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
pygments.lexers.web
|
4
|
+
~~~~~~~~~~~~~~~~~~~
|
5
|
+
|
6
|
+
Lexers for web-related languages and markup.
|
7
|
+
|
8
|
+
:copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
|
9
|
+
:license: BSD, see LICENSE for details.
|
10
|
+
"""
|
11
|
+
|
12
|
+
import re
|
13
|
+
|
14
|
+
from pygments.lexer import RegexLexer, ExtendedRegexLexer, bygroups, using, \
|
15
|
+
include, this
|
16
|
+
from pygments.token import \
|
17
|
+
Text, Comment, Operator, Keyword, Name, String, Number, Other, Punctuation
|
18
|
+
from pygments.util import get_bool_opt, get_list_opt, looks_like_xml, \
|
19
|
+
html_doctype_matches
|
20
|
+
from pygments.lexers.agile import RubyLexer
|
21
|
+
|
22
|
+
|
23
|
+
__all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'CssLexer',
|
24
|
+
'PhpLexer', 'ActionScriptLexer', 'XsltLexer', 'ActionScript3Lexer',
|
25
|
+
'MxmlLexer', 'HaxeLexer', 'HamlLexer', 'SassLexer',
|
26
|
+
'ObjectiveJLexer', 'CoffeeScriptLexer']
|
27
|
+
|
28
|
+
|
29
|
+
class JavascriptLexer(RegexLexer):
|
30
|
+
"""
|
31
|
+
For JavaScript source code.
|
32
|
+
"""
|
33
|
+
|
34
|
+
name = 'JavaScript'
|
35
|
+
aliases = ['js', 'javascript']
|
36
|
+
filenames = ['*.js']
|
37
|
+
mimetypes = ['application/x-javascript', 'text/x-javascript', 'text/javascript']
|
38
|
+
|
39
|
+
flags = re.DOTALL
|
40
|
+
tokens = {
|
41
|
+
'commentsandwhitespace': [
|
42
|
+
(r'\s+', Text),
|
43
|
+
(r'<!--', Comment),
|
44
|
+
(r'//.*?\n', Comment.Single),
|
45
|
+
(r'/\*.*?\*/', Comment.Multiline)
|
46
|
+
],
|
47
|
+
'slashstartsregex': [
|
48
|
+
include('commentsandwhitespace'),
|
49
|
+
(r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
|
50
|
+
r'([gim]+\b|\B)', String.Regex, '#pop'),
|
51
|
+
(r'(?=/)', Text, ('#pop', 'badregex')),
|
52
|
+
(r'', Text, '#pop')
|
53
|
+
],
|
54
|
+
'badregex': [
|
55
|
+
('\n', Text, '#pop')
|
56
|
+
],
|
57
|
+
'root': [
|
58
|
+
(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
|
59
|
+
include('commentsandwhitespace'),
|
60
|
+
(r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
|
61
|
+
r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'),
|
62
|
+
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
|
63
|
+
(r'[})\].]', Punctuation),
|
64
|
+
(r'(for|in|while|do|break|return|continue|switch|case|default|if|else|'
|
65
|
+
r'throw|try|catch|finally|new|delete|typeof|instanceof|void|'
|
66
|
+
r'this)\b', Keyword, 'slashstartsregex'),
|
67
|
+
(r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
|
68
|
+
(r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|'
|
69
|
+
r'extends|final|float|goto|implements|import|int|interface|long|native|'
|
70
|
+
r'package|private|protected|public|short|static|super|synchronized|throws|'
|
71
|
+
r'transient|volatile)\b', Keyword.Reserved),
|
72
|
+
(r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
|
73
|
+
(r'(Array|Boolean|Date|Error|Function|Math|netscape|'
|
74
|
+
r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
|
75
|
+
r'decodeURIComponent|encodeURI|encodeURIComponent|'
|
76
|
+
r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
|
77
|
+
r'window)\b', Name.Builtin),
|
78
|
+
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
|
79
|
+
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
|
80
|
+
(r'0x[0-9a-fA-F]+', Number.Hex),
|
81
|
+
(r'[0-9]+', Number.Integer),
|
82
|
+
(r'"(\\\\|\\"|[^"])*"', String.Double),
|
83
|
+
(r"'(\\\\|\\'|[^'])*'", String.Single),
|
84
|
+
]
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
class ActionScriptLexer(RegexLexer):
|
89
|
+
"""
|
90
|
+
For ActionScript source code.
|
91
|
+
|
92
|
+
*New in Pygments 0.9.*
|
93
|
+
"""
|
94
|
+
|
95
|
+
name = 'ActionScript'
|
96
|
+
aliases = ['as', 'actionscript']
|
97
|
+
filenames = ['*.as']
|
98
|
+
mimetypes = ['application/x-actionscript', 'text/x-actionscript',
|
99
|
+
'text/actionscript']
|
100
|
+
|
101
|
+
flags = re.DOTALL
|
102
|
+
tokens = {
|
103
|
+
'root': [
|
104
|
+
(r'\s+', Text),
|
105
|
+
(r'//.*?\n', Comment.Single),
|
106
|
+
(r'/\*.*?\*/', Comment.Multiline),
|
107
|
+
(r'/(\\\\|\\/|[^/\n])*/[gim]*', String.Regex),
|
108
|
+
(r'[~\^\*!%&<>\|+=:;,/?\\-]+', Operator),
|
109
|
+
(r'[{}\[\]();.]+', Punctuation),
|
110
|
+
(r'(case|default|for|each|in|while|do|break|return|continue|if|else|'
|
111
|
+
r'throw|try|catch|var|with|new|typeof|arguments|instanceof|this|'
|
112
|
+
r'switch)\b', Keyword),
|
113
|
+
(r'(class|public|final|internal|native|override|private|protected|'
|
114
|
+
r'static|import|extends|implements|interface|intrinsic|return|super|'
|
115
|
+
r'dynamic|function|const|get|namespace|package|set)\b',
|
116
|
+
Keyword.Declaration),
|
117
|
+
(r'(true|false|null|NaN|Infinity|-Infinity|undefined|Void)\b',
|
118
|
+
Keyword.Constant),
|
119
|
+
(r'(Accessibility|AccessibilityProperties|ActionScriptVersion|'
|
120
|
+
r'ActivityEvent|AntiAliasType|ApplicationDomain|AsBroadcaster|Array|'
|
121
|
+
r'AsyncErrorEvent|AVM1Movie|BevelFilter|Bitmap|BitmapData|'
|
122
|
+
r'BitmapDataChannel|BitmapFilter|BitmapFilterQuality|BitmapFilterType|'
|
123
|
+
r'BlendMode|BlurFilter|Boolean|ByteArray|Camera|Capabilities|CapsStyle|'
|
124
|
+
r'Class|Color|ColorMatrixFilter|ColorTransform|ContextMenu|'
|
125
|
+
r'ContextMenuBuiltInItems|ContextMenuEvent|ContextMenuItem|'
|
126
|
+
r'ConvultionFilter|CSMSettings|DataEvent|Date|DefinitionError|'
|
127
|
+
r'DeleteObjectSample|Dictionary|DisplacmentMapFilter|DisplayObject|'
|
128
|
+
r'DisplacmentMapFilterMode|DisplayObjectContainer|DropShadowFilter|'
|
129
|
+
r'Endian|EOFError|Error|ErrorEvent|EvalError|Event|EventDispatcher|'
|
130
|
+
r'EventPhase|ExternalInterface|FileFilter|FileReference|'
|
131
|
+
r'FileReferenceList|FocusDirection|FocusEvent|Font|FontStyle|FontType|'
|
132
|
+
r'FrameLabel|FullScreenEvent|Function|GlowFilter|GradientBevelFilter|'
|
133
|
+
r'GradientGlowFilter|GradientType|Graphics|GridFitType|HTTPStatusEvent|'
|
134
|
+
r'IBitmapDrawable|ID3Info|IDataInput|IDataOutput|IDynamicPropertyOutput'
|
135
|
+
r'IDynamicPropertyWriter|IEventDispatcher|IExternalizable|'
|
136
|
+
r'IllegalOperationError|IME|IMEConversionMode|IMEEvent|int|'
|
137
|
+
r'InteractiveObject|InterpolationMethod|InvalidSWFError|InvokeEvent|'
|
138
|
+
r'IOError|IOErrorEvent|JointStyle|Key|Keyboard|KeyboardEvent|KeyLocation|'
|
139
|
+
r'LineScaleMode|Loader|LoaderContext|LoaderInfo|LoadVars|LocalConnection|'
|
140
|
+
r'Locale|Math|Matrix|MemoryError|Microphone|MorphShape|Mouse|MouseEvent|'
|
141
|
+
r'MovieClip|MovieClipLoader|Namespace|NetConnection|NetStatusEvent|'
|
142
|
+
r'NetStream|NewObjectSample|Number|Object|ObjectEncoding|PixelSnapping|'
|
143
|
+
r'Point|PrintJob|PrintJobOptions|PrintJobOrientation|ProgressEvent|Proxy|'
|
144
|
+
r'QName|RangeError|Rectangle|ReferenceError|RegExp|Responder|Sample|Scene|'
|
145
|
+
r'ScriptTimeoutError|Security|SecurityDomain|SecurityError|'
|
146
|
+
r'SecurityErrorEvent|SecurityPanel|Selection|Shape|SharedObject|'
|
147
|
+
r'SharedObjectFlushStatus|SimpleButton|Socket|Sound|SoundChannel|'
|
148
|
+
r'SoundLoaderContext|SoundMixer|SoundTransform|SpreadMethod|Sprite|'
|
149
|
+
r'StackFrame|StackOverflowError|Stage|StageAlign|StageDisplayState|'
|
150
|
+
r'StageQuality|StageScaleMode|StaticText|StatusEvent|String|StyleSheet|'
|
151
|
+
r'SWFVersion|SyncEvent|SyntaxError|System|TextColorType|TextField|'
|
152
|
+
r'TextFieldAutoSize|TextFieldType|TextFormat|TextFormatAlign|'
|
153
|
+
r'TextLineMetrics|TextRenderer|TextSnapshot|Timer|TimerEvent|Transform|'
|
154
|
+
r'TypeError|uint|URIError|URLLoader|URLLoaderDataFormat|URLRequest|'
|
155
|
+
r'URLRequestHeader|URLRequestMethod|URLStream|URLVariabeles|VerifyError|'
|
156
|
+
r'Video|XML|XMLDocument|XMLList|XMLNode|XMLNodeType|XMLSocket|XMLUI)\b',
|
157
|
+
Name.Builtin),
|
158
|
+
(r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|'
|
159
|
+
r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|'
|
160
|
+
r'isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|'
|
161
|
+
r'unescape)\b',Name.Function),
|
162
|
+
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
|
163
|
+
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
|
164
|
+
(r'0x[0-9a-f]+', Number.Hex),
|
165
|
+
(r'[0-9]+', Number.Integer),
|
166
|
+
(r'"(\\\\|\\"|[^"])*"', String.Double),
|
167
|
+
(r"'(\\\\|\\'|[^'])*'", String.Single),
|
168
|
+
]
|
169
|
+
}
|
170
|
+
|
171
|
+
def analyse_text(text):
|
172
|
+
return 0.05
|
173
|
+
|
174
|
+
|
175
|
+
class ActionScript3Lexer(RegexLexer):
|
176
|
+
"""
|
177
|
+
For ActionScript 3 source code.
|
178
|
+
|
179
|
+
*New in Pygments 0.11.*
|
180
|
+
"""
|
181
|
+
|
182
|
+
name = 'ActionScript 3'
|
183
|
+
aliases = ['as3', 'actionscript3']
|
184
|
+
filenames = ['*.as']
|
185
|
+
mimetypes = ['application/x-actionscript', 'text/x-actionscript',
|
186
|
+
'text/actionscript']
|
187
|
+
|
188
|
+
identifier = r'[$a-zA-Z_][a-zA-Z0-9_]*'
|
189
|
+
|
190
|
+
flags = re.DOTALL | re.MULTILINE
|
191
|
+
tokens = {
|
192
|
+
'root': [
|
193
|
+
(r'\s+', Text),
|
194
|
+
(r'(function\s+)(' + identifier + r')(\s*)(\()',
|
195
|
+
bygroups(Keyword.Declaration, Name.Function, Text, Operator),
|
196
|
+
'funcparams'),
|
197
|
+
(r'(var|const)(\s+)(' + identifier + r')(\s*)(:)(\s*)(' + identifier + r')',
|
198
|
+
bygroups(Keyword.Declaration, Text, Name, Text, Punctuation, Text,
|
199
|
+
Keyword.Type)),
|
200
|
+
(r'(import|package)(\s+)((?:' + identifier + r'|\.)+)(\s*)',
|
201
|
+
bygroups(Keyword, Text, Name.Namespace, Text)),
|
202
|
+
(r'(new)(\s+)(' + identifier + r')(\s*)(\()',
|
203
|
+
bygroups(Keyword, Text, Keyword.Type, Text, Operator)),
|
204
|
+
(r'//.*?\n', Comment.Single),
|
205
|
+
(r'/\*.*?\*/', Comment.Multiline),
|
206
|
+
(r'/(\\\\|\\/|[^\n])*/[gisx]*', String.Regex),
|
207
|
+
(r'(\.)(' + identifier + r')', bygroups(Operator, Name.Attribute)),
|
208
|
+
(r'(case|default|for|each|in|while|do|break|return|continue|if|else|'
|
209
|
+
r'throw|try|catch|with|new|typeof|arguments|instanceof|this|'
|
210
|
+
r'switch|import|include|as|is)\b',
|
211
|
+
Keyword),
|
212
|
+
(r'(class|public|final|internal|native|override|private|protected|'
|
213
|
+
r'static|import|extends|implements|interface|intrinsic|return|super|'
|
214
|
+
r'dynamic|function|const|get|namespace|package|set)\b',
|
215
|
+
Keyword.Declaration),
|
216
|
+
(r'(true|false|null|NaN|Infinity|-Infinity|undefined|void)\b',
|
217
|
+
Keyword.Constant),
|
218
|
+
(r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|'
|
219
|
+
r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|'
|
220
|
+
r'isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|'
|
221
|
+
r'unescape)\b', Name.Function),
|
222
|
+
(identifier, Name),
|
223
|
+
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
|
224
|
+
(r'0x[0-9a-f]+', Number.Hex),
|
225
|
+
(r'[0-9]+', Number.Integer),
|
226
|
+
(r'"(\\\\|\\"|[^"])*"', String.Double),
|
227
|
+
(r"'(\\\\|\\'|[^'])*'", String.Single),
|
228
|
+
(r'[~\^\*!%&<>\|+=:;,/?\\{}\[\]();.-]+', Operator),
|
229
|
+
],
|
230
|
+
'funcparams': [
|
231
|
+
(r'\s+', Text),
|
232
|
+
(r'(\s*)(\.\.\.)?(' + identifier + r')(\s*)(:)(\s*)(' +
|
233
|
+
identifier + r'|\*)(\s*)',
|
234
|
+
bygroups(Text, Punctuation, Name, Text, Operator, Text,
|
235
|
+
Keyword.Type, Text), 'defval'),
|
236
|
+
(r'\)', Operator, 'type')
|
237
|
+
],
|
238
|
+
'type': [
|
239
|
+
(r'(\s*)(:)(\s*)(' + identifier + r'|\*)',
|
240
|
+
bygroups(Text, Operator, Text, Keyword.Type), '#pop:2'),
|
241
|
+
(r'\s*', Text, '#pop:2')
|
242
|
+
],
|
243
|
+
'defval': [
|
244
|
+
(r'(=)(\s*)([^(),]+)(\s*)(,?)',
|
245
|
+
bygroups(Operator, Text, using(this), Text, Operator), '#pop'),
|
246
|
+
(r',?', Operator, '#pop')
|
247
|
+
]
|
248
|
+
}
|
249
|
+
|
250
|
+
def analyse_text(text):
|
251
|
+
if re.match(r'\w+\s*:\s*\w', text): return 0.3
|
252
|
+
return 0.1
|
253
|
+
|
254
|
+
|
255
|
+
class CssLexer(RegexLexer):
|
256
|
+
"""
|
257
|
+
For CSS (Cascading Style Sheets).
|
258
|
+
"""
|
259
|
+
|
260
|
+
name = 'CSS'
|
261
|
+
aliases = ['css']
|
262
|
+
filenames = ['*.css']
|
263
|
+
mimetypes = ['text/css']
|
264
|
+
|
265
|
+
tokens = {
|
266
|
+
'root': [
|
267
|
+
include('basics'),
|
268
|
+
],
|
269
|
+
'basics': [
|
270
|
+
(r'\s+', Text),
|
271
|
+
(r'/\*(?:.|\n)*?\*/', Comment),
|
272
|
+
(r'{', Punctuation, 'content'),
|
273
|
+
(r'\:[a-zA-Z0-9_-]+', Name.Decorator),
|
274
|
+
(r'\.[a-zA-Z0-9_-]+', Name.Class),
|
275
|
+
(r'\#[a-zA-Z0-9_-]+', Name.Function),
|
276
|
+
(r'@[a-zA-Z0-9_-]+', Keyword, 'atrule'),
|
277
|
+
(r'[a-zA-Z0-9_-]+', Name.Tag),
|
278
|
+
(r'[~\^\*!%&\[\]\(\)<>\|+=@:;,./?-]', Operator),
|
279
|
+
(r'"(\\\\|\\"|[^"])*"', String.Double),
|
280
|
+
(r"'(\\\\|\\'|[^'])*'", String.Single)
|
281
|
+
],
|
282
|
+
'atrule': [
|
283
|
+
(r'{', Punctuation, 'atcontent'),
|
284
|
+
(r';', Punctuation, '#pop'),
|
285
|
+
include('basics'),
|
286
|
+
],
|
287
|
+
'atcontent': [
|
288
|
+
include('basics'),
|
289
|
+
(r'}', Punctuation, '#pop:2'),
|
290
|
+
],
|
291
|
+
'content': [
|
292
|
+
(r'\s+', Text),
|
293
|
+
(r'}', Punctuation, '#pop'),
|
294
|
+
(r'url\(.*?\)', String.Other),
|
295
|
+
(r'^@.*?$', Comment.Preproc),
|
296
|
+
(r'(azimuth|background-attachment|background-color|'
|
297
|
+
r'background-image|background-position|background-repeat|'
|
298
|
+
r'background|border-bottom-color|border-bottom-style|'
|
299
|
+
r'border-bottom-width|border-left-color|border-left-style|'
|
300
|
+
r'border-left-width|border-right|border-right-color|'
|
301
|
+
r'border-right-style|border-right-width|border-top-color|'
|
302
|
+
r'border-top-style|border-top-width|border-bottom|'
|
303
|
+
r'border-collapse|border-left|border-width|border-color|'
|
304
|
+
r'border-spacing|border-style|border-top|border|caption-side|'
|
305
|
+
r'clear|clip|color|content|counter-increment|counter-reset|'
|
306
|
+
r'cue-after|cue-before|cue|cursor|direction|display|'
|
307
|
+
r'elevation|empty-cells|float|font-family|font-size|'
|
308
|
+
r'font-size-adjust|font-stretch|font-style|font-variant|'
|
309
|
+
r'font-weight|font|height|letter-spacing|line-height|'
|
310
|
+
r'list-style-type|list-style-image|list-style-position|'
|
311
|
+
r'list-style|margin-bottom|margin-left|margin-right|'
|
312
|
+
r'margin-top|margin|marker-offset|marks|max-height|max-width|'
|
313
|
+
r'min-height|min-width|opacity|orphans|outline|outline-color|'
|
314
|
+
r'outline-style|outline-width|overflow(?:-x|-y|)|padding-bottom|'
|
315
|
+
r'padding-left|padding-right|padding-top|padding|page|'
|
316
|
+
r'page-break-after|page-break-before|page-break-inside|'
|
317
|
+
r'pause-after|pause-before|pause|pitch|pitch-range|'
|
318
|
+
r'play-during|position|quotes|richness|right|size|'
|
319
|
+
r'speak-header|speak-numeral|speak-punctuation|speak|'
|
320
|
+
r'speech-rate|stress|table-layout|text-align|text-decoration|'
|
321
|
+
r'text-indent|text-shadow|text-transform|top|unicode-bidi|'
|
322
|
+
r'vertical-align|visibility|voice-family|volume|white-space|'
|
323
|
+
r'widows|width|word-spacing|z-index|bottom|left|'
|
324
|
+
r'above|absolute|always|armenian|aural|auto|avoid|baseline|'
|
325
|
+
r'behind|below|bidi-override|blink|block|bold|bolder|both|'
|
326
|
+
r'capitalize|center-left|center-right|center|circle|'
|
327
|
+
r'cjk-ideographic|close-quote|collapse|condensed|continuous|'
|
328
|
+
r'crop|crosshair|cross|cursive|dashed|decimal-leading-zero|'
|
329
|
+
r'decimal|default|digits|disc|dotted|double|e-resize|embed|'
|
330
|
+
r'extra-condensed|extra-expanded|expanded|fantasy|far-left|'
|
331
|
+
r'far-right|faster|fast|fixed|georgian|groove|hebrew|help|'
|
332
|
+
r'hidden|hide|higher|high|hiragana-iroha|hiragana|icon|'
|
333
|
+
r'inherit|inline-table|inline|inset|inside|invert|italic|'
|
334
|
+
r'justify|katakana-iroha|katakana|landscape|larger|large|'
|
335
|
+
r'left-side|leftwards|level|lighter|line-through|list-item|'
|
336
|
+
r'loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|'
|
337
|
+
r'lower|low|medium|message-box|middle|mix|monospace|'
|
338
|
+
r'n-resize|narrower|ne-resize|no-close-quote|no-open-quote|'
|
339
|
+
r'no-repeat|none|normal|nowrap|nw-resize|oblique|once|'
|
340
|
+
r'open-quote|outset|outside|overline|pointer|portrait|px|'
|
341
|
+
r'relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|'
|
342
|
+
r'rightwards|s-resize|sans-serif|scroll|se-resize|'
|
343
|
+
r'semi-condensed|semi-expanded|separate|serif|show|silent|'
|
344
|
+
r'slow|slower|small-caps|small-caption|smaller|soft|solid|'
|
345
|
+
r'spell-out|square|static|status-bar|super|sw-resize|'
|
346
|
+
r'table-caption|table-cell|table-column|table-column-group|'
|
347
|
+
r'table-footer-group|table-header-group|table-row|'
|
348
|
+
r'table-row-group|text|text-bottom|text-top|thick|thin|'
|
349
|
+
r'transparent|ultra-condensed|ultra-expanded|underline|'
|
350
|
+
r'upper-alpha|upper-latin|upper-roman|uppercase|url|'
|
351
|
+
r'visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|'
|
352
|
+
r'x-low|x-small|x-soft|xx-large|xx-small|yes)\b', Keyword),
|
353
|
+
(r'(indigo|gold|firebrick|indianred|yellow|darkolivegreen|'
|
354
|
+
r'darkseagreen|mediumvioletred|mediumorchid|chartreuse|'
|
355
|
+
r'mediumslateblue|black|springgreen|crimson|lightsalmon|brown|'
|
356
|
+
r'turquoise|olivedrab|cyan|silver|skyblue|gray|darkturquoise|'
|
357
|
+
r'goldenrod|darkgreen|darkviolet|darkgray|lightpink|teal|'
|
358
|
+
r'darkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|'
|
359
|
+
r'violet|navy|orchid|blue|ghostwhite|honeydew|cornflowerblue|'
|
360
|
+
r'darkblue|darkkhaki|mediumpurple|cornsilk|red|bisque|slategray|'
|
361
|
+
r'darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|'
|
362
|
+
r'gainsboro|mediumturquoise|floralwhite|coral|purple|lightgrey|'
|
363
|
+
r'lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|'
|
364
|
+
r'greenyellow|royalblue|lightseagreen|mistyrose|sienna|'
|
365
|
+
r'lightcoral|orangered|navajowhite|lime|palegreen|burlywood|'
|
366
|
+
r'seashell|mediumspringgreen|fuchsia|papayawhip|blanchedalmond|'
|
367
|
+
r'peru|aquamarine|white|darkslategray|ivory|dodgerblue|'
|
368
|
+
r'lemonchiffon|chocolate|orange|forestgreen|slateblue|olive|'
|
369
|
+
r'mintcream|antiquewhite|darkorange|cadetblue|moccasin|'
|
370
|
+
r'limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|'
|
371
|
+
r'plum|aqua|darkgoldenrod|maroon|sandybrown|magenta|tan|'
|
372
|
+
r'rosybrown|pink|lightblue|palevioletred|mediumseagreen|'
|
373
|
+
r'dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|'
|
374
|
+
r'paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|'
|
375
|
+
r'lightslategray|lawngreen|lightgreen|tomato|hotpink|'
|
376
|
+
r'lightyellow|lavenderblush|linen|mediumaquamarine|green|'
|
377
|
+
r'blueviolet|peachpuff)\b', Name.Builtin),
|
378
|
+
(r'\!important', Comment.Preproc),
|
379
|
+
(r'/\*(?:.|\n)*?\*/', Comment),
|
380
|
+
(r'\#[a-zA-Z0-9]{1,6}', Number),
|
381
|
+
(r'[\.-]?[0-9]*[\.]?[0-9]+(em|px|\%|pt|pc|in|mm|cm|ex)', Number),
|
382
|
+
(r'-?[0-9]+', Number),
|
383
|
+
(r'[~\^\*!%&<>\|+=@:,./?-]+', Operator),
|
384
|
+
(r'[\[\]();]+', Punctuation),
|
385
|
+
(r'"(\\\\|\\"|[^"])*"', String.Double),
|
386
|
+
(r"'(\\\\|\\'|[^'])*'", String.Single),
|
387
|
+
(r'[a-zA-Z][a-zA-Z0-9]+', Name)
|
388
|
+
]
|
389
|
+
}
|
390
|
+
|
391
|
+
|
392
|
+
class ObjectiveJLexer(RegexLexer):
|
393
|
+
"""
|
394
|
+
For Objective-J source code with preprocessor directives.
|
395
|
+
|
396
|
+
*New in Pygments 1.3.*
|
397
|
+
"""
|
398
|
+
|
399
|
+
name = 'Objective-J'
|
400
|
+
aliases = ['objective-j', 'objectivej', 'obj-j', 'objj']
|
401
|
+
filenames = ['*.j']
|
402
|
+
mimetypes = ['text/x-objective-j']
|
403
|
+
|
404
|
+
#: optional Comment or Whitespace
|
405
|
+
_ws = r'(?:\s|//.*?\n|/[*].*?[*]/)*'
|
406
|
+
|
407
|
+
flags = re.DOTALL | re.MULTILINE
|
408
|
+
|
409
|
+
tokens = {
|
410
|
+
'root': [
|
411
|
+
include('whitespace'),
|
412
|
+
|
413
|
+
# function definition
|
414
|
+
(r'^(' + _ws + r'[\+-]' + _ws + r')([\(a-zA-Z_].*?[^\(])(' + _ws + '{)',
|
415
|
+
bygroups(using(this), using(this, state='function_signature'),
|
416
|
+
using(this))),
|
417
|
+
|
418
|
+
# class definition
|
419
|
+
(r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text),
|
420
|
+
'classname'),
|
421
|
+
(r'(@class|@protocol)(\s*)', bygroups(Keyword, Text),
|
422
|
+
'forward_classname'),
|
423
|
+
(r'(\s*)(@end)(\s*)', bygroups(Text, Keyword, Text)),
|
424
|
+
|
425
|
+
include('statements'),
|
426
|
+
('[{\(\)}]', Punctuation),
|
427
|
+
(';', Punctuation),
|
428
|
+
],
|
429
|
+
'whitespace': [
|
430
|
+
(r'(@import)(\s+)("(\\\\|\\"|[^"])*")',
|
431
|
+
bygroups(Comment.Preproc, Text, String.Double)),
|
432
|
+
(r'(@import)(\s+)(<(\\\\|\\>|[^>])*>)',
|
433
|
+
bygroups(Comment.Preproc, Text, String.Double)),
|
434
|
+
(r'(#(?:include|import))(\s+)("(\\\\|\\"|[^"])*")',
|
435
|
+
bygroups(Comment.Preproc, Text, String.Double)),
|
436
|
+
(r'(#(?:include|import))(\s+)(<(\\\\|\\>|[^>])*>)',
|
437
|
+
bygroups(Comment.Preproc, Text, String.Double)),
|
438
|
+
|
439
|
+
(r'#if\s+0', Comment.Preproc, 'if0'),
|
440
|
+
(r'#', Comment.Preproc, 'macro'),
|
441
|
+
|
442
|
+
(r'\n', Text),
|
443
|
+
(r'\s+', Text),
|
444
|
+
(r'\\\n', Text), # line continuation
|
445
|
+
(r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
|
446
|
+
(r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
|
447
|
+
(r'<!--', Comment),
|
448
|
+
],
|
449
|
+
'slashstartsregex': [
|
450
|
+
include('whitespace'),
|
451
|
+
(r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
|
452
|
+
r'([gim]+\b|\B)', String.Regex, '#pop'),
|
453
|
+
(r'(?=/)', Text, ('#pop', 'badregex')),
|
454
|
+
(r'', Text, '#pop'),
|
455
|
+
],
|
456
|
+
'badregex': [
|
457
|
+
('\n', Text, '#pop'),
|
458
|
+
],
|
459
|
+
'statements': [
|
460
|
+
(r'(L|@)?"', String, 'string'),
|
461
|
+
(r"(L|@)?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
|
462
|
+
String.Char),
|
463
|
+
(r'"(\\\\|\\"|[^"])*"', String.Double),
|
464
|
+
(r"'(\\\\|\\'|[^'])*'", String.Single),
|
465
|
+
(r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
|
466
|
+
(r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
|
467
|
+
(r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
|
468
|
+
(r'0[0-7]+[Ll]?', Number.Oct),
|
469
|
+
(r'\d+[Ll]?', Number.Integer),
|
470
|
+
|
471
|
+
(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
|
472
|
+
|
473
|
+
(r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
|
474
|
+
r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?',
|
475
|
+
Operator, 'slashstartsregex'),
|
476
|
+
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
|
477
|
+
(r'[})\].]', Punctuation),
|
478
|
+
|
479
|
+
(r'(for|in|while|do|break|return|continue|switch|case|default|if|'
|
480
|
+
r'else|throw|try|catch|finally|new|delete|typeof|instanceof|void|'
|
481
|
+
r'prototype|__proto__)\b', Keyword, 'slashstartsregex'),
|
482
|
+
|
483
|
+
(r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
|
484
|
+
|
485
|
+
(r'(@selector|@private|@protected|@public|@encode|'
|
486
|
+
r'@synchronized|@try|@throw|@catch|@finally|@end|@property|'
|
487
|
+
r'@synthesize|@dynamic|@for|@accessors|new)\b', Keyword),
|
488
|
+
|
489
|
+
(r'(int|long|float|short|double|char|unsigned|signed|void|'
|
490
|
+
r'id|BOOL|bool|boolean|IBOutlet|IBAction|SEL|@outlet|@action)\b',
|
491
|
+
Keyword.Type),
|
492
|
+
|
493
|
+
(r'(self|super)\b', Name.Builtin),
|
494
|
+
|
495
|
+
(r'(TRUE|YES|FALSE|NO|Nil|nil|NULL)\b', Keyword.Constant),
|
496
|
+
(r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
|
497
|
+
(r'(ABS|ASIN|ACOS|ATAN|ATAN2|SIN|COS|TAN|EXP|POW|CEIL|FLOOR|ROUND|'
|
498
|
+
r'MIN|MAX|RAND|SQRT|E|LN2|LN10|LOG2E|LOG10E|PI|PI2|PI_2|SQRT1_2|'
|
499
|
+
r'SQRT2)\b', Keyword.Constant),
|
500
|
+
|
501
|
+
(r'(Array|Boolean|Date|Error|Function|Math|netscape|'
|
502
|
+
r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
|
503
|
+
r'decodeURIComponent|encodeURI|encodeURIComponent|'
|
504
|
+
r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
|
505
|
+
r'window)\b', Name.Builtin),
|
506
|
+
|
507
|
+
(r'([$a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r')(?=\()',
|
508
|
+
bygroups(Name.Function, using(this))),
|
509
|
+
|
510
|
+
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name),
|
511
|
+
],
|
512
|
+
'classname' : [
|
513
|
+
# interface definition that inherits
|
514
|
+
(r'([a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r':' + _ws +
|
515
|
+
r')([a-zA-Z_][a-zA-Z0-9_]*)?',
|
516
|
+
bygroups(Name.Class, using(this), Name.Class), '#pop'),
|
517
|
+
# interface definition for a category
|
518
|
+
(r'([a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r'\()([a-zA-Z_][a-zA-Z0-9_]*)(\))',
|
519
|
+
bygroups(Name.Class, using(this), Name.Label, Text), '#pop'),
|
520
|
+
# simple interface / implementation
|
521
|
+
(r'([a-zA-Z_][a-zA-Z0-9_]*)', Name.Class, '#pop'),
|
522
|
+
],
|
523
|
+
'forward_classname' : [
|
524
|
+
(r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*,\s*)',
|
525
|
+
bygroups(Name.Class, Text), '#push'),
|
526
|
+
(r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*;?)',
|
527
|
+
bygroups(Name.Class, Text), '#pop'),
|
528
|
+
],
|
529
|
+
'function_signature': [
|
530
|
+
include('whitespace'),
|
531
|
+
|
532
|
+
# start of a selector w/ parameters
|
533
|
+
(r'(\(' + _ws + r')' # open paren
|
534
|
+
r'([a-zA-Z_][a-zA-Z0-9_]+)' # return type
|
535
|
+
r'(' + _ws + r'\)' + _ws + r')' # close paren
|
536
|
+
r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name
|
537
|
+
bygroups(using(this), Keyword.Type, using(this),
|
538
|
+
Name.Function), 'function_parameters'),
|
539
|
+
|
540
|
+
# no-param function
|
541
|
+
(r'(\(' + _ws + r')' # open paren
|
542
|
+
r'([a-zA-Z_][a-zA-Z0-9_]+)' # return type
|
543
|
+
r'(' + _ws + r'\)' + _ws + r')' # close paren
|
544
|
+
r'([$a-zA-Z_][a-zA-Z0-9_]+)', # function name
|
545
|
+
bygroups(using(this), Keyword.Type, using(this),
|
546
|
+
Name.Function), "#pop"),
|
547
|
+
|
548
|
+
# no return type given, start of a selector w/ parameters
|
549
|
+
(r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name
|
550
|
+
bygroups (Name.Function), 'function_parameters'),
|
551
|
+
|
552
|
+
# no return type given, no-param function
|
553
|
+
(r'([$a-zA-Z_][a-zA-Z0-9_]+)', # function name
|
554
|
+
bygroups(Name.Function), "#pop"),
|
555
|
+
|
556
|
+
('', Text, '#pop'),
|
557
|
+
],
|
558
|
+
'function_parameters': [
|
559
|
+
include('whitespace'),
|
560
|
+
|
561
|
+
# parameters
|
562
|
+
(r'(\(' + _ws + ')' # open paren
|
563
|
+
r'([^\)]+)' # type
|
564
|
+
r'(' + _ws + r'\)' + _ws + r')+' # close paren
|
565
|
+
r'([$a-zA-Z_][a-zA-Z0-9_]+)', # param name
|
566
|
+
bygroups(using(this), Keyword.Type, using(this), Text)),
|
567
|
+
|
568
|
+
# one piece of a selector name
|
569
|
+
(r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name
|
570
|
+
Name.Function),
|
571
|
+
|
572
|
+
# smallest possible selector piece
|
573
|
+
(r'(:)', Name.Function),
|
574
|
+
|
575
|
+
# var args
|
576
|
+
(r'(,' + _ws + r'...)', using(this)),
|
577
|
+
|
578
|
+
# param name
|
579
|
+
(r'([$a-zA-Z_][a-zA-Z0-9_]+)', Text),
|
580
|
+
],
|
581
|
+
'expression' : [
|
582
|
+
(r'([$a-zA-Z_][a-zA-Z0-9_]*)(\()', bygroups(Name.Function,
|
583
|
+
Punctuation)),
|
584
|
+
(r'(\))', Punctuation, "#pop"),
|
585
|
+
],
|
586
|
+
'string': [
|
587
|
+
(r'"', String, '#pop'),
|
588
|
+
(r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
|
589
|
+
(r'[^\\"\n]+', String), # all other characters
|
590
|
+
(r'\\\n', String), # line continuation
|
591
|
+
(r'\\', String), # stray backslash
|
592
|
+
],
|
593
|
+
'macro': [
|
594
|
+
(r'[^/\n]+', Comment.Preproc),
|
595
|
+
(r'/[*](.|\n)*?[*]/', Comment.Multiline),
|
596
|
+
(r'//.*?\n', Comment.Single, '#pop'),
|
597
|
+
(r'/', Comment.Preproc),
|
598
|
+
(r'(?<=\\)\n', Comment.Preproc),
|
599
|
+
(r'\n', Comment.Preproc, '#pop'),
|
600
|
+
],
|
601
|
+
'if0': [
|
602
|
+
(r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
|
603
|
+
(r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
|
604
|
+
(r'.*?\n', Comment),
|
605
|
+
]
|
606
|
+
}
|
607
|
+
|
608
|
+
def analyse_text(text):
|
609
|
+
if re.search('^\s*@import\s+[<"]', text, re.MULTILINE):
|
610
|
+
# special directive found in most Objective-J files
|
611
|
+
return True
|
612
|
+
return False
|
613
|
+
|
614
|
+
|
615
|
+
class HtmlLexer(RegexLexer):
|
616
|
+
"""
|
617
|
+
For HTML 4 and XHTML 1 markup. Nested JavaScript and CSS is highlighted
|
618
|
+
by the appropriate lexer.
|
619
|
+
"""
|
620
|
+
|
621
|
+
name = 'HTML'
|
622
|
+
aliases = ['html']
|
623
|
+
filenames = ['*.html', '*.htm', '*.xhtml', '*.xslt']
|
624
|
+
mimetypes = ['text/html', 'application/xhtml+xml']
|
625
|
+
|
626
|
+
flags = re.IGNORECASE | re.DOTALL
|
627
|
+
tokens = {
|
628
|
+
'root': [
|
629
|
+
('[^<&]+', Text),
|
630
|
+
(r'&\S*?;', Name.Entity),
|
631
|
+
(r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc),
|
632
|
+
('<!--', Comment, 'comment'),
|
633
|
+
(r'<\?.*?\?>', Comment.Preproc),
|
634
|
+
('<![^>]*>', Comment.Preproc),
|
635
|
+
(r'<\s*script\s*', Name.Tag, ('script-content', 'tag')),
|
636
|
+
(r'<\s*style\s*', Name.Tag, ('style-content', 'tag')),
|
637
|
+
(r'<\s*[a-zA-Z0-9:]+', Name.Tag, 'tag'),
|
638
|
+
(r'<\s*/\s*[a-zA-Z0-9:]+\s*>', Name.Tag),
|
639
|
+
],
|
640
|
+
'comment': [
|
641
|
+
('[^-]+', Comment),
|
642
|
+
('-->', Comment, '#pop'),
|
643
|
+
('-', Comment),
|
644
|
+
],
|
645
|
+
'tag': [
|
646
|
+
(r'\s+', Text),
|
647
|
+
(r'[a-zA-Z0-9_:-]+\s*=', Name.Attribute, 'attr'),
|
648
|
+
(r'[a-zA-Z0-9_:-]+', Name.Attribute),
|
649
|
+
(r'/?\s*>', Name.Tag, '#pop'),
|
650
|
+
],
|
651
|
+
'script-content': [
|
652
|
+
(r'<\s*/\s*script\s*>', Name.Tag, '#pop'),
|
653
|
+
(r'.+?(?=<\s*/\s*script\s*>)', using(JavascriptLexer)),
|
654
|
+
],
|
655
|
+
'style-content': [
|
656
|
+
(r'<\s*/\s*style\s*>', Name.Tag, '#pop'),
|
657
|
+
(r'.+?(?=<\s*/\s*style\s*>)', using(CssLexer)),
|
658
|
+
],
|
659
|
+
'attr': [
|
660
|
+
('".*?"', String, '#pop'),
|
661
|
+
("'.*?'", String, '#pop'),
|
662
|
+
(r'[^\s>]+', String, '#pop'),
|
663
|
+
],
|
664
|
+
}
|
665
|
+
|
666
|
+
def analyse_text(text):
|
667
|
+
if html_doctype_matches(text):
|
668
|
+
return 0.5
|
669
|
+
|
670
|
+
|
671
|
+
class PhpLexer(RegexLexer):
|
672
|
+
"""
|
673
|
+
For `PHP <http://www.php.net/>`_ source code.
|
674
|
+
For PHP embedded in HTML, use the `HtmlPhpLexer`.
|
675
|
+
|
676
|
+
Additional options accepted:
|
677
|
+
|
678
|
+
`startinline`
|
679
|
+
If given and ``True`` the lexer starts highlighting with
|
680
|
+
php code (i.e.: no starting ``<?php`` required). The default
|
681
|
+
is ``False``.
|
682
|
+
`funcnamehighlighting`
|
683
|
+
If given and ``True``, highlight builtin function names
|
684
|
+
(default: ``True``).
|
685
|
+
`disabledmodules`
|
686
|
+
If given, must be a list of module names whose function names
|
687
|
+
should not be highlighted. By default all modules are highlighted
|
688
|
+
except the special ``'unknown'`` module that includes functions
|
689
|
+
that are known to php but are undocumented.
|
690
|
+
|
691
|
+
To get a list of allowed modules have a look into the
|
692
|
+
`_phpbuiltins` module:
|
693
|
+
|
694
|
+
.. sourcecode:: pycon
|
695
|
+
|
696
|
+
>>> from pygments.lexers._phpbuiltins import MODULES
|
697
|
+
>>> MODULES.keys()
|
698
|
+
['PHP Options/Info', 'Zip', 'dba', ...]
|
699
|
+
|
700
|
+
In fact the names of those modules match the module names from
|
701
|
+
the php documentation.
|
702
|
+
"""
|
703
|
+
|
704
|
+
name = 'PHP'
|
705
|
+
aliases = ['php', 'php3', 'php4', 'php5']
|
706
|
+
filenames = ['*.php', '*.php[345]']
|
707
|
+
mimetypes = ['text/x-php']
|
708
|
+
|
709
|
+
flags = re.IGNORECASE | re.DOTALL | re.MULTILINE
|
710
|
+
tokens = {
|
711
|
+
'root': [
|
712
|
+
(r'<\?(php)?', Comment.Preproc, 'php'),
|
713
|
+
(r'[^<]+', Other),
|
714
|
+
(r'<', Other)
|
715
|
+
],
|
716
|
+
'php': [
|
717
|
+
(r'\?>', Comment.Preproc, '#pop'),
|
718
|
+
(r'<<<(\'?)([a-zA-Z_][a-zA-Z0-9_]*)\1\n.*?\n\2\;?\n', String),
|
719
|
+
(r'\s+', Text),
|
720
|
+
(r'#.*?\n', Comment.Single),
|
721
|
+
(r'//.*?\n', Comment.Single),
|
722
|
+
# put the empty comment here, it is otherwise seen as
|
723
|
+
# the start of a docstring
|
724
|
+
(r'/\*\*/', Comment.Multiline),
|
725
|
+
(r'/\*\*.*?\*/', String.Doc),
|
726
|
+
(r'/\*.*?\*/', Comment.Multiline),
|
727
|
+
(r'(->|::)(\s*)([a-zA-Z_][a-zA-Z0-9_]*)',
|
728
|
+
bygroups(Operator, Text, Name.Attribute)),
|
729
|
+
(r'[~!%^&*+=|:.<>/?@-]+', Operator),
|
730
|
+
(r'[\[\]{}();,]+', Punctuation),
|
731
|
+
(r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
|
732
|
+
(r'(function)(\s*)(?=\()', bygroups(Keyword, Text)),
|
733
|
+
(r'(function)(\s+)(&?)(\s*)',
|
734
|
+
bygroups(Keyword, Text, Operator, Text), 'functionname'),
|
735
|
+
(r'(const)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)',
|
736
|
+
bygroups(Keyword, Text, Name.Constant)),
|
737
|
+
(r'(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|'
|
738
|
+
r'eval|PHP_OS|break|exit|case|extends|PHP_VERSION|cfunction|'
|
739
|
+
r'FALSE|print|for|require|continue|foreach|require_once|'
|
740
|
+
r'declare|return|default|static|do|switch|die|stdClass|'
|
741
|
+
r'echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|'
|
742
|
+
r'virtual|endfor|include_once|while|endforeach|global|__FILE__|'
|
743
|
+
r'endif|list|__LINE__|endswitch|new|__sleep|endwhile|not|'
|
744
|
+
r'array|__wakeup|E_ALL|NULL|final|php_user_filter|interface|'
|
745
|
+
r'implements|public|private|protected|abstract|clone|try|'
|
746
|
+
r'catch|throw|this|use|namespace)\b', Keyword),
|
747
|
+
('(true|false|null)\b', Keyword.Constant),
|
748
|
+
(r'\$\{\$+[a-zA-Z_][a-zA-Z0-9_]*\}', Name.Variable),
|
749
|
+
(r'\$+[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable),
|
750
|
+
(r'[\\a-zA-Z_][\\a-zA-Z0-9_]*', Name.Other),
|
751
|
+
(r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|"
|
752
|
+
r"0[xX][0-9a-fA-F]+[Ll]?", Number),
|
753
|
+
(r"'([^'\\]*(?:\\.[^'\\]*)*)'", String.Single),
|
754
|
+
(r'`([^`\\]*(?:\\.[^`\\]*)*)`', String.Backtick),
|
755
|
+
(r'"', String.Double, 'string'),
|
756
|
+
],
|
757
|
+
'classname': [
|
758
|
+
(r'[a-zA-Z_][\\a-zA-Z0-9_]*', Name.Class, '#pop')
|
759
|
+
],
|
760
|
+
'functionname': [
|
761
|
+
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop')
|
762
|
+
],
|
763
|
+
'string': [
|
764
|
+
(r'"', String.Double, '#pop'),
|
765
|
+
(r'[^{$"\\]+', String.Double),
|
766
|
+
(r'\\([nrt\"$]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2})', String.Escape),
|
767
|
+
(r'\$[a-zA-Z_][a-zA-Z0-9_]*(\[\S+\]|->[a-zA-Z_][a-zA-Z0-9_]*)?',
|
768
|
+
String.Interpol),
|
769
|
+
(r'(\{\$\{)(.*?)(\}\})',
|
770
|
+
bygroups(String.Interpol, using(this, _startinline=True),
|
771
|
+
String.Interpol)),
|
772
|
+
(r'(\{)(\$.*?)(\})',
|
773
|
+
bygroups(String.Interpol, using(this, _startinline=True),
|
774
|
+
String.Interpol)),
|
775
|
+
(r'(\$\{)(\S+)(\})',
|
776
|
+
bygroups(String.Interpol, Name.Variable, String.Interpol)),
|
777
|
+
(r'[${\\]+', String.Double)
|
778
|
+
],
|
779
|
+
}
|
780
|
+
|
781
|
+
def __init__(self, **options):
|
782
|
+
self.funcnamehighlighting = get_bool_opt(
|
783
|
+
options, 'funcnamehighlighting', True)
|
784
|
+
self.disabledmodules = get_list_opt(
|
785
|
+
options, 'disabledmodules', ['unknown'])
|
786
|
+
self.startinline = get_bool_opt(options, 'startinline', False)
|
787
|
+
|
788
|
+
# private option argument for the lexer itself
|
789
|
+
if '_startinline' in options:
|
790
|
+
self.startinline = options.pop('_startinline')
|
791
|
+
|
792
|
+
# collect activated functions in a set
|
793
|
+
self._functions = set()
|
794
|
+
if self.funcnamehighlighting:
|
795
|
+
from pygments.lexers._phpbuiltins import MODULES
|
796
|
+
for key, value in MODULES.iteritems():
|
797
|
+
if key not in self.disabledmodules:
|
798
|
+
self._functions.update(value)
|
799
|
+
RegexLexer.__init__(self, **options)
|
800
|
+
|
801
|
+
def get_tokens_unprocessed(self, text):
|
802
|
+
stack = ['root']
|
803
|
+
if self.startinline:
|
804
|
+
stack.append('php')
|
805
|
+
for index, token, value in \
|
806
|
+
RegexLexer.get_tokens_unprocessed(self, text, stack):
|
807
|
+
if token is Name.Other:
|
808
|
+
if value in self._functions:
|
809
|
+
yield index, Name.Builtin, value
|
810
|
+
continue
|
811
|
+
yield index, token, value
|
812
|
+
|
813
|
+
def analyse_text(text):
|
814
|
+
rv = 0.0
|
815
|
+
if re.search(r'<\?(?!xml)', text):
|
816
|
+
rv += 0.3
|
817
|
+
if '?>' in text:
|
818
|
+
rv += 0.1
|
819
|
+
return rv
|
820
|
+
|
821
|
+
|
822
|
+
class XmlLexer(RegexLexer):
|
823
|
+
"""
|
824
|
+
Generic lexer for XML (eXtensible Markup Language).
|
825
|
+
"""
|
826
|
+
|
827
|
+
flags = re.MULTILINE | re.DOTALL
|
828
|
+
|
829
|
+
name = 'XML'
|
830
|
+
aliases = ['xml']
|
831
|
+
filenames = ['*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl']
|
832
|
+
mimetypes = ['text/xml', 'application/xml', 'image/svg+xml',
|
833
|
+
'application/rss+xml', 'application/atom+xml',
|
834
|
+
'application/xsl+xml', 'application/xslt+xml']
|
835
|
+
|
836
|
+
tokens = {
|
837
|
+
'root': [
|
838
|
+
('[^<&]+', Text),
|
839
|
+
(r'&\S*?;', Name.Entity),
|
840
|
+
(r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc),
|
841
|
+
('<!--', Comment, 'comment'),
|
842
|
+
(r'<\?.*?\?>', Comment.Preproc),
|
843
|
+
('<![^>]*>', Comment.Preproc),
|
844
|
+
(r'<\s*[a-zA-Z0-9:._-]+', Name.Tag, 'tag'),
|
845
|
+
(r'<\s*/\s*[a-zA-Z0-9:._-]+\s*>', Name.Tag),
|
846
|
+
],
|
847
|
+
'comment': [
|
848
|
+
('[^-]+', Comment),
|
849
|
+
('-->', Comment, '#pop'),
|
850
|
+
('-', Comment),
|
851
|
+
],
|
852
|
+
'tag': [
|
853
|
+
(r'\s+', Text),
|
854
|
+
(r'[a-zA-Z0-9_.:-]+\s*=', Name.Attribute, 'attr'),
|
855
|
+
(r'/?\s*>', Name.Tag, '#pop'),
|
856
|
+
],
|
857
|
+
'attr': [
|
858
|
+
('\s+', Text),
|
859
|
+
('".*?"', String, '#pop'),
|
860
|
+
("'.*?'", String, '#pop'),
|
861
|
+
(r'[^\s>]+', String, '#pop'),
|
862
|
+
],
|
863
|
+
}
|
864
|
+
|
865
|
+
def analyse_text(text):
|
866
|
+
if looks_like_xml(text):
|
867
|
+
return 0.5
|
868
|
+
|
869
|
+
|
870
|
+
class XsltLexer(XmlLexer):
|
871
|
+
'''
|
872
|
+
A lexer for XSLT.
|
873
|
+
|
874
|
+
*New in Pygments 0.10.*
|
875
|
+
'''
|
876
|
+
|
877
|
+
name = 'XSLT'
|
878
|
+
aliases = ['xslt']
|
879
|
+
filenames = ['*.xsl', '*.xslt']
|
880
|
+
|
881
|
+
EXTRA_KEYWORDS = set([
|
882
|
+
'apply-imports', 'apply-templates', 'attribute',
|
883
|
+
'attribute-set', 'call-template', 'choose', 'comment',
|
884
|
+
'copy', 'copy-of', 'decimal-format', 'element', 'fallback',
|
885
|
+
'for-each', 'if', 'import', 'include', 'key', 'message',
|
886
|
+
'namespace-alias', 'number', 'otherwise', 'output', 'param',
|
887
|
+
'preserve-space', 'processing-instruction', 'sort',
|
888
|
+
'strip-space', 'stylesheet', 'template', 'text', 'transform',
|
889
|
+
'value-of', 'variable', 'when', 'with-param'
|
890
|
+
])
|
891
|
+
|
892
|
+
def get_tokens_unprocessed(self, text):
|
893
|
+
for index, token, value in XmlLexer.get_tokens_unprocessed(self, text):
|
894
|
+
m = re.match('</?xsl:([^>]*)/?>?', value)
|
895
|
+
|
896
|
+
if token is Name.Tag and m and m.group(1) in self.EXTRA_KEYWORDS:
|
897
|
+
yield index, Keyword, value
|
898
|
+
else:
|
899
|
+
yield index, token, value
|
900
|
+
|
901
|
+
def analyse_text(text):
|
902
|
+
if looks_like_xml(text) and '<xsl' in text:
|
903
|
+
return 0.8
|
904
|
+
|
905
|
+
|
906
|
+
class MxmlLexer(RegexLexer):
|
907
|
+
"""
|
908
|
+
For MXML markup.
|
909
|
+
Nested AS3 in <script> tags is highlighted by the appropriate lexer.
|
910
|
+
"""
|
911
|
+
flags = re.MULTILINE | re.DOTALL
|
912
|
+
name = 'MXML'
|
913
|
+
aliases = ['mxml']
|
914
|
+
filenames = ['*.mxml']
|
915
|
+
mimetimes = ['text/xml', 'application/xml']
|
916
|
+
|
917
|
+
tokens = {
|
918
|
+
'root': [
|
919
|
+
('[^<&]+', Text),
|
920
|
+
(r'&\S*?;', Name.Entity),
|
921
|
+
(r'(\<\!\[CDATA\[)(.*?)(\]\]\>)',
|
922
|
+
bygroups(String, using(ActionScript3Lexer), String)),
|
923
|
+
('<!--', Comment, 'comment'),
|
924
|
+
(r'<\?.*?\?>', Comment.Preproc),
|
925
|
+
('<![^>]*>', Comment.Preproc),
|
926
|
+
(r'<\s*[a-zA-Z0-9:._-]+', Name.Tag, 'tag'),
|
927
|
+
(r'<\s*/\s*[a-zA-Z0-9:._-]+\s*>', Name.Tag),
|
928
|
+
],
|
929
|
+
'comment': [
|
930
|
+
('[^-]+', Comment),
|
931
|
+
('-->', Comment, '#pop'),
|
932
|
+
('-', Comment),
|
933
|
+
],
|
934
|
+
'tag': [
|
935
|
+
(r'\s+', Text),
|
936
|
+
(r'[a-zA-Z0-9_.:-]+\s*=', Name.Attribute, 'attr'),
|
937
|
+
(r'/?\s*>', Name.Tag, '#pop'),
|
938
|
+
],
|
939
|
+
'attr': [
|
940
|
+
('\s+', Text),
|
941
|
+
('".*?"', String, '#pop'),
|
942
|
+
("'.*?'", String, '#pop'),
|
943
|
+
(r'[^\s>]+', String, '#pop'),
|
944
|
+
],
|
945
|
+
}
|
946
|
+
|
947
|
+
|
948
|
+
class HaxeLexer(RegexLexer):
|
949
|
+
"""
|
950
|
+
For haXe source code (http://haxe.org/).
|
951
|
+
"""
|
952
|
+
|
953
|
+
name = 'haXe'
|
954
|
+
aliases = ['hx', 'haXe']
|
955
|
+
filenames = ['*.hx']
|
956
|
+
mimetypes = ['text/haxe']
|
957
|
+
|
958
|
+
ident = r'(?:[a-zA-Z_][a-zA-Z0-9_]*)'
|
959
|
+
typeid = r'(?:(?:[a-z0-9_\.])*[A-Z_][A-Za-z0-9_]*)'
|
960
|
+
key_prop = r'(?:default|null|never)'
|
961
|
+
key_decl_mod = r'(?:public|private|override|static|inline|extern|dynamic)'
|
962
|
+
|
963
|
+
flags = re.DOTALL | re.MULTILINE
|
964
|
+
|
965
|
+
tokens = {
|
966
|
+
'root': [
|
967
|
+
include('whitespace'),
|
968
|
+
include('comments'),
|
969
|
+
(key_decl_mod, Keyword.Declaration),
|
970
|
+
include('enumdef'),
|
971
|
+
include('typedef'),
|
972
|
+
include('classdef'),
|
973
|
+
include('imports'),
|
974
|
+
],
|
975
|
+
|
976
|
+
# General constructs
|
977
|
+
'comments': [
|
978
|
+
(r'//.*?\n', Comment.Single),
|
979
|
+
(r'/\*.*?\*/', Comment.Multiline),
|
980
|
+
(r'#[^\n]*', Comment.Preproc),
|
981
|
+
],
|
982
|
+
'whitespace': [
|
983
|
+
include('comments'),
|
984
|
+
(r'\s+', Text),
|
985
|
+
],
|
986
|
+
'codekeywords': [
|
987
|
+
(r'\b(if|else|while|do|for|in|break|continue|'
|
988
|
+
r'return|switch|case|try|catch|throw|null|trace|'
|
989
|
+
r'new|this|super|untyped|cast|callback|here)\b',
|
990
|
+
Keyword.Reserved),
|
991
|
+
],
|
992
|
+
'literals': [
|
993
|
+
(r'0[xX][0-9a-fA-F]+', Number.Hex),
|
994
|
+
(r'[0-9]+', Number.Integer),
|
995
|
+
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
|
996
|
+
(r"'(\\\\|\\'|[^'])*'", String.Single),
|
997
|
+
(r'"(\\\\|\\"|[^"])*"', String.Double),
|
998
|
+
(r'~/([^\n])*?/[gisx]*', String.Regex),
|
999
|
+
(r'\b(true|false|null)\b', Keyword.Constant),
|
1000
|
+
],
|
1001
|
+
'codeblock': [
|
1002
|
+
include('whitespace'),
|
1003
|
+
include('new'),
|
1004
|
+
include('case'),
|
1005
|
+
include('anonfundef'),
|
1006
|
+
include('literals'),
|
1007
|
+
include('vardef'),
|
1008
|
+
include('codekeywords'),
|
1009
|
+
(r'[();,\[\]]', Punctuation),
|
1010
|
+
(r'(?:=|\+=|-=|\*=|/=|%=|&=|\|=|\^=|<<=|>>=|>>>=|\|\||&&|'
|
1011
|
+
r'\.\.\.|==|!=|>|<|>=|<=|\||&|\^|<<|>>|>>>|\+|\-|\*|/|%|'
|
1012
|
+
r'!|\+\+|\-\-|~|\.|\?|\:)',
|
1013
|
+
Operator),
|
1014
|
+
(ident, Name),
|
1015
|
+
|
1016
|
+
(r'}', Punctuation,'#pop'),
|
1017
|
+
(r'{', Punctuation,'#push'),
|
1018
|
+
],
|
1019
|
+
|
1020
|
+
# Instance/Block level constructs
|
1021
|
+
'propertydef': [
|
1022
|
+
(r'(\()(' + key_prop + ')(,)(' + key_prop + ')(\))',
|
1023
|
+
bygroups(Punctuation, Keyword.Reserved, Punctuation,
|
1024
|
+
Keyword.Reserved, Punctuation)),
|
1025
|
+
],
|
1026
|
+
'new': [
|
1027
|
+
(r'\bnew\b', Keyword, 'typedecl'),
|
1028
|
+
],
|
1029
|
+
'case': [
|
1030
|
+
(r'\b(case)(\s+)(' + ident + ')(\s*)(\()',
|
1031
|
+
bygroups(Keyword.Reserved, Text, Name, Text, Punctuation),
|
1032
|
+
'funargdecl'),
|
1033
|
+
],
|
1034
|
+
'vardef': [
|
1035
|
+
(r'\b(var)(\s+)(' + ident + ')',
|
1036
|
+
bygroups(Keyword.Declaration, Text, Name.Variable), 'vardecl'),
|
1037
|
+
],
|
1038
|
+
'vardecl': [
|
1039
|
+
include('whitespace'),
|
1040
|
+
include('typelabel'),
|
1041
|
+
(r'=', Operator,'#pop'),
|
1042
|
+
(r';', Punctuation,'#pop'),
|
1043
|
+
],
|
1044
|
+
'instancevardef': [
|
1045
|
+
(key_decl_mod,Keyword.Declaration),
|
1046
|
+
(r'\b(var)(\s+)(' + ident + ')',
|
1047
|
+
bygroups(Keyword.Declaration, Text, Name.Variable.Instance),
|
1048
|
+
'instancevardecl'),
|
1049
|
+
],
|
1050
|
+
'instancevardecl': [
|
1051
|
+
include('vardecl'),
|
1052
|
+
include('propertydef'),
|
1053
|
+
],
|
1054
|
+
|
1055
|
+
'anonfundef': [
|
1056
|
+
(r'\bfunction\b', Keyword.Declaration, 'fundecl'),
|
1057
|
+
],
|
1058
|
+
'instancefundef': [
|
1059
|
+
(key_decl_mod, Keyword.Declaration),
|
1060
|
+
(r'\b(function)(\s+)(' + ident + ')',
|
1061
|
+
bygroups(Keyword.Declaration, Text, Name.Function), 'fundecl'),
|
1062
|
+
],
|
1063
|
+
'fundecl': [
|
1064
|
+
include('whitespace'),
|
1065
|
+
include('typelabel'),
|
1066
|
+
include('generictypedecl'),
|
1067
|
+
(r'\(',Punctuation,'funargdecl'),
|
1068
|
+
(r'(?=[a-zA-Z0-9_])',Text,'#pop'),
|
1069
|
+
(r'{',Punctuation,('#pop','codeblock')),
|
1070
|
+
(r';',Punctuation,'#pop'),
|
1071
|
+
],
|
1072
|
+
'funargdecl': [
|
1073
|
+
include('whitespace'),
|
1074
|
+
(ident, Name.Variable),
|
1075
|
+
include('typelabel'),
|
1076
|
+
include('literals'),
|
1077
|
+
(r'=', Operator),
|
1078
|
+
(r',', Punctuation),
|
1079
|
+
(r'\?', Punctuation),
|
1080
|
+
(r'\)', Punctuation, '#pop'),
|
1081
|
+
],
|
1082
|
+
|
1083
|
+
'typelabel': [
|
1084
|
+
(r':', Punctuation, 'type'),
|
1085
|
+
],
|
1086
|
+
'typedecl': [
|
1087
|
+
include('whitespace'),
|
1088
|
+
(typeid, Name.Class),
|
1089
|
+
(r'<', Punctuation, 'generictypedecl'),
|
1090
|
+
(r'(?=[{}()=,a-z])', Text,'#pop'),
|
1091
|
+
],
|
1092
|
+
'type': [
|
1093
|
+
include('whitespace'),
|
1094
|
+
(typeid, Name.Class),
|
1095
|
+
(r'<', Punctuation, 'generictypedecl'),
|
1096
|
+
(r'->', Keyword.Type),
|
1097
|
+
(r'(?=[{}(),;=])', Text, '#pop'),
|
1098
|
+
],
|
1099
|
+
'generictypedecl': [
|
1100
|
+
include('whitespace'),
|
1101
|
+
(typeid, Name.Class),
|
1102
|
+
(r'<', Punctuation, '#push'),
|
1103
|
+
(r'>', Punctuation, '#pop'),
|
1104
|
+
(r',', Punctuation),
|
1105
|
+
],
|
1106
|
+
|
1107
|
+
# Top level constructs
|
1108
|
+
'imports': [
|
1109
|
+
(r'(package|import|using)(\s+)([^;]+)(;)',
|
1110
|
+
bygroups(Keyword.Namespace, Text, Name.Namespace,Punctuation)),
|
1111
|
+
],
|
1112
|
+
'typedef': [
|
1113
|
+
(r'typedef', Keyword.Declaration, ('typedefprebody', 'typedecl')),
|
1114
|
+
],
|
1115
|
+
'typedefprebody': [
|
1116
|
+
include('whitespace'),
|
1117
|
+
(r'(=)(\s*)({)', bygroups(Punctuation, Text, Punctuation),
|
1118
|
+
('#pop', 'typedefbody')),
|
1119
|
+
],
|
1120
|
+
'enumdef': [
|
1121
|
+
(r'enum', Keyword.Declaration, ('enumdefprebody', 'typedecl')),
|
1122
|
+
],
|
1123
|
+
'enumdefprebody': [
|
1124
|
+
include('whitespace'),
|
1125
|
+
(r'{', Punctuation, ('#pop','enumdefbody')),
|
1126
|
+
],
|
1127
|
+
'classdef': [
|
1128
|
+
(r'class', Keyword.Declaration, ('classdefprebody', 'typedecl')),
|
1129
|
+
],
|
1130
|
+
'classdefprebody': [
|
1131
|
+
include('whitespace'),
|
1132
|
+
(r'(extends|implements)', Keyword.Declaration,'typedecl'),
|
1133
|
+
(r'{', Punctuation, ('#pop', 'classdefbody')),
|
1134
|
+
],
|
1135
|
+
'interfacedef': [
|
1136
|
+
(r'interface', Keyword.Declaration,
|
1137
|
+
('interfacedefprebody', 'typedecl')),
|
1138
|
+
],
|
1139
|
+
'interfacedefprebody': [
|
1140
|
+
include('whitespace'),
|
1141
|
+
(r'(extends)', Keyword.Declaration, 'typedecl'),
|
1142
|
+
(r'{', Punctuation, ('#pop', 'classdefbody')),
|
1143
|
+
],
|
1144
|
+
|
1145
|
+
'typedefbody': [
|
1146
|
+
include('whitespace'),
|
1147
|
+
include('instancevardef'),
|
1148
|
+
include('instancefundef'),
|
1149
|
+
(r'>', Punctuation, 'typedecl'),
|
1150
|
+
(r',', Punctuation),
|
1151
|
+
(r'}', Punctuation, '#pop'),
|
1152
|
+
],
|
1153
|
+
'enumdefbody': [
|
1154
|
+
include('whitespace'),
|
1155
|
+
(ident, Name.Variable.Instance),
|
1156
|
+
(r'\(', Punctuation, 'funargdecl'),
|
1157
|
+
(r';', Punctuation),
|
1158
|
+
(r'}', Punctuation, '#pop'),
|
1159
|
+
],
|
1160
|
+
'classdefbody': [
|
1161
|
+
include('whitespace'),
|
1162
|
+
include('instancevardef'),
|
1163
|
+
include('instancefundef'),
|
1164
|
+
(r'}', Punctuation, '#pop'),
|
1165
|
+
include('codeblock'),
|
1166
|
+
],
|
1167
|
+
}
|
1168
|
+
|
1169
|
+
def analyse_text(text):
|
1170
|
+
if re.match(r'\w+\s*:\s*\w', text): return 0.3
|
1171
|
+
|
1172
|
+
|
1173
|
+
def _indentation(lexer, match, ctx):
|
1174
|
+
indentation = match.group(0)
|
1175
|
+
yield match.start(), Text, indentation
|
1176
|
+
ctx.last_indentation = indentation
|
1177
|
+
ctx.pos = match.end()
|
1178
|
+
|
1179
|
+
if hasattr(ctx, 'block_state') and ctx.block_state and \
|
1180
|
+
indentation.startswith(ctx.block_indentation) and \
|
1181
|
+
indentation != ctx.block_indentation:
|
1182
|
+
ctx.stack.append(ctx.block_state)
|
1183
|
+
else:
|
1184
|
+
ctx.block_state = None
|
1185
|
+
ctx.block_indentation = None
|
1186
|
+
ctx.stack.append('content')
|
1187
|
+
|
1188
|
+
def _starts_block(token, state):
|
1189
|
+
def callback(lexer, match, ctx):
|
1190
|
+
yield match.start(), token, match.group(0)
|
1191
|
+
|
1192
|
+
if hasattr(ctx, 'last_indentation'):
|
1193
|
+
ctx.block_indentation = ctx.last_indentation
|
1194
|
+
else:
|
1195
|
+
ctx.block_indentation = ''
|
1196
|
+
|
1197
|
+
ctx.block_state = state
|
1198
|
+
ctx.pos = match.end()
|
1199
|
+
|
1200
|
+
return callback
|
1201
|
+
|
1202
|
+
|
1203
|
+
class HamlLexer(ExtendedRegexLexer):
|
1204
|
+
"""
|
1205
|
+
For Haml markup.
|
1206
|
+
|
1207
|
+
*New in Pygments 1.3.*
|
1208
|
+
"""
|
1209
|
+
|
1210
|
+
name = 'Haml'
|
1211
|
+
aliases = ['haml', 'HAML']
|
1212
|
+
filenames = ['*.haml']
|
1213
|
+
mimetypes = ['text/x-haml']
|
1214
|
+
|
1215
|
+
flags = re.IGNORECASE
|
1216
|
+
# Haml can include " |\n" anywhere,
|
1217
|
+
# which is ignored and used to wrap long lines.
|
1218
|
+
# To accomodate this, use this custom faux dot instead.
|
1219
|
+
_dot = r'(?: \|\n(?=.* \|)|.)'
|
1220
|
+
tokens = {
|
1221
|
+
'root': [
|
1222
|
+
(r'[ \t]*\n', Text),
|
1223
|
+
(r'[ \t]*', _indentation),
|
1224
|
+
],
|
1225
|
+
|
1226
|
+
'css': [
|
1227
|
+
(r'\.[a-z0-9_:-]+', Name.Class, 'tag'),
|
1228
|
+
(r'\#[a-z0-9_:-]+', Name.Function, 'tag'),
|
1229
|
+
],
|
1230
|
+
|
1231
|
+
'eval-or-plain': [
|
1232
|
+
(r'[&!]?==', Punctuation, 'plain'),
|
1233
|
+
(r'([&!]?[=~])(' + _dot + '*\n)',
|
1234
|
+
bygroups(Punctuation, using(RubyLexer)),
|
1235
|
+
'root'),
|
1236
|
+
(r'', Text, 'plain'),
|
1237
|
+
],
|
1238
|
+
|
1239
|
+
'content': [
|
1240
|
+
include('css'),
|
1241
|
+
(r'%[a-z0-9_:-]+', Name.Tag, 'tag'),
|
1242
|
+
(r'!!!' + _dot + '*\n', Name.Namespace, '#pop'),
|
1243
|
+
(r'(/)(\[' + _dot + '*?\])(' + _dot + '*\n)',
|
1244
|
+
bygroups(Comment, Comment.Special, Comment),
|
1245
|
+
'#pop'),
|
1246
|
+
(r'/' + _dot + '*\n', _starts_block(Comment, 'html-comment-block'),
|
1247
|
+
'#pop'),
|
1248
|
+
(r'-#' + _dot + '*\n', _starts_block(Comment.Preproc,
|
1249
|
+
'haml-comment-block'), '#pop'),
|
1250
|
+
(r'(-)(' + _dot + '*\n)',
|
1251
|
+
bygroups(Punctuation, using(RubyLexer)),
|
1252
|
+
'#pop'),
|
1253
|
+
(r':' + _dot + '*\n', _starts_block(Name.Decorator, 'filter-block'),
|
1254
|
+
'#pop'),
|
1255
|
+
include('eval-or-plain'),
|
1256
|
+
],
|
1257
|
+
|
1258
|
+
'tag': [
|
1259
|
+
include('css'),
|
1260
|
+
(r'\{(,\n|' + _dot + ')*?\}', using(RubyLexer)),
|
1261
|
+
(r'\[' + _dot + '*?\]', using(RubyLexer)),
|
1262
|
+
(r'\(', Text, 'html-attributes'),
|
1263
|
+
(r'/[ \t]*\n', Punctuation, '#pop:2'),
|
1264
|
+
(r'[<>]{1,2}(?=[ \t=])', Punctuation),
|
1265
|
+
include('eval-or-plain'),
|
1266
|
+
],
|
1267
|
+
|
1268
|
+
'plain': [
|
1269
|
+
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text),
|
1270
|
+
(r'(#\{)(' + _dot + '*?)(\})',
|
1271
|
+
bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
|
1272
|
+
(r'\n', Text, 'root'),
|
1273
|
+
],
|
1274
|
+
|
1275
|
+
'html-attributes': [
|
1276
|
+
(r'\s+', Text),
|
1277
|
+
(r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'),
|
1278
|
+
(r'[a-z0-9_:-]+', Name.Attribute),
|
1279
|
+
(r'\)', Text, '#pop'),
|
1280
|
+
],
|
1281
|
+
|
1282
|
+
'html-attribute-value': [
|
1283
|
+
(r'[ \t]+', Text),
|
1284
|
+
(r'[a-z0-9_]+', Name.Variable, '#pop'),
|
1285
|
+
(r'@[a-z0-9_]+', Name.Variable.Instance, '#pop'),
|
1286
|
+
(r'\$[a-z0-9_]+', Name.Variable.Global, '#pop'),
|
1287
|
+
(r"'(\\\\|\\'|[^'\n])*'", String, '#pop'),
|
1288
|
+
(r'"(\\\\|\\"|[^"\n])*"', String, '#pop'),
|
1289
|
+
],
|
1290
|
+
|
1291
|
+
'html-comment-block': [
|
1292
|
+
(_dot + '+', Comment),
|
1293
|
+
(r'\n', Text, 'root'),
|
1294
|
+
],
|
1295
|
+
|
1296
|
+
'haml-comment-block': [
|
1297
|
+
(_dot + '+', Comment.Preproc),
|
1298
|
+
(r'\n', Text, 'root'),
|
1299
|
+
],
|
1300
|
+
|
1301
|
+
'filter-block': [
|
1302
|
+
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator),
|
1303
|
+
(r'(#\{)(' + _dot + '*?)(\})',
|
1304
|
+
bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
|
1305
|
+
(r'\n', Text, 'root'),
|
1306
|
+
],
|
1307
|
+
}
|
1308
|
+
|
1309
|
+
|
1310
|
+
class SassLexer(ExtendedRegexLexer):
|
1311
|
+
"""
|
1312
|
+
For Sass stylesheets.
|
1313
|
+
|
1314
|
+
*New in Pygments 1.3.*
|
1315
|
+
"""
|
1316
|
+
|
1317
|
+
name = 'Sass'
|
1318
|
+
aliases = ['sass', 'SASS']
|
1319
|
+
filenames = ['*.sass']
|
1320
|
+
mimetypes = ['text/x-sass']
|
1321
|
+
|
1322
|
+
flags = re.IGNORECASE
|
1323
|
+
tokens = {
|
1324
|
+
'root': [
|
1325
|
+
(r'[ \t]*\n', Text),
|
1326
|
+
(r'[ \t]*', _indentation),
|
1327
|
+
],
|
1328
|
+
|
1329
|
+
'content': [
|
1330
|
+
(r'//[^\n]*', _starts_block(Comment.Single, 'single-comment'),
|
1331
|
+
'root'),
|
1332
|
+
(r'/\*[^\n]*', _starts_block(Comment.Multiline, 'multi-comment'),
|
1333
|
+
'root'),
|
1334
|
+
(r'@import', Keyword, 'import'),
|
1335
|
+
(r'@for', Keyword, 'for'),
|
1336
|
+
(r'@(debug|if|while)', Keyword, 'script'),
|
1337
|
+
(r'@[a-z0-9_-]+', Keyword, 'selector'),
|
1338
|
+
(r'=[\w-]+', Name.Function, 'script'),
|
1339
|
+
(r'\+[\w-]+', Name.Decorator, 'script'),
|
1340
|
+
(r'(![a-z_]\w*)([ \t]*(?:\|\|)?=)',
|
1341
|
+
bygroups(Name.Variable, Operator), 'script'),
|
1342
|
+
(r':', Name.Attribute, 'old-style-attr'),
|
1343
|
+
(r'(?=[^\s:"\[]+\s*[=:]([ \t]|$))', Name.Attribute, 'new-style-attr'),
|
1344
|
+
(r'', Text, 'selector'),
|
1345
|
+
],
|
1346
|
+
|
1347
|
+
'single-comment': [
|
1348
|
+
(r'.+', Comment.Single),
|
1349
|
+
(r'\n', Text, 'root'),
|
1350
|
+
],
|
1351
|
+
|
1352
|
+
'multi-comment': [
|
1353
|
+
(r'.+', Comment.Multiline),
|
1354
|
+
(r'\n', Text, 'root'),
|
1355
|
+
],
|
1356
|
+
|
1357
|
+
'import': [
|
1358
|
+
(r'[ \t]+', Text),
|
1359
|
+
(r'[^\s]+', String),
|
1360
|
+
(r'\n', Text, 'root'),
|
1361
|
+
],
|
1362
|
+
|
1363
|
+
'for': [
|
1364
|
+
(r'(from|to|through)', Operator.Word),
|
1365
|
+
include('script'),
|
1366
|
+
],
|
1367
|
+
|
1368
|
+
'old-style-attr': [
|
1369
|
+
(r'[^\s:="\[]+', Name.Attribute),
|
1370
|
+
(r'#{', String.Interpol, 'interpolation'),
|
1371
|
+
(r'[ \t]*=', Operator, 'script'),
|
1372
|
+
(r'', Text, 'value'),
|
1373
|
+
],
|
1374
|
+
|
1375
|
+
'new-style-attr': [
|
1376
|
+
(r'[^\s:="\[]+', Name.Attribute),
|
1377
|
+
(r'#{', String.Interpol, 'interpolation'),
|
1378
|
+
(r'[ \t]*=', Operator, 'script'),
|
1379
|
+
(r':', Name.Attribute, 'value'),
|
1380
|
+
],
|
1381
|
+
|
1382
|
+
'value': [
|
1383
|
+
(r'[ \t]+', Text),
|
1384
|
+
(r'url\(', String.Other, 'string-url'),
|
1385
|
+
(r'(azimuth|background-attachment|background-color|'
|
1386
|
+
r'background-image|background-position|background-repeat|'
|
1387
|
+
r'background|border-bottom-color|border-bottom-style|'
|
1388
|
+
r'border-bottom-width|border-left-color|border-left-style|'
|
1389
|
+
r'border-left-width|border-right|border-right-color|'
|
1390
|
+
r'border-right-style|border-right-width|border-top-color|'
|
1391
|
+
r'border-top-style|border-top-width|border-bottom|'
|
1392
|
+
r'border-collapse|border-left|border-width|border-color|'
|
1393
|
+
r'border-spacing|border-style|border-top|border|caption-side|'
|
1394
|
+
r'clear|clip|color|content|counter-increment|counter-reset|'
|
1395
|
+
r'cue-after|cue-before|cue|cursor|direction|display|'
|
1396
|
+
r'elevation|empty-cells|float|font-family|font-size|'
|
1397
|
+
r'font-size-adjust|font-stretch|font-style|font-variant|'
|
1398
|
+
r'font-weight|font|height|letter-spacing|line-height|'
|
1399
|
+
r'list-style-type|list-style-image|list-style-position|'
|
1400
|
+
r'list-style|margin-bottom|margin-left|margin-right|'
|
1401
|
+
r'margin-top|margin|marker-offset|marks|max-height|max-width|'
|
1402
|
+
r'min-height|min-width|opacity|orphans|outline|outline-color|'
|
1403
|
+
r'outline-style|outline-width|overflow|padding-bottom|'
|
1404
|
+
r'padding-left|padding-right|padding-top|padding|page|'
|
1405
|
+
r'page-break-after|page-break-before|page-break-inside|'
|
1406
|
+
r'pause-after|pause-before|pause|pitch|pitch-range|'
|
1407
|
+
r'play-during|position|quotes|richness|right|size|'
|
1408
|
+
r'speak-header|speak-numeral|speak-punctuation|speak|'
|
1409
|
+
r'speech-rate|stress|table-layout|text-align|text-decoration|'
|
1410
|
+
r'text-indent|text-shadow|text-transform|top|unicode-bidi|'
|
1411
|
+
r'vertical-align|visibility|voice-family|volume|white-space|'
|
1412
|
+
r'widows|width|word-spacing|z-index|bottom|left|'
|
1413
|
+
r'above|absolute|always|armenian|aural|auto|avoid|baseline|'
|
1414
|
+
r'behind|below|bidi-override|blink|block|bold|bolder|both|'
|
1415
|
+
r'capitalize|center-left|center-right|center|circle|'
|
1416
|
+
r'cjk-ideographic|close-quote|collapse|condensed|continuous|'
|
1417
|
+
r'crop|crosshair|cross|cursive|dashed|decimal-leading-zero|'
|
1418
|
+
r'decimal|default|digits|disc|dotted|double|e-resize|embed|'
|
1419
|
+
r'extra-condensed|extra-expanded|expanded|fantasy|far-left|'
|
1420
|
+
r'far-right|faster|fast|fixed|georgian|groove|hebrew|help|'
|
1421
|
+
r'hidden|hide|higher|high|hiragana-iroha|hiragana|icon|'
|
1422
|
+
r'inherit|inline-table|inline|inset|inside|invert|italic|'
|
1423
|
+
r'justify|katakana-iroha|katakana|landscape|larger|large|'
|
1424
|
+
r'left-side|leftwards|level|lighter|line-through|list-item|'
|
1425
|
+
r'loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|'
|
1426
|
+
r'lower|low|medium|message-box|middle|mix|monospace|'
|
1427
|
+
r'n-resize|narrower|ne-resize|no-close-quote|no-open-quote|'
|
1428
|
+
r'no-repeat|none|normal|nowrap|nw-resize|oblique|once|'
|
1429
|
+
r'open-quote|outset|outside|overline|pointer|portrait|px|'
|
1430
|
+
r'relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|'
|
1431
|
+
r'rightwards|s-resize|sans-serif|scroll|se-resize|'
|
1432
|
+
r'semi-condensed|semi-expanded|separate|serif|show|silent|'
|
1433
|
+
r'slow|slower|small-caps|small-caption|smaller|soft|solid|'
|
1434
|
+
r'spell-out|square|static|status-bar|super|sw-resize|'
|
1435
|
+
r'table-caption|table-cell|table-column|table-column-group|'
|
1436
|
+
r'table-footer-group|table-header-group|table-row|'
|
1437
|
+
r'table-row-group|text|text-bottom|text-top|thick|thin|'
|
1438
|
+
r'transparent|ultra-condensed|ultra-expanded|underline|'
|
1439
|
+
r'upper-alpha|upper-latin|upper-roman|uppercase|url|'
|
1440
|
+
r'visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|'
|
1441
|
+
r'x-low|x-small|x-soft|xx-large|xx-small|yes)\b', Name.Constant),
|
1442
|
+
(r'(indigo|gold|firebrick|indianred|yellow|darkolivegreen|'
|
1443
|
+
r'darkseagreen|mediumvioletred|mediumorchid|chartreuse|'
|
1444
|
+
r'mediumslateblue|black|springgreen|crimson|lightsalmon|brown|'
|
1445
|
+
r'turquoise|olivedrab|cyan|silver|skyblue|gray|darkturquoise|'
|
1446
|
+
r'goldenrod|darkgreen|darkviolet|darkgray|lightpink|teal|'
|
1447
|
+
r'darkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|'
|
1448
|
+
r'violet|navy|orchid|blue|ghostwhite|honeydew|cornflowerblue|'
|
1449
|
+
r'darkblue|darkkhaki|mediumpurple|cornsilk|red|bisque|slategray|'
|
1450
|
+
r'darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|'
|
1451
|
+
r'gainsboro|mediumturquoise|floralwhite|coral|purple|lightgrey|'
|
1452
|
+
r'lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|'
|
1453
|
+
r'greenyellow|royalblue|lightseagreen|mistyrose|sienna|'
|
1454
|
+
r'lightcoral|orangered|navajowhite|lime|palegreen|burlywood|'
|
1455
|
+
r'seashell|mediumspringgreen|fuchsia|papayawhip|blanchedalmond|'
|
1456
|
+
r'peru|aquamarine|white|darkslategray|ivory|dodgerblue|'
|
1457
|
+
r'lemonchiffon|chocolate|orange|forestgreen|slateblue|olive|'
|
1458
|
+
r'mintcream|antiquewhite|darkorange|cadetblue|moccasin|'
|
1459
|
+
r'limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|'
|
1460
|
+
r'plum|aqua|darkgoldenrod|maroon|sandybrown|magenta|tan|'
|
1461
|
+
r'rosybrown|pink|lightblue|palevioletred|mediumseagreen|'
|
1462
|
+
r'dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|'
|
1463
|
+
r'paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|'
|
1464
|
+
r'lightslategray|lawngreen|lightgreen|tomato|hotpink|'
|
1465
|
+
r'lightyellow|lavenderblush|linen|mediumaquamarine|green|'
|
1466
|
+
r'blueviolet|peachpuff)\b', Name.Entity),
|
1467
|
+
(r'\!important', Name.Exception),
|
1468
|
+
(r'/\*', Comment, 'inline-comment'),
|
1469
|
+
(r'\#[a-z0-9]{1,6}', Number.Hex),
|
1470
|
+
(r'(-?\d+)(\%|[a-z]+)?', bygroups(Number.Integer, Keyword.Type)),
|
1471
|
+
(r'(-?\d*\.\d+)(\%|[a-z]+)?', bygroups(Number.Float, Keyword.Type)),
|
1472
|
+
(r'#{', String.Interpol, 'interpolation'),
|
1473
|
+
(r'[~\^\*!&%<>\|+=@:,./?-]+', Operator),
|
1474
|
+
(r'[\[\]();]+', Punctuation),
|
1475
|
+
(r'"', String.Double, 'string-double'),
|
1476
|
+
(r"'", String.Single, 'string-single'),
|
1477
|
+
(r'[a-z][\w-]*', Name),
|
1478
|
+
(r'\n', Text, 'root'),
|
1479
|
+
],
|
1480
|
+
|
1481
|
+
'script': [
|
1482
|
+
(r'[ \t]+', Text),
|
1483
|
+
(r'![\w_]+', Name.Variable),
|
1484
|
+
(r'[+\-*/%=(),!><]', Operator),
|
1485
|
+
(r'"', String.Double, 'string-double'),
|
1486
|
+
(r"'", String.Single, 'string-single'),
|
1487
|
+
(r'\#[a-z0-9]{1,6}', Number.Hex),
|
1488
|
+
(r'(-?\d+)(\%|[a-z]+)?', bygroups(Number.Integer, Keyword.Type)),
|
1489
|
+
(r'(-?\d*\.\d+)(\%|[a-z]+)?', bygroups(Number.Float, Keyword.Type)),
|
1490
|
+
(r'(black|silver|gray|white|maroon|red|purple|fuchsia|green|'
|
1491
|
+
r'lime|olive|yellow|navy|blue|teal|aqua)\b', Name.Builtin),
|
1492
|
+
(r'(true|false)', Name.Pseudo),
|
1493
|
+
(r'(and|or|not)', Operator.Word),
|
1494
|
+
(r'(\\.|[^\s\\+*\/%(),=!])+(?=[ \t]*\()', Name.Function),
|
1495
|
+
(r'(\\.|[^\s\\+*\/%(),=!])+', Name),
|
1496
|
+
(r'\n', Text, 'root'),
|
1497
|
+
],
|
1498
|
+
|
1499
|
+
'interpolation': [
|
1500
|
+
(r'\}', String.Interpol, '#pop'),
|
1501
|
+
include('script'),
|
1502
|
+
],
|
1503
|
+
|
1504
|
+
'selector': [
|
1505
|
+
(r'[ \t]+', Text),
|
1506
|
+
(r'\:', Name.Decorator, 'pseudo-class'),
|
1507
|
+
(r'\.', Name.Class, 'class'),
|
1508
|
+
(r'\#', Name.Namespace, 'id'),
|
1509
|
+
(r'[a-zA-Z0-9_-]+', Name.Tag),
|
1510
|
+
(r'#\{', String.Interpol, 'interpolation'),
|
1511
|
+
(r'&', Keyword),
|
1512
|
+
(r'[~\^\*!&\[\]\(\)<>\|+=@:;,./?-]', Operator),
|
1513
|
+
(r'"', String.Double, 'string-double'),
|
1514
|
+
(r"'", String.Single, 'string-single'),
|
1515
|
+
(r'\n', Text, 'root'),
|
1516
|
+
],
|
1517
|
+
|
1518
|
+
'string-double': [
|
1519
|
+
(r'(\\.|#(?=[^\n{])|[^\n"#])+', String.Double),
|
1520
|
+
(r'#\{', String.Interpol, 'interpolation'),
|
1521
|
+
(r'"', String.Double, '#pop'),
|
1522
|
+
],
|
1523
|
+
|
1524
|
+
'string-single': [
|
1525
|
+
(r"(\\.|#(?=[^\n{])|[^\n'#])+", String.Double),
|
1526
|
+
(r'#\{', String.Interpol, 'interpolation'),
|
1527
|
+
(r"'", String.Double, '#pop'),
|
1528
|
+
],
|
1529
|
+
|
1530
|
+
'string-url': [
|
1531
|
+
(r'(\\#|#(?=[^\n{])|[^\n#)])+', String.Other),
|
1532
|
+
(r'#\{', String.Interpol, 'interpolation'),
|
1533
|
+
(r'\)', String.Other, '#pop'),
|
1534
|
+
],
|
1535
|
+
|
1536
|
+
'inline-comment': [
|
1537
|
+
(r"(\\#|#(?=[^\n{])|\*(?=[^\n/])|[^\n#*])+", Comment),
|
1538
|
+
(r'#\{', String.Interpol, 'interpolation'),
|
1539
|
+
(r"\*/", Comment, '#pop'),
|
1540
|
+
],
|
1541
|
+
|
1542
|
+
'pseudo-class': [
|
1543
|
+
(r'[\w-]+', Name.Decorator),
|
1544
|
+
(r'#\{', String.Interpol, 'interpolation'),
|
1545
|
+
(r'', Text, '#pop'),
|
1546
|
+
],
|
1547
|
+
|
1548
|
+
'class': [
|
1549
|
+
(r'[\w-]+', Name.Class),
|
1550
|
+
(r'#\{', String.Interpol, 'interpolation'),
|
1551
|
+
(r'', Text, '#pop'),
|
1552
|
+
],
|
1553
|
+
|
1554
|
+
'id': [
|
1555
|
+
(r'[\w-]+', Name.Namespace),
|
1556
|
+
(r'#\{', String.Interpol, 'interpolation'),
|
1557
|
+
(r'', Text, '#pop'),
|
1558
|
+
],
|
1559
|
+
}
|
1560
|
+
|
1561
|
+
|
1562
|
+
class CoffeeScriptLexer(RegexLexer):
|
1563
|
+
"""
|
1564
|
+
For `CoffeeScript`_ source code.
|
1565
|
+
|
1566
|
+
.. _CoffeeScript: http://jashkenas.github.com/coffee-script/
|
1567
|
+
|
1568
|
+
*New in Pygments 1.3.*
|
1569
|
+
"""
|
1570
|
+
|
1571
|
+
name = 'CoffeeScript'
|
1572
|
+
aliases = ['coffee-script', 'coffeescript']
|
1573
|
+
filenames = ['*.coffee']
|
1574
|
+
mimetypes = ['text/coffeescript']
|
1575
|
+
|
1576
|
+
flags = re.DOTALL
|
1577
|
+
tokens = {
|
1578
|
+
'commentsandwhitespace': [
|
1579
|
+
(r'\s+', Text),
|
1580
|
+
(r'#.*?\n', Comment.Single),
|
1581
|
+
],
|
1582
|
+
'slashstartsregex': [
|
1583
|
+
include('commentsandwhitespace'),
|
1584
|
+
(r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
|
1585
|
+
r'([gim]+\b|\B)', String.Regex, '#pop'),
|
1586
|
+
(r'(?=/)', Text, ('#pop', 'badregex')),
|
1587
|
+
(r'', Text, '#pop'),
|
1588
|
+
],
|
1589
|
+
'badregex': [
|
1590
|
+
('\n', Text, '#pop'),
|
1591
|
+
],
|
1592
|
+
'root': [
|
1593
|
+
(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
|
1594
|
+
include('commentsandwhitespace'),
|
1595
|
+
(r'\+\+|--|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|'
|
1596
|
+
r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*`%&\|\^/])=?',
|
1597
|
+
Operator, 'slashstartsregex'),
|
1598
|
+
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
|
1599
|
+
(r'[})\].]', Punctuation),
|
1600
|
+
(r'(for|in|of|while|break|return|continue|switch|when|then|if|else|'
|
1601
|
+
r'throw|try|catch|finally|new|delete|typeof|instanceof|super|'
|
1602
|
+
r'extends|this)\b', Keyword, 'slashstartsregex'),
|
1603
|
+
(r'(true|false|yes|no|on|off|null|NaN|Infinity|undefined)\b',
|
1604
|
+
Keyword.Constant),
|
1605
|
+
(r'(Array|Boolean|Date|Error|Function|Math|netscape|'
|
1606
|
+
r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
|
1607
|
+
r'decodeURIComponent|encodeURI|encodeURIComponent|'
|
1608
|
+
r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
|
1609
|
+
r'window)\b', Name.Builtin),
|
1610
|
+
(r'[$a-zA-Z_][a-zA-Z0-9_\.:]*:\s', Name.Variable,
|
1611
|
+
'slashstartsregex'),
|
1612
|
+
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
|
1613
|
+
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
|
1614
|
+
(r'0x[0-9a-fA-F]+', Number.Hex),
|
1615
|
+
(r'[0-9]+', Number.Integer),
|
1616
|
+
(r'"(\\\\|\\"|[^"])*"', String.Double),
|
1617
|
+
(r"'(\\\\|\\'|[^'])*'", String.Single),
|
1618
|
+
]
|
1619
|
+
}
|