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

Improve laziness for strings #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

anka-213
Copy link
Contributor

@anka-213 anka-213 commented Nov 21, 2018

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

@cdepillabout
Copy link
Owner

@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

@andrew-lei
Copy link
Collaborator

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.

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.

3 participants