Skip to content
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

Fix pretty-printer to preserve original numeric literals #1674

Merged
merged 1 commit into from
Feb 15, 2020

Conversation

Gabriella439
Copy link
Collaborator

Fixes #1671

Copy link
Collaborator

@sjakobi sjakobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for preserving hexadecimals!

Will this also work for dhall lint and dhall freeze?

@@ -473,6 +473,12 @@ prettyVar (V x n) = label (Pretty.unAnnotate (prettyLabel x <> "@" <> prettyInt
prettyEnvironmentVariable :: Text -> Doc ann
prettyEnvironmentVariable t = Pretty.pretty (escapeEnvironmentVariable t)

preserveSource :: Expr Src a -> Maybe (Doc Ann)
preserveSource (Note Src{..} (DoubleLit {})) = Just (Pretty.pretty srcText)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the motivation for including Doubles here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same rationale: to preserve them the way the user wrote them

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well in the case of Integer and Natural I understand that we want to preserve an original hexadecimal formatting for readability. In the case of Doubles it's not so obvious to me why we should prefer an original 001.20 over a "standard" 1.2. Although we may assume that the user may have their reasons to write 001.20 in the first place.

I guess I'm just wondering where we draw the line between expressions where we apply the standard formatting, and expressions where we preserve the original formatting. For example, we could also try to preserve the formatting of Text literals.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjakobi: People have requested that we do a better job of preserving user formatting in general (see the requests for Vonderhaar-style pretty-printing), but in this specific case I preserved the formatting of Double literals because I felt that it was in the same spirit as preserving formatting for hexadecimal literals.

@Gabriella439
Copy link
Collaborator Author

@sjakobi: Yes, this will work for dhall lint and dhall freeze

@Gabriella439 Gabriella439 merged commit e320661 into master Feb 15, 2020
@Gabriella439 Gabriella439 deleted the gabriel/preserveSource branch February 15, 2020 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dhall format converts hexadecimal to decimal
2 participants