1
1
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:
Basile Henry 2019-06-16 12:36:47 +02:00 committed by Mark Karpov
parent f9c58af594
commit 73cc30c5d1
11 changed files with 70 additions and 5 deletions

View File

@ -0,0 +1,12 @@
{-# ANN module (5 :: Int) #-}
{-# ANN
module
( 5
:: Int
)
#-}
{-# ANN foo "hey" #-}
{-# ANN
Char
(Just 42)
#-}{- Comment -}

View File

@ -0,0 +1,14 @@
{-#ANN module (5 :: Int)#-}
{-# ANN module (5
:: Int)#-}
{-# ANN foo "hey" #-}
{-# ANN
Char
(Just 42)#-}
{- Comment -}

View File

@ -0,0 +1,5 @@
foo = 5 :: Int
bar =
5
:: Int

View File

@ -0,0 +1,4 @@
foo = 5 :: Int
bar = 5
:: Int

View File

@ -8,5 +8,5 @@ multiline = case () of
y
) -> ()
$( y
"something'"
"something"
) -> ()

View File

@ -8,4 +8,4 @@ multiline = case () of
$(x
+ y) -> ()
$(y
"something'") -> ()
"something") -> ()

View File

@ -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

View File

@ -1,4 +1,4 @@
-- | Ormolu-specfiic representation of GHC annotations.
-- | Ormolu-specific representation of GHC annotations.
module Ormolu.Anns
( Anns (..)

View File

@ -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"

View 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"

View File

@ -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