pretty-simple icon indicating copy to clipboard operation
pretty-simple copied to clipboard

Improve laziness for strings

Open anka-213 opened this issue 6 years ago • 2 comments

By parsing one character at a time with Data.Char.readLitChar, we can avoid the need to read the entire string at once.

anka-213 avatar Nov 21 '18 03:11 anka-213

@andrew-lei Would you be able to review this one as well?

If it looks good, you can merge it and make a new release if you want. Here is a release checklist:

https://functor.tokyo/blog/2018-07-16-release-haskell-packages-to-hackage

cdepillabout avatar Nov 21 '18 04:11 cdepillabout

Travis failed this for the test that was implemented yesterday. This could be remedied, but it depends on what parseStringLit should give in cases of malformed input.

The proposed code will parse string literals from a shown string to a literal string. I believe I had wanted to do something along those lines, but there is the problem of malformed input (non-existent escaped characters). The case is accounted for, but results in ambiguity. For example,

> parseStringLit "\\c\""
("\\c","")
> parseStringLit "\\\\c\""
("\\c","")

This would only be the case for a very unusual show instance. For instance, consider

data Foo = Foo

instance Show Foo where
  show Foo = "\"\\c\\\\c\""

In which case

> pPrintNoColor Foo
"\c\c"

It's a pretty weird edge case that is probably unlikely to occur, but that's why I wanted to have the parser preserve the strings verbatim.

andrew-lei avatar Nov 21 '18 18:11 andrew-lei