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

the parser doesn't understand Haskell characters like 'a' #45

Closed
neongreen opened this issue Feb 16, 2019 · 2 comments · Fixed by #57
Closed

the parser doesn't understand Haskell characters like 'a' #45

neongreen opened this issue Feb 16, 2019 · 2 comments · Fixed by #57

Comments

@neongreen
Copy link

Text.Pretty.Simple> pStringNoColor "[']']"
"[ ' ]'"

The correct output should be "[']'".

@cdepillabout
Copy link
Owner

cdepillabout commented Feb 17, 2019

@neongreen I think the problem with pretty-simple is two-fold:

  1. pretty-simple doesn't handle non-balanced brackets: allow non-balanced brackets, parens, etc #27. Here's the expression that "[']']" is parsed into:

    [ Brackets 
        ( CommaSeparated 
            { unCommaSeparated = 
                [ [ Other "'" ] ]
            }
        )
    , Other "'" 
    ]

    Basically this means there are brackets surrounding a ', and then a single '. The final bracket is removed. The reason there are spaces around the first quote is that pretty-simple prints spaces inside of brackets by default.

    This should instead be parsed into something like this:

    [ Brackets 
        ( CommaSeparated 
            { unCommaSeparated = 
                [ [ CharLit ']' ] ]
            }
        )
    ]
  2. pretty-simple doesn't have a special parser for Haskell characters (e.g. things like 'a' or 'X' or ']'). So it doesn't realize that ']' is supposed to be a character (and not a closing bracket).

    It would be nice to add an expression for characters (like the CharLit I've used above).


If you want to send a PR fixing either of these things, it would definitely be accepted!

If you wanted to fix this, you'd mainly have to edit the expression parser, which lives in these two files:

https://github.com/cdepillabout/pretty-simple/blob/787cec7d170077f21407d5b7f65b6694b5b318d3/src/Text/Pretty/Simple/Internal/Expr.hs

https://github.com/cdepillabout/pretty-simple/blob/787cec7d170077f21407d5b7f65b6694b5b318d3/src/Text/Pretty/Simple/Internal/ExprParser.hs

@cdepillabout cdepillabout changed the title The parser fails on [']'] The parser fails doesn't understand Haskell characters like 'a' Feb 17, 2019
@cdepillabout cdepillabout changed the title The parser fails doesn't understand Haskell characters like 'a' the parser doesn't understand Haskell characters like 'a' Feb 17, 2019
@sjakobi
Copy link
Contributor

sjakobi commented Dec 12, 2019

Text.Pretty.Simple> pStringNoColor "[']']"
"[ ' ]'"

The correct output should be "[']'".

Should that be "[ ']' ]" in analogy to

> pStringNoColor "[1]"
"[ 1 ]"

?

sjakobi added a commit to sjakobi/pretty-simple that referenced this issue Dec 12, 2019
sjakobi added a commit to sjakobi/pretty-simple that referenced this issue Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants