on master help sign in
Implement ‘HsSpliceE’ and ‘SplicePat’
057a3cfwaddlaw
data/examples/declaration/value/function/quasi-quotes-out.hsnew file+12
@@ -0,0 +1,12 @@
1+{-# LANGUAGE QuasiQuotes #-}
2+singleline :: Value
3+singleline = [yamlQQ|something|]
4+
5+multiline :: Value
6+multiline =
7+ [yamlQQ|
8+ name: John Doe
9+ age: 23
10+
11+ something: foo
12+ |]
data/examples/declaration/value/function/quasi-quotes-pattern-out.hsnew file+10
@@ -0,0 +1,10 @@
1+{-# LANGUAGE QuasiQuotes #-}
2+singleline :: ()
3+singleline [yamlQQ|something|] = ()
4+
5+multiline :: ()
6+multiline = case y of
7+ [yamlQQ|
8+ name: John Doe
9+ age: 23
10+ |] -> ()
data/examples/declaration/value/function/quasi-quotes-pattern.hsnew file+9
@@ -0,0 +1,9 @@
1+{-# LANGUAGE QuasiQuotes #-}
2+singleline :: ()
3+singleline [yamlQQ|something|] = ()
4+
5+multiline :: ()
6+multiline = case y of
7+ [yamlQQ| name: John Doe
8+age: 23
9+|] -> ()
data/examples/declaration/value/function/quasi-quotes.hsnew file+10
@@ -0,0 +1,10 @@
1+{-# LANGUAGE QuasiQuotes #-}
2+singleline :: Value
3+singleline = [yamlQQ|something|]
4+
5+multiline :: Value
6+multiline = [yamlQQ| name: John Doe
7+age: 23
8+
9+something: foo
10+|]
src/Ormolu/Printer/Meat/Declaration/Value.hs+28−2
@@ -13,6 +13,8 @@ import BasicTypes
13import Control.Monad
13import Control.Monad
14import Data.Data
14import Data.Data
15import Data.List (sortOn)
15import Data.List (sortOn)
16+import Data.String (fromString)
17+import FastString as GHC
16import GHC
18import GHC
17import Ormolu.Printer.Combinators
19import Ormolu.Printer.Combinators
18import Ormolu.Printer.Meat.Common
20import Ormolu.Printer.Meat.Common
@@ -22,6 +24,7 @@ import Ormolu.Utils
22import Outputable (Outputable (..))
24import Outputable (Outputable (..))
23import SrcLoc (isOneLineSpan)
25import SrcLoc (isOneLineSpan)
24import qualified Data.List.NonEmpty as NE
26import qualified Data.List.NonEmpty as NE
27+import qualified Data.Text as T
25
28
26data MatchGroupStyle
29data MatchGroupStyle
27 = Function (Located RdrName)
30 = Function (Located RdrName)
@@ -383,7 +386,7 @@ p_hsExpr = \case
383 HsBracket {} -> notImplemented "HsBracket"
386 HsBracket {} -> notImplemented "HsBracket"
384 HsRnBracketOut {} -> notImplemented "HsRnBracketOut"
387 HsRnBracketOut {} -> notImplemented "HsRnBracketOut"
385 HsTcBracketOut {} -> notImplemented "HsTcBracketOut"
388 HsTcBracketOut {} -> notImplemented "HsTcBracketOut"
386− HsSpliceE {} -> notImplemented "HsSpliceE"
389+ HsSpliceE NoExt splice -> p_hsSplice splice
387 HsProc {} -> notImplemented "HsProc"
390 HsProc {} -> notImplemented "HsProc"
388 HsStatic _ e -> do
391 HsStatic _ e -> do
389 txt "static"
392 txt "static"
@@ -495,7 +498,7 @@ p_pat = \case
495 txt " ->"
498 txt " ->"
496 breakpoint
499 breakpoint
497 inci (located pat p_pat)
500 inci (located pat p_pat)
498− SplicePat {} -> notImplemented "SplicePat"
501+ SplicePat NoExt splice -> p_hsSplice splice
499 LitPat NoExt p -> atom p
502 LitPat NoExt p -> atom p
500 NPat NoExt v _ _ -> located v (atom . ol_val)
503 NPat NoExt v _ _ -> located v (atom . ol_val)
501 NPlusKPat {} -> notImplemented "NPlusKPat"
504 NPlusKPat {} -> notImplemented "NPlusKPat"
@@ -514,6 +517,29 @@ p_pat_hsRecField HsRecField {..} = do
514 breakpoint
517 breakpoint
515 inci (located hsRecFieldArg p_pat)
518 inci (located hsRecFieldArg p_pat)
516
519
520+p_hsSplice :: HsSplice GhcPs -> R ()
521+p_hsSplice = \case
522+ HsTypedSplice {} -> notImplemented "HsTypedSplice"
523+ HsUntypedSplice {} -> notImplemented "HsUntypedSplice"
524+ HsQuasiQuote NoExt _ quoterName srcSpan str -> do
525+ let locatedQuoterName = L srcSpan quoterName
526+ p_quasiQuote locatedQuoterName $ do
527+ let p x = unless (T.null x) (txt x)
528+ newlineSep (p . T.strip) (T.lines . T.strip . fromString . GHC.unpackFS $ str)
529+ HsSpliced {} -> notImplemented "HsSpliced"
530+ XSplice {} -> notImplemented "XSplice"
531+
532+p_quasiQuote :: Located RdrName -> R () -> R ()
533+p_quasiQuote quoter m = do
534+ txt "["
535+ p_rdrName quoter
536+ txt "|"
537+ let breakpoint' = vlayout (return ()) newline
538+ breakpoint'
539+ inci m
540+ breakpoint'
541+ txt "|]"
542+
517----------------------------------------------------------------------------
543----------------------------------------------------------------------------
518-- Helpers
544-- Helpers
519
545