-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch changes the parsed syntax tree normalization with the goal of simplifying the formatting code. JuliaSyntax is not very consistent with where whitespace ends up which make formatting tricky since you always have to "peek" into the next node (sometimes multiple levels) to check if the next leaf is e.g. whitespace. This patch reworks the normalization to "bubble up" whitespace so that all nodes start and end with a non-whitespace node. For example, given `a + b * c`, the output from JuliaSyntax is: ``` [call] Identifier Whitespace + [call] Whitespace Identifier Whitespace * Whitespace Identifier ``` and now after normalization the leading whitespace of the `*`-call is bubbled up: ``` [call] Identifier Whitespace + Whitespace [call] Identifier Whitespace * Whitespace Identifier ``` As seen from the diff, this make it possible to remove a lot of complicated code that were necessary to handle the random whitespace placement. In particular, there is no need to peek into the nodes to check for whitespace. As a bonus, this fixes two issues: - `global\n\n x = 1` would previously not indent correctly because we had to double-peek (first into the `=` node, then into the LHS node). - `runic: (off|on) toggling within array literals. Previously the toggle comments would end up inside the `row` nodes so in the tree they weren't on the same "level" which is required for the toggling.
- Loading branch information
1 parent
91fff16
commit 36f65aa
Showing
3 changed files
with
292 additions
and
423 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
Oops, something went wrong.