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