1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language
[
<!ENTITY simpleName "(?:[a-z][a-z\d]*:)?[a-z][a-z\d]*">
<!ENTITY baseName "[a-zA-Z_\$[:^ascii:]](?:[\w\$\-\.[:^ascii:]]*[\w\$[:^ascii:]])?">
<!ENTITY name "(?:&baseName;:)?&baseName;">
<!ENTITY baseNameWithBound "(?:\b[a-zA-Z_\$]|[^[:ascii:]])(?:[\w\$\-\.[:^ascii:]]*[\w\$[:^ascii:]])?">
<!ENTITY nameWithBound "(?:&baseNameWithBound;:)?&baseNameWithBound;"> <!-- Use this instead of "\b&name;" -->
<!ENTITY simpleTag "<\s*&simpleName;"> <!-- Element tag -->
<!ENTITY tag "<\s*(?:&name;|>)">
<!ENTITY entref "&(?:[a-zA-Z\d]+|#\d+|#x[a-fA-F\d]+);">
<!ENTITY mlComment "/\*(?:[^\*]|\*+[^/\*])*\*+/">
<!ENTITY endTagName "[\s<>]|/[>/\*]|$"> <!-- Delimiter of end of Tag name -->
<!ENTITY identifier "[a-zA-Z_$[:^ascii:]][\w$[:^ascii:]]*">
<!ENTITY objectOp "[\?!]?">
<!ENTITY endLine "\s*(?:$|//|(?:/\*.*\*/\s*)+(?:$|//))">
<!ENTITY codeContent ""(?:[^"]|\\.)*"|'(?:[^']|\\.)*'|`(?:[^`]|\\.)`|/\*.*\*/|/(?:[^/\\\[]|\\.|\[(?:[^\]\\]|\\.)+\])+/">
<!ENTITY conditionalExpression "\?(?=\s*(?:(?:[^/"'`\s\?:\.;,\=\}\]\)]|&codeContent;)(?:[^/"'`]|&codeContent;)*)?&identifier;\s*(?:/\*.*\*/\s*)*:|(?:&&|\|\||\s*(?:/\*.*\*/\s*)*&identifier;)?&endLine;)">
<!-- Because TSX cannot have "cast" expression, we can say "<T extends" starts the type parameter of arrow
See: https://github.com/microsoft/TypeScript-TmLanguage/commit/11b1a4f8dc3a3eaa4df71e8cc1ad6f01a688961d#diff-d5222b162266b45fd998419db416fddd -->
<!ENTITY typesAngleBracket1 "<(?=\s*&identifier;\s+extends\s*[^\=>])">
<!-- Invalid Tag, do not highlight tags in these cases:
* "?" or "," after tag name:
<Tag ? ...
<Tag< ? ...
<Tag /* comment */ ? ...
* Invalid delimiter after comment (without spaces):
<Tag/* comment */#
-->
<!ENTITY typesAngleBracket2 "<(?=\s*&name;(?:(<(?:\s*&mlComment;)*)?(?:\s*&mlComment;)*\s*[\?,]|(?:&mlComment;)+(?!&endTagName;|&baseName;|\{)))">
]>
<!--
====================================================================
This file is part of the KDE's KSyntaxHighlighting framework.
Copyright 2018-2020 Nibaldo González S. (nibgonz@gmail.com)
This Source Code Form is subject to the terms of the MIT License.
If a copy of the license was not distributed with this file,
You can obtain one at: https://opensource.org/licenses/MIT
====================================================================
This file is an extension of the TypeScript highlighter
(typescript.xml, Version 7 and higher).
IMPORTANT: Keep sync with "javascript-react.xml".
Based on the XML syntax highlighting (v7), by Wilbert Berendsen
(wilbert@kde.nl), and the TypeScript React grammar files,
available at: https://github.com/Microsoft/TypeScript-TmLanguage
Change log:
* v10 [2020-06-03]: Add folding in templates.
* v9 [2020-02-23]: Adapt to version 9 of "typescript.xml".
* v8 [2019-11-21]: Tag detection is more stricter.
* v7 [2019-11-19]: Rename definition "TypeScript React" to "TypeScript React (TSX)".
* v6 [2019-10-01]: Highlight "<T extends" as a type assertion, not as a Tag.
* v5 [2019-08-30]: Adapt to version 5 of "typescript.xml".
* v4 [2019-07-16]: Adapt to version 4 of "typescript.xml".
* v3 [2019-02-20]: Don't highlight tags within declarations of
types, variables, classes and interfaces.
Fixes tags after substitutions in templates.
Adapt to version 3 of "typescript.xml".
* v2 [2018-12-30]: Adapt to version 2 of "typescript.xml".
Allow type assertion in the tag name.
Allow tags after the keywords "await" & "yield".
Allow empty tags and non-ASCII tag name & attributes.
* v1 [2018-11-18]: Initial version
-->
<language name="TypeScript React (TSX)" alternativeNames="TSX" version="12" kateversion="5.53" section="Scripts" indenter="cstyle"
priority="9" extensions="*.tsx" mimetype="text/tsx;text/x-tsx;application/tsx;application/x-tsx;"
author="Nibaldo González (nibgonz@gmail.com)" license="MIT">
<highlighting>
<contexts>
<context name="Shebang" attribute="Normal Text" lineEndContext="#pop!Normal" lineEmptyContext="#pop!Normal" fallthrough="true" fallthroughContext="#pop!Normal">
<Detect2Chars context="ShebangLine" attribute="Comment" char="#" char1="!" column="0" />
</context>
<context name="ShebangLine" attribute="Comment" lineEndContext="#pop#pop!Normal" />
<context name="Normal" attribute="Normal Text" lineEndContext="#stay">
<IncludeRules context="React" />
<IncludeRules context="Normal##TypeScript" />
</context>
<!-- TypeScript -->
<!-- Overwrite rules of 'typescript.xml'. These rules send to contexts
that contain: <IncludeRules context="Normal"/> in the TypeScript XML file.
NOTE: After the keyword "type" tags will not be highlighted ("TypeDeclaration" context). -->
<context name="OverwriteTypeScript" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="Template" attribute="Template" char="`" beginRegion="Template" />
<DetectChar context="Object" attribute="Normal Text" char="{" beginRegion="Brace" />
<DetectChar context="#stay" attribute="Normal Text" char="[" beginRegion="List" />
<DetectChar context="NoRegExp" attribute="Normal Text" char="]" endRegion="List" />
<DetectChar context="Types" attribute="Symbol" char=":" />
<RegExpr context="TypesAngleBracket" attribute="Symbol" String="<(?=(?:&identifier;|[\[\{\(<]).*>)" />
</context>
<context name="Object" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="#pop" attribute="Normal Text" char="}" endRegion="Brace" />
<RegExpr context="TypesNewLine" attribute="Symbol" String=":(?=&endLine;)" minimal="true" />
<IncludeRules context="React" />
<IncludeRules context="Object##TypeScript" />
</context>
<context name="Template" attribute="Template" lineEndContext="#stay">
<DetectChar context="RegExpAfterString##JavaScript" attribute="Template" char="`" endRegion="Template" />
<!-- Find tags and send to the "Substitution" context -->
<Detect2Chars context="Substitution-BeforeTag" attribute="Substitution" char="$" char1="{" />
<IncludeRules context="Template##TypeScript" />
</context>
<context name="Substitution" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="#pop" attribute="Substitution" char="}" />
<IncludeRules context="React" />
<IncludeRules context="Substitution##TypeScript" />
</context>
<!-- NOTE: Contexts completely overwritten! -->
<context name="NoRegExp" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop">
<IncludeRules context="NoRegExp##TypeScript" />
</context>
<context name="ConditionalExpression" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="#pop!ValidTag" attribute="Symbol" char=":" />
<IncludeRules context="ConditionalExpressionEnd##TypeScript" />
<IncludeRules context="FindConditionalExpressionBrackets" />
<!-- React -->
<IncludeRules context="NoStartConditionalExpression" />
<IncludeRules context="React" />
<!-- ConditionalExpression##TypeScript -->
<IncludeRules context="Normal-ParametersOverridden##TypeScript" />
</context>
<context name="FindConditionalExpressionBrackets" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="ConditionalExpressionRoundBracket-BeforeTag" attribute="Normal Text" char="(" />
<DetectChar context="ConditionalExpressionSquareBracket-BeforeTag" attribute="Symbol" char="[" beginRegion="List" />
</context>
<context name="ConditionalExpressionRoundBracket" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="#pop!NoRegExp" attribute="Normal Text" char=")" />
<IncludeRules context="FindConditionalExpressionBrackets" />
<IncludeRules context="React" />
<IncludeRules context="Normal" />
</context>
<context name="ConditionalExpressionSquareBracket" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="#pop!NoRegExp" attribute="Symbol" char="]" endRegion="List" />
<IncludeRules context="FindConditionalExpressionBrackets" />
<IncludeRules context="React" />
<IncludeRules context="Normal" />
</context>
<context name="NoStartConditionalExpression" attribute="Normal Text" lineEndContext="#stay">
<RegExpr context="ValidTag" attribute="Symbol" String="\?\s*(?=&tag;|/\*)" />
<DetectChar context="#stay" attribute="Symbol" char="?" />
</context>
<context name="Types" attribute="Normal Text" lineEndContext="#pop">
<IncludeRules context="FixPopLineEndContext##TypeScript" />
<IncludeRules context="TypesCommon" />
</context>
<context name="TypesCommon" attribute="Normal Text" lineEndContext="#pop">
<DetectSpaces />
<IncludeRules context="TypesEnd##TypeScript" />
<RegExpr context="#pop!TypesNewLine" attribute="Symbol" String="[\|&](?=&endLine;)" minimal="true" />
<!-- React -->
<IncludeRules context="TypesFindBrackets" />
<IncludeRules context="NoStartConditionalExpression" />
<IncludeRules context="React" />
<!-- TypesCommon##TypeScript -->
<IncludeRules context="DefaultTypes##TypeScript" />
<IncludeRules context="Normal-ParametersOverridden##TypeScript" />
</context>
<context name="TypesNewLine" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!TypesCommon">
<IncludeRules context="TypesNewLine##TypeScript" />
</context>
<!-- Overwrite TypesFindBrackets##TypeScript (place before "React").
Since there may be tags after "[", "{" or "(". -->
<context name="TypesFindBrackets" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="TypesSquareBracket-BeforeTag" attribute="Normal Text" char="[" beginRegion="List" />
<DetectChar context="TypesCurlyBracket-BeforeTag" attribute="Normal Text" char="{" beginRegion="Brace" />
<DetectChar context="TypesRoundBracket-BeforeTag" attribute="Normal Text" char="(" />
</context>
<context name="TypesSquareBracket" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="#pop!NoRegExp" attribute="Normal Text" char="]" endRegion="List" />
<!-- React -->
<IncludeRules context="TypesFindBrackets" />
<IncludeRules context="NoStartConditionalExpression" />
<IncludeRules context="React" />
<!-- TypesSquareBracket##TypeScript -->
<IncludeRules context="DefaultTypes##TypeScript" />
<IncludeRules context="Normal##TypeScript" />
</context>
<context name="TypesCurlyBracket" attribute="Normal Text" lineEndContext="#pop!Object">
<DetectChar context="#pop" attribute="Normal Text" char="}" endRegion="Brace" />
<!-- FixPopLineEndContext##TypeScript -->
<RegExpr context="#pop!Object" String="\S" firstNonSpace="true" lookAhead="true" />
<!-- React -->
<IncludeRules context="TypesFindBrackets" />
<IncludeRules context="NoStartConditionalExpression" />
<IncludeRules context="React" />
<!-- TypesCurlyBracket##TypeScript -->
<IncludeRules context="DefaultTypes##TypeScript" />
<IncludeRules context="Object##TypeScript" />
</context>
<context name="TypesRoundBracket" attribute="Normal Text" lineEndContext="#pop">
<DetectChar context="#pop!NoRegExp" attribute="Normal Text" char=")" />
<IncludeRules context="FixPopLineEndContext##TypeScript" />
<!-- React -->
<IncludeRules context="TypesFindBrackets" />
<IncludeRules context="NoStartConditionalExpression" />
<IncludeRules context="React" />
<!-- TypesRoundBracket##TypeScript -->
<IncludeRules context="DefaultTypes##TypeScript" />
<IncludeRules context="Normal##TypeScript" />
</context>
<context name="TypesAngleBracket" attribute="Normal Text" lineEndContext="#pop">
<RegExpr context="#pop!ValidTag" attribute="Symbol" String=">\s*(?=&tag;|/\*)" />
<DetectChar context="#pop" attribute="Symbol" char=">" />
<IncludeRules context="TypesAngleBracketEnd##TypeScript" />
<IncludeRules context="FixPopLineEndContext##TypeScript" />
<!-- React! -->
<IncludeRules context="TypesFindBrackets" />
<IncludeRules context="NoStartConditionalExpression" />
<IncludeRules context="React" />
<!-- TypesAngleBracket##TypeScript -->
<IncludeRules context="DefaultTypes##TypeScript" />
<IncludeRules context="Normal##TypeScript" />
</context>
<!-- Do not highlight tags in some special contexts -->
<context name="FindDeclarationsWithNoTags" attribute="Normal Text" lineEndContext="#stay">
<WordDetect context="InterfaceDeclaration" attribute="Reserved" String="interface" />
<WordDetect context="ClassDeclaration" attribute="Reserved" String="class" />
<WordDetect context="VarDeclaration" attribute="Reserved" String="let" />
<WordDetect context="VarDeclaration" attribute="Keyword" String="var" />
<WordDetect context="VarDeclaration" attribute="Keyword" String="const" />
</context>
<!-- Do not highlight tags after ":" in variable declarations -->
<context name="VarDeclaration" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop">
<DetectSpaces />
<RegExpr context="#pop!VarDeclTypesNewLine" attribute="Symbol" String=":(?=&endLine;)" minimal="true" />
<DetectChar context="#pop!VarDeclTypes" attribute="Symbol" char=":" />
<RegExpr context="#stay" attribute="Normal Text" String="&identifier;(?=\s*&objectOp;\s*:)" />
<AnyChar context="#stay" attribute="Symbol" String="?!" /> <!-- &objectOp; -->
<IncludeRules context="AllComments" />
</context>
<context name="VarDeclTypes" attribute="Normal Text" lineEndContext="#pop">
<IncludeRules context="Types##TypeScript" />
</context>
<context name="VarDeclTypesNewLine" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!VarDeclTypesCommon">
<DetectSpaces />
<IncludeRules context="AllComments" />
</context>
<context name="VarDeclTypesCommon" attribute="Normal Text" lineEndContext="#pop">
<IncludeRules context="TypesCommon##TypeScript" />
</context>
<!-- Do not highlight tags in interface declarations -->
<context name="InterfaceDeclaration" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="#pop!InterfaceContentDeclaration" attribute="Normal Text" char="{" beginRegion="Brace" />
<DetectChar context="#pop" char="}" lookAhead="true" />
<IncludeRules context="Normal##TypeScript" />
</context>
<context name="InterfaceContentDeclaration" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="#pop" attribute="Normal Text" char="}" endRegion="Brace" />
<IncludeRules context="Object##TypeScript" />
</context>
<!-- Do not highlight tags in class declarations -->
<context name="ClassDeclaration" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="#pop!ClassDeclarationContent" attribute="Normal Text" char="{" beginRegion="Brace" />
<DetectChar context="#pop" char="}" lookAhead="true" />
<IncludeRules context="Normal##TypeScript" />
</context>
<context name="ClassDeclarationContent" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="#pop" attribute="Normal Text" char="}" endRegion="Brace" />
<RegExpr context="VarDeclTypesNewLine" attribute="Symbol" String=":(?=&endLine;)" minimal="true" />
<DetectChar context="VarDeclTypes" attribute="Symbol" char=":" />
<IncludeRules context="Object" />
</context>
<!-- ReactJS -->
<!-- Tags highlighting -->
<context name="React" attribute="Normal Text" lineEndContext="#stay">
<!-- Tag in new line -->
<RegExpr context="ValidTag" attribute="Normal Text" String="&tag;" firstNonSpace="true" lookAhead="true" />
<!-- Highlight tags only after some keywords -->
<RegExpr context="ValidTag" attribute="ControlFlow" String="\b(?:return|await)\s*(?=&tag;|/\*)" />
<RegExpr context="ValidTag" attribute="Module" String="\b(?:default)\s*(?=&tag;|/\*)" />
<RegExpr context="ValidTag" attribute="Reserved" String="\b(?:yield)\s*(?=&tag;|/\*)" />
<!-- Characters before a valid tag -->
<RegExpr context="ValidTag" attribute="Special Operators" String="\=>\s*(?=&tag;|/\*)" />
<RegExpr context="ValidTag" attribute="Symbol" String="(?:[,\=>\*]|&&|\|\||\?\?)\s*(?=&tag;|/\*)" />
<RegExpr context="ValidTag" attribute="Normal Text" String="\[\s*(?=&tag;|/\*)" beginRegion="List" />
<RegExpr context="ValidTag" attribute="Normal Text" String="\(\s*(?=&tag;|/\*)" />
<!-- The "Object-BeforeTag" context looks for a valid Tag and then sends the "Object" context -->
<RegExpr context="Object-BeforeTag" attribute="Normal Text" String="\{\s*(?=&tag;|/\*)" beginRegion="Brace" />
<RegExpr context="Types-BeforeTag" attribute="Symbol" String=":\s*(?=&tag;|/\*)" />
<RegExpr context="ConditionalExpression-BeforeTag" attribute="Symbol" String="&conditionalExpression;" minimal="true" />
<RegExpr context="ValidTag" attribute="Symbol" String="\?\s*(?=&tag;|/\*)|<\s*>\s*(?=&tag;|/\*)" />
<!-- Tag after a comment on a new line -->
<Detect2Chars context="ValidTag" attribute="Comment" char="/" char1="*" firstNonSpace="true" lookAhead="true" />
<!-- Overwrite TypeScript rules to highlight tags within some contexts -->
<IncludeRules context="FindDeclarationsWithNoTags" />
<IncludeRules context="OverwriteTypeScript" />
</context>
<!-- Detect tags before starting a context -->
<context name="Object-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!Object">
<IncludeRules context="ValidTag" />
</context>
<context name="Substitution-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!Substitution">
<IncludeRules context="ValidTag" />
</context>
<context name="EvaluatedCode-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!EvaluatedCode">
<IncludeRules context="ValidTag" />
</context>
<context name="Types-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!Types">
<Detect2Chars context="#pop" attribute="Comment" char="/" char1="/" lookAhead="true" />
<IncludeRules context="ValidTag" />
</context>
<context name="TypesSquareBracket-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!TypesSquareBracket">
<IncludeRules context="ValidTag" />
</context>
<context name="TypesCurlyBracket-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!TypesCurlyBracket">
<Detect2Chars context="#pop!Object" attribute="Comment" char="/" char1="/" lookAhead="true" />
<IncludeRules context="ValidTag" />
</context>
<context name="TypesRoundBracket-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!TypesRoundBracket">
<Detect2Chars context="#pop" attribute="Comment" char="/" char1="/" lookAhead="true" />
<IncludeRules context="ValidTag" />
</context>
<context name="ConditionalExpression-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!ConditionalExpression">
<IncludeRules context="ValidTag" />
</context>
<context name="ConditionalExpressionRoundBracket-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!ConditionalExpressionRoundBracket">
<IncludeRules context="ValidTag" />
</context>
<context name="ConditionalExpressionSquareBracket-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!ConditionalExpressionSquareBracket">
<IncludeRules context="ValidTag" />
</context>
<!-- TAGS:
NOTE & TODO: The following code is common for 'javascript-react.xml' and 'typescript-react.xml'
and is replicated in both files. Look for some way to avoid having repeated code, for example,
with a common XML file or with a generator script. The only drawback is that the
"EvaluatedCode" context includes "Normal". -->
<!-- Highlight nested tags with comments in between.
NOTE: The highlighting of Tags after a multiline comment does not work with: lineEndContext="#pop" -->
<context name="ValidTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop">
<RegExpr context="#stay" attribute="Normal Text" String="\s+(?=<|/\*)" />
<IncludeRules context="FindTags" />
<IncludeRules context="AllComments" />
</context>
<!-- Start tag.
There are two contexts to find Tags:
* FindTags: For Tags within TypeScript code; invalid name tags aren't highlighted.
* FindTagsInTagContent: For Tag within another tag; highlight any Tag.
Tags with invalid names are highlighted as "Error".
-->
<context name="FindTags" attribute="Normal Text" lineEndContext="#stay">
<RegExpr context="#pop!TypesAngleBracket" attribute="Symbol" String="&typesAngleBracket1;|&typesAngleBracket2;" />
<!-- Empty tag (element) -->
<RegExpr context="ElementTagContent" attribute="Element Tag" String="<\s*>" beginRegion="Element" />
<!-- Detect Tags -->
<RegExpr context="ElementTagFindType" attribute="Element Tag" String="&simpleTag;(?=&endTagName;)" beginRegion="Element" />
<RegExpr context="ComponentTagFindType" attribute="Component Tag" String="&tag;(?=&endTagName;)" beginRegion="ComponentElement" />
<!-- If a valid Tag was not detected -->
<DetectChar context="#pop!TypesAngleBracket" attribute="Symbol" char="<" />
</context>
<context name="FindTagsInTagContent" attribute="Normal Text" lineEndContext="#stay">
<!-- Empty tag (element) -->
<RegExpr context="ElementTagContent" attribute="Element Tag" String="<\s*>" beginRegion="Element" />
<!-- Detect non-ASCII character in the tag name (component). This prevents highlighting as Element,
tag names that don't start with a non-ASCII character. -->
<RegExpr context="ComponentTagNonASCII" attribute="Component Tag" String="<\s*(?=(?:[a-z][a-z\d]*:)?(?:[a-z][a-z\d]*)?[^[:ascii:]])" beginRegion="ComponentElement" /> <!-- &simpleName; -->
<!-- Element & component tags -->
<RegExpr context="ElementTagFindType" attribute="Element Tag" String="&simpleTag;(?=[^\w\$\-\.:]|$|[\-\.]+(?:[^\w\$\-\.]|$)|:(?:[^a-zA-Z_\$]|$))" beginRegion="Element" />
<RegExpr context="ComponentTagFindType" attribute="Component Tag" String="&tag;" beginRegion="ComponentElement" />
</context>
<!-- Highlight tag name with non-ASCII characters -->
<context name="ComponentTagNonASCII" attribute="Normal Text" lineEndContext="#pop!ComponentTag" fallthrough="true" fallthroughContext="#pop!ComponentTag">
<RegExpr context="#pop!ComponentTagFindType" attribute="Component Tag" String="&name;" />
</context>
<context name="FindEntityRefs" attribute="Normal Text" lineEndContext="#stay">
<RegExpr context="#stay" attribute="EntityRef" String="&entref;" />
</context>
<!-- Type after the tag name. Ex: <C<number> /> -->
<context name="ComponentTagFindType" attribute="Normal Text" lineEndContext="#pop!ComponentTag" fallthrough="true" fallthroughContext="#pop!ComponentTag">
<DetectChar context="#pop!TypeInsideTag" attribute="Symbol" char="<" />
</context>
<context name="ElementTagFindType" attribute="Normal Text" lineEndContext="#pop!ElementTag" fallthrough="true" fallthroughContext="#pop!ElementTag">
<DetectChar context="#pop!TypeInsideTag" attribute="Symbol" char="<" />
</context>
<!-- Type assertion after the tag name -->
<context name="TypeInsideTag" attribute="Component Tag" lineEndContext="#stay">
<DetectChar context="#pop!ComponentTag" attribute="Symbol" char=">" />
<IncludeRules context="DefaultTypeInsideTag" />
</context>
<context name="DefaultTypeInsideTag" attribute="Component Tag" lineEndContext="#stay">
<DetectChar context="TypeInsideTag-AngleBracket" attribute="Symbol" char="<" />
<DetectChar context="TypeInsideTag-CurlyBracket" attribute="Symbol" char="{" />
<DetectChar context="TypeInsideTag-SquareBracket" attribute="Symbol" char="[" />
<DetectChar context="TypeInsideTag-RoundBracket" attribute="Symbol" char="(" />
<IncludeRules context="AllComments" />
</context>
<context name="TypeInsideTag-AngleBracket" attribute="Component Tag" lineEndContext="#stay">
<DetectChar context="#pop" attribute="Symbol" char=">" />
<IncludeRules context="DefaultTypeInsideTag" />
</context>
<context name="TypeInsideTag-CurlyBracket" attribute="Component Tag" lineEndContext="#stay">
<DetectChar context="#pop" attribute="Symbol" char="}" />
<IncludeRules context="DefaultTypeInsideTag" />
</context>
<context name="TypeInsideTag-SquareBracket" attribute="Component Tag" lineEndContext="#stay">
<DetectChar context="#pop!NoRegExp" attribute="Symbol" char="]" />
<IncludeRules context="DefaultTypeInsideTag" />
</context>
<context name="TypeInsideTag-RoundBracket" attribute="Component Tag" lineEndContext="#stay">
<DetectChar context="#pop!NoRegExp" attribute="Symbol" char=")" />
<IncludeRules context="DefaultTypeInsideTag" />
</context>
<!-- Inside the tag -->
<context name="ElementTag" attribute="Normal Text" lineEndContext="#stay">
<Detect2Chars context="#pop" attribute="Element Tag" char="/" char1=">" endRegion="Element" />
<DetectChar context="#pop!ElementTagContent" attribute="Element Tag" char=">" />
<IncludeRules context="DefaultTag" />
</context>
<context name="ComponentTag" attribute="Normal Text" lineEndContext="#stay">
<Detect2Chars context="#pop" attribute="Component Tag" char="/" char1=">" endRegion="ComponentElement" />
<DetectChar context="#pop!ComponentTagContent" attribute="Component Tag" char=">" />
<IncludeRules context="DefaultTag" />
</context>
<context name="DefaultTag" attribute="Normal Text" lineEndContext="#stay">
<RegExpr context="Attribute" attribute="Attribute" String="&nameWithBound;" />
<IncludeRules context="FindEvaluatedCode" />
<IncludeRules context="AllComments" />
<RegExpr context="#stay" attribute="Error" String="\S+&name;|\S" />
</context>
<!-- Tag content: <Tag> content </Tag> -->
<context name="ElementTagContent" attribute="Tag Content Text" lineEndContext="#stay">
<RegExpr context="#pop" attribute="Element Tag" String="</\s*>" endRegion="Element" />
<!-- With component tag (error) -->
<RegExpr context="ElementTagEnd" attribute="Element Tag" String="</\s*&simpleName;|</\s*(?=[A-Z_\$])" />
<IncludeRules context="DefaultTagContent" />
</context>
<context name="ComponentTagContent" attribute="Tag Content Text" lineEndContext="#stay">
<RegExpr context="#pop" attribute="Component Tag" String="</\s*>" endRegion="ComponentElement" />
<RegExpr context="ComponentTagEnd" attribute="Component Tag" String="</\s*&name;" />
<IncludeRules context="DefaultTagContent" />
</context>
<context name="DefaultTagContent" attribute="Tag Content Text" lineEndContext="#stay">
<IncludeRules context="FindTagsInTagContent" />
<IncludeRules context="FindEntityRefs" />
<IncludeRules context="FindEvaluatedCode" />
<DetectChar context="#stay" attribute="Error" char="<" />
</context>
<context name="ElementTagEnd" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="#pop#pop" attribute="Element Tag" char=">" endRegion="Element" />
<RegExpr context="#stay" attribute="Error" String="\S" />
</context>
<context name="ComponentTagEnd" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="#pop#pop" attribute="Component Tag" char=">" endRegion="ComponentElement" />
<RegExpr context="#stay" attribute="Error" String="\S" />
</context>
<!-- Tag attribute -->
<context name="Attribute" attribute="Normal Text" lineEndContext="#stay">
<RegExpr context="#pop" attribute="Error" String="\=(?=\s*/?>)" />
<DetectChar context="#pop!Value" attribute="Symbol" char="=" />
<IncludeRules context="FindEndTag" />
<DetectChar context="#pop" char="{" lookAhead="true" /> <!-- EvaluatedCode -->
<IncludeRules context="AllComments" />
<RegExpr context="#stay" attribute="Attribute" String="&nameWithBound;" />
<RegExpr context="#stay" attribute="Error" String="\S+&name;|\S" />
</context>
<context name="Value" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="#pop!ValueDQ" attribute="Value" char=""" />
<DetectChar context="#pop!ValueSQ" attribute="Value" char="'" />
<DetectChar context="#pop" char="{" lookAhead="true" /> <!-- EvaluatedCode -->
<IncludeRules context="FindEndTag" />
<IncludeRules context="AllComments" />
<RegExpr context="#stay" attribute="Error" String="\S" />
</context>
<context name="ValueDQ" attribute="Value" lineEndContext="#stay">
<DetectChar context="#pop" attribute="Value" char=""" />
<IncludeRules context="FindEntityRefs" />
</context>
<context name="ValueSQ" attribute="Value" lineEndContext="#stay">
<DetectChar context="#pop" attribute="Value" char="'" />
<IncludeRules context="FindEntityRefs" />
</context>
<context name="FindEndTag" attribute="Normal Text" lineEndContext="#stay">
<Detect2Chars context="#pop" char="/" char1=">" lookAhead="true" />
<DetectChar context="#pop" char=">" lookAhead="true" />
</context>
<context name="FindEvaluatedCode" attribute="Normal Text" lineEndContext="#stay">
<!-- Find tags and send to the "EvaluatedCode" context -->
<DetectChar context="EvaluatedCode-BeforeTag" attribute="Code Brackets" char="{" beginRegion="Code" />
</context>
<context name="EvaluatedCode" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="#pop" attribute="Code Brackets" char="}" endRegion="Code" />
<IncludeRules context="Normal" />
</context>
<context name="AllComments" attribute="Normal Text" lineEndContext="#stay">
<!-- TypeScript uses this for comments -->
<IncludeRules context="FindComments##JavaScript" />
</context>
</contexts>
<itemDatas>
<itemData name="Normal Text" defStyleNum="dsNormal" spellChecking="false" />
<itemData name="Comment" defStyleNum="dsComment" />
<itemData name="Tag Content Text" defStyleNum="dsNormal" />
<itemData name="Element Tag" defStyleNum="dsKeyword" spellChecking="false" />
<itemData name="Component Tag" defStyleNum="dsFunction" bold="1" spellChecking="false" />
<itemData name="Attribute" defStyleNum="dsOthers" spellChecking="false" />
<itemData name="Value" defStyleNum="dsString" spellChecking="false" />
<itemData name="EntityRef" defStyleNum="dsDecVal" spellChecking="false" />
<itemData name="Code Brackets" defStyleNum="dsVariable" spellChecking="false" />
<itemData name="Error" defStyleNum="dsError" spellChecking="false" />
<!-- itemDatas in TypeScript XML file -->
<itemData name="Symbol" defStyleNum="dsOperator" />
<itemData name="ControlFlow" defStyleNum="dsControlFlow" spellChecking="false" />
<itemData name="Reserved" defStyleNum="dsKeyword" italic="true" spellChecking="false" />
<itemData name="Keyword" defStyleNum="dsKeyword" spellChecking="false" />
<itemData name="Module" defStyleNum="dsImport" spellChecking="false" />
<itemData name="Template" defStyleNum="dsVerbatimString" />
<itemData name="Substitution" defStyleNum="dsSpecialChar" spellChecking="false" />
<itemData name="Special Operators" defStyleNum="dsKeyword" spellChecking="false" />
</itemDatas>
</highlighting>
<general>
<keywords casesensitive="1" />
<comments>
<comment name="singleLine" start="//" />
<comment name="multiLine" start="/*" end="*/" />
</comments>
</general>
</language>
<!-- kate: replace-tabs off; tab-width 3; indent-width 3; remove-trailing-spaces mod; dynamic-word-wrap off; -->
|