Cabal Exactprint new proposal - #7
Conversation
|
Splendid. Thank you for not settling for a so-so design. Is the document standalone or does it assume the acquaintance with the two older ones or refer to them a lot? |
| representation `fl'`. | ||
|
|
||
| - - Should the field be multiple (e.g. `build-depends` or | ||
| `license-files`), For each item `it`, we swap out the old textual |
There was a problem hiding this comment.
Swap out in fl'? But it is "new" one already, no?
There was a problem hiding this comment.
I agree that this explanation is hand-wavy. I split the algorithm into two cases and added implementation examples and desired outcome. Please give it a read and let me know if it is clearer. Thank you for reviewing this :)
I wrote down all the experiments I have done in the past year in a section, and then detailed the learning for each of them in this document, so it is self contained :) |
|
My views on the open questions:
I think it is feasible to replace a line with only whitespace as a single blank line (i would prefer if blank lines stuck around, but would be comfortable with them being removed if necessary). I think removing trailing whitespaces is also fine. And I also agree that uniformly replacing tab with four spaces would be welcome, cabal already yells at us for tabs (and I think hackage rejects them), so we really shouldn't be using them.
In general I think in mixed line endings there should be an option to the pretty-printer for which to default to, which consumers (such as cabal) can then configure based on user preference or which system they are being run on. Basically, detect it in the parser so it can be inspected, and "kick the problem downstream" to consumers.
This seems fine, as long as the information is exposed to consumers. Then, as you say, the formatters can try to resolve this in their own ways. |
e1ec12b to
033db67
Compare
Awesome. It would make the exactprint task significant easier if cabal developers can agree on this choice formally.
Just to be clear, it is totally possible for the current exactprinter implementation to use either Currently the printer "prints", but is not "exact". It will use the configured lineending everywhere. In comparison, I think it would be simpler to implement exactprint for braces. The reason being that braces is clearly attached to a field or a section so we know which The idea to make the printer's lineending configurable is now implemented. It should work, but it hasn't been tested.
Awesome, thanks for the feedback. |
7062a00 to
5088cfd
Compare
|
This is the proof of concept implementation: haskell/cabal#12316 note it manages already the 99% and it's small (4.5k lines addition). that's because this approach is a lot easier todo. |
| -- | Build a @[FieldLine Position]@ modification function given a function @a -> a@, parsed as @b@. | ||
| modifyValueAtomAla | ||
| :: forall (b :: Type) (a :: Type) | ||
| . ( Newtype b a |
|
|
||
| ``` haskell | ||
| addNewDependency :: Dependency -> ([FieldLine Position] -> [FieldLine Position]) | ||
| addNewDependency = addValueList @CommaVSep @Identity @Dependency Prepend |
There was a problem hiding this comment.
| addNewDependency = addValueList @CommaVSep @Identity @Dependency Prepend | |
| addNewDependency = addValueList @CommaVSep @Identity @Dependency Append |
| ``` haskell | ||
| setBaseVersionTo :: Version -> ([FieldLine Position] -> [FieldLine Position]) | ||
| setBaseVersionTo targetVersion = modifyValueList @CommaVSep @Identity @Dependency $ \case | ||
| (Depedency pname _ libs) | pname == mkPackageName "base" -> Just (Depedency pname targetVersion libs) |
There was a problem hiding this comment.
| (Depedency pname _ libs) | pname == mkPackageName "base" -> Just (Depedency pname targetVersion libs) | |
| (Dependency pname _ libs) | pname == mkPackageName "base" -> Just (Dependency pname targetVersion libs) |
| removeDependency | ||
| :: (Dependency -> Bool) | ||
| -> ([FieldLine Position] -> [FieldLine Position]) | ||
| removeDependency = removeValueList @CommaVSep @Identity @Depedency |
There was a problem hiding this comment.
| removeDependency = removeValueList @CommaVSep @Identity @Depedency | |
| removeDependency = removeValueList @CommaVSep @Identity @Dependency |
| , Parsec (List sep b (Located a)) | ||
| , Pretty (List sep b (Located a)) | ||
| ) | ||
| -> (a -> Bool) |
There was a problem hiding this comment.
| -> (a -> Bool) | |
| => (a -> Bool) |
This succeeds Jappie's proposal in #5 by documenting the multiple changes of direction during the implementation.
On a practical note: the document was written in typst and then converted to markdown using pandoc, so I could use variables to generate references at the end of the document.
Rendered: https://github.com/leana8959/cabal-proposals/blob/eb11c41ba512ed712f1a701c3261e91d59fa6bfb/proposals/cabal-exactprint.md