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

Tests: Better pretty print #2600

Merged

Conversation

RunDevelopment
Copy link
Member

@RunDevelopment RunDevelopment commented Oct 23, 2020

This is a major improvement for the pretty-printer.

The main change is that TokenStreamTransformer.prettyprint now takes a Prism token stream instead of a simplified token stream. This means that it has a lot more information to work with and it uses that information.

It mostly behaves like the old pretty-printer with 3 main differences:

  1. Tokens that contain a nested token stream that only contains a single string are printed as one line.
    Example: ["namespace", ["java"]]
  2. The pretty-printer can now glue tokens together so that they are printed in a single line.
    Example: ["number", "100"], ["operator", ".."], ["number", "100"]
  3. Line breaks in the input code may now cause empty lines in the output. Previously, only blank strings containing more at least 2 line breaks produce empty lines. This helps readability as it groups tokens together.

If anyone wants to know about how it works in detail, I'll explain, but it's a bit much so I won't do so here.


I also want to ask whether I should reformat all .test files.
The pretty-printer is quite good and it would be nice if all test files were formatted consistently. However, 50% of all test files change when reformatted.

@RunDevelopment RunDevelopment merged commit 8bfcc81 into PrismJS:master Nov 21, 2020
@RunDevelopment RunDevelopment deleted the test-better-pretty-print branch November 21, 2020 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant