Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
GHC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
4,310
Issues
4,310
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
382
Merge Requests
382
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
9c889adc
Commit
9c889adc
authored
Aug 22, 2011
by
Simon Peyton Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pretty-printing improvements in HsSyn
parent
cd3d6f88
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
29 deletions
+35
-29
compiler/hsSyn/HsBinds.lhs
compiler/hsSyn/HsBinds.lhs
+16
-14
compiler/hsSyn/HsDecls.lhs
compiler/hsSyn/HsDecls.lhs
+19
-15
No files found.
compiler/hsSyn/HsBinds.lhs
View file @
9c889adc
...
...
@@ -191,40 +191,42 @@ instance (OutputableBndr idL, OutputableBndr idR) => Outputable (HsLocalBindsLR
instance (OutputableBndr idL, OutputableBndr idR) => Outputable (HsValBindsLR idL idR) where
ppr (ValBindsIn binds sigs)
= ppr
Val
BindsForUser binds sigs
= ppr
LHs
BindsForUser binds sigs
ppr (ValBindsOut sccs sigs)
= getPprStyle $ \ sty ->
if debugStyle sty then -- Print with sccs showing
vcat (map ppr sigs) $$ vcat (map ppr_scc sccs)
else
ppr
Val
BindsForUser (unionManyBags (map snd sccs)) sigs
ppr
LHs
BindsForUser (unionManyBags (map snd sccs)) sigs
where
ppr_scc (rec_flag, binds) = pp_rec rec_flag <+> pprLHsBinds binds
pp_rec Recursive = ptext (sLit "rec")
pp_rec NonRecursive = ptext (sLit "nonrec")
-- *not* pprLHsBinds because we don't want braces; 'let' and
-- 'where' include a list of HsBindGroups and we don't want
-- several groups of bindings each with braces around.
-- Sort by location before printing
pprValBindsForUser :: (OutputableBndr idL, OutputableBndr idR, OutputableBndr id2)
pprLHsBinds :: (OutputableBndr idL, OutputableBndr idR) => LHsBindsLR idL idR -> SDoc
pprLHsBinds binds
| isEmptyLHsBinds binds = empty
| otherwise = lbrace <+> pprDeeperList vcat (map ppr (bagToList binds)) <+> rbrace
pprLHsBindsForUser :: (OutputableBndr idL, OutputableBndr idR, OutputableBndr id2)
=> LHsBindsLR idL idR -> [LSig id2] -> SDoc
pprValBindsForUser binds sigs
-- pprLHsBindsForUser is different to pprLHsBinds because
-- a) No braces: 'let' and 'where' include a list of HsBindGroups
-- and we don't want several groups of bindings each
-- with braces around
-- b) Sort by location before printing
-- c) Include signatures
pprLHsBindsForUser binds sigs
= pprDeeperList vcat (map snd (sort_by_loc decls))
where
decls :: [(SrcSpan, SDoc)]
decls = [(loc, ppr sig) | L loc sig <- sigs] ++
[(loc, ppr bind) | L loc bind <- bagToList binds]
[(loc, ppr bind) | L loc bind <- bagToList binds]
sort_by_loc decls = sortLe (\(l1,_) (l2,_) -> l1 <= l2) decls
pprLHsBinds :: (OutputableBndr idL, OutputableBndr idR) => LHsBindsLR idL idR -> SDoc
pprLHsBinds binds
| isEmptyLHsBinds binds = empty
| otherwise = lbrace <+> pprDeeperList vcat (map ppr (bagToList binds)) <+> rbrace
------------
emptyLocalBinds :: HsLocalBindsLR a b
emptyLocalBinds = EmptyLocalBinds
...
...
compiler/hsSyn/HsDecls.lhs
View file @
9c889adc
...
...
@@ -73,6 +73,7 @@ import Util
import SrcLoc
import FastString
import Bag
import Control.Monad ( liftM )
import Data.Data hiding (TyCon)
import Data.Maybe ( isJust )
...
...
@@ -639,17 +640,13 @@ instance OutputableBndr name
= top_matter
| otherwise -- Laid out
= sep [hsep [top_matter, ptext (sLit "where {")],
nest 4 (sep [ sep (map ppr_semi ats)
, sep (map ppr_semi sigs)
, pprLHsBinds methods
, char '}'])]
= hang (hsep [top_matter, ptext (sLit "where")])
2 (bracesSp (sep [ vcat (map ppr ats)
, pprLHsBindsForUser methods sigs ]))
where
top_matter = ptext (sLit "class")
<+> pp_decl_head (unLoc context) lclas tyvars Nothing
<+> pprFundeps (map unLoc fds)
ppr_semi :: Outputable a => a -> SDoc
ppr_semi decl = ppr decl <> semi
top_matter = ptext (sLit "class")
<+> pp_decl_head (unLoc context) lclas tyvars Nothing
<+> pprFundeps (map unLoc fds)
pp_decl_head :: OutputableBndr name
=> HsContext name
...
...
@@ -818,17 +815,24 @@ data InstDecl name
deriving (Data, Typeable)
instance (OutputableBndr name) => Outputable (InstDecl name) where
ppr (InstDecl inst_ty binds sigs ats)
| null sigs && null ats && isEmptyBag binds -- No "where" part
= top_matter
ppr (InstDecl inst_ty binds uprags ats)
= vcat [hsep [ptext (sLit "instance"), ppr inst_ty, ptext (sLit "where")]
, nest 4 $ vcat (map ppr ats)
, nest 4 $ vcat (map ppr uprags)
, nest 4 $ pprLHsBinds binds ]
| otherwise -- Laid out
= hang (top_matter <+> ptext (sLit "where"))
2 (bracesSp (vcat [ vcat (map ppr ats)
, pprLHsBindsForUser binds sigs ]))
where
top_matter = ptext (sLit "instance") <+> ppr inst_ty
-- Extract the declarations of associated types from an instance
--
instDeclATs :: [LInstDecl name] -> [LTyClDecl name]
instDeclATs inst_decls = [at | L _ (InstDecl _ _ _ ats) <- inst_decls, at <- ats]
bracesSp :: SDoc -> SDoc -- Braces with a space
bracesSp d = lbrace <+> d <+> rbrace
\end{code}
%************************************************************************
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment