brittany icon indicating copy to clipboard operation
brittany copied to clipboard

Formatting comments with semicolon newlines

Open bredelings opened this issue 4 years ago • 0 comments

Hi, thank you for implementing newlines for semicolons! This might be more complicated, but I wonder if it might be possible to handle comments intermingled with the semicolons.

Suppose we have

do {
; A
;
;-- This is a comment
;
; B
}

Right now this gets indented like this:

do
   A--This is a comment
   B

First, it seems that if there are any comments mixed in with the semicolons, then the comments are retained, but the newlines are lost. Would it be possible to make the semi-colon -> newline translation work when there are comments embedded?

(Note, I think in some cases A--comment would not be parsed as a comment, but if we have e.g. let x=y--comment, then --comment is indeed parsed as a comment.)

Second, this might be too messy, but would it be possible to handle cases where we have a line like

;--comment

and indent the comment to the level of the ;?

My apologies for the complication, but would be useful (to me at least) when trying to generate Haskell code with comments. That is, ideally, I would be able to write

do {
;-- part 1
;A
;
;-- part 2
;B
}

and get

do
  -- part 1
  A

  --part 2
  B

bredelings avatar Dec 10 '19 19:12 bredelings