Commit 3346c07
committed
remake else if as repeat($._else_clause)
Before, it looked like this:
```
if ... {
} else if let ... = ... {
} else if ... {
} else {
}
(if_expression ... consequence: (block)
alternative: (else_clause (if_let_expression ... consequence: (block)
alternative: (else_clause (if_expression consequence: (block)
alternative: (else_clause (block)))))))
```
After, it looks like this:
```
if ... {
} else if let ... = ... {
} else if ... {
} else {
}
(if_expression condition: ... consequence: (block)
(else_if_let_clause pattern: ... value: ... consequence: (block))
(else_if_clause condition: ... consequence: (block))
(else_clause (block)))
```
Previously, the "else" and "if" were not adjacent tokens, and therefore
could not be grouped together in an `("else" "if") @match` query.
The main motivation here is highlighting each if/else if/else branch
with vim-matchup.
It was also difficult to query only a complete if/else expression, and
exclude if_expressions that were simply the "if" in an "else if". It is
maybe wrong to say that the latter is actually an expression, but
moreover if you wanted to query only the former, you would have to
either list all the contexts where an if_expression can occur (except
else_clause) or use an #if-not? to exclude the
`(else_clause (if_expression) @not_this)`. Again, the motivation is
attempting to navigate between if/else branches in the editor using vim
matchup, which requires matching one single `(if_expression) @scope.if`
to link all the branches to, and not creating a bunch of smaller scopes
on all the if_expressions contained within.
The resulting tree is flatter. There is no need for the alternative:
field name as each of the three clause types can only appear in the tail
of an if[_let]_expression. And both of the above problems are solved.1 parent a3e6768 commit 3346c07
File tree
5 files changed
+64829
-62164
lines changed- corpus
- src
5 files changed
+64829
-62164
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
| 335 | + | |
| 336 | + | |
335 | 337 | | |
| 338 | + | |
336 | 339 | | |
337 | 340 | | |
338 | 341 | | |
| |||
348 | 351 | | |
349 | 352 | | |
350 | 353 | | |
351 | | - | |
352 | | - | |
353 | | - | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
354 | 358 | | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
362 | 367 | | |
363 | 368 | | |
364 | 369 | | |
365 | | - | |
366 | | - | |
367 | | - | |
| 370 | + | |
368 | 371 | | |
369 | | - | |
| 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 | + | |
370 | 405 | | |
371 | 406 | | |
372 | | - | |
| 407 | + | |
373 | 408 | | |
374 | 409 | | |
375 | 410 | | |
| |||
798 | 833 | | |
799 | 834 | | |
800 | 835 | | |
801 | | - | |
| 836 | + | |
802 | 837 | | |
803 | 838 | | |
804 | 839 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
1069 | 1070 | | |
1070 | 1071 | | |
1071 | 1072 | | |
1072 | | - | |
| 1073 | + | |
1073 | 1074 | | |
1074 | 1075 | | |
1075 | 1076 | | |
| |||
1079 | 1080 | | |
1080 | 1081 | | |
1081 | 1082 | | |
1082 | | - | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
1083 | 1107 | | |
1084 | 1108 | | |
1085 | 1109 | | |
1086 | 1110 | | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
| 1111 | + | |
1092 | 1112 | | |
1093 | 1113 | | |
1094 | 1114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6190 | 6190 | | |
6191 | 6191 | | |
6192 | 6192 | | |
6193 | | - | |
6194 | | - | |
6195 | | - | |
6196 | | - | |
6197 | | - | |
6198 | | - | |
6199 | | - | |
6200 | | - | |
6201 | | - | |
6202 | | - | |
6203 | | - | |
6204 | | - | |
6205 | | - | |
6206 | | - | |
| 6193 | + | |
| 6194 | + | |
| 6195 | + | |
| 6196 | + | |
| 6197 | + | |
6207 | 6198 | | |
6208 | 6199 | | |
6209 | 6200 | | |
| |||
6247 | 6238 | | |
6248 | 6239 | | |
6249 | 6240 | | |
6250 | | - | |
6251 | | - | |
6252 | | - | |
6253 | | - | |
6254 | | - | |
6255 | | - | |
6256 | | - | |
6257 | | - | |
6258 | | - | |
6259 | | - | |
6260 | | - | |
6261 | | - | |
6262 | | - | |
6263 | | - | |
| 6241 | + | |
| 6242 | + | |
| 6243 | + | |
| 6244 | + | |
| 6245 | + | |
| 6246 | + | |
| 6247 | + | |
| 6248 | + | |
| 6249 | + | |
| 6250 | + | |
| 6251 | + | |
| 6252 | + | |
| 6253 | + | |
| 6254 | + | |
| 6255 | + | |
| 6256 | + | |
| 6257 | + | |
| 6258 | + | |
| 6259 | + | |
| 6260 | + | |
| 6261 | + | |
| 6262 | + | |
| 6263 | + | |
| 6264 | + | |
| 6265 | + | |
| 6266 | + | |
| 6267 | + | |
| 6268 | + | |
| 6269 | + | |
| 6270 | + | |
| 6271 | + | |
| 6272 | + | |
| 6273 | + | |
| 6274 | + | |
| 6275 | + | |
| 6276 | + | |
| 6277 | + | |
| 6278 | + | |
| 6279 | + | |
| 6280 | + | |
| 6281 | + | |
| 6282 | + | |
| 6283 | + | |
| 6284 | + | |
| 6285 | + | |
| 6286 | + | |
| 6287 | + | |
| 6288 | + | |
| 6289 | + | |
| 6290 | + | |
| 6291 | + | |
| 6292 | + | |
| 6293 | + | |
| 6294 | + | |
| 6295 | + | |
| 6296 | + | |
| 6297 | + | |
| 6298 | + | |
| 6299 | + | |
| 6300 | + | |
| 6301 | + | |
| 6302 | + | |
| 6303 | + | |
| 6304 | + | |
| 6305 | + | |
| 6306 | + | |
| 6307 | + | |
| 6308 | + | |
| 6309 | + | |
| 6310 | + | |
| 6311 | + | |
| 6312 | + | |
| 6313 | + | |
| 6314 | + | |
| 6315 | + | |
| 6316 | + | |
| 6317 | + | |
| 6318 | + | |
| 6319 | + | |
| 6320 | + | |
| 6321 | + | |
| 6322 | + | |
| 6323 | + | |
| 6324 | + | |
| 6325 | + | |
| 6326 | + | |
| 6327 | + | |
| 6328 | + | |
| 6329 | + | |
| 6330 | + | |
| 6331 | + | |
| 6332 | + | |
| 6333 | + | |
| 6334 | + | |
| 6335 | + | |
| 6336 | + | |
6264 | 6337 | | |
6265 | 6338 | | |
6266 | 6339 | | |
| |||
6272 | 6345 | | |
6273 | 6346 | | |
6274 | 6347 | | |
6275 | | - | |
6276 | | - | |
6277 | | - | |
6278 | | - | |
6279 | | - | |
6280 | | - | |
6281 | | - | |
6282 | | - | |
6283 | | - | |
6284 | | - | |
6285 | | - | |
6286 | | - | |
6287 | | - | |
6288 | | - | |
6289 | | - | |
| 6348 | + | |
| 6349 | + | |
6290 | 6350 | | |
6291 | 6351 | | |
6292 | 6352 | | |
| |||
8348 | 8408 | | |
8349 | 8409 | | |
8350 | 8410 | | |
8351 | | - | |
| 8411 | + | |
| 8412 | + | |
8352 | 8413 | | |
8353 | 8414 | | |
8354 | 8415 | | |
0 commit comments