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

Pretty-printer: escape unprintable characters #2595

Open
kukimik opened this issue Jun 11, 2024 · 3 comments
Open

Pretty-printer: escape unprintable characters #2595

kukimik opened this issue Jun 11, 2024 · 3 comments

Comments

@kukimik
Copy link
Collaborator

kukimik commented Jun 11, 2024

Can we modify the pretty-printer (or at least the dhall format and dhall freeze commands) to unicode-escape unprintable characters? Perhaps this could be switched by an option?

I have some text containing unprintable characters that I want to be visible in the source code, so I use the escaping (e.g. "\u007f"). Unfortunately dhall format replaces it with the unprintable character verbatim.

It would be great if the original form (escaped/unescaped) could be preserved, but that is perhaps too much to ask for.

@Gabriella439
Copy link
Collaborator

Yeah, I think this is a reasonable change

@kukimik
Copy link
Collaborator Author

kukimik commented Jul 1, 2024

I've found out that the escaping rules used by the formatter are the same as used by Text/show and are defined here:

https://github.com/dhall-lang/dhall-haskell/blob/main/dhall/src/Dhall/Pretty/Internal.hs#L1871-L1890

Changing the rules for Text/show would need a backward incompatible change to the standard. Moreover, the escaping would probably become slower (the list of unprintable Unicode characters is not fixed, so we'd have to use a Unicode character class instead of a range comparison). Therefore, I think it would be preferable to add separate escaping rules for the formatter and keep Text/show as it is.

On the other hand keeping the formatter in sync with Text/show also has its merits. So I think adding an option (defaulting to the current behaviour, to keep things backward compatible) that would affect the pretty-printer is the way to go.

@Gabriella439
Copy link
Collaborator

I think I'd have a split preference for decoupling the formatting code and Text/show

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

No branches or pull requests

2 participants