Changeset View
Changeset View
Standalone View
Standalone View
data/syntax/javascript-react.xml
- This file was added.
1 | <?xml version="1.0" encoding="UTF-8"?> | ||||
---|---|---|---|---|---|
2 | <!DOCTYPE language SYSTEM "language.dtd" | ||||
3 | [ | ||||
4 | <!ENTITY simpleName "([a-z][a-z\d]*:)?[a-z][a-z\d]*"> | ||||
5 | <!ENTITY name "([a-zA-Z_\$]([\w\$\-\.]*[\w\$])?:)?[a-zA-Z_\$]([\w\$\-\.]*[\w\$])?"> | ||||
6 | <!ENTITY simpleTag "<\s*&simpleName;"> | ||||
7 | <!ENTITY tag "<\s*&name;"> | ||||
8 | <!ENTITY entref "&([a-zA-Z\d]+|#\d+|#x[a-fA-F\d]+);"> | ||||
9 | ]> | ||||
10 | | ||||
11 | <!-- | ||||
12 | ==================================================================== | ||||
13 | | ||||
14 | This file is part of the KDE's KSyntaxHighlighting framework. | ||||
15 | | ||||
16 | Copyright 2018 Nibaldo González S. (nibgonz@gmail.com) | ||||
17 | | ||||
18 | This Source Code Form is subject to the terms of the MIT License. | ||||
19 | If a copy of the license was not distributed with this file, | ||||
20 | You can obtain one at: https://opensource.org/licenses/MIT | ||||
21 | | ||||
22 | ==================================================================== | ||||
23 | | ||||
24 | This file is an extension of the JavaScript highlighter | ||||
25 | (javascript.xml). | ||||
26 | Based on the XML syntax highlighting (v7), by Wilbert Berendsen | ||||
27 | (wilbert@kde.nl), and the TypeScript React grammar files of VS Code, | ||||
28 | available at: https://github.com/Microsoft/TypeScript-TmLanguage | ||||
29 | | ||||
30 | Change log: | ||||
31 | * v1 [2018-06-20]: Initial version | ||||
32 | --> | ||||
33 | | ||||
34 | <!-- NOTE: TSX extension of TypeScript React is included --> | ||||
35 | <language name="JavaScript React" version="1" kateversion="5.0" section="Scripts" indenter="cstyle" | ||||
36 | priority="6" extensions="*.jsx;*.tsx" mimetype="text/jsx;text/x-jsx;application/jsx;application/x-jsx;" | ||||
37 | author="Nibaldo González (nibgonz@gmail.com)" license="MIT"> | ||||
38 | | ||||
39 | <highlighting> | ||||
40 | | ||||
41 | <contexts> | ||||
42 | | ||||
43 | <context name="Shebang" attribute="Normal Text" lineEndContext="#pop!Normal" fallthrough="true" fallthroughContext="#pop!Normal"> | ||||
44 | <Detect2Chars context="ShebangLine" attribute="Comment" char="#" char1="!" column="0" /> | ||||
45 | </context> | ||||
46 | <context name="ShebangLine" attribute="Comment" lineEndContext="#pop#pop!Normal" /> | ||||
47 | | ||||
48 | <context name="Normal" attribute="Normal Text" lineEndContext="#stay"> | ||||
49 | <IncludeRules context="React" /> | ||||
50 | <IncludeRules context="Normal##JavaScript" /> | ||||
51 | </context> | ||||
52 | | ||||
53 | <!-- JavaScript --> | ||||
54 | | ||||
55 | <!-- NOTE: Keep synchronized with 'javascript.xml'! | ||||
56 | Overwrite rules of 'javascript.xml'. These rules send to contexts | ||||
57 | that contain: <IncludeRules context="Normal"/> in the JavaScript XML file. --> | ||||
58 | <context name="OverwriteJavascript" attribute="Normal Text" lineEndContext="#stay"> | ||||
59 | <DetectChar context="Template" attribute="Template" char="`" /> | ||||
60 | <DetectChar context="Object" attribute="Symbol" char="{" beginRegion="Brace" /> | ||||
61 | <DetectChar context="Conditional Expression" attribute="Symbol" char="?" /> | ||||
62 | </context> | ||||
63 | <context name="Object" attribute="Normal Text" lineEndContext="#stay"> | ||||
64 | <IncludeRules context="React" /> | ||||
65 | <IncludeRules context="Object##JavaScript" /> | ||||
66 | </context> | ||||
67 | <context name="Conditional Expression" attribute="Normal Text" lineEndContext="#stay"> | ||||
68 | <IncludeRules context="React" /> | ||||
69 | <IncludeRules context="Conditional Expression##JavaScript" /> | ||||
70 | </context> | ||||
71 | <context name="Template" attribute="Template" lineEndContext="#stay"> | ||||
72 | <Detect2Chars context="Substitution" attribute="Substitution" char="$" char1="{" /> | ||||
73 | <IncludeRules context="Template##JavaScript" /> | ||||
74 | </context> | ||||
75 | <context name="Substitution" attribute="Normal Text" lineEndContext="#stay"> | ||||
76 | <IncludeRules context="React" /> | ||||
77 | <IncludeRules context="Substitution##JavaScript" /> | ||||
78 | </context> | ||||
79 | | ||||
80 | <!-- ReactJS --> | ||||
81 | | ||||
82 | <context name="React" attribute="Normal Text" lineEndContext="#stay"> | ||||
83 | <!-- Characters before a valid tag. Keep synchronized with 'javascript.xml'! --> | ||||
84 | <RegExpr context="ValidTag" attribute="Normal Text" String="&tag;" firstNonSpace="true" lookAhead="true" /> | ||||
85 | <RegExpr context="ValidTag" attribute="ControlFlow" String="\b(return)\s*(?=&tag;|/\*)" /> | ||||
86 | <RegExpr context="ValidTag" attribute="Module" String="\b(default)\s*(?=&tag;|/\*)" /> | ||||
87 | <RegExpr context="ValidTag" attribute="Symbol" String="([,\=>:\*]|&&|\|\|)\s*(?=&tag;|/\*)" /> | ||||
88 | <RegExpr context="ValidTag" attribute="Normal Text" String="[\(\[]\s*(?=&tag;|/\*)" /> | ||||
89 | | ||||
90 | <RegExpr context="Object-BeforeTag" attribute="Symbol" String="\{\s*(?=&tag;|/\*)" beginRegion="Brace" /> | ||||
91 | <RegExpr context="ConditionalExpression-BeforeTag" attribute="Symbol" String="\?\s*(?=&tag;|/\*)" /> | ||||
92 | <Detect2Chars context="ValidTag" attribute="Comment" char="/" char1="*" firstNonSpace="true" lookAhead="true" /> | ||||
93 | | ||||
94 | <IncludeRules context="OverwriteJavascript" /> | ||||
95 | <IncludeRules context="AllComments" /> | ||||
96 | </context> | ||||
97 | | ||||
98 | <!-- NOTE: The highlighting of Tags after a multiline comment does not work with: lineEndContext="#pop" --> | ||||
99 | <context name="ValidTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop"> | ||||
100 | <RegExpr context="#stay" attribute="Normal Text" String="\s+(?=<|/\*)" /> | ||||
101 | <IncludeRules context="FindTags" /> | ||||
102 | <Detect2Chars context="MultiInlineComment" attribute="Comment" char="/" char1="*" beginRegion="Comment" /> | ||||
103 | </context> | ||||
104 | <context name="Object-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!Object"> | ||||
105 | <IncludeRules context="ValidTag" /> | ||||
106 | </context> | ||||
107 | <context name="ConditionalExpression-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!Conditional Expression"> | ||||
108 | <IncludeRules context="ValidTag" /> | ||||
109 | </context> | ||||
110 | <context name="EvaluatedCode-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!EvaluatedCode"> | ||||
111 | <IncludeRules context="ValidTag" /> | ||||
112 | </context> | ||||
113 | | ||||
114 | <context name="FindTags" attribute="Normal Text" lineEndContext="#stay"> | ||||
115 | <RegExpr context="ElementTag" attribute="Element Tag" String="&simpleTag;(?=[^\w\$\-\.:]|$|[\-\.]+([^\w\$\-\.]|$)|:([^a-zA-Z_\$]|$))" beginRegion="Element" /> | ||||
116 | <RegExpr context="ComponentTag" attribute="Component Tag" String="&tag;" beginRegion="ComponentElement" /> | ||||
117 | </context> | ||||
118 | <context name="FindEntityRefs" attribute="Normal Text" lineEndContext="#stay"> | ||||
119 | <RegExpr context="#stay" attribute="EntityRef" String="&entref;" /> | ||||
120 | </context> | ||||
121 | | ||||
122 | <context name="ElementTag" attribute="Normal Text" lineEndContext="#stay"> | ||||
123 | <Detect2Chars context="#pop" attribute="Element Tag" char="/" char1=">" endRegion="Element" /> | ||||
124 | <DetectChar context="#pop!ElementTagContent" attribute="Element Tag" char=">" /> | ||||
125 | <IncludeRules context="DefaultTag" /> | ||||
126 | </context> | ||||
127 | <context name="ComponentTag" attribute="Normal Text" lineEndContext="#stay"> | ||||
128 | <Detect2Chars context="#pop" attribute="Component Tag" char="/" char1=">" endRegion="ComponentElement" /> | ||||
129 | <DetectChar context="#pop!ComponentTagContent" attribute="Component Tag" char=">" /> | ||||
130 | <IncludeRules context="DefaultTag" /> | ||||
131 | </context> | ||||
132 | <context name="DefaultTag" attribute="Normal Text" lineEndContext="#stay"> | ||||
133 | <RegExpr context="Attribute" attribute="Attribute" String="\b&name;" /> | ||||
134 | <IncludeRules context="AllComments" /> | ||||
135 | <RegExpr context="#stay" attribute="Error" String="\S+&name;" /> | ||||
136 | <RegExpr context="#stay" attribute="Error" String="\S" /> | ||||
137 | </context> | ||||
138 | | ||||
139 | <context name="ElementTagContent" attribute="Tag Content Text" lineEndContext="#stay"> | ||||
140 | <RegExpr context="ElementTagEnd" attribute="Element Tag" String="</\s*&simpleName;" /> | ||||
141 | <RegExpr context="ElementTagEnd" attribute="Element Tag" String="</\s*(?=[A-Z_\$])" /> <!-- Component tag (error) --> | ||||
142 | <IncludeRules context="DefaultTagContent" /> | ||||
143 | </context> | ||||
144 | <context name="ComponentTagContent" attribute="Tag Content Text" lineEndContext="#stay"> | ||||
145 | <RegExpr context="ComponentTagEnd" attribute="Component Tag" String="</\s*&name;" /> | ||||
146 | <IncludeRules context="DefaultTagContent" /> | ||||
147 | </context> | ||||
148 | <context name="DefaultTagContent" attribute="Tag Content Text" lineEndContext="#stay"> | ||||
149 | <IncludeRules context="FindTags" /> | ||||
150 | <IncludeRules context="FindEntityRefs" /> | ||||
151 | <RegExpr context="EvaluatedCode-BeforeTag" attribute="Code Brackets" String="\{\s*(?=&tag;|/\*)" beginRegion="Code" /> | ||||
152 | <DetectChar context="EvaluatedCode" attribute="Code Brackets" char="{" beginRegion="Code" /> | ||||
153 | <DetectChar context="#stay" attribute="Error" char="<" /> | ||||
154 | </context> | ||||
155 | | ||||
156 | <context name="ElementTagEnd" attribute="Normal Text" lineEndContext="#stay"> | ||||
157 | <DetectChar context="#pop#pop" attribute="Element Tag" char=">" endRegion="Element" /> | ||||
158 | <RegExpr context="#stay" attribute="Error" String="\S" /> | ||||
159 | </context> | ||||
160 | <context name="ComponentTagEnd" attribute="Normal Text" lineEndContext="#stay"> | ||||
161 | <DetectChar context="#pop#pop" attribute="Component Tag" char=">" endRegion="ComponentElement" /> | ||||
162 | <RegExpr context="#stay" attribute="Error" String="\S" /> | ||||
163 | </context> | ||||
164 | | ||||
165 | <context name="Attribute" attribute="Normal Text" lineEndContext="#stay"> | ||||
166 | <DetectChar context="#pop!Value" attribute="Symbol" char="=" /> | ||||
167 | <Detect2Chars context="#pop" attribute="Normal Text" char="/" char1=">" lookAhead="true" /> | ||||
168 | <DetectChar context="#pop" attribute="Normal Text" char=">" lookAhead="true" /> | ||||
169 | <IncludeRules context="AllComments" /> | ||||
170 | <RegExpr context="#stay" attribute="Attribute" String="\b&name;" /> | ||||
171 | <RegExpr context="#stay" attribute="Error" String="\S+&name;" /> | ||||
172 | <RegExpr context="#stay" attribute="Error" String="\S" /> | ||||
173 | </context> | ||||
174 | | ||||
175 | <context name="Value" attribute="Normal Text" lineEndContext="#stay"> | ||||
176 | <DetectChar context="#pop!ValueDQ" attribute="Value" char=""" /> | ||||
177 | <DetectChar context="#pop!ValueSQ" attribute="Value" char="'" /> | ||||
178 | <RegExpr context="#pop!EvaluatedCode-BeforeTag" attribute="Code Brackets" String="\{\s*(?=&tag;|/\*)" beginRegion="Code" /> | ||||
179 | <DetectChar context="#pop!EvaluatedCode" attribute="Code Brackets" char="{" beginRegion="Code" /> | ||||
180 | <IncludeRules context="AllComments" /> | ||||
181 | <RegExpr context="#stay" attribute="Error" String="\S" /> | ||||
182 | </context> | ||||
183 | <context name="ValueDQ" attribute="Value" lineEndContext="#stay"> | ||||
184 | <DetectChar context="#pop" attribute="Value" char=""" /> | ||||
185 | <IncludeRules context="FindEntityRefs" /> | ||||
186 | </context> | ||||
187 | <context name="ValueSQ" attribute="Value" lineEndContext="#stay"> | ||||
188 | <DetectChar context="#pop" attribute="Value" char="'" /> | ||||
189 | <IncludeRules context="FindEntityRefs" /> | ||||
190 | </context> | ||||
191 | <context name="EvaluatedCode" attribute="Normal Text" lineEndContext="#stay"> | ||||
192 | <DetectChar context="#pop" attribute="Code Brackets" char="}" endRegion="Code" /> | ||||
193 | <IncludeRules context="Normal" /> | ||||
194 | </context> | ||||
195 | | ||||
196 | <context name="AllComments" attribute="Normal Text" lineEndContext="#stay"> | ||||
197 | <Detect2Chars context="SingleLineComment" attribute="Comment" char="/" char1="/" /> | ||||
198 | <Detect2Chars context="MultiInlineComment" attribute="Comment" char="/" char1="*" beginRegion="Comment" /> | ||||
199 | </context> | ||||
200 | <context name="SingleLineComment" attribute="Comment" lineEndContext="#pop"> | ||||
201 | <IncludeRules context="##Alerts" /> | ||||
202 | <IncludeRules context="##Modelines" /> | ||||
203 | <RegExpr context="SingleLineCommentURL" attribute="Comment URL" String="\bhttps?://(?=[^\s<>"'`])" /> | ||||
204 | <IncludeRules context="DefaultComment" /> | ||||
205 | </context> | ||||
206 | <context name="MultiInlineComment" attribute="Comment" lineEndContext="#stay"> | ||||
207 | <Detect2Chars context="#pop" attribute="Comment" char="*" char1="/" endRegion="Comment" /> | ||||
208 | <IncludeRules context="##Alerts" /> | ||||
209 | <IncludeRules context="##Modelines" /> | ||||
210 | <RegExpr context="MultiInlineCommentURL" attribute="Comment URL" String="\bhttps?://(?=[^\s<>"'`])" /> | ||||
211 | <IncludeRules context="DefaultComment" /> | ||||
212 | </context> | ||||
213 | <context name="DefaultComment" attribute="Comment" lineEndContext="#stay"> | ||||
214 | <RegExpr context="#stay" attribute="Comment URL" String="(([^<>\(\)\[\]\\\.,;:\s@"]+(\.[^<>\(\)\[\]\\\.,;:\s@"]+)*)|("[^"]+"))@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}])|(([a-zA-Z\-\d]+\.)+[a-zA-Z]{2,}))\b" /> <!-- Detect e-mail (Source: http://emailregex.com) --> | ||||
215 | </context> | ||||
216 | <context name="SingleLineCommentURL" attribute="Comment URL" lineEndContext="#pop#pop"> | ||||
217 | <DetectSpaces context="#pop" attribute="Comment" lookAhead="true" /> | ||||
218 | <AnyChar context="#pop" attribute="Comment" String="<>"'`" lookAhead="true" /> | ||||
219 | <RegExpr context="#pop" attribute="Comment" String="[\}\)\]\.,;\|]+([\s<>"'`]|$)" lookAhead="true" /> | ||||
220 | </context> | ||||
221 | <context name="MultiInlineCommentURL" attribute="Comment URL" lineEndContext="#pop"> | ||||
222 | <Detect2Chars context="#pop" attribute="Comment" char="*" char1="/" lookAhead="true" /> | ||||
223 | <RegExpr context="#pop" attribute="Comment" String="[\}\)\]\.,;\|]+\*/" lookAhead="true" /> | ||||
224 | <IncludeRules context="SingleLineCommentURL" /> | ||||
225 | </context> | ||||
226 | | ||||
227 | </contexts> | ||||
228 | | ||||
229 | <itemDatas> | ||||
230 | <itemData name="Normal Text" defStyleNum="dsNormal" spellChecking="false" /> | ||||
231 | <itemData name="Comment" defStyleNum="dsComment" /> | ||||
232 | | ||||
233 | <itemData name="Tag Content Text" defStyleNum="dsNormal" /> | ||||
234 | <itemData name="Element Tag" defStyleNum="dsKeyword" spellChecking="false" /> | ||||
235 | <itemData name="Component Tag" defStyleNum="dsFunction" bold="1" spellChecking="false" /> | ||||
236 | <itemData name="Attribute" defStyleNum="dsOthers" spellChecking="false" /> | ||||
237 | <itemData name="Value" defStyleNum="dsString" spellChecking="false" /> | ||||
238 | <itemData name="EntityRef" defStyleNum="dsDecVal" spellChecking="false" /> | ||||
239 | <itemData name="Code Brackets" defStyleNum="dsVariable" spellChecking="false" /> | ||||
240 | <itemData name="Error" defStyleNum="dsError" spellChecking="false" /> | ||||
241 | <itemData name="Comment URL" defStyleNum="dsComment" underline="1" spellChecking="false" /> | ||||
242 | | ||||
243 | <!-- itemDatas in JavaScript XML file --> | ||||
244 | <itemData name="Symbol" defStyleNum="dsOperator" /> | ||||
245 | <itemData name="ControlFlow" defStyleNum="dsControlFlow" spellChecking="false" /> | ||||
246 | <itemData name="Module" defStyleNum="dsImport" spellChecking="false" /> | ||||
247 | <itemData name="Template" defStyleNum="dsVerbatimString" /> | ||||
248 | <itemData name="Substitution" defStyleNum="dsSpecialChar" spellChecking="false" /> | ||||
249 | </itemDatas> | ||||
250 | | ||||
251 | </highlighting> | ||||
252 | | ||||
253 | <general> | ||||
254 | <keywords casesensitive="1" /> | ||||
255 | <comments> | ||||
256 | <comment name="singleLine" start="//" /> | ||||
257 | <comment name="multiLine" start="/*" end="*/" /> | ||||
258 | </comments> | ||||
259 | </general> | ||||
260 | | ||||
261 | </language> |