Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better tree normalization #101

Merged
merged 1 commit into from
Nov 20, 2024
Merged

Better tree normalization #101

merged 1 commit into from
Nov 20, 2024

Conversation

fredrikekre
Copy link
Owner

No description provided.

Copy link

codecov bot commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 97.23757% with 5 lines in your changes missing coverage. Please review.

Project coverage is 93.68%. Comparing base (91fff16) to head (041fcbf).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/runestone.jl 97.32% 3 Missing ⚠️
src/chisels.jl 97.10% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #101      +/-   ##
==========================================
+ Coverage   93.42%   93.68%   +0.25%     
==========================================
  Files           9        9              
  Lines        3712     3577     -135     
==========================================
- Hits         3468     3351     -117     
+ Misses        244      226      -18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@fredrikekre fredrikekre force-pushed the fe/normalize branch 3 times, most recently from 73ae26e to 36f65aa Compare November 20, 2024 12:43
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.
@fredrikekre fredrikekre marked this pull request as ready for review November 20, 2024 12:58
@fredrikekre fredrikekre merged commit 6eeb397 into master Nov 20, 2024
10 checks passed
@fredrikekre fredrikekre deleted the fe/normalize branch November 20, 2024 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant