on master help sign in
Add AnnD printer
commit73cc30c5d1564ea8846956cef2cf742a50ea003e authorBasile Henry <bjm.henry@gmail.com> dateSun 16 Jun 2019, 12:36 (7 years ago) parentf9c58af
11 files changed+70−5
data/examples/declaration/annotation/annotation-out.hs+12 data/examples/declaration/annotation/annotation.hs+14 data/examples/declaration/value/function/explicit-type-out.hs+5 data/examples/declaration/value/function/explicit-type.hs+4 data/examples/declaration/value/function/pattern/splice-pattern-out.hs+1−1 data/examples/declaration/value/function/pattern/splice-pattern.hs+1−1 ormolu.cabal+1 src/Ormolu/Anns.hs+1−1 src/Ormolu/Printer/Meat/Declaration.hs+2−1 src/Ormolu/Printer/Meat/Declaration/Annotation.hs+27 src/Ormolu/Printer/Meat/Declaration/Value.hs+2−1
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
88 y
99 ) -> ()
1010 $( y
11− "something'"
11+ "something"
1212 ) -> ()
data/examples/declaration/value/function/pattern/splice-pattern.hs+1−1
@@ -8,4 +8,4 @@ multiline = case () of
88 $(x
99 + y) -> ()
1010 $(y
11− "something'") -> ()
11+ "something") -> ()
ormolu.cabal+1
@@ -60,6 +60,7 @@ library
6060 , Ormolu.Printer.Internal
6161 , Ormolu.Printer.Meat.Common
6262 , Ormolu.Printer.Meat.Declaration
63+ , Ormolu.Printer.Meat.Declaration.Annotation
6364 , Ormolu.Printer.Meat.Declaration.Class
6465 , Ormolu.Printer.Meat.Declaration.Data
6566 , 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.
22
33module Ormolu.Anns
44 ( Anns (..)
src/Ormolu/Printer/Meat/Declaration.hs+2−1
@@ -11,6 +11,7 @@ where
1111import GHC
1212import Ormolu.Printer.Combinators
1313import Ormolu.Printer.Meat.Common
14+import Ormolu.Printer.Meat.Declaration.Annotation
1415import Ormolu.Printer.Meat.Declaration.Class
1516import Ormolu.Printer.Meat.Declaration.Data
1617import Ormolu.Printer.Meat.Declaration.Default
@@ -33,7 +34,7 @@ p_hsDecl = \case
3334 DefD NoExt x -> p_defaultDecl x
3435 ForD _ _ -> notImplemented "ForD"
3536 WarningD _ _ -> notImplemented "WarningD"
36− AnnD _ _ -> notImplemented "AnnD"
37+ AnnD NoExt x -> p_annDecl x
3738 RuleD _ _ -> notImplemented "RuleD"
3839 SpliceD _ _ -> notImplemented "SpliceD"
3940 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 @@
55module Ormolu.Printer.Meat.Declaration.Value
66 ( p_valDecl
77 , p_pat
8+ , p_hsExpr
89 )
910where
1011
@@ -359,7 +360,7 @@ p_hsExpr = \case
359360 located rupd_expr p_hsExpr
360361 breakpoint
361362 inci $ braces $ velt (withSep comma (located' p_hsRecField) rupd_flds)
362− ExprWithTySig affix x -> do
363+ ExprWithTySig affix x -> sitcc $ do
363364 located x p_hsExpr
364365 breakpoint
365366 inci $ do