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

Add Text.Megaparsec.Error.errorBundlePrettyForGhcPreProcessors #573

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

sol
Copy link
Contributor

@sol sol commented Nov 13, 2024

If you use errorBundlePretty when writing a GHC pre-processor then error output does not look pretty:
before

To address this, this PR adds errorBundlePrettyForGhcPreProcessors, which results in:
after

Details:

  1. When a GHC pre-processor fails, then GHC parses source locations and error messages from the pre-processor's output.
  2. Multi-line error messages have to be indented, otherwise GHC won't parse them properly.
  3. When GHC pretty-prints error message it indents multi-line error messages by four spaces, but it does not strip any whitespace from parsed error messages before pretty-printing them.

As a consequence, the best you can achieve for a pre-processor is to have multi-line error messages indented by five spaces. To achieve this you have to produce error messages of the form:

src/Foo.hs:23:42: foo
 bar
 baz

That is:

  1. The first line of the message has to be on the same same line as the source location separated by exactly one space.
  2. Each subsequent line has to be indented by one space.

Note that single-line error message should be of the form:

src/Foo.hs:23:42:foo

(no space between the last : and the error message, otherwise you will end up with two spaces in the pretty-printed output)

@sol sol force-pushed the pre-processors branch 2 times, most recently from 4f492a1 to 097660f Compare November 13, 2024 02:18
@mrkkrp mrkkrp force-pushed the pre-processors branch 2 times, most recently from c0b7856 to 64870cf Compare November 19, 2024 15:18
@mrkkrp mrkkrp merged commit 075477b into mrkkrp:master Nov 19, 2024
4 checks passed
@mrkkrp
Copy link
Owner

mrkkrp commented Nov 19, 2024

Thanks!

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.

2 participants