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