Commit a94c996
committed
remake else if as repeat($.else_clause)
Before, it looked like this:
``` if ... {
} else if let ... = ... {
} else if ... {
} else {
}
(if_expression condition: ... consequence: (block)
alternative: (else_clause (if_expression condition: (let_condition pattern: ... value: ...)
consequence: (block)
alternative: (else_clause (if_expression condition: ... consequence: (block)
alternative: (else_clause (block)))))))
```
After, it looks like this:
``` if ... {
} else if let ... = ... {
} else if ... {
} else {
}
(if_expression condition: ... consequence: (block)
(else_clause condition: (let_condition pattern: ... value: ...)
consequence: (block))
(else_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 (else_clause) only appears in the tail of an
(if_expression) and never at the top level in the condition/consequence, hence writing (else_clause) in a query unambiguously selects nodes at the tail. And the previous two problems are solved:
- `(else_clause "else" "if")` can match now, and it will not match a
final `else {}` clause. Previously it was an impossible pattern.
- `(if_expression)` will only match once in a chain of `if {} else if {}
...`s, with the match over the entire expression. No need for hacky
tricks to avoid matches on inner `if_expression`s.1 parent 3275f51 commit a94c996
File tree
5 files changed
+65969
-64747
lines changed- corpus
- src
5 files changed
+65969
-64747
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
| 484 | + | |
| 485 | + | |
484 | 486 | | |
| 487 | + | |
485 | 488 | | |
486 | 489 | | |
487 | 490 | | |
| |||
502 | 505 | | |
503 | 506 | | |
504 | 507 | | |
505 | | - | |
506 | | - | |
507 | | - | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
508 | 513 | | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
517 | 524 | | |
518 | 525 | | |
519 | 526 | | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | | - | |
526 | | - | |
527 | | - | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
528 | 530 | | |
529 | 531 | | |
530 | | - | |
531 | | - | |
532 | | - | |
| 532 | + | |
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
536 | 536 | | |
537 | | - | |
538 | | - | |
539 | | - | |
| 537 | + | |
540 | 538 | | |
541 | 539 | | |
542 | 540 | | |
| |||
558 | 556 | | |
559 | 557 | | |
560 | 558 | | |
561 | | - | |
562 | | - | |
563 | | - | |
| 559 | + | |
564 | 560 | | |
565 | 561 | | |
566 | 562 | | |
567 | 563 | | |
568 | | - | |
569 | | - | |
570 | | - | |
| 564 | + | |
571 | 565 | | |
572 | 566 | | |
573 | 567 | | |
574 | 568 | | |
575 | 569 | | |
576 | 570 | | |
577 | 571 | | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
578 | 605 | | |
579 | 606 | | |
580 | 607 | | |
| |||
1270 | 1297 | | |
1271 | 1298 | | |
1272 | 1299 | | |
1273 | | - | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
| 1300 | + | |
1277 | 1301 | | |
1278 | 1302 | | |
1279 | 1303 | | |
| |||
1285 | 1309 | | |
1286 | 1310 | | |
1287 | 1311 | | |
1288 | | - | |
1289 | | - | |
1290 | | - | |
| 1312 | + | |
1291 | 1313 | | |
1292 | 1314 | | |
1293 | 1315 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1096 | 1096 | | |
1097 | 1097 | | |
1098 | 1098 | | |
1099 | | - | |
| 1099 | + | |
1100 | 1100 | | |
1101 | 1101 | | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
1102 | 1122 | | |
1103 | 1123 | | |
1104 | 1124 | | |
| |||
1114 | 1134 | | |
1115 | 1135 | | |
1116 | 1136 | | |
1117 | | - | |
1118 | | - | |
1119 | | - | |
1120 | | - | |
1121 | | - | |
1122 | | - | |
1123 | | - | |
1124 | | - | |
1125 | | - | |
1126 | | - | |
1127 | | - | |
1128 | | - | |
1129 | | - | |
1130 | | - | |
1131 | 1137 | | |
1132 | 1138 | | |
1133 | 1139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6337 | 6337 | | |
6338 | 6338 | | |
6339 | 6339 | | |
6340 | | - | |
6341 | | - | |
6342 | | - | |
6343 | | - | |
6344 | | - | |
6345 | | - | |
6346 | | - | |
6347 | | - | |
6348 | | - | |
6349 | | - | |
6350 | | - | |
6351 | | - | |
6352 | | - | |
6353 | | - | |
| 6340 | + | |
| 6341 | + | |
| 6342 | + | |
| 6343 | + | |
| 6344 | + | |
6354 | 6345 | | |
6355 | 6346 | | |
6356 | 6347 | | |
6357 | 6348 | | |
| 6349 | + | |
| 6350 | + | |
| 6351 | + | |
| 6352 | + | |
| 6353 | + | |
| 6354 | + | |
| 6355 | + | |
| 6356 | + | |
| 6357 | + | |
| 6358 | + | |
| 6359 | + | |
| 6360 | + | |
| 6361 | + | |
| 6362 | + | |
| 6363 | + | |
| 6364 | + | |
| 6365 | + | |
| 6366 | + | |
| 6367 | + | |
| 6368 | + | |
| 6369 | + | |
| 6370 | + | |
| 6371 | + | |
| 6372 | + | |
| 6373 | + | |
| 6374 | + | |
| 6375 | + | |
| 6376 | + | |
| 6377 | + | |
| 6378 | + | |
| 6379 | + | |
| 6380 | + | |
| 6381 | + | |
| 6382 | + | |
| 6383 | + | |
| 6384 | + | |
| 6385 | + | |
| 6386 | + | |
| 6387 | + | |
| 6388 | + | |
| 6389 | + | |
| 6390 | + | |
| 6391 | + | |
| 6392 | + | |
| 6393 | + | |
| 6394 | + | |
| 6395 | + | |
| 6396 | + | |
| 6397 | + | |
| 6398 | + | |
| 6399 | + | |
| 6400 | + | |
| 6401 | + | |
| 6402 | + | |
| 6403 | + | |
| 6404 | + | |
| 6405 | + | |
| 6406 | + | |
| 6407 | + | |
| 6408 | + | |
| 6409 | + | |
| 6410 | + | |
| 6411 | + | |
| 6412 | + | |
| 6413 | + | |
| 6414 | + | |
| 6415 | + | |
| 6416 | + | |
| 6417 | + | |
| 6418 | + | |
| 6419 | + | |
| 6420 | + | |
| 6421 | + | |
6358 | 6422 | | |
6359 | 6423 | | |
6360 | 6424 | | |
| |||
6482 | 6546 | | |
6483 | 6547 | | |
6484 | 6548 | | |
6485 | | - | |
6486 | | - | |
6487 | | - | |
6488 | | - | |
6489 | | - | |
6490 | | - | |
6491 | | - | |
6492 | | - | |
6493 | | - | |
6494 | | - | |
6495 | | - | |
6496 | | - | |
6497 | | - | |
6498 | | - | |
6499 | | - | |
6500 | | - | |
6501 | | - | |
6502 | | - | |
6503 | | - | |
6504 | | - | |
6505 | | - | |
6506 | | - | |
6507 | | - | |
6508 | | - | |
6509 | | - | |
6510 | | - | |
6511 | | - | |
6512 | | - | |
6513 | | - | |
6514 | | - | |
6515 | | - | |
6516 | | - | |
6517 | | - | |
6518 | | - | |
6519 | | - | |
6520 | | - | |
6521 | | - | |
6522 | | - | |
6523 | | - | |
6524 | | - | |
6525 | | - | |
6526 | | - | |
6527 | | - | |
6528 | | - | |
6529 | 6549 | | |
6530 | 6550 | | |
6531 | 6551 | | |
| |||
0 commit comments