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