1<?xml version="1.0" encoding="UTF-8"?> 2<!-- 3 4 This file is part of GtkSourceView 5 6 Copyright (C) 2003 Gustavo Giráldez <gustavo.giraldez@gmx.net> 7 Copyright (C) 2006 Jeff Walden <jwalden@mit.edu> 8 Copyright (C) 2017 Roman Donchenko 9 10 GtkSourceView is free software; you can redistribute it and/or 11 modify it under the terms of the GNU Lesser General Public 12 License as published by the Free Software Foundation; either 13 version 2.1 of the License, or (at your option) any later version. 14 15 GtkSourceView is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 Lesser General Public License for more details. 19 20 You should have received a copy of the GNU Lesser General Public License 21 along with this library; if not, see <http://www.gnu.org/licenses/>. 22 23--> 24<language id="groovy" name="Groovy" version="2.0" _section="Source"> 25 <metadata> 26 <property name="globs">*.groovy</property> 27 <property name="line-comment-start">//</property> 28 <property name="block-comment-start">/*</property> 29 <property name="block-comment-end">*/</property> 30 </metadata> 31 32 <styles> 33 <style id="comment" name="Comment" map-to="def:comment"/> 34 <style id="escaped-character" name="Escaped Character" map-to="def:special-char"/> 35 <style id="interpolation" name="Interpolation Syntax" map-to="def:special-char"/> 36 <style id="interpolated" name="Interpolated Expression" map-to="def:identifier"/> 37 <style id="string" name="String" map-to="def:string"/> 38 <style id="external" name="External" map-to="def:preprocessor"/> 39 <style id="declaration" name="Declaration" map-to="def:type"/> 40 <style id="storage-class" name="Storage Class" map-to="def:type"/> 41 <style id="scope-declaration" name="Scope Declaration" map-to="def:type"/> 42 <style id="operator" name="Operator" map-to="def:operator"/> 43 <style id="keyword" name="Keyword" map-to="def:keyword"/> 44 <style id="null-value" name="Null Value" map-to="def:special-constant"/> 45 <style id="boolean" name="Boolean value" map-to="def:boolean"/> 46 <style id="number" name="Number" map-to="def:number"/> 47 <style id="type" name="Data Type" map-to="def:type"/> 48 </styles> 49 50 <definitions> 51 <define-regex id="escaped-character" extended="true"> 52 \\( 53 # character escape 54 [nrtbf"'\\$] | 55 # unicode escape 56 u[0-9A-Fa-f]{4} | 57 # octal escape 58 [0-3] ([0-7] [0-7]?)? | [4-7] [0-7]? 59 ) 60 </define-regex> 61 62 <define-regex id="letter" extended="true"> 63 [a-zA-Z\x{c0}-\x{d6}\x{d8}-\x{f6}\x{f8}-\x{ff}\x{100}-\x{fffe}_] 64 </define-regex> 65 66 <context id="escaped-character"> 67 <include> 68 <context style-ref="escaped-character"> 69 <match>\%{escaped-character}</match> 70 </context> 71 <context ref="def:line-continue"/> 72 <context style-ref="def:error"> 73 <!-- backslashes not part of a valid escape sequence are erroneous --> 74 <match>\\</match> 75 </context> 76 </include> 77 </context> 78 79 <context id="placeholder"> 80 <include> 81 <context style-ref="interpolated"> 82 <match extended="true"> 83 (\$) 84 # one or more dollarless identifiers separated by dots 85 \%{letter} (\%{letter} | \d)* 86 (\. \%{letter} (\%{letter} | \d)*)* 87 </match> 88 <include> 89 <context sub-pattern="1" style-ref="interpolation"/> 90 </include> 91 </context> 92 <context style-ref="interpolated"> 93 <start>\$\{</start> 94 <end>\}</end> 95 <include> 96 <context sub-pattern="0" where="start" style-ref="interpolation"/> 97 <context sub-pattern="0" where="end" style-ref="interpolation"/> 98 <context ref="groovy"/> 99 </include> 100 </context> 101 </include> 102 </context> 103 104 <!-- a dollar that isn't part of a placeholder is erroneous in some instances --> 105 <context id="bad-placeholder" style-ref="def:error"> 106 <match>\$</match> 107 </context> 108 109 <context id="triple-single-quoted-string" style-ref="string" class="string" class-disabled="no-spell-check"> 110 <start>'''</start> 111 <end>'''</end> 112 <include> 113 <context ref="escaped-character"/> 114 </include> 115 </context> 116 117 <context id="single-quoted-string" end-at-line-end="true" style-ref="string" class="string" class-disabled="no-spell-check"> 118 <start>'</start> 119 <end>'</end> 120 <include> 121 <context ref="escaped-character"/> 122 </include> 123 </context> 124 125 <context id="triple-double-quoted-string" style-ref="string" class="string" class-disabled="no-spell-check"> 126 <start>"""</start> 127 <end>"""</end> 128 <include> 129 <context ref="escaped-character"/> 130 <context ref="placeholder"/> 131 <context ref="bad-placeholder"/> 132 </include> 133 </context> 134 135 <context id="double-quoted-string" end-at-line-end="true" style-ref="string" class="string" class-disabled="no-spell-check"> 136 <start>"</start> 137 <end>"</end> 138 <include> 139 <context ref="escaped-character"/> 140 <context ref="placeholder"/> 141 <context ref="bad-placeholder"/> 142 </include> 143 </context> 144 145 <context id="slashy-string" style-ref="string" class="string"> 146 <start extended="true"> 147 # The initial slash must not be preceded by a token that can end an expression. 148 # Otherwise, it's interpreted as a division operator, not the start of a slashy string. 149 # It'd be complicated to verify whole tokens with a regex, but the last non-space 150 # character is a good indicator by itself. We can use a negative lookbehind assertion 151 # to verify that it's not a character that an expression-ending token can end with. 152 153 # Trouble is, a lookbehind assertion has to consist of fixed-length alternatives, so 154 # we can't have it match an arbitrary amount of whitespace. Thus, we do an approximate 155 # check, only trying zero and one spaces. 156 157 (?<! \+\+ | -- | [])}'"\$\d] | \%{letter} | 158 \+\+\s | --\s | [])}'"\$\d]\s | \%{letter}\s ) 159 160 / 161 </start> 162 <end>/</end> 163 <include> 164 <context style-ref="escaped-character"> 165 <match>\\/</match> 166 </context> 167 <context ref="def:line-continue"/> 168 <context ref="placeholder"/> 169 <!-- standalone dollars and backslashes are interpreted literally --> 170 </include> 171 </context> 172 173 <context id="dollar-slashy-string" style-ref="string" class="string"> 174 <start extended="true"> 175 \$/ 176 177 # Dollar slashy strings can't be empty (a would-be empty one is parsed 178 # as a dollar followed by a single-line comment instead). 179 (?! /\$) 180 </start> 181 <end>/\$</end> 182 <include> 183 <context style-ref="escaped-character"> 184 <match>\$[$/]</match> 185 </context> 186 <context ref="def:line-continue"/> 187 <context ref="placeholder"/> 188 </include> 189 </context> 190 191 <context id="numeric" style-ref="number"> 192 <match extended="true"> 193 \b ( 194 # floating-point 195 \d ([\d_]* \d)? ( 196 \. \d ([\d_]* \d)? ([eE] [+-]? [\d_]* \d)? [dDfFgG]? | 197 [eE] [+-]? [\d_]* \d [dDfFgG]? | 198 [dDfF] 199 ) | 200 # integer 201 ( 202 0 | # decimal zero 203 0[bB] [01] ([01_]* [01])? | # binary 204 0 [0-7] ([0-7_]* [0-7])? | # octal 205 [1-9] ([\d_]* \d)? | # decimal 206 0[xX] [\da-fA-F] ([\da-fA-F_]* [\da-fA-F])? # hexadecimal 207 ) [iIlLgG]? 208 ) \b 209 </match> 210 </context> 211 212 <!-- 213 Some of the Java keywords are reserved in Groovy. We don't mark them 214 with a special style, though, because in some instances keywords can 215 be used as identifiers (e.g. when used as a member name), and even 216 reserved keywords are valid when used like that. 217 --> 218 219 <context id="externals" style-ref="external"> 220 <keyword>import</keyword> 221 <keyword>package</keyword> 222 </context> 223 224 <context id="declarations" style-ref="declaration"> 225 <keyword>class</keyword> 226 <keyword>enum</keyword> 227 <keyword>extends</keyword> 228 <keyword>implements</keyword> 229 <keyword>interface</keyword> 230 <keyword>native</keyword> 231 <keyword>throws</keyword> 232 <keyword>trait</keyword> 233 </context> 234 235 <context id="primitive-types" style-ref="type"> 236 <keyword>boolean</keyword> 237 <keyword>byte</keyword> 238 <keyword>char</keyword> 239 <keyword>def</keyword> 240 <keyword>double</keyword> 241 <keyword>float</keyword> 242 <keyword>int</keyword> 243 <keyword>long</keyword> 244 <keyword>short</keyword> 245 <keyword>void</keyword> 246 </context> 247 248 <context id="storage-class" style-ref="storage-class"> 249 <keyword>abstract</keyword> 250 <keyword>const</keyword> 251 <keyword>final</keyword> 252 <keyword>static</keyword> 253 <keyword>strictfp</keyword> 254 <keyword>synchronized</keyword> 255 <keyword>transient</keyword> 256 <keyword>volatile</keyword> 257 </context> 258 259 <context id="scope-declarations" style-ref="scope-declaration"> 260 <keyword>private</keyword> 261 <keyword>protected</keyword> 262 <keyword>public</keyword> 263 </context> 264 265 <context id="flow" style-ref="keyword"> 266 <keyword>assert</keyword> 267 <keyword>break</keyword> 268 <keyword>case</keyword> 269 <keyword>catch</keyword> 270 <keyword>continue</keyword> 271 <keyword>default</keyword> 272 <keyword>do</keyword> 273 <keyword>else</keyword> 274 <keyword>finally</keyword> 275 <keyword>for</keyword> 276 <keyword>goto</keyword> 277 <keyword>if</keyword> 278 <keyword>return</keyword> 279 <keyword>throw</keyword> 280 <keyword>switch</keyword> 281 <keyword>try</keyword> 282 <keyword>while</keyword> 283 </context> 284 285 <context id="operator" style-ref="operator"> 286 <keyword>as</keyword> 287 <keyword>in</keyword> 288 <keyword>instanceof</keyword> 289 <keyword>new</keyword> 290 <keyword>super</keyword> 291 <keyword>this</keyword> 292 </context> 293 294 <context id="null-value" style-ref="null-value"> 295 <keyword>null</keyword> 296 </context> 297 298 <context id="boolean" style-ref="boolean"> 299 <keyword>false</keyword> 300 <keyword>true</keyword> 301 </context> 302 303 <context id="groovy" class="no-spell-check"> 304 <include> 305 <context ref="def:shebang" style-ref="comment"/> 306 <context ref="def:c-like-comment" style-ref="comment"/> 307 <context ref="def:c-like-comment-multiline" style-ref="comment"/> 308 <context ref="def:line-continue"/> 309 310 <context ref="triple-single-quoted-string"/> 311 <context ref="single-quoted-string"/> 312 <context ref="triple-double-quoted-string"/> 313 <context ref="double-quoted-string"/> 314 <context ref="slashy-string"/> 315 <context ref="dollar-slashy-string"/> 316 <context ref="numeric"/> 317 318 <context ref="externals"/> 319 <context ref="declarations"/> 320 <context ref="primitive-types"/> 321 <context ref="storage-class"/> 322 <context ref="scope-declarations"/> 323 <context ref="flow"/> 324 <context ref="operator"/> 325 <context ref="null-value"/> 326 <context ref="boolean"/> 327 </include> 328 </context> 329 </definitions> 330</language> 331