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

Switch to more modern parsing/pretty-printing libraries #27

Open
taktoa opened this issue Mar 8, 2018 · 3 comments
Open

Switch to more modern parsing/pretty-printing libraries #27

taktoa opened this issue Mar 8, 2018 · 3 comments

Comments

@taktoa
Copy link

taktoa commented Mar 8, 2018

You guys currently depend on parsec and pretty for parsing and pretty-printing respectively. Assuming that you are not doing this purely as a way of minimizing your dependency footprint (since pretty at least is a boot package that ships with GHC), I would recommend that you migrate to more modern parsing/pretty-printing libraries. These can improve parsing speed, parser error message readability, and code reusability.

For parsers, there are two main options, depending on what matters to you:

  • If speed is important, then you should use the parsers library to write a typeclass-generic parser, which can then be instantiated with a concrete parser type from trifecta when debugging (trifecta is slow but has good error messages) or with a parser type from attoparsec in production (attoparsec is fast but has bad error messages).
  • If nice error messages are important and you want to migrate from your parsec parser easily, but speed is not particularly important, megaparsec is a good option. In the version 6 and above of megaparsec, primitives are provided that make it as fast as attoparsec.

For pretty-printers, my main recommendation is prettyprinter, which is a pretty comprehensive replacement for all the pre-existing pretty-printing libraries in Haskell. It supports terminal output with ANSI colors, HTML output, it doesn't have name clashes with common operators, and it uses Text for performance.

@dlthomas
Copy link
Contributor

dlthomas commented Mar 9, 2018

So far as I'm aware, parsing speed hasn't been an issue. Moving to megaparsec might be good, but should be weighed against "if it ain't broke" (it was fairly new when the project started, and there hasn't been enough of an impetus to switch).

As to pretty printing, that's presently mostly unimplemented; I don't expect there would be any objection to switching away from pretty if it came with a diff that did more.

@dlthomas
Copy link
Contributor

dlthomas commented Mar 9, 2018

Two other notes:

  1. Choice of parsing library could be per-dialect with minimal drawbacks, so migration could be gradual or limited to new packages (or not - just worth noting we have the flexibility)
  2. A much more interesting change to parsing would be something that could handle incomplete statements, but that's also a much bigger change generally.

@Fuuzetsu
Copy link

uu-parsinglib has error-correcting facilities, depending on what kind of incomplete statements you're after, this might be something to consider

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

3 participants