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