-
Notifications
You must be signed in to change notification settings - Fork 10
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
Formatter - initial basic implementation #144
Merged
Conversation
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
and implement a few more formatting rules
To allow the unicode conversion branch to handle it
This is the job of the VS Code extension (not LSP)
Refine "single character token" condition with "is punctuation"
To handle multiple consecutive allowed characters w/o a space in between
fizruk
approved these changes
Dec 8, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements a very basic formatter that scans the lexical tokens for some known patterns and applies text edits to have them adhere to the style guide. The code is still in an early stage and can definitely be improved a lot, so a code review would be tremendously helpful.
Also, an issue was discovered with LSP's VFS wherein it includes carriage return (
\r
) character on Windows, causing issues with the parser. A workaround has been added (filter (/= '\r')
), but can probably be improved.Notable features
:
) and construction (body, starting with:=
) on new lines\
of a lambda term and around binary operators (like,
)rzk format
) with--check
and--write
optionsKnown limitations
Moving binary operators from the end of the line to the beginning of the next is not yet implemented. Edit: Implemented for,
and->
. What other binary operators are needed?#define
(and its alias#def
) are handled yet.I will open separate issues to work on these in the future.
Possible inconsistencies in the style guide
These may not be inconsistencies as much as a lack of understand on my side, but I'd like to understand either way:
( ( a-term-of-a-type) ...)
(with a space after the inner paren), while another is written as( (x : A) ...)
(without a space before thex
)Regarding the same recommendation about space in opening parentheses, it seems that it only applies when that open paren is the first character in its line. For example, it appears as(mostly clarified in Auto-format all files sHoTT#142 (comment) and partially implemented): (x = z)
in the type. However, in the sHoTT repo itself, a definition has: ( concat A w x z p ...)
with a space after the paren. Which one should it be?Planned improvements
rzk.yaml
, but possible also.vscode/settings.json
) for controlling options like auto-replacement of ASCII sequences, line width, ...A pull request to the sHoTT repo (and others) will follow after more work is done into stabilizing the formatter and implementing more rules.