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-simple drops characters that come after non-balanced parenthesis #52

Open
sjakobi opened this issue Nov 22, 2019 · 8 comments
Open

Comments

@sjakobi
Copy link
Contributor

sjakobi commented Nov 22, 2019

Sorry for the large example!

> x
Union (Cat (Cat Empty (Char 'f')) (Cat (Char ' ') (Cat (Char '"') (Cat Empty (Cat (Text 2 "\\n") (Char '"')))))) (Union (Cat (Cat Empty (Char 'f')) (Cat (Char ' ') (Cat (Char '"') (Cat Empty (Cat (Text 2 "\\n") (Char '"')))))) (FlatAlt (Column [(10,Nesting [(10,Cat (Cat Empty (Char 'f')) (Cat Line (Cat Empty (Column [(10,Nesting [(10,Nest 2 (Cat (Text 2 "  ") (FlatAlt (Column [(10,Nesting [(10,Cat (Text 2 "''") (Cat Line (Cat (Column [(10,Nesting [(10,Cat Empty (Cat Empty (Cat Line Empty)))])]) (Text 2 "''"))))])]) (Cat (Char '"') (Cat Empty (Cat (Text 2 "\\n") (Char '"')))))))])]))))])]) (Cat (Cat Empty (Char 'f')) (Cat (Char ' ') (FlatAlt (Column [(10,Nesting [(10,Cat (Text 2 "''") (Cat Line (Cat (Column [(10,Nesting [(10,Cat Empty (Cat Empty (Cat Line Empty)))])]) (Text 2 "''"))))])]) (Cat (Char '"') (Cat Empty (Cat (Text 2 "\\n") (Char '"')))))))))
> pPrintNoColor  x
Union 
    ( Cat 
        ( Cat Empty ( Char 'f' ) ) 
        ( Cat ( Char ' ' ) 
            ( Cat ( Char '"') (Cat Empty (Cat (Text 2 " \\n") (Char '" ' ) )
        )
    )
> show x
"Union (Cat (Cat Empty (Char 'f')) (Cat (Char ' ') (Cat (Char '\"') (Cat Empty (Cat (Text 2 \"\\\\n\") (Char '\"')))))) (Union (Cat (Cat Empty (Char 'f')) (Cat (Char ' ') (Cat (Char '\"') (Cat Empty (Cat (Text 2 \"\\\\n\") (Char '\"')))))) (FlatAlt (Column [(10,Nesting [(10,Cat (Cat Empty (Char 'f')) (Cat Line (Cat Empty (Column [(10,Nesting [(10,Nest 2 (Cat (Text 2 \"  \") (FlatAlt (Column [(10,Nesting [(10,Cat (Text 2 \"''\") (Cat Line (Cat (Column [(10,Nesting [(10,Cat Empty (Cat Empty (Cat Line Empty)))])]) (Text 2 \"''\"))))])]) (Cat (Char '\"') (Cat Empty (Cat (Text 2 \"\\\\n\") (Char '\"')))))))])]))))])]) (Cat (Cat Empty (Char 'f')) (Cat (Char ' ') (FlatAlt (Column [(10,Nesting [(10,Cat (Text 2 \"''\") (Cat Line (Cat (Column [(10,Nesting [(10,Cat Empty (Cat Empty (Cat Line Empty)))])]) (Text 2 \"''\"))))])]) (Cat (Char '\"') (Cat Empty (Cat (Text 2 \"\\\\n\") (Char '\"')))))))))"

The Union constructor has two fields, but pPrintNoColor shows only the first!

@sjakobi
Copy link
Contributor Author

sjakobi commented Nov 22, 2019

Also note the incorrect representation of the second '"' Char as '" '! The first one is actually fine.

@cdepillabout
Copy link
Owner

@sjakobi Thanks for reporting this. Could you give the whole code used to produce x?

My guess is that this happens because pretty-simple doesn't have any support for reading Haskell-style single characters (like 'a'), but it does have support for reading strings (like "foobar"), so what is happening here is that '"' ... '"' actually gets interpreted as something like ' "'some string that starts and ends with a single quote'" '.

Here are two related issues. I imagine solving either of them would also solve this problem, if you'd like to take a shot at it:

@cdepillabout
Copy link
Owner

cdepillabout commented Nov 22, 2019

I tried looking into this a little more. Here's my reproduction of this issue:

image

You can see that everything after the final ) gets lost. This happens because pretty-simple has no support for Haskell characters (#45), and it doesn't support non-balanced brackets very well (#27).

I'd happily accept fixes for either of these! I imagine #45 should be particularly easy to fix.

@cdepillabout cdepillabout changed the title pretty-simple shows only the first part of an expression pretty-simple drops characters that come after non-balanced parenthesis Nov 22, 2019
@sjakobi
Copy link
Contributor Author

sjakobi commented Nov 22, 2019

Could you give the whole code used to produce x?

  1. Checkout dhall-lang/dhall-haskell@3b222cd
  2. Update stack.yaml to use this prettyprinter version.
  3. In stack repl, run
> app = App (Var (V "f" 0)) (TextLit (Chunks [] "\n")) :: Expr () ()
> x = diag $ unAnnotate $ prettyExpr app

@sjakobi
Copy link
Contributor Author

sjakobi commented Nov 22, 2019

Thanks for the quick response! I'll try to look for alternative packages first, but may come back if I don't find anything better! :)

@sjakobi
Copy link
Contributor Author

sjakobi commented Nov 22, 2019

BTW I don't understand the new title. There's no unbalanced parenthesis here – it's apparently just that the characters are misparsed.

@cdepillabout
Copy link
Owner

There's no unbalanced parenthesis here – it's apparently just that the characters are misparsed.

Ah, so like I said in #52 (comment), this is caused because of #45 and #27.

The unbalanced parenthesis are happening because there is no smart parsing for Haskell characters. However, if the unbalanced parenthesis thing was fixed, then at least all the characters would be output, even if there is no pretty-printing of them.

@sjakobi
Copy link
Contributor Author

sjakobi commented Dec 21, 2019

Also note the incorrect representation of the second '"' Char as '" '! The first one is actually fine.

This is fixed as of v3.2.0.0, probably due to 0b95aec. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants