[Git][ghc/ghc][wip/az/ghc-9.10-backports-1] EPA: Extend StringLiteral range to include trailing commas

Alan Zimmerman (@alanz) gitlab at gitlab.haskell.org
Sun Apr 21 14:32:48 UTC 2024



Alan Zimmerman pushed to branch wip/az/ghc-9.10-backports-1 at Glasgow Haskell Compiler / GHC


Commits:
9f509a09 by Alan Zimmerman at 2024-04-21T15:32:17+01:00
EPA: Extend StringLiteral range to include trailing commas

This goes slightly against the exact printing philosophy where
trailing decorations should be in an annotation, but the
practicalities of adding it to the WarningTxt environment, and the
problems caused by deviating do not make a more principles approach
worthwhile.

(cherry picked from commit 00d3ecf0775c1a3f1ab8495e5e125f21d450394e)

- - - - -


2 changed files:

- compiler/GHC/Parser.y
- utils/check-exact/ExactPrint.hs


Changes:

=====================================
compiler/GHC/Parser.y
=====================================
@@ -4558,7 +4558,8 @@ addTrailingCommaN (L anns a) span = do
   return (L anns' a)
 
 addTrailingCommaS :: Located StringLiteral -> EpaLocation -> Located StringLiteral
-addTrailingCommaS (L l sl) span = L l (sl { sl_tc = Just (epaToNoCommentsLocation span) })
+addTrailingCommaS (L l sl) span
+    = L (widenSpan l [AddEpAnn AnnComma span]) (sl { sl_tc = Just (epaToNoCommentsLocation span) })
 
 -- -------------------------------------
 


=====================================
utils/check-exact/ExactPrint.hs
=====================================
@@ -652,6 +652,10 @@ printSourceText :: (Monad m, Monoid w) => SourceText -> String -> EP w m ()
 printSourceText (NoSourceText) txt   =  printStringAdvance txt >> return ()
 printSourceText (SourceText   txt) _ =  printStringAdvance (unpackFS txt) >> return ()
 
+printSourceTextAA :: (Monad m, Monoid w) => SourceText -> String -> EP w m ()
+printSourceTextAA (NoSourceText) txt   = printStringAtAA (EpaDelta (SameLine 0) []) txt >> return ()
+printSourceTextAA (SourceText   txt) _ =  printStringAtAA (EpaDelta (SameLine 0) []) (unpackFS txt) >> return ()
+
 -- ---------------------------------------------------------------------
 
 printStringAtSs :: (Monad m, Monoid w) => SrcSpan -> String -> EP w m ()
@@ -2121,7 +2125,7 @@ instance ExactPrint StringLiteral where
   setAnnotationAnchor a _ _ _ = a
 
   exact (StringLiteral src fs mcomma) = do
-    printSourceText src (show (unpackFS fs))
+    printSourceTextAA src (show (unpackFS fs))
     mcomma' <- mapM (\r -> printStringAtNC r ",") mcomma
     return (StringLiteral src fs mcomma')
 



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9f509a09f60707024cac6557f2b07c2e06bd9b23

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9f509a09f60707024cac6557f2b07c2e06bd9b23
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240421/f5532db5/attachment-0001.html>


More information about the ghc-commits mailing list