-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
3275f51
commit a94c996
Showing
5 changed files
with
65,969 additions
and
64,747 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.