|
251 | 251 | "}" @interior.end.startOf @branch.iteration.end.startOf @condition.iteration.end.startOf |
252 | 252 | ) @value.domain |
253 | 253 |
|
254 | | -;; The outermost if statement |
| 254 | +;;!! if () {} else {} |
255 | 255 | ( |
256 | 256 | (if_statement) @ifStatement @statement @branch.iteration |
257 | 257 | (#not-parent-type? @ifStatement if_statement) |
258 | 258 | ) |
259 | 259 |
|
260 | | -;; first if in an if-else chain |
| 260 | +;;!! if () {} |
261 | 261 | ( |
262 | 262 | (if_statement |
263 | | - consequence: (block) @branch.end.endOf |
264 | | - ) @branch.start.startOf |
265 | | - (#not-parent-type? @branch.start.startOf if_statement) |
266 | | - (#insertion-delimiter! @branch.start.startOf " ") |
| 263 | + "if" @branch.start @branch.removal.start |
| 264 | + condition: (_) @condition |
| 265 | + consequence: (_) @branch.end @branch.removal.end |
| 266 | + "else"? @branch.removal.end.startOf |
| 267 | + alternative: (if_statement)? @branch.removal.end.startOf |
| 268 | + ) @condition.domain |
| 269 | + (#not-parent-type? @condition.domain if_statement) |
| 270 | + (#insertion-delimiter! @branch.start " ") |
| 271 | + (#shrink-to-match! @condition "^\\(?(?<keep>[^)]*)\\)?$") |
267 | 272 | ) |
268 | 273 |
|
269 | | -;; internal if in an if-else chain |
| 274 | +;;!! else if () {} |
270 | 275 | (if_statement |
271 | | - "else" @branch.start |
| 276 | + "else" @branch.start @condition.domain.start |
272 | 277 | alternative: (if_statement |
273 | | - consequence: (block) @branch.end |
| 278 | + condition: (_) @condition |
| 279 | + consequence: (_) @branch.end @condition.domain.end |
274 | 280 | ) |
275 | 281 | (#insertion-delimiter! @branch.start " ") |
| 282 | + (#shrink-to-match! @condition "^\\(?(?<keep>[^)]*)\\)?$") |
276 | 283 | ) |
277 | 284 |
|
278 | | -;; final else branch in an if-else chain |
279 | | -( |
280 | | - (if_statement |
281 | | - "else" @branch.start.startOf |
282 | | - alternative: (block) |
283 | | - ) @branch.end.endOf |
284 | | - (#insertion-delimiter! @branch.start.startOf " ") |
| 285 | +;;!! else {} |
| 286 | + |
| 287 | +(if_statement |
| 288 | + "else" @branch.start |
| 289 | + alternative: (block) @branch.end |
| 290 | + (#insertion-delimiter! @branch.start " ") |
285 | 291 | ) |
286 | 292 |
|
287 | 293 | [ |
|
356 | 362 | result: (_) @type |
357 | 363 | ) @_.domain |
358 | 364 |
|
359 | | -;;!! if true {} |
360 | | -( |
361 | | - (_ |
362 | | - condition: (_) @condition |
363 | | - ) @_.domain |
364 | | - (#not-type? @condition parenthesized_expression) |
365 | | - (#not-type? @_.domain for_clause) |
366 | | -) |
367 | | - |
368 | | -;;!! if (true) {} |
369 | | -( |
370 | | - (_ |
371 | | - condition: (parenthesized_expression) @condition |
372 | | - ) @_.domain |
373 | | - (#child-range! @condition 0 -1 true true) |
374 | | -) |
375 | | - |
376 | 365 | ;;!! for i := 0; i < size; i++ {} |
377 | 366 | ;;! ^^^^^^^^ |
378 | 367 | (for_statement |
|
0 commit comments