Ticket #13 (closed feature request: fixed)

Opened 5 years ago

Last modified 5 years ago

Add support for comments

Reported by: nibro Owned by: nibro
Priority: blocker Milestone: Full document support
Component: other Version:
Keywords: Cc: ndmitchell@…

Description (last modified by nibro) (diff)

This is an overarching ticket that will be broken down into smaller pieces as I get closer and start picking at the details.

The overall goal is to support a round-trip parser and pretty-printer so that pretty . parse == id. This requires a number of additions to the current library:

  • The AST must be embellished with support for comments. These will not be interspersed in the actual AST (unless we want to give special treatment to Haddock comments), instead residing in a separate structure along the AST.
  • We must have a (presumably two pass) parser that handles both code and comments, and remembers exact source locations for both.
  • The pretty-printer is probably the most involved. It must print the AST and comments exactly as they were parsed, at the exact same line and column. This will probably require an entirely new pretty-printer, leaving the old one as it stands for simple usage.

There are some open issues here too, such as what to do with trailing whitespace, and what to do with tabs. I'm currently leaning towards discarding trailing whitespace and transforming tabs into 8 spaces.

Change History

Changed 5 years ago by nibro

  • description modified (diff)

Changed 5 years ago by nibro

  • component changed from parser to other

Changed 5 years ago by nicolas.pouillard@…

The first step is to keep comments.

Even if 'pretty . parse == id' could be really nice the old printer should be kept since it can serve as a prettyfier.

A simpler goal to reach is 'pretty . parse . pretty . parse == id'. Which means that we are stable on the output of the pretty-printer. This property maybe already hold though.

Changed 5 years ago by Neil Mitchell

  • cc ndmitchell@… added

There would be massive utility in just having access to the comments from the parser, even if the pretty printer does nothing with them and they're stored in a separate stream that can be referenced relative to a part of the AST.

Changed 5 years ago by nibro

'parse . pretty . parse == parse' should already hold, yes, modulo SrcLoc? information obviously. But the raw AST should be the same in both cases. I'm sure there are places where this breaks though, and it would be helpful to have the test suite track them down.

The first step for this would definitely be to make the parser store comments, disregarding the pretty-printing of them. Only once we can get a full AST and comment stream will I turn to the task of printing both together.

I agree that the old printer should be kept regardless.

Changed 5 years ago by nibro

  • status changed from new to closed
  • resolution set to fixed

Comments are now kept and supported (and we have roundtripping too!). There's only bare-bones support though, but specific issues with it should be reported as separate tickets. Case closed.

Note: See TracTickets for help on using tickets.