|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.webmisc |
|
4 ~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexers for misc. web stuff. |
|
7 |
|
8 :copyright: Copyright 2006-2014 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, include, bygroups, \ |
|
15 default, using |
|
16 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
|
17 Number, Punctuation, Literal |
|
18 from pygments.util import unirange |
|
19 |
|
20 from pygments.lexers.css import _indentation, _starts_block |
|
21 from pygments.lexers.html import HtmlLexer |
|
22 from pygments.lexers.javascript import JavascriptLexer |
|
23 from pygments.lexers.ruby import RubyLexer |
|
24 |
|
25 __all__ = ['DuelLexer', 'SlimLexer', 'XQueryLexer', 'QmlLexer', 'CirruLexer'] |
|
26 |
|
27 |
|
28 class DuelLexer(RegexLexer): |
|
29 """ |
|
30 Lexer for Duel Views Engine (formerly JBST) markup with JavaScript code blocks. |
|
31 See http://duelengine.org/. |
|
32 See http://jsonml.org/jbst/. |
|
33 |
|
34 .. versionadded:: 1.4 |
|
35 """ |
|
36 |
|
37 name = 'Duel' |
|
38 aliases = ['duel', 'jbst', 'jsonml+bst'] |
|
39 filenames = ['*.duel', '*.jbst'] |
|
40 mimetypes = ['text/x-duel', 'text/x-jbst'] |
|
41 |
|
42 flags = re.DOTALL |
|
43 |
|
44 tokens = { |
|
45 'root': [ |
|
46 (r'(<%[@=#!:]?)(.*?)(%>)', |
|
47 bygroups(Name.Tag, using(JavascriptLexer), Name.Tag)), |
|
48 (r'(<%\$)(.*?)(:)(.*?)(%>)', |
|
49 bygroups(Name.Tag, Name.Function, Punctuation, String, Name.Tag)), |
|
50 (r'(<%--)(.*?)(--%>)', |
|
51 bygroups(Name.Tag, Comment.Multiline, Name.Tag)), |
|
52 (r'(<script.*?>)(.*?)(</script>)', |
|
53 bygroups(using(HtmlLexer), |
|
54 using(JavascriptLexer), using(HtmlLexer))), |
|
55 (r'(.+?)(?=<)', using(HtmlLexer)), |
|
56 (r'.+', using(HtmlLexer)), |
|
57 ], |
|
58 } |
|
59 |
|
60 |
|
61 class XQueryLexer(ExtendedRegexLexer): |
|
62 """ |
|
63 An XQuery lexer, parsing a stream and outputting the tokens needed to |
|
64 highlight xquery code. |
|
65 |
|
66 .. versionadded:: 1.4 |
|
67 """ |
|
68 name = 'XQuery' |
|
69 aliases = ['xquery', 'xqy', 'xq', 'xql', 'xqm'] |
|
70 filenames = ['*.xqy', '*.xquery', '*.xq', '*.xql', '*.xqm'] |
|
71 mimetypes = ['text/xquery', 'application/xquery'] |
|
72 |
|
73 xquery_parse_state = [] |
|
74 |
|
75 # FIX UNICODE LATER |
|
76 # ncnamestartchar = ( |
|
77 # ur"[A-Z]|_|[a-z]|[\u00C0-\u00D6]|[\u00D8-\u00F6]|[\u00F8-\u02FF]|" |
|
78 # ur"[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|" |
|
79 # ur"[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]|" |
|
80 # ur"[\u10000-\uEFFFF]" |
|
81 # ) |
|
82 ncnamestartchar = r"(?:[A-Z]|_|[a-z])" |
|
83 # FIX UNICODE LATER |
|
84 # ncnamechar = ncnamestartchar + (ur"|-|\.|[0-9]|\u00B7|[\u0300-\u036F]|" |
|
85 # ur"[\u203F-\u2040]") |
|
86 ncnamechar = r"(?:" + ncnamestartchar + r"|-|\.|[0-9])" |
|
87 ncname = "(?:%s+%s*)" % (ncnamestartchar, ncnamechar) |
|
88 pitarget_namestartchar = r"(?:[A-KN-WYZ]|_|:|[a-kn-wyz])" |
|
89 pitarget_namechar = r"(?:" + pitarget_namestartchar + r"|-|\.|[0-9])" |
|
90 pitarget = "%s+%s*" % (pitarget_namestartchar, pitarget_namechar) |
|
91 prefixedname = "%s:%s" % (ncname, ncname) |
|
92 unprefixedname = ncname |
|
93 qname = "(?:%s|%s)" % (prefixedname, unprefixedname) |
|
94 |
|
95 entityref = r'(?:&(?:lt|gt|amp|quot|apos|nbsp);)' |
|
96 charref = r'(?:&#[0-9]+;|&#x[0-9a-fA-F]+;)' |
|
97 |
|
98 stringdouble = r'(?:"(?:' + entityref + r'|' + charref + r'|""|[^&"])*")' |
|
99 stringsingle = r"(?:'(?:" + entityref + r"|" + charref + r"|''|[^&'])*')" |
|
100 |
|
101 # FIX UNICODE LATER |
|
102 # elementcontentchar = (ur'\t|\r|\n|[\u0020-\u0025]|[\u0028-\u003b]|' |
|
103 # ur'[\u003d-\u007a]|\u007c|[\u007e-\u007F]') |
|
104 elementcontentchar = r'[A-Za-z]|\s|\d|[!"#$%()*+,\-./:;=?@\[\\\]^_\'`|~]' |
|
105 # quotattrcontentchar = (ur'\t|\r|\n|[\u0020-\u0021]|[\u0023-\u0025]|' |
|
106 # ur'[\u0027-\u003b]|[\u003d-\u007a]|\u007c|[\u007e-\u007F]') |
|
107 quotattrcontentchar = r'[A-Za-z]|\s|\d|[!#$%()*+,\-./:;=?@\[\\\]^_\'`|~]' |
|
108 # aposattrcontentchar = (ur'\t|\r|\n|[\u0020-\u0025]|[\u0028-\u003b]|' |
|
109 # ur'[\u003d-\u007a]|\u007c|[\u007e-\u007F]') |
|
110 aposattrcontentchar = r'[A-Za-z]|\s|\d|[!"#$%()*+,\-./:;=?@\[\\\]^_`|~]' |
|
111 |
|
112 # CHAR elements - fix the above elementcontentchar, quotattrcontentchar, |
|
113 # aposattrcontentchar |
|
114 # x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] |
|
115 |
|
116 flags = re.DOTALL | re.MULTILINE | re.UNICODE |
|
117 |
|
118 def punctuation_root_callback(lexer, match, ctx): |
|
119 yield match.start(), Punctuation, match.group(1) |
|
120 # transition to root always - don't pop off stack |
|
121 ctx.stack = ['root'] |
|
122 ctx.pos = match.end() |
|
123 |
|
124 def operator_root_callback(lexer, match, ctx): |
|
125 yield match.start(), Operator, match.group(1) |
|
126 # transition to root always - don't pop off stack |
|
127 ctx.stack = ['root'] |
|
128 ctx.pos = match.end() |
|
129 |
|
130 def popstate_tag_callback(lexer, match, ctx): |
|
131 yield match.start(), Name.Tag, match.group(1) |
|
132 ctx.stack.append(lexer.xquery_parse_state.pop()) |
|
133 ctx.pos = match.end() |
|
134 |
|
135 def popstate_xmlcomment_callback(lexer, match, ctx): |
|
136 yield match.start(), String.Doc, match.group(1) |
|
137 ctx.stack.append(lexer.xquery_parse_state.pop()) |
|
138 ctx.pos = match.end() |
|
139 |
|
140 def popstate_kindtest_callback(lexer, match, ctx): |
|
141 yield match.start(), Punctuation, match.group(1) |
|
142 next_state = lexer.xquery_parse_state.pop() |
|
143 if next_state == 'occurrenceindicator': |
|
144 if re.match("[?*+]+", match.group(2)): |
|
145 yield match.start(), Punctuation, match.group(2) |
|
146 ctx.stack.append('operator') |
|
147 ctx.pos = match.end() |
|
148 else: |
|
149 ctx.stack.append('operator') |
|
150 ctx.pos = match.end(1) |
|
151 else: |
|
152 ctx.stack.append(next_state) |
|
153 ctx.pos = match.end(1) |
|
154 |
|
155 def popstate_callback(lexer, match, ctx): |
|
156 yield match.start(), Punctuation, match.group(1) |
|
157 # if we have run out of our state stack, pop whatever is on the pygments |
|
158 # state stack |
|
159 if len(lexer.xquery_parse_state) == 0: |
|
160 ctx.stack.pop() |
|
161 elif len(ctx.stack) > 1: |
|
162 ctx.stack.append(lexer.xquery_parse_state.pop()) |
|
163 else: |
|
164 # i don't know if i'll need this, but in case, default back to root |
|
165 ctx.stack = ['root'] |
|
166 ctx.pos = match.end() |
|
167 |
|
168 def pushstate_element_content_starttag_callback(lexer, match, ctx): |
|
169 yield match.start(), Name.Tag, match.group(1) |
|
170 lexer.xquery_parse_state.append('element_content') |
|
171 ctx.stack.append('start_tag') |
|
172 ctx.pos = match.end() |
|
173 |
|
174 def pushstate_cdata_section_callback(lexer, match, ctx): |
|
175 yield match.start(), String.Doc, match.group(1) |
|
176 ctx.stack.append('cdata_section') |
|
177 lexer.xquery_parse_state.append(ctx.state.pop) |
|
178 ctx.pos = match.end() |
|
179 |
|
180 def pushstate_starttag_callback(lexer, match, ctx): |
|
181 yield match.start(), Name.Tag, match.group(1) |
|
182 lexer.xquery_parse_state.append(ctx.state.pop) |
|
183 ctx.stack.append('start_tag') |
|
184 ctx.pos = match.end() |
|
185 |
|
186 def pushstate_operator_order_callback(lexer, match, ctx): |
|
187 yield match.start(), Keyword, match.group(1) |
|
188 yield match.start(), Text, match.group(2) |
|
189 yield match.start(), Punctuation, match.group(3) |
|
190 ctx.stack = ['root'] |
|
191 lexer.xquery_parse_state.append('operator') |
|
192 ctx.pos = match.end() |
|
193 |
|
194 def pushstate_operator_root_validate(lexer, match, ctx): |
|
195 yield match.start(), Keyword, match.group(1) |
|
196 yield match.start(), Text, match.group(2) |
|
197 yield match.start(), Punctuation, match.group(3) |
|
198 ctx.stack = ['root'] |
|
199 lexer.xquery_parse_state.append('operator') |
|
200 ctx.pos = match.end() |
|
201 |
|
202 def pushstate_operator_root_validate_withmode(lexer, match, ctx): |
|
203 yield match.start(), Keyword, match.group(1) |
|
204 yield match.start(), Text, match.group(2) |
|
205 yield match.start(), Keyword, match.group(3) |
|
206 ctx.stack = ['root'] |
|
207 lexer.xquery_parse_state.append('operator') |
|
208 ctx.pos = match.end() |
|
209 |
|
210 def pushstate_operator_processing_instruction_callback(lexer, match, ctx): |
|
211 yield match.start(), String.Doc, match.group(1) |
|
212 ctx.stack.append('processing_instruction') |
|
213 lexer.xquery_parse_state.append('operator') |
|
214 ctx.pos = match.end() |
|
215 |
|
216 def pushstate_element_content_processing_instruction_callback(lexer, match, ctx): |
|
217 yield match.start(), String.Doc, match.group(1) |
|
218 ctx.stack.append('processing_instruction') |
|
219 lexer.xquery_parse_state.append('element_content') |
|
220 ctx.pos = match.end() |
|
221 |
|
222 def pushstate_element_content_cdata_section_callback(lexer, match, ctx): |
|
223 yield match.start(), String.Doc, match.group(1) |
|
224 ctx.stack.append('cdata_section') |
|
225 lexer.xquery_parse_state.append('element_content') |
|
226 ctx.pos = match.end() |
|
227 |
|
228 def pushstate_operator_cdata_section_callback(lexer, match, ctx): |
|
229 yield match.start(), String.Doc, match.group(1) |
|
230 ctx.stack.append('cdata_section') |
|
231 lexer.xquery_parse_state.append('operator') |
|
232 ctx.pos = match.end() |
|
233 |
|
234 def pushstate_element_content_xmlcomment_callback(lexer, match, ctx): |
|
235 yield match.start(), String.Doc, match.group(1) |
|
236 ctx.stack.append('xml_comment') |
|
237 lexer.xquery_parse_state.append('element_content') |
|
238 ctx.pos = match.end() |
|
239 |
|
240 def pushstate_operator_xmlcomment_callback(lexer, match, ctx): |
|
241 yield match.start(), String.Doc, match.group(1) |
|
242 ctx.stack.append('xml_comment') |
|
243 lexer.xquery_parse_state.append('operator') |
|
244 ctx.pos = match.end() |
|
245 |
|
246 def pushstate_kindtest_callback(lexer, match, ctx): |
|
247 yield match.start(), Keyword, match.group(1) |
|
248 yield match.start(), Text, match.group(2) |
|
249 yield match.start(), Punctuation, match.group(3) |
|
250 lexer.xquery_parse_state.append('kindtest') |
|
251 ctx.stack.append('kindtest') |
|
252 ctx.pos = match.end() |
|
253 |
|
254 def pushstate_operator_kindtestforpi_callback(lexer, match, ctx): |
|
255 yield match.start(), Keyword, match.group(1) |
|
256 yield match.start(), Text, match.group(2) |
|
257 yield match.start(), Punctuation, match.group(3) |
|
258 lexer.xquery_parse_state.append('operator') |
|
259 ctx.stack.append('kindtestforpi') |
|
260 ctx.pos = match.end() |
|
261 |
|
262 def pushstate_operator_kindtest_callback(lexer, match, ctx): |
|
263 yield match.start(), Keyword, match.group(1) |
|
264 yield match.start(), Text, match.group(2) |
|
265 yield match.start(), Punctuation, match.group(3) |
|
266 lexer.xquery_parse_state.append('operator') |
|
267 ctx.stack.append('kindtest') |
|
268 ctx.pos = match.end() |
|
269 |
|
270 def pushstate_occurrenceindicator_kindtest_callback(lexer, match, ctx): |
|
271 yield match.start(), Name.Tag, match.group(1) |
|
272 yield match.start(), Text, match.group(2) |
|
273 yield match.start(), Punctuation, match.group(3) |
|
274 lexer.xquery_parse_state.append('occurrenceindicator') |
|
275 ctx.stack.append('kindtest') |
|
276 ctx.pos = match.end() |
|
277 |
|
278 def pushstate_operator_starttag_callback(lexer, match, ctx): |
|
279 yield match.start(), Name.Tag, match.group(1) |
|
280 lexer.xquery_parse_state.append('operator') |
|
281 ctx.stack.append('start_tag') |
|
282 ctx.pos = match.end() |
|
283 |
|
284 def pushstate_operator_root_callback(lexer, match, ctx): |
|
285 yield match.start(), Punctuation, match.group(1) |
|
286 lexer.xquery_parse_state.append('operator') |
|
287 ctx.stack = ['root'] |
|
288 ctx.pos = match.end() |
|
289 |
|
290 def pushstate_operator_root_construct_callback(lexer, match, ctx): |
|
291 yield match.start(), Keyword, match.group(1) |
|
292 yield match.start(), Text, match.group(2) |
|
293 yield match.start(), Punctuation, match.group(3) |
|
294 lexer.xquery_parse_state.append('operator') |
|
295 ctx.stack = ['root'] |
|
296 ctx.pos = match.end() |
|
297 |
|
298 def pushstate_root_callback(lexer, match, ctx): |
|
299 yield match.start(), Punctuation, match.group(1) |
|
300 cur_state = ctx.stack.pop() |
|
301 lexer.xquery_parse_state.append(cur_state) |
|
302 ctx.stack = ['root'] |
|
303 ctx.pos = match.end() |
|
304 |
|
305 def pushstate_operator_attribute_callback(lexer, match, ctx): |
|
306 yield match.start(), Name.Attribute, match.group(1) |
|
307 ctx.stack.append('operator') |
|
308 ctx.pos = match.end() |
|
309 |
|
310 def pushstate_operator_callback(lexer, match, ctx): |
|
311 yield match.start(), Keyword, match.group(1) |
|
312 yield match.start(), Text, match.group(2) |
|
313 yield match.start(), Punctuation, match.group(3) |
|
314 lexer.xquery_parse_state.append('operator') |
|
315 ctx.pos = match.end() |
|
316 |
|
317 tokens = { |
|
318 'comment': [ |
|
319 # xquery comments |
|
320 (r'(:\))', Comment, '#pop'), |
|
321 (r'(\(:)', Comment, '#push'), |
|
322 (r'[^:)]', Comment), |
|
323 (r'([^:)]|:|\))', Comment), |
|
324 ], |
|
325 'whitespace': [ |
|
326 (r'\s+', Text), |
|
327 ], |
|
328 'operator': [ |
|
329 include('whitespace'), |
|
330 (r'(\})', popstate_callback), |
|
331 (r'\(:', Comment, 'comment'), |
|
332 |
|
333 (r'(\{)', pushstate_root_callback), |
|
334 (r'then|else|external|at|div|except', Keyword, 'root'), |
|
335 (r'order by', Keyword, 'root'), |
|
336 (r'is|mod|order\s+by|stable\s+order\s+by', Keyword, 'root'), |
|
337 (r'and|or', Operator.Word, 'root'), |
|
338 (r'(eq|ge|gt|le|lt|ne|idiv|intersect|in)(?=\b)', |
|
339 Operator.Word, 'root'), |
|
340 (r'return|satisfies|to|union|where|preserve\s+strip', |
|
341 Keyword, 'root'), |
|
342 (r'(>=|>>|>|<=|<<|<|-|\*|!=|\+|\|\||\||:=|=)', |
|
343 operator_root_callback), |
|
344 (r'(::|;|\[|//|/|,)', |
|
345 punctuation_root_callback), |
|
346 (r'(castable|cast)(\s+)(as)\b', |
|
347 bygroups(Keyword, Text, Keyword), 'singletype'), |
|
348 (r'(instance)(\s+)(of)\b', |
|
349 bygroups(Keyword, Text, Keyword), 'itemtype'), |
|
350 (r'(treat)(\s+)(as)\b', |
|
351 bygroups(Keyword, Text, Keyword), 'itemtype'), |
|
352 (r'(case|as)\b', Keyword, 'itemtype'), |
|
353 (r'(\))(\s*)(as)', |
|
354 bygroups(Punctuation, Text, Keyword), 'itemtype'), |
|
355 (r'\$', Name.Variable, 'varname'), |
|
356 (r'(for|let)(\s+)(\$)', |
|
357 bygroups(Keyword, Text, Name.Variable), 'varname'), |
|
358 # (r'\)|\?|\]', Punctuation, '#push'), |
|
359 (r'\)|\?|\]', Punctuation), |
|
360 (r'(empty)(\s+)(greatest|least)', bygroups(Keyword, Text, Keyword)), |
|
361 (r'ascending|descending|default', Keyword, '#push'), |
|
362 (r'external', Keyword), |
|
363 (r'collation', Keyword, 'uritooperator'), |
|
364 # finally catch all string literals and stay in operator state |
|
365 (stringdouble, String.Double), |
|
366 (stringsingle, String.Single), |
|
367 |
|
368 (r'(catch)(\s*)', bygroups(Keyword, Text), 'root'), |
|
369 ], |
|
370 'uritooperator': [ |
|
371 (stringdouble, String.Double, '#pop'), |
|
372 (stringsingle, String.Single, '#pop'), |
|
373 ], |
|
374 'namespacedecl': [ |
|
375 include('whitespace'), |
|
376 (r'\(:', Comment, 'comment'), |
|
377 (r'(at)(\s+)('+stringdouble+')', bygroups(Keyword, Text, String.Double)), |
|
378 (r"(at)(\s+)("+stringsingle+')', bygroups(Keyword, Text, String.Single)), |
|
379 (stringdouble, String.Double), |
|
380 (stringsingle, String.Single), |
|
381 (r',', Punctuation), |
|
382 (r'=', Operator), |
|
383 (r';', Punctuation, 'root'), |
|
384 (ncname, Name.Namespace), |
|
385 ], |
|
386 'namespacekeyword': [ |
|
387 include('whitespace'), |
|
388 (r'\(:', Comment, 'comment'), |
|
389 (stringdouble, String.Double, 'namespacedecl'), |
|
390 (stringsingle, String.Single, 'namespacedecl'), |
|
391 (r'inherit|no-inherit', Keyword, 'root'), |
|
392 (r'namespace', Keyword, 'namespacedecl'), |
|
393 (r'(default)(\s+)(element)', bygroups(Keyword, Text, Keyword)), |
|
394 (r'preserve|no-preserve', Keyword), |
|
395 (r',', Punctuation), |
|
396 ], |
|
397 'varname': [ |
|
398 (r'\(:', Comment, 'comment'), |
|
399 (qname, Name.Variable, 'operator'), |
|
400 ], |
|
401 'singletype': [ |
|
402 (r'\(:', Comment, 'comment'), |
|
403 (ncname + r'(:\*)', Name.Variable, 'operator'), |
|
404 (qname, Name.Variable, 'operator'), |
|
405 ], |
|
406 'itemtype': [ |
|
407 include('whitespace'), |
|
408 (r'\(:', Comment, 'comment'), |
|
409 (r'\$', Punctuation, 'varname'), |
|
410 (r'(void)(\s*)(\()(\s*)(\))', |
|
411 bygroups(Keyword, Text, Punctuation, Text, Punctuation), 'operator'), |
|
412 (r'(element|attribute|schema-element|schema-attribute|comment|text|' |
|
413 r'node|binary|document-node|empty-sequence)(\s*)(\()', |
|
414 pushstate_occurrenceindicator_kindtest_callback), |
|
415 # Marklogic specific type? |
|
416 (r'(processing-instruction)(\s*)(\()', |
|
417 bygroups(Keyword, Text, Punctuation), |
|
418 ('occurrenceindicator', 'kindtestforpi')), |
|
419 (r'(item)(\s*)(\()(\s*)(\))(?=[*+?])', |
|
420 bygroups(Keyword, Text, Punctuation, Text, Punctuation), |
|
421 'occurrenceindicator'), |
|
422 (r'\(\#', Punctuation, 'pragma'), |
|
423 (r';', Punctuation, '#pop'), |
|
424 (r'then|else', Keyword, '#pop'), |
|
425 (r'(at)(\s+)(' + stringdouble + ')', |
|
426 bygroups(Keyword, Text, String.Double), 'namespacedecl'), |
|
427 (r'(at)(\s+)(' + stringsingle + ')', |
|
428 bygroups(Keyword, Text, String.Single), 'namespacedecl'), |
|
429 (r'except|intersect|in|is|return|satisfies|to|union|where', |
|
430 Keyword, 'root'), |
|
431 (r'and|div|eq|ge|gt|le|lt|ne|idiv|mod|or', Operator.Word, 'root'), |
|
432 (r':=|=|,|>=|>>|>|\[|\(|<=|<<|<|-|!=|\|\||\|', Operator, 'root'), |
|
433 (r'external|at', Keyword, 'root'), |
|
434 (r'(stable)(\s+)(order)(\s+)(by)', |
|
435 bygroups(Keyword, Text, Keyword, Text, Keyword), 'root'), |
|
436 (r'(castable|cast)(\s+)(as)', |
|
437 bygroups(Keyword, Text, Keyword), 'singletype'), |
|
438 (r'(treat)(\s+)(as)', bygroups(Keyword, Text, Keyword)), |
|
439 (r'(instance)(\s+)(of)', bygroups(Keyword, Text, Keyword)), |
|
440 (r'case|as', Keyword, 'itemtype'), |
|
441 (r'(\))(\s*)(as)', bygroups(Operator, Text, Keyword), 'itemtype'), |
|
442 (ncname + r':\*', Keyword.Type, 'operator'), |
|
443 (qname, Keyword.Type, 'occurrenceindicator'), |
|
444 ], |
|
445 'kindtest': [ |
|
446 (r'\(:', Comment, 'comment'), |
|
447 (r'\{', Punctuation, 'root'), |
|
448 (r'(\))([*+?]?)', popstate_kindtest_callback), |
|
449 (r'\*', Name, 'closekindtest'), |
|
450 (qname, Name, 'closekindtest'), |
|
451 (r'(element|schema-element)(\s*)(\()', pushstate_kindtest_callback), |
|
452 ], |
|
453 'kindtestforpi': [ |
|
454 (r'\(:', Comment, 'comment'), |
|
455 (r'\)', Punctuation, '#pop'), |
|
456 (ncname, Name.Variable), |
|
457 (stringdouble, String.Double), |
|
458 (stringsingle, String.Single), |
|
459 ], |
|
460 'closekindtest': [ |
|
461 (r'\(:', Comment, 'comment'), |
|
462 (r'(\))', popstate_callback), |
|
463 (r',', Punctuation), |
|
464 (r'(\{)', pushstate_operator_root_callback), |
|
465 (r'\?', Punctuation), |
|
466 ], |
|
467 'xml_comment': [ |
|
468 (r'(-->)', popstate_xmlcomment_callback), |
|
469 (r'[^-]{1,2}', Literal), |
|
470 (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + |
|
471 unirange(0x10000, 0x10ffff), Literal), |
|
472 ], |
|
473 'processing_instruction': [ |
|
474 (r'\s+', Text, 'processing_instruction_content'), |
|
475 (r'\?>', String.Doc, '#pop'), |
|
476 (pitarget, Name), |
|
477 ], |
|
478 'processing_instruction_content': [ |
|
479 (r'\?>', String.Doc, '#pop'), |
|
480 (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + |
|
481 unirange(0x10000, 0x10ffff), Literal), |
|
482 ], |
|
483 'cdata_section': [ |
|
484 (r']]>', String.Doc, '#pop'), |
|
485 (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + |
|
486 unirange(0x10000, 0x10ffff), Literal), |
|
487 ], |
|
488 'start_tag': [ |
|
489 include('whitespace'), |
|
490 (r'(/>)', popstate_tag_callback), |
|
491 (r'>', Name.Tag, 'element_content'), |
|
492 (r'"', Punctuation, 'quot_attribute_content'), |
|
493 (r"'", Punctuation, 'apos_attribute_content'), |
|
494 (r'=', Operator), |
|
495 (qname, Name.Tag), |
|
496 ], |
|
497 'quot_attribute_content': [ |
|
498 (r'"', Punctuation, 'start_tag'), |
|
499 (r'(\{)', pushstate_root_callback), |
|
500 (r'""', Name.Attribute), |
|
501 (quotattrcontentchar, Name.Attribute), |
|
502 (entityref, Name.Attribute), |
|
503 (charref, Name.Attribute), |
|
504 (r'\{\{|\}\}', Name.Attribute), |
|
505 ], |
|
506 'apos_attribute_content': [ |
|
507 (r"'", Punctuation, 'start_tag'), |
|
508 (r'\{', Punctuation, 'root'), |
|
509 (r"''", Name.Attribute), |
|
510 (aposattrcontentchar, Name.Attribute), |
|
511 (entityref, Name.Attribute), |
|
512 (charref, Name.Attribute), |
|
513 (r'\{\{|\}\}', Name.Attribute), |
|
514 ], |
|
515 'element_content': [ |
|
516 (r'</', Name.Tag, 'end_tag'), |
|
517 (r'(\{)', pushstate_root_callback), |
|
518 (r'(<!--)', pushstate_element_content_xmlcomment_callback), |
|
519 (r'(<\?)', pushstate_element_content_processing_instruction_callback), |
|
520 (r'(<!\[CDATA\[)', pushstate_element_content_cdata_section_callback), |
|
521 (r'(<)', pushstate_element_content_starttag_callback), |
|
522 (elementcontentchar, Literal), |
|
523 (entityref, Literal), |
|
524 (charref, Literal), |
|
525 (r'\{\{|\}\}', Literal), |
|
526 ], |
|
527 'end_tag': [ |
|
528 include('whitespace'), |
|
529 (r'(>)', popstate_tag_callback), |
|
530 (qname, Name.Tag), |
|
531 ], |
|
532 'xmlspace_decl': [ |
|
533 (r'\(:', Comment, 'comment'), |
|
534 (r'preserve|strip', Keyword, '#pop'), |
|
535 ], |
|
536 'declareordering': [ |
|
537 (r'\(:', Comment, 'comment'), |
|
538 include('whitespace'), |
|
539 (r'ordered|unordered', Keyword, '#pop'), |
|
540 ], |
|
541 'xqueryversion': [ |
|
542 include('whitespace'), |
|
543 (r'\(:', Comment, 'comment'), |
|
544 (stringdouble, String.Double), |
|
545 (stringsingle, String.Single), |
|
546 (r'encoding', Keyword), |
|
547 (r';', Punctuation, '#pop'), |
|
548 ], |
|
549 'pragma': [ |
|
550 (qname, Name.Variable, 'pragmacontents'), |
|
551 ], |
|
552 'pragmacontents': [ |
|
553 (r'#\)', Punctuation, 'operator'), |
|
554 (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + |
|
555 unirange(0x10000, 0x10ffff), Literal), |
|
556 (r'(\s+)', Text), |
|
557 ], |
|
558 'occurrenceindicator': [ |
|
559 include('whitespace'), |
|
560 (r'\(:', Comment, 'comment'), |
|
561 (r'\*|\?|\+', Operator, 'operator'), |
|
562 (r':=', Operator, 'root'), |
|
563 default('operator'), |
|
564 ], |
|
565 'option': [ |
|
566 include('whitespace'), |
|
567 (qname, Name.Variable, '#pop'), |
|
568 ], |
|
569 'qname_braren': [ |
|
570 include('whitespace'), |
|
571 (r'(\{)', pushstate_operator_root_callback), |
|
572 (r'(\()', Punctuation, 'root'), |
|
573 ], |
|
574 'element_qname': [ |
|
575 (qname, Name.Variable, 'root'), |
|
576 ], |
|
577 'attribute_qname': [ |
|
578 (qname, Name.Variable, 'root'), |
|
579 ], |
|
580 'root': [ |
|
581 include('whitespace'), |
|
582 (r'\(:', Comment, 'comment'), |
|
583 |
|
584 # handle operator state |
|
585 # order on numbers matters - handle most complex first |
|
586 (r'\d+(\.\d*)?[eE][+-]?\d+', Number.Float, 'operator'), |
|
587 (r'(\.\d+)[eE][+-]?\d+', Number.Float, 'operator'), |
|
588 (r'(\.\d+|\d+\.\d*)', Number.Float, 'operator'), |
|
589 (r'(\d+)', Number.Integer, 'operator'), |
|
590 (r'(\.\.|\.|\))', Punctuation, 'operator'), |
|
591 (r'(declare)(\s+)(construction)', |
|
592 bygroups(Keyword, Text, Keyword), 'operator'), |
|
593 (r'(declare)(\s+)(default)(\s+)(order)', |
|
594 bygroups(Keyword, Text, Keyword, Text, Keyword), 'operator'), |
|
595 (ncname + ':\*', Name, 'operator'), |
|
596 ('\*:'+ncname, Name.Tag, 'operator'), |
|
597 ('\*', Name.Tag, 'operator'), |
|
598 (stringdouble, String.Double, 'operator'), |
|
599 (stringsingle, String.Single, 'operator'), |
|
600 |
|
601 (r'(\})', popstate_callback), |
|
602 |
|
603 # NAMESPACE DECL |
|
604 (r'(declare)(\s+)(default)(\s+)(collation)', |
|
605 bygroups(Keyword, Text, Keyword, Text, Keyword)), |
|
606 (r'(module|declare)(\s+)(namespace)', |
|
607 bygroups(Keyword, Text, Keyword), 'namespacedecl'), |
|
608 (r'(declare)(\s+)(base-uri)', |
|
609 bygroups(Keyword, Text, Keyword), 'namespacedecl'), |
|
610 |
|
611 # NAMESPACE KEYWORD |
|
612 (r'(declare)(\s+)(default)(\s+)(element|function)', |
|
613 bygroups(Keyword, Text, Keyword, Text, Keyword), 'namespacekeyword'), |
|
614 (r'(import)(\s+)(schema|module)', |
|
615 bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'namespacekeyword'), |
|
616 (r'(declare)(\s+)(copy-namespaces)', |
|
617 bygroups(Keyword, Text, Keyword), 'namespacekeyword'), |
|
618 |
|
619 # VARNAMEs |
|
620 (r'(for|let|some|every)(\s+)(\$)', |
|
621 bygroups(Keyword, Text, Name.Variable), 'varname'), |
|
622 (r'\$', Name.Variable, 'varname'), |
|
623 (r'(declare)(\s+)(variable)(\s+)(\$)', |
|
624 bygroups(Keyword, Text, Keyword, Text, Name.Variable), 'varname'), |
|
625 |
|
626 # ITEMTYPE |
|
627 (r'(\))(\s+)(as)', bygroups(Operator, Text, Keyword), 'itemtype'), |
|
628 |
|
629 (r'(element|attribute|schema-element|schema-attribute|comment|' |
|
630 r'text|node|document-node|empty-sequence)(\s+)(\()', |
|
631 pushstate_operator_kindtest_callback), |
|
632 |
|
633 (r'(processing-instruction)(\s+)(\()', |
|
634 pushstate_operator_kindtestforpi_callback), |
|
635 |
|
636 (r'(<!--)', pushstate_operator_xmlcomment_callback), |
|
637 |
|
638 (r'(<\?)', pushstate_operator_processing_instruction_callback), |
|
639 |
|
640 (r'(<!\[CDATA\[)', pushstate_operator_cdata_section_callback), |
|
641 |
|
642 # (r'</', Name.Tag, 'end_tag'), |
|
643 (r'(<)', pushstate_operator_starttag_callback), |
|
644 |
|
645 (r'(declare)(\s+)(boundary-space)', |
|
646 bygroups(Keyword, Text, Keyword), 'xmlspace_decl'), |
|
647 |
|
648 (r'(validate)(\s+)(lax|strict)', |
|
649 pushstate_operator_root_validate_withmode), |
|
650 (r'(validate)(\s*)(\{)', pushstate_operator_root_validate), |
|
651 (r'(typeswitch)(\s*)(\()', bygroups(Keyword, Text, Punctuation)), |
|
652 (r'(element|attribute)(\s*)(\{)', |
|
653 pushstate_operator_root_construct_callback), |
|
654 |
|
655 (r'(document|text|processing-instruction|comment)(\s*)(\{)', |
|
656 pushstate_operator_root_construct_callback), |
|
657 # ATTRIBUTE |
|
658 (r'(attribute)(\s+)(?=' + qname + r')', |
|
659 bygroups(Keyword, Text), 'attribute_qname'), |
|
660 # ELEMENT |
|
661 (r'(element)(\s+)(?=' + qname + r')', |
|
662 bygroups(Keyword, Text), 'element_qname'), |
|
663 # PROCESSING_INSTRUCTION |
|
664 (r'(processing-instruction)(\s+)(' + ncname + r')(\s*)(\{)', |
|
665 bygroups(Keyword, Text, Name.Variable, Text, Punctuation), |
|
666 'operator'), |
|
667 |
|
668 (r'(declare|define)(\s+)(function)', |
|
669 bygroups(Keyword, Text, Keyword)), |
|
670 |
|
671 (r'(\{)', pushstate_operator_root_callback), |
|
672 |
|
673 (r'(unordered|ordered)(\s*)(\{)', |
|
674 pushstate_operator_order_callback), |
|
675 |
|
676 (r'(declare)(\s+)(ordering)', |
|
677 bygroups(Keyword, Text, Keyword), 'declareordering'), |
|
678 |
|
679 (r'(xquery)(\s+)(version)', |
|
680 bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'xqueryversion'), |
|
681 |
|
682 (r'(\(#)', Punctuation, 'pragma'), |
|
683 |
|
684 # sometimes return can occur in root state |
|
685 (r'return', Keyword), |
|
686 |
|
687 (r'(declare)(\s+)(option)', bygroups(Keyword, Text, Keyword), |
|
688 'option'), |
|
689 |
|
690 # URI LITERALS - single and double quoted |
|
691 (r'(at)(\s+)('+stringdouble+')', String.Double, 'namespacedecl'), |
|
692 (r'(at)(\s+)('+stringsingle+')', String.Single, 'namespacedecl'), |
|
693 |
|
694 (r'(ancestor-or-self|ancestor|attribute|child|descendant-or-self)(::)', |
|
695 bygroups(Keyword, Punctuation)), |
|
696 (r'(descendant|following-sibling|following|parent|preceding-sibling' |
|
697 r'|preceding|self)(::)', bygroups(Keyword, Punctuation)), |
|
698 |
|
699 (r'(if)(\s*)(\()', bygroups(Keyword, Text, Punctuation)), |
|
700 |
|
701 (r'then|else', Keyword), |
|
702 |
|
703 # ML specific |
|
704 (r'(try)(\s*)', bygroups(Keyword, Text), 'root'), |
|
705 (r'(catch)(\s*)(\()(\$)', |
|
706 bygroups(Keyword, Text, Punctuation, Name.Variable), 'varname'), |
|
707 |
|
708 (r'(@'+qname+')', Name.Attribute), |
|
709 (r'(@'+ncname+')', Name.Attribute), |
|
710 (r'@\*:'+ncname, Name.Attribute), |
|
711 (r'(@)', Name.Attribute), |
|
712 |
|
713 (r'//|/|\+|-|;|,|\(|\)', Punctuation), |
|
714 |
|
715 # STANDALONE QNAMES |
|
716 (qname + r'(?=\s*\{)', Name.Tag, 'qname_braren'), |
|
717 (qname + r'(?=\s*\([^:])', Name.Function, 'qname_braren'), |
|
718 (qname, Name.Tag, 'operator'), |
|
719 ] |
|
720 } |
|
721 |
|
722 |
|
723 class QmlLexer(RegexLexer): |
|
724 """ |
|
725 For QML files. See http://doc.qt.digia.com/4.7/qdeclarativeintroduction.html. |
|
726 |
|
727 .. versionadded:: 1.6 |
|
728 """ |
|
729 |
|
730 # QML is based on javascript, so much of this is taken from the |
|
731 # JavascriptLexer above. |
|
732 |
|
733 name = 'QML' |
|
734 aliases = ['qml'] |
|
735 filenames = ['*.qml'] |
|
736 mimetypes = ['application/x-qml'] |
|
737 |
|
738 # pasted from JavascriptLexer, with some additions |
|
739 flags = re.DOTALL | re.MULTILINE |
|
740 |
|
741 tokens = { |
|
742 'commentsandwhitespace': [ |
|
743 (r'\s+', Text), |
|
744 (r'<!--', Comment), |
|
745 (r'//.*?\n', Comment.Single), |
|
746 (r'/\*.*?\*/', Comment.Multiline) |
|
747 ], |
|
748 'slashstartsregex': [ |
|
749 include('commentsandwhitespace'), |
|
750 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
751 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
752 (r'(?=/)', Text, ('#pop', 'badregex')), |
|
753 default('#pop') |
|
754 ], |
|
755 'badregex': [ |
|
756 (r'\n', Text, '#pop') |
|
757 ], |
|
758 'root': [ |
|
759 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
760 include('commentsandwhitespace'), |
|
761 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' |
|
762 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), |
|
763 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
764 (r'[})\].]', Punctuation), |
|
765 |
|
766 # QML insertions |
|
767 (r'\bid\s*:\s*[A-Za-z][\w.]*', Keyword.Declaration, |
|
768 'slashstartsregex'), |
|
769 (r'\b[A-Za-z][\w.]*\s*:', Keyword, 'slashstartsregex'), |
|
770 |
|
771 # the rest from JavascriptLexer |
|
772 (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' |
|
773 r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' |
|
774 r'this)\b', Keyword, 'slashstartsregex'), |
|
775 (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), |
|
776 (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' |
|
777 r'extends|final|float|goto|implements|import|int|interface|long|native|' |
|
778 r'package|private|protected|public|short|static|super|synchronized|throws|' |
|
779 r'transient|volatile)\b', Keyword.Reserved), |
|
780 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), |
|
781 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
782 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
783 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
784 r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' |
|
785 r'window)\b', Name.Builtin), |
|
786 (r'[$a-zA-Z_]\w*', Name.Other), |
|
787 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
788 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
789 (r'[0-9]+', Number.Integer), |
|
790 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
791 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
792 ] |
|
793 } |
|
794 |
|
795 |
|
796 class CirruLexer(RegexLexer): |
|
797 """ |
|
798 Syntax rules of Cirru can be found at: |
|
799 http://cirru.org/ |
|
800 |
|
801 * using ``()`` to markup blocks, but limited in the same line |
|
802 * using ``""`` to markup strings, allow ``\`` to escape |
|
803 * using ``$`` as a shorthand for ``()`` till indentation end or ``)`` |
|
804 * using indentations for create nesting |
|
805 |
|
806 .. versionadded:: 2.0 |
|
807 """ |
|
808 |
|
809 name = 'Cirru' |
|
810 aliases = ['cirru'] |
|
811 filenames = ['*.cirru'] |
|
812 mimetypes = ['text/x-cirru'] |
|
813 flags = re.MULTILINE |
|
814 |
|
815 tokens = { |
|
816 'string': [ |
|
817 (r'[^"\\\n]', String), |
|
818 (r'\\', String.Escape, 'escape'), |
|
819 (r'"', String, '#pop'), |
|
820 ], |
|
821 'escape': [ |
|
822 (r'.', String.Escape, '#pop'), |
|
823 ], |
|
824 'function': [ |
|
825 (r'[^\s"()]+', Name.Function, '#pop'), |
|
826 (r'\)', Operator, '#pop'), |
|
827 (r'(?=\n)', Text, '#pop'), |
|
828 (r'\(', Operator, '#push'), |
|
829 (r'"', String, ('#pop', 'string')), |
|
830 (r'[ ]+', Text.Whitespace), |
|
831 (r'\,', Operator, '#pop'), |
|
832 ], |
|
833 'line': [ |
|
834 (r'\$', Operator, 'function'), |
|
835 (r'\(', Operator, 'function'), |
|
836 (r'\)', Operator), |
|
837 (r'\n', Text, '#pop'), |
|
838 (r'"', String, 'string'), |
|
839 (r'[ ]+', Text.Whitespace), |
|
840 (r'[+-]?[\d.]+\b', Number), |
|
841 (r'[^\s"()]+', Name.Variable) |
|
842 ], |
|
843 'root': [ |
|
844 (r'^\n+', Text.Whitespace), |
|
845 default(('line', 'function')), |
|
846 ] |
|
847 } |
|
848 |
|
849 |
|
850 class SlimLexer(ExtendedRegexLexer): |
|
851 """ |
|
852 For Slim markup. |
|
853 |
|
854 .. versionadded:: 2.0 |
|
855 """ |
|
856 |
|
857 name = 'Slim' |
|
858 aliases = ['slim'] |
|
859 filenames = ['*.slim'] |
|
860 mimetypes = ['text/x-slim'] |
|
861 |
|
862 flags = re.IGNORECASE |
|
863 _dot = r'(?: \|\n(?=.* \|)|.)' |
|
864 tokens = { |
|
865 'root': [ |
|
866 (r'[ \t]*\n', Text), |
|
867 (r'[ \t]*', _indentation), |
|
868 ], |
|
869 |
|
870 'css': [ |
|
871 (r'\.[\w:-]+', Name.Class, 'tag'), |
|
872 (r'\#[\w:-]+', Name.Function, 'tag'), |
|
873 ], |
|
874 |
|
875 'eval-or-plain': [ |
|
876 (r'([ \t]*==?)(.*\n)', |
|
877 bygroups(Punctuation, using(RubyLexer)), |
|
878 'root'), |
|
879 (r'[ \t]+[\w:-]+(?==)', Name.Attribute, 'html-attributes'), |
|
880 default('plain'), |
|
881 ], |
|
882 |
|
883 'content': [ |
|
884 include('css'), |
|
885 (r'[\w:-]+:[ \t]*\n', Text, 'plain'), |
|
886 (r'(-)(.*\n)', |
|
887 bygroups(Punctuation, using(RubyLexer)), |
|
888 '#pop'), |
|
889 (r'\|' + _dot + r'*\n', _starts_block(Text, 'plain'), '#pop'), |
|
890 (r'/' + _dot + r'*\n', _starts_block(Comment.Preproc, 'slim-comment-block'), '#pop'), |
|
891 (r'[\w:-]+', Name.Tag, 'tag'), |
|
892 include('eval-or-plain'), |
|
893 ], |
|
894 |
|
895 'tag': [ |
|
896 include('css'), |
|
897 (r'[<>]{1,2}(?=[ \t=])', Punctuation), |
|
898 (r'[ \t]+\n', Punctuation, '#pop:2'), |
|
899 include('eval-or-plain'), |
|
900 ], |
|
901 |
|
902 'plain': [ |
|
903 (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text), |
|
904 (r'(#\{)(.*?)(\})', |
|
905 bygroups(String.Interpol, using(RubyLexer), String.Interpol)), |
|
906 (r'\n', Text, 'root'), |
|
907 ], |
|
908 |
|
909 'html-attributes': [ |
|
910 (r'=', Punctuation), |
|
911 (r'"[^"]+"', using(RubyLexer), 'tag'), |
|
912 (r'\'[^\']+\'', using(RubyLexer), 'tag'), |
|
913 (r'\w+', Text, 'tag'), |
|
914 ], |
|
915 |
|
916 'slim-comment-block': [ |
|
917 (_dot + '+', Comment.Preproc), |
|
918 (r'\n', Text, 'root'), |
|
919 ], |
|
920 } |