on master help sign in
Add AnnD printer
73cc30cBasile Henry
data/examples/declaration/annotation/annotation-out.hsnew file+12
@@ -0,0 +1,12 @@
1+{-# ANN module (5 :: Int) #-}
2+{-# ANN
3+ module
4+ ( 5
5+ :: Int
6+ )
7+ #-}
8+{-# ANN foo "hey" #-}
9+{-# ANN
10+ Char
11+ (Just 42)
12+ #-}{- Comment -}
data/examples/declaration/annotation/annotation.hsnew file+14
@@ -0,0 +1,14 @@
1+{-#ANN module (5 :: Int)#-}
2+
3+{-# ANN module (5
4+ :: Int)#-}
5+
6+{-# ANN foo "hey" #-}
7+
8+{-# ANN
9+ Char
10+
11+
12+ (Just 42)#-}
13+
14+{- Comment -}
data/examples/declaration/value/function/explicit-type-out.hsnew file+5
@@ -0,0 +1,5 @@
1+foo = 5 :: Int
2+
3+bar =
4+ 5
5+ :: Int
data/examples/declaration/value/function/explicit-type.hsnew file+4
@@ -0,0 +1,4 @@
1+foo = 5 :: Int
2+
3+bar = 5
4+ :: Int
data/examples/declaration/value/function/pattern/splice-pattern-out.hs+1−1
@@ -8,5 +8,5 @@ multiline = case () of
8 y
8 y
9 ) -> ()
9 ) -> ()
10 $( y
10 $( y
11− "something'"
11+ "something"
12 ) -> ()
12 ) -> ()
data/examples/declaration/value/function/pattern/splice-pattern.hs+1−1
@@ -8,4 +8,4 @@ multiline = case () of
8 $(x
8 $(x
9 + y) -> ()
9 + y) -> ()
10 $(y
10 $(y
11− "something'") -> ()
11+ "something") -> ()
ormolu.cabal+1
@@ -60,6 +60,7 @@ library
60 , Ormolu.Printer.Internal
60 , Ormolu.Printer.Internal
61 , Ormolu.Printer.Meat.Common
61 , Ormolu.Printer.Meat.Common
62 , Ormolu.Printer.Meat.Declaration
62 , Ormolu.Printer.Meat.Declaration
63+ , Ormolu.Printer.Meat.Declaration.Annotation
63 , Ormolu.Printer.Meat.Declaration.Class
64 , Ormolu.Printer.Meat.Declaration.Class
64 , Ormolu.Printer.Meat.Declaration.Data
65 , Ormolu.Printer.Meat.Declaration.Data
65 , Ormolu.Printer.Meat.Declaration.Default
66 , Ormolu.Printer.Meat.Declaration.Default
src/Ormolu/Anns.hs+1−1
@@ -1,4 +1,4 @@
1−-- | Ormolu-specfiic representation of GHC annotations.
1+-- | Ormolu-specific representation of GHC annotations.
2
2
3module Ormolu.Anns
3module Ormolu.Anns
4 ( Anns (..)
4 ( Anns (..)
src/Ormolu/Printer/Meat/Declaration.hs+2−1
@@ -11,6 +11,7 @@ where
11import GHC
11import GHC
12import Ormolu.Printer.Combinators
12import Ormolu.Printer.Combinators
13import Ormolu.Printer.Meat.Common
13import Ormolu.Printer.Meat.Common
14+import Ormolu.Printer.Meat.Declaration.Annotation
14import Ormolu.Printer.Meat.Declaration.Class
15import Ormolu.Printer.Meat.Declaration.Class
15import Ormolu.Printer.Meat.Declaration.Data
16import Ormolu.Printer.Meat.Declaration.Data
16import Ormolu.Printer.Meat.Declaration.Default
17import Ormolu.Printer.Meat.Declaration.Default
@@ -33,7 +34,7 @@ p_hsDecl = \case
33 DefD NoExt x -> p_defaultDecl x
34 DefD NoExt x -> p_defaultDecl x
34 ForD _ _ -> notImplemented "ForD"
35 ForD _ _ -> notImplemented "ForD"
35 WarningD _ _ -> notImplemented "WarningD"
36 WarningD _ _ -> notImplemented "WarningD"
36− AnnD _ _ -> notImplemented "AnnD"
37+ AnnD NoExt x -> p_annDecl x
37 RuleD _ _ -> notImplemented "RuleD"
38 RuleD _ _ -> notImplemented "RuleD"
38 SpliceD _ _ -> notImplemented "SpliceD"
39 SpliceD _ _ -> notImplemented "SpliceD"
39 DocD _ _ -> notImplemented "DocD"
40 DocD _ _ -> notImplemented "DocD"
src/Ormolu/Printer/Meat/Declaration/Annotation.hsnew file+27
@@ -0,0 +1,27 @@
1+{-# LANGUAGE LambdaCase #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+
4+module Ormolu.Printer.Meat.Declaration.Annotation
5+ ( p_annDecl
6+ )
7+where
8+
9+import GHC
10+import Ormolu.Printer.Combinators
11+import Ormolu.Printer.Meat.Common
12+import Ormolu.Printer.Meat.Declaration.Value
13+import Ormolu.Utils
14+
15+p_annDecl :: AnnDecl GhcPs -> R ()
16+p_annDecl = \case
17+ HsAnnotation NoExt _ annProv expr -> pragma "ANN" $ do
18+ p_annProv annProv
19+ breakpoint
20+ located expr p_hsExpr
21+ XAnnDecl {} -> notImplemented "XAnnDecl"
22+
23+p_annProv :: AnnProvenance (IdP GhcPs) -> R ()
24+p_annProv = \case
25+ ValueAnnProvenance name -> p_rdrName name
26+ TypeAnnProvenance name -> p_rdrName name
27+ ModuleAnnProvenance -> txt "module"
src/Ormolu/Printer/Meat/Declaration/Value.hs+2−1
@@ -5,6 +5,7 @@
5module Ormolu.Printer.Meat.Declaration.Value
5module Ormolu.Printer.Meat.Declaration.Value
6 ( p_valDecl
6 ( p_valDecl
7 , p_pat
7 , p_pat
8+ , p_hsExpr
8 )
9 )
9where
10where
10
11
@@ -359,7 +360,7 @@ p_hsExpr = \case
359 located rupd_expr p_hsExpr
360 located rupd_expr p_hsExpr
360 breakpoint
361 breakpoint
361 inci $ braces $ velt (withSep comma (located' p_hsRecField) rupd_flds)
362 inci $ braces $ velt (withSep comma (located' p_hsRecField) rupd_flds)
362− ExprWithTySig affix x -> do
363+ ExprWithTySig affix x -> sitcc $ do
363 located x p_hsExpr
364 located x p_hsExpr
364 breakpoint
365 breakpoint
365 inci $ do
366 inci $ do