hindent 2.2 → 2.3
raw patch · 4 files changed
+36/−28 lines, 4 files
Files
- hindent.cabal +1/−1
- src/HIndent.hs +0/−8
- src/HIndent/Pretty.hs +24/−13
- src/HIndent/Types.hs +11/−6
hindent.cabal view
@@ -1,5 +1,5 @@ name: hindent-version: 2.2+version: 2.3 synopsis: Extensible Haskell pretty printer description: Extensible Haskell pretty printer. Both a library and an executable. .
src/HIndent.hs view
@@ -125,11 +125,3 @@ (srcSpanStartLine after > srcSpanEndLine before) || ((srcSpanStartLine after == srcSpanEndLine before) && (srcSpanStartColumn after > srcSpanEndColumn before))--srcspan :: SrcSpan -> String-srcspan s =- show (srcSpanStartLine s) ++ ":" ++ show (srcSpanStartColumn s) ++ "-" ++- show (srcSpanEndLine s) ++ ":" ++ show (srcSpanEndColumn s)--com :: Comment -> String-com (Comment _ s _) = srcspan s
src/HIndent/Pretty.hs view
@@ -83,24 +83,22 @@ do st <- get case st of PrintState{psExtenders = es,psUserState = s} ->- case listToMaybe (mapMaybe (makePrinter s) es) of- Just m ->- do m- printComments a- Nothing -> prettyNoExt a+ do case listToMaybe (mapMaybe (makePrinter s) es) of+ Just m -> m+ Nothing -> prettyNoExt a+ printComments a where makePrinter s (Extender f) = case cast a of Just v -> Just (f s v) Nothing -> Nothing+ makePrinter s (CatchAll f) = Just (f s a) -- | Run the basic printer for the given node without calling an -- extension hook for this node, but do allow extender hooks in child -- nodes. Also auto-inserts comments. prettyNoExt :: (Pretty ast) => ast NodeInfo -> Printer ()-prettyNoExt a =- do prettyInternal a- printComments a+prettyNoExt a = prettyInternal a -- | Print comments of a node. printComments :: (Pretty ast)@@ -125,7 +123,7 @@ -- | Pretty print using HSE's own printer. The 'P.Pretty' class here -- is HSE's.-pretty' :: (P.Pretty (ast SrcSpanInfo),Functor ast)+pretty' :: (Pretty ast,P.Pretty (ast SrcSpanInfo),Functor ast) => ast NodeInfo -> Printer () pretty' = write . T.fromText . T.pack . P.prettyPrint . fmap nodeInfoSpan @@ -598,6 +596,17 @@ write "|") (do string s write "|"))+exp (LCase _ alts) =+ do write "\\case"+ indentSpaces <- getIndentSpaces+ newline+ indented indentSpaces (lined (map pretty alts))+exp (MultiIf _ alts) =+ depend (write "if ")+ (lined (map (\p ->+ do write "| "+ pretty p)+ alts)) exp x@XTag{} = pretty' x exp x@XETag{} = pretty' x exp x@XPcdata{} = pretty' x@@ -615,12 +624,14 @@ exp x@RightArrApp{} = pretty' x exp x@LeftArrHighApp{} = pretty' x exp x@RightArrHighApp{} = pretty' x-exp (LCase _ _) =- error "FIXME: No implementation for LCase."-exp (MultiIf _ _) =- error "FIXME: No implementation for MultiIf." exp ParComp{} = error "FIXME: No implementation for ParComp."++instance Pretty IfAlt where+ prettyInternal (IfAlt _ cond body) =+ do pretty cond+ swing (write " -> ")+ (pretty body) instance Pretty Stmt where prettyInternal x =
src/HIndent/Types.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE GADTs #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE ExistentialQuantification #-}@@ -25,7 +27,8 @@ import Language.Haskell.Exts.SrcLoc -- | A pretty printing monad.-newtype Printer a = Printer { runPrinter :: State PrintState a }+newtype Printer a =+ Printer {runPrinter :: State PrintState a} deriving (Monad,Functor,MonadState PrintState) -- | The state of the pretty printer.@@ -47,9 +50,10 @@ -- | A printer extender. Takes as argument the user state that the -- printer was run with, and the current node to print. Use--- 'prettyInternal' to fallback to the built-in printer.-data Extender s =- forall a. (Typeable a) => Extender (s -> a -> Printer ())+-- 'prettyNoExt' to fallback to the built-in printer.+data Extender s where+ Extender :: forall s a. (Typeable a) => (s -> a -> Printer ()) -> Extender s+ CatchAll :: forall s. (forall a. Typeable a => s -> a -> Printer ()) -> Extender s -- | A printer style. data Style =@@ -82,6 +86,7 @@ -- | Comment with some more info. data ComInfo =- ComInfo {comInfoComment :: !Comment- ,comInfoOwnLine :: !Bool}+ ComInfo {comInfoComment :: !Comment -- ^ The normal comment type.+ ,comInfoOwnLine :: !Bool -- ^ Does the comment rest on its own line?+ } deriving (Show,Typeable,Data)