Skip to content

Add Text.Megaparsec.Error.errorBundlePrettyForGhcPreProcessors - #573

Merged
mrkkrp merged 1 commit into
mrkkrp:masterfrom
sol:pre-processors
Nov 19, 2024
Merged

mrkkrp merged 1 commit into
mrkkrp:masterfrom
sol:pre-processors

Conversation

@sol

@sol sol commented Nov 13, 2024 •

Copy link
Copy Markdown
Contributor

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
@mrkkrp

mrkkrp commented Nov 19, 2024

Copy link
Copy Markdown
Owner

Thanks!

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Jan 31, 2025
## Megaparsec 9.7.0

* Implemented correct handling of wide Unicode characters in error messages.
  To that end, a new module `Text.Megaparsec.Unicode` was introduced. [Issue
  370](mrkkrp/megaparsec#370).
* Inlined `Applicative` operators `(<*)` and `(*>)`. [PR
  566](mrkkrp/megaparsec#566).
* `many` and `some` of the `Alternative` instance of `ParsecT` are now more
  efficient, since they use the monadic implementations under the hood.
  [Issue 567](mrkkrp/megaparsec#567).
* Added `Text.Megaparsec.Error.errorBundlePrettyForGhcPreProcessors`. [PR
  573](mrkkrp/megaparsec#573).
msk pushed a commit to msk/pkgsrc that referenced this pull request May 11, 2026
## Megaparsec 9.7.0

* Implemented correct handling of wide Unicode characters in error messages.
  To that end, a new module `Text.Megaparsec.Unicode` was introduced. [Issue
  370](mrkkrp/megaparsec#370).
* Inlined `Applicative` operators `(<*)` and `(*>)`. [PR
  566](mrkkrp/megaparsec#566).
* `many` and `some` of the `Alternative` instance of `ParsecT` are now more
  efficient, since they use the monadic implementations under the hood.
  [Issue 567](mrkkrp/megaparsec#567).
* Added `Text.Megaparsec.Error.errorBundlePrettyForGhcPreProcessors`. [PR
  573](mrkkrp/megaparsec#573).
jperkin pushed a commit to TritonDataCenter/pkgsrc that referenced this pull request May 14, 2026
## Megaparsec 9.7.0

* Implemented correct handling of wide Unicode characters in error messages.
  To that end, a new module `Text.Megaparsec.Unicode` was introduced. [Issue
  370](mrkkrp/megaparsec#370).
* Inlined `Applicative` operators `(<*)` and `(*>)`. [PR
  566](mrkkrp/megaparsec#566).
* `many` and `some` of the `Alternative` instance of `ParsecT` are now more
  efficient, since they use the monadic implementations under the hood.
  [Issue 567](mrkkrp/megaparsec#567).
* Added `Text.Megaparsec.Error.errorBundlePrettyForGhcPreProcessors`. [PR
  573](mrkkrp/megaparsec#573).
tsutsui pushed a commit to tsutsui/pkgsrc that referenced this pull request Oct 17, 2026
## Megaparsec 9.7.0

* Implemented correct handling of wide Unicode characters in error messages.
  To that end, a new module `Text.Megaparsec.Unicode` was introduced. [Issue
  370](mrkkrp/megaparsec#370).
* Inlined `Applicative` operators `(<*)` and `(*>)`. [PR
  566](mrkkrp/megaparsec#566).
* `many` and `some` of the `Alternative` instance of `ParsecT` are now more
  efficient, since they use the monadic implementations under the hood.
  [Issue 567](mrkkrp/megaparsec#567).
* Added `Text.Megaparsec.Error.errorBundlePrettyForGhcPreProcessors`. [PR
  573](mrkkrp/megaparsec#573).
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