Fix empty lines & trailing comments #278
Merged
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.
Fixes #244
Fixes #277
I think I finally figured out a way to make comments and empty lines more usable. This hinges on refactoring the representation of completely empty lines vs. comment lines that terminate immediately after the
#
.At the moment, empty lines in source are parsed into
spaceBefore
boolean values or completely dropped, and comments consisting of just a#
are represented by an empty line in thecomment
orcommentBefore
value.However, let's change that a bit. With this PR, an empty line in the source is represented by an empty line in the
comment
orcommentBefore
value, and a bare#
is represented by a line consisting of a single space character. This relatively small change allows for any combination of comment and blank lines to be cleanly represented by a single string, with the cost of a comment consisting of a single space character being unrepresentable.At least for now, an empty line before comments remains represented as the boolean
spaceBefore
property, but that property could be dropped entirely as it's equivalent to acommentBefore
value of'\n'
.Simultaneously, the handling of trailing comments is simplified somewhat; they now need to be more indented than their parent collection to attach to the preceding rather than the following node.