Exact Print Annotations : Anchor in a SrcSpan

Alan & Kim Zimmerman alan.zimm at gmail.com
Thu Oct 28 21:18:01 UTC 2021

I have been updating the ghc-exactprint library for real world use cases on
the about to be released GHC 9.2.1, and realised I need to be able to put
an Anchor into every SrcSpan in the ParsedSource AST.

I prepared !6854 to sort it out in master and turned to the problem of GHC
9.2.1, where I had missed the boat.

And then I discovered that we have SrcSpan defined as

    data SrcSpan =
        RealSrcSpan !RealSrcSpan !(Maybe BufSpan)
      | UnhelpfulSpan !UnhelpfulSpanReason

and the (Maybe BufSpan) is only used for attaching haddock comments after

This means there is an isomorphism between the RealSrcSpan variant and an
Anchor, which I take advantage of with the code in [1], by using the Maybe
to encode the AnchorOperation and the BufSpan to encode the DeltaPos.

And it struck me that perhaps we should make this a more official
approach.  The only problem is the detail of the BufSpan, to be able to
play both roles cleanly.


[1] https://gist.github.com/alanz/5e262599ab79138606cdfcf3792ef635
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20211028/a57bdd32/attachment.html>

More information about the ghc-devs mailing list