on master help sign in
Introduce ‘commaDel’
commit78e2d3df4c5a9406bdd1cabf73c5ea7480abb609 authorMark Karpov <markkarpov92@gmail.com> dateWed 27 May 2020, 16:12 (6 years ago) parentc84eaa9
9 files changed+36−35
src/Ormolu/Printer/Combinators.hs+5 src/Ormolu/Printer/Meat/Declaration/Class.hs+1−1 src/Ormolu/Printer/Meat/Declaration/Data.hs+2−2 src/Ormolu/Printer/Meat/Declaration/Default.hs+1−1 src/Ormolu/Printer/Meat/Declaration/Signature.hs+6−6 src/Ormolu/Printer/Meat/Declaration/Value.hs+12−12 src/Ormolu/Printer/Meat/Declaration/Warning.hs+2−2 src/Ormolu/Printer/Meat/ImportExport.hs+1−1 src/Ormolu/Printer/Meat/Type.hs+6−10
src/Ormolu/Printer/Combinators.hs+5
@@ -51,6 +51,7 @@ module Ormolu.Printer.Combinators
5151
5252 -- ** Literals
5353 comma,
54+ commaDel,
5455 equals,
5556
5657 -- ** Stateful markers
@@ -280,6 +281,10 @@ brackets_ needBreaks open close style m = sitcc (vlayout singleLine multiLine)
280281comma :: R ()
281282comma = txt ","
282283
284+-- | Delimiting combination with 'comma'. To be used with 'sep'.
285+commaDel :: R ()
286+commaDel = comma >> breakpoint
287+
283288-- | Print @=@. Do not use @'txt' "="@.
284289equals :: R ()
285290equals = interferingTxt "="
src/Ormolu/Printer/Meat/Declaration/Class.hs+1−1
@@ -82,7 +82,7 @@ p_classFundeps fdeps = unless (null fdeps) $ do
8282 breakpoint
8383 txt "|"
8484 space
85− sitcc $ sep (comma >> breakpoint) (sitcc . located' p_funDep) fdeps
85+ sitcc $ sep commaDel (sitcc . located' p_funDep) fdeps
8686
8787p_funDep :: FunDep (Located RdrName) -> R ()
8888p_funDep (before, after) = do
src/Ormolu/Printer/Meat/Declaration/Data.hs+2−2
@@ -108,7 +108,7 @@ p_conDecl singleConstRec = \case
108108 unless (null cs) . inci $ do
109109 comma
110110 breakpoint
111− sitcc $ sep (comma >> breakpoint) p_rdrName cs
111+ sitcc $ sep commaDel p_rdrName cs
112112 space
113113 inci $ do
114114 txt "::"
@@ -213,7 +213,7 @@ p_hsDerivingClause HsDerivingClause {..} = do
213213 xs ->
214214 parens N $
215215 sep
216− (comma >> breakpoint)
216+ commaDel
217217 (sitcc . located' p_hsType . hsib_body)
218218 xs
219219 space
src/Ormolu/Printer/Meat/Declaration/Default.hs+1−1
@@ -16,5 +16,5 @@ p_defaultDecl = \case
1616 txt "default"
1717 breakpoint
1818 inci . parens N $
19− sep (comma >> breakpoint) (sitcc . located' p_hsType) ts
19+ sep commaDel (sitcc . located' p_hsType) ts
2020 XDefaultDecl x -> noExtCon x
src/Ormolu/Printer/Meat/Declaration/Signature.hs+6−6
@@ -52,7 +52,7 @@ p_typeSig indentTail (n : ns) hswc = do
5252 comma
5353 breakpoint
5454 bool id inci indentTail $ do
55− sep (comma >> breakpoint) p_rdrName ns
55+ sep commaDel p_rdrName ns
5656 p_typeAscription hswc
5757
5858p_typeAscription ::
@@ -108,7 +108,7 @@ p_fixSig = \case
108108 space
109109 atom n
110110 space
111− sitcc $ sep (comma >> breakpoint) p_rdrName names
111+ sitcc $ sep commaDel p_rdrName names
112112 XFixitySig x -> noExtCon x
113113
114114p_inlineSig ::
@@ -147,7 +147,7 @@ p_specSig name ts InlinePragma {..} = pragmaBraces $ do
147147 space
148148 txt "::"
149149 breakpoint
150− inci $ sep (comma >> breakpoint) (located' p_hsType . hsib_body) ts
150+ inci $ sep commaDel (located' p_hsType . hsib_body) ts
151151
152152p_inlineSpec :: InlineSpec -> R ()
153153p_inlineSpec = \case
@@ -191,13 +191,13 @@ p_booleanFormula = \case
191191 And xs ->
192192 sitcc $
193193 sep
194− (comma >> breakpoint)
194+ commaDel
195195 (located' p_booleanFormula)
196196 xs
197197 Or xs ->
198198 sitcc $
199199 sep
200− (breakpoint >> txt "| ")
200+ (breakpoint >> txt "|" >> space)
201201 (located' p_booleanFormula)
202202 xs
203203 Parens l -> located l (parens N . p_booleanFormula)
@@ -211,7 +211,7 @@ p_completeSig ::
211211p_completeSig cs' mty =
212212 located cs' $ \cs ->
213213 pragma "COMPLETE" . inci $ do
214− sep (comma >> breakpoint) p_rdrName cs
214+ sep commaDel p_rdrName cs
215215 forM_ mty $ \ty -> do
216216 space
217217 txt "::"
src/Ormolu/Printer/Meat/Declaration/Value.hs+12−12
@@ -284,7 +284,7 @@ p_grhs' placer render style (GRHS NoExtField guards body) =
284284 xs -> do
285285 txt "|"
286286 space
287− sitcc (sep (comma >> breakpoint) (sitcc . located' p_stmt) xs)
287+ sitcc (sep commaDel (sitcc . located' p_stmt) xs)
288288 space
289289 inci $ case style of
290290 EqualSign -> equals
@@ -655,7 +655,7 @@ p_hsExpr' s = \case
655655 sep comma (located' p_hsTupArg) args
656656 else
657657 switchLayout (getLoc <$> args) . parens' s $
658− sep (comma >> breakpoint) (sitcc . located' p_hsTupArg) args
658+ sep commaDel (sitcc . located' p_hsTupArg) args
659659 ExplicitSum NoExtField tag arity e ->
660660 p_unboxedSum N tag arity (located e p_hsExpr)
661661 HsCase NoExtField e mgroup ->
@@ -685,7 +685,7 @@ p_hsExpr' s = \case
685685 p_seqBody =
686686 sitcc
687687 . sep
688− (comma >> breakpoint)
688+ commaDel
689689 (located' (sitcc . p_stmt))
690690 stmts = init xs
691691 yield = last xs
@@ -707,7 +707,7 @@ p_hsExpr' s = \case
707707 TransStmtCtxt _ -> notImplemented "TransStmtCtxt"
708708 ExplicitList _ _ xs ->
709709 brackets s $
710− sep (comma >> breakpoint) (sitcc . located' p_hsExpr) xs
710+ sep commaDel (sitcc . located' p_hsExpr) xs
711711 RecordCon {..} -> do
712712 located rcon_con_name atom
713713 breakpoint
@@ -724,7 +724,7 @@ p_hsExpr' s = \case
724724 Just {} -> [txt ".."]
725725 Nothing -> []
726726 inci . braces N $
727− sep (comma >> breakpoint) sitcc (fields <> dotdot)
727+ sep commaDel sitcc (fields <> dotdot)
728728 RecordUpd {..} -> do
729729 located rupd_expr p_hsExpr
730730 useRecordDot' <- useRecordDot
@@ -744,7 +744,7 @@ p_hsExpr' s = \case
744744 }
745745 inci . braces N $
746746 sep
747− (comma >> breakpoint)
747+ commaDel
748748 (sitcc . located' (p_hsRecField . updName))
749749 rupd_flds
750750 ExprWithTySig NoExtField x HsWC {hswc_body = HsIB {..}} -> sitcc $ do
@@ -762,7 +762,7 @@ p_hsExpr' s = \case
762762 breakpoint
763763 txt ".."
764764 FromThen from next -> brackets s $ do
765− sep (comma >> breakpoint) (located' p_hsExpr) [from, next]
765+ sep commaDel (located' p_hsExpr) [from, next]
766766 breakpoint
767767 txt ".."
768768 FromTo from to -> brackets s $ do
@@ -772,7 +772,7 @@ p_hsExpr' s = \case
772772 space
773773 located to p_hsExpr
774774 FromThenTo from next to -> brackets s $ do
775− sep (comma >> breakpoint) (located' p_hsExpr) [from, next]
775+ sep commaDel (located' p_hsExpr) [from, next]
776776 breakpoint
777777 txt ".."
778778 space
@@ -850,7 +850,7 @@ p_patSynBind PSB {..} = do
850850 switchLayout (getLoc . recordPatSynPatVar <$> xs) $ do
851851 unless (null xs) breakpoint
852852 braces N $
853− sep (comma >> breakpoint) (p_rdrName . recordPatSynPatVar) xs
853+ sep commaDel (p_rdrName . recordPatSynPatVar) xs
854854 rhs
855855 InfixCon l r -> do
856856 switchLayout [getLoc l, getLoc r] $ do
@@ -946,13 +946,13 @@ p_pat = \case
946946 txt "!"
947947 located pat p_pat
948948 ListPat NoExtField pats ->
949− brackets S $ sep (comma >> breakpoint) (located' p_pat) pats
949+ brackets S $ sep commaDel (located' p_pat) pats
950950 TuplePat NoExtField pats boxing -> do
951951 let parens' =
952952 case boxing of
953953 Boxed -> parens S
954954 Unboxed -> parensHash S
955− parens' $ sep (comma >> breakpoint) (sitcc . located' p_pat) pats
955+ parens' $ sep commaDel (sitcc . located' p_pat) pats
956956 SumPat NoExtField pat tag arity ->
957957 p_unboxedSum S tag arity (located pat p_pat)
958958 ConPatIn pat details ->
@@ -968,7 +968,7 @@ p_pat = \case
968968 let f = \case
969969 Nothing -> txt ".."
970970 Just x -> located x p_pat_hsRecField
971− inci . braces N . sep (comma >> breakpoint) f $
971+ inci . braces N . sep commaDel f $
972972 case dotdot of
973973 Nothing -> Just <$> fields
974974 Just (L _ n) -> (Just <$> take n fields) ++ [Nothing]
src/Ormolu/Printer/Meat/Declaration/Warning.hs+2−2
@@ -35,7 +35,7 @@ p_topLevelWarning fnames wtxt = do
3535 switchLayout (fmap getLoc fnames ++ fmap getLoc lits)
3636 $ pragma pragmaText . inci
3737 $ do
38− sep (comma >> breakpoint) p_rdrName fnames
38+ sep commaDel p_rdrName fnames
3939 breakpoint
4040 p_lits lits
4141
@@ -47,4 +47,4 @@ warningText = \case
4747p_lits :: [Located StringLiteral] -> R ()
4848p_lits = \case
4949 [l] -> atom l
50− ls -> brackets N $ sep (comma >> breakpoint) atom ls
50+ ls -> brackets N $ sep commaDel atom ls
src/Ormolu/Printer/Meat/ImportExport.hs+1−1
@@ -94,7 +94,7 @@ p_lie encLayout relativePos = \case
9494 let names :: [R ()]
9595 names = located' p_ieWrappedName <$> xs
9696 parens N
97− $ sep (comma >> breakpoint) sitcc
97+ $ sep commaDel sitcc
9898 $ case w of
9999 NoIEWildcard -> names
100100 IEWildcard n ->
src/Ormolu/Printer/Meat/Type.hs+6−10
@@ -98,8 +98,7 @@ p_hsType' multilineArgs docStyle = \case
9898 HsBoxedTuple -> parens N
9999 HsConstraintTuple -> parens N
100100 HsBoxedOrConstraintTuple -> parens N
101− in parens' $
102− sep (comma >> breakpoint) (sitcc . located' p_hsType) xs
101+ in parens' $ sep commaDel (sitcc . located' p_hsType) xs
103102 HsSumTy NoExtField xs ->
104103 parensHash N $
105104 sep (txt "|" >> breakpoint) (sitcc . located' p_hsType) xs
@@ -154,14 +153,14 @@ p_hsType' multilineArgs docStyle = \case
154153 case (p, xs) of
155154 (IsPromoted, L _ t : _) | isPromoted t -> space
156155 _ -> return ()
157− sep (comma >> breakpoint) (sitcc . located' p_hsType) xs
156+ sep commaDel (sitcc . located' p_hsType) xs
158157 HsExplicitTupleTy NoExtField xs -> do
159158 txt "'"
160159 parens N $ do
161160 case xs of
162161 L _ t : _ | isPromoted t -> space
163162 _ -> return ()
164− sep (comma >> breakpoint) (located' p_hsType) xs
163+ sep commaDel (located' p_hsType) xs
165164 HsTyLit NoExtField t ->
166165 case t of
167166 HsStrTy (SourceText s) _ -> p_stringLit s
@@ -192,9 +191,7 @@ p_hsContext :: HsContext GhcPs -> R ()
192191p_hsContext = \case
193192 [] -> txt "()"
194193 [x] -> located x p_hsType
195− xs ->
196− parens N $
197− sep (comma >> breakpoint) (sitcc . located' p_hsType) xs
194+ xs -> parens N $ sep commaDel (sitcc . located' p_hsType) xs
198195
199196p_hsTyVarBndr :: HsTyVarBndr GhcPs -> R ()
200197p_hsTyVarBndr = \case
@@ -224,15 +221,14 @@ p_forallBndrs vis p tyvars =
224221
225222p_conDeclFields :: [LConDeclField GhcPs] -> R ()
226223p_conDeclFields xs =
227− braces N $
228− sep (comma >> breakpoint) (sitcc . located' p_conDeclField) xs
224+ braces N $ sep commaDel (sitcc . located' p_conDeclField) xs
229225
230226p_conDeclField :: ConDeclField GhcPs -> R ()
231227p_conDeclField ConDeclField {..} = do
232228 mapM_ (p_hsDocString Pipe True) cd_fld_doc
233229 sitcc $
234230 sep
235− (comma >> breakpoint)
231+ commaDel
236232 (located' (p_rdrName . rdrNameFieldOcc))
237233 cd_fld_names
238234 space