@@ -6,6 +6,7 @@ module Ormolu.Printer.Meat.Declaration.Value
66 ( p_valDecl
77 , p_pat
88 , p_hsExpr
9+ , p_hsSplice
910 )
1011where
1112
@@ -14,8 +15,7 @@ import BasicTypes
1415import Control.Monad
1516import Data.Data
1617import Data.List (sortOn)
17−import Data.String (fromString)
18−import FastString as GHC
18+import Data.Text (Text)
1919import GHC
2020import Ormolu.Printer.Combinators
2121import Ormolu.Printer.Meat.Common
@@ -25,7 +25,7 @@ import Ormolu.Utils
2525import Outputable (Outputable (..))
2626import SrcLoc (combineSrcSpans, isOneLineSpan)
2727import qualified Data.List.NonEmpty as NE
28−import qualified Data.Text as T
28+import {-# SOURCE #-} Ormolu.Printer.Meat.Declaration
2929
3030data MatchGroupStyle
3131 = Function (Located RdrName)
@@ -381,7 +381,6 @@ p_hsExpr = \case
381381 HsIB {..} = hswc_body
382382 located hsib_body p_hsType
383383 ArithSeq NoExt _ x -> do
384− let breakpoint' = vlayout (return ()) newline
385384 case x of
386385 From from -> brackets $ do
387386 located from p_hsExpr
@@ -413,7 +412,7 @@ p_hsExpr = \case
413412 txt " #-}"
414413 breakpoint
415414 located x p_hsExpr
416− HsBracket {} -> notImplemented "HsBracket"
415+ HsBracket NoExt x -> p_hsBracket x
417416 HsRnBracketOut {} -> notImplemented "HsRnBracketOut"
418417 HsTcBracketOut {} -> notImplemented "HsTcBracketOut"
419418 HsSpliceE NoExt splice -> p_hsSplice splice
@@ -557,10 +556,13 @@ p_hsSplice = \case
557556 HsTypedSplice NoExt deco _ expr -> p_hsSpliceTH True expr deco
558557 HsUntypedSplice NoExt deco _ expr -> p_hsSpliceTH False expr deco
559558 HsQuasiQuote NoExt _ quoterName srcSpan str -> do
560− let locatedQuoterName = L srcSpan quoterName
561− p_quasiQuote locatedQuoterName $ do
562− let p x = unless (T.null x) (txt x)
563− newlineSep (p . T.strip) (T.lines . T.strip . fromString . GHC.unpackFS $ str)
559+ txt "["
560+ p_rdrName (L srcSpan quoterName)
561+ txt "|"
562+ -- NOTE QuasiQuoters often rely on precise custom strings. We cannot do
563+ -- any formatting here without potentially breaking someone's code.
564+ atom str
565+ txt "|]"
564566 HsSpliced {} -> notImplemented "HsSpliced"
565567 XSplice {} -> notImplemented "XSplice"
566568
@@ -572,25 +574,40 @@ p_hsSpliceTH
572574p_hsSpliceTH isTyped expr = \case
573575 HasParens -> do
574576 txt decoSymbol
575− parens (located expr p_hsExpr)
577+ parens (located expr (sitcc . p_hsExpr))
576578 HasDollar -> do
577579 txt decoSymbol
578− located expr p_hsExpr
580+ located expr (sitcc . p_hsExpr)
579581 NoParens -> do
580− located expr p_hsExpr
582+ located expr (sitcc . p_hsExpr)
581583 where
582584 decoSymbol = if isTyped then "$$" else "$"
583585
584−p_quasiQuote :: Located RdrName -> R () -> R ()
585−p_quasiQuote quoter m = do
586− txt "["
587− p_rdrName quoter
588− txt "|"
589− let breakpoint' = vlayout (return ()) newline
590− breakpoint'
591− inci m
592− breakpoint'
593− txt "|]"
586+p_hsBracket :: HsBracket GhcPs -> R ()
587+p_hsBracket = \case
588+ ExpBr NoExt expr -> quote "e" (located expr p_hsExpr)
589+ PatBr NoExt pat -> quote "p" (located pat p_pat)
590+ DecBrL NoExt decls -> quote "d" (p_hsDecls decls)
591+ DecBrG NoExt _ -> notImplemented "DecBrG" -- result of renamer
592+ TypBr NoExt ty -> quote "t" (located ty p_hsType)
593+ VarBr NoExt _ _ -> notImplemented "VarBr"
594+ TExpBr NoExt expr -> do
595+ txt "[||"
596+ breakpoint'
597+ located expr p_hsExpr
598+ breakpoint'
599+ txt "||]"
600+ XBracket {} -> notImplemented "XBracket"
601+ where
602+ quote :: Text -> R () -> R ()
603+ quote name body = do
604+ txt "["
605+ txt name
606+ txt "|"
607+ breakpoint'
608+ body
609+ breakpoint'
610+ txt "|]"
594611
595612----------------------------------------------------------------------------
596613-- Helpers