mirror of
https://github.com/google/ormolu.git
synced 2025-01-05 22:16:03 +03:00
Add AnnD printer
This commit is contained in:
parent
f9c58af594
commit
73cc30c5d1
12
data/examples/declaration/annotation/annotation-out.hs
Normal file
12
data/examples/declaration/annotation/annotation-out.hs
Normal file
@ -0,0 +1,12 @@
|
||||
{-# ANN module (5 :: Int) #-}
|
||||
{-# ANN
|
||||
module
|
||||
( 5
|
||||
:: Int
|
||||
)
|
||||
#-}
|
||||
{-# ANN foo "hey" #-}
|
||||
{-# ANN
|
||||
Char
|
||||
(Just 42)
|
||||
#-}{- Comment -}
|
14
data/examples/declaration/annotation/annotation.hs
Normal file
14
data/examples/declaration/annotation/annotation.hs
Normal file
@ -0,0 +1,14 @@
|
||||
{-#ANN module (5 :: Int)#-}
|
||||
|
||||
{-# ANN module (5
|
||||
:: Int)#-}
|
||||
|
||||
{-# ANN foo "hey" #-}
|
||||
|
||||
{-# ANN
|
||||
Char
|
||||
|
||||
|
||||
(Just 42)#-}
|
||||
|
||||
{- Comment -}
|
@ -0,0 +1,5 @@
|
||||
foo = 5 :: Int
|
||||
|
||||
bar =
|
||||
5
|
||||
:: Int
|
@ -0,0 +1,4 @@
|
||||
foo = 5 :: Int
|
||||
|
||||
bar = 5
|
||||
:: Int
|
@ -8,5 +8,5 @@ multiline = case () of
|
||||
y
|
||||
) -> ()
|
||||
$( y
|
||||
"something'"
|
||||
"something"
|
||||
) -> ()
|
||||
|
@ -8,4 +8,4 @@ multiline = case () of
|
||||
$(x
|
||||
+ y) -> ()
|
||||
$(y
|
||||
"something'") -> ()
|
||||
"something") -> ()
|
||||
|
@ -60,6 +60,7 @@ library
|
||||
, Ormolu.Printer.Internal
|
||||
, Ormolu.Printer.Meat.Common
|
||||
, Ormolu.Printer.Meat.Declaration
|
||||
, Ormolu.Printer.Meat.Declaration.Annotation
|
||||
, Ormolu.Printer.Meat.Declaration.Class
|
||||
, Ormolu.Printer.Meat.Declaration.Data
|
||||
, Ormolu.Printer.Meat.Declaration.Default
|
||||
|
@ -1,4 +1,4 @@
|
||||
-- | Ormolu-specfiic representation of GHC annotations.
|
||||
-- | Ormolu-specific representation of GHC annotations.
|
||||
|
||||
module Ormolu.Anns
|
||||
( Anns (..)
|
||||
|
@ -11,6 +11,7 @@ where
|
||||
import GHC
|
||||
import Ormolu.Printer.Combinators
|
||||
import Ormolu.Printer.Meat.Common
|
||||
import Ormolu.Printer.Meat.Declaration.Annotation
|
||||
import Ormolu.Printer.Meat.Declaration.Class
|
||||
import Ormolu.Printer.Meat.Declaration.Data
|
||||
import Ormolu.Printer.Meat.Declaration.Default
|
||||
@ -33,7 +34,7 @@ p_hsDecl = \case
|
||||
DefD NoExt x -> p_defaultDecl x
|
||||
ForD _ _ -> notImplemented "ForD"
|
||||
WarningD _ _ -> notImplemented "WarningD"
|
||||
AnnD _ _ -> notImplemented "AnnD"
|
||||
AnnD NoExt x -> p_annDecl x
|
||||
RuleD _ _ -> notImplemented "RuleD"
|
||||
SpliceD _ _ -> notImplemented "SpliceD"
|
||||
DocD _ _ -> notImplemented "DocD"
|
||||
|
27
src/Ormolu/Printer/Meat/Declaration/Annotation.hs
Normal file
27
src/Ormolu/Printer/Meat/Declaration/Annotation.hs
Normal file
@ -0,0 +1,27 @@
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Ormolu.Printer.Meat.Declaration.Annotation
|
||||
( p_annDecl
|
||||
)
|
||||
where
|
||||
|
||||
import GHC
|
||||
import Ormolu.Printer.Combinators
|
||||
import Ormolu.Printer.Meat.Common
|
||||
import Ormolu.Printer.Meat.Declaration.Value
|
||||
import Ormolu.Utils
|
||||
|
||||
p_annDecl :: AnnDecl GhcPs -> R ()
|
||||
p_annDecl = \case
|
||||
HsAnnotation NoExt _ annProv expr -> pragma "ANN" $ do
|
||||
p_annProv annProv
|
||||
breakpoint
|
||||
located expr p_hsExpr
|
||||
XAnnDecl {} -> notImplemented "XAnnDecl"
|
||||
|
||||
p_annProv :: AnnProvenance (IdP GhcPs) -> R ()
|
||||
p_annProv = \case
|
||||
ValueAnnProvenance name -> p_rdrName name
|
||||
TypeAnnProvenance name -> p_rdrName name
|
||||
ModuleAnnProvenance -> txt "module"
|
@ -5,6 +5,7 @@
|
||||
module Ormolu.Printer.Meat.Declaration.Value
|
||||
( p_valDecl
|
||||
, p_pat
|
||||
, p_hsExpr
|
||||
)
|
||||
where
|
||||
|
||||
@ -359,7 +360,7 @@ p_hsExpr = \case
|
||||
located rupd_expr p_hsExpr
|
||||
breakpoint
|
||||
inci $ braces $ velt (withSep comma (located' p_hsRecField) rupd_flds)
|
||||
ExprWithTySig affix x -> do
|
||||
ExprWithTySig affix x -> sitcc $ do
|
||||
located x p_hsExpr
|
||||
breakpoint
|
||||
inci $ do
|
||||
|
Loading…
Reference in New Issue
Block a user