git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1709 from purescript/1645

Fix #1645, implement new indentation rules for types

commit6fee61345e7771fcf54948e0cde677c1ba867701 authorPhil Freeman <paf31@cantab.net> dateSun 13 Dec 2015, 14:11 (11 years ago) parent1eccf7c0d104d9
2 files changed+13−6
src/Language/PureScript/Pretty/Types.hs+12−6 src/Language/PureScript/Pretty/Values.hs+1
src/Language/PureScript/Pretty/Types.hs+12−6
@@ -121,21 +121,27 @@ constrained = mkPattern match
121121 match _ = Nothing
122122
123123matchTypeAtom :: Pattern () Type Box
124−matchTypeAtom = typeLiterals <+> fmap ((`before` text ")") . (text "(" <>)) matchType
124+matchTypeAtom = typeLiterals <+> fmap ((`before` (text ")")) . (text "(" <>)) matchType
125125
126126matchType :: Pattern () Type Box
127127matchType = buildPrettyPrinter operators matchTypeAtom
128128 where
129129 operators :: OperatorTable () Type Box
130130 operators =
131− OperatorTable [ [ AssocL typeApp $ \f x -> f `beforeWithSpace` x ]
132− , [ AssocR appliedFunction $ \arg ret -> (arg <> text " ") `before` (text "-> " <> ret)
133− ]
131+ OperatorTable [ [ AssocL typeApp $ \f x -> keepSingleLinesOr (moveRight 2) f x ]
132+ , [ AssocR appliedFunction $ \arg ret -> keepSingleLinesOr id arg (text "-> " <> ret) ]
134133 , [ Wrap constrained $ \deps ty -> constraintsAsBox deps ty ]
135− , [ Wrap forall_ $ \idents ty -> text ("forall " ++ unwords idents ++ ". ") <> ty ]
136− , [ Wrap kinded $ \k ty -> ty `before` text (" :: " ++ prettyPrintKind k) ]
134+ , [ Wrap forall_ $ \idents ty -> keepSingleLinesOr (moveRight 2) (text ("forall " ++ unwords idents ++ ".")) ty ]
135+ , [ Wrap kinded $ \k ty -> keepSingleLinesOr (moveRight 2) ty (text (":: " ++ prettyPrintKind k)) ]
137136 ]
138137
138+ -- If both boxes span a single line, keep them on the same line, or else
139+ -- use the specified function to modify the second box, then combine vertically.
140+ keepSingleLinesOr :: (Box -> Box) -> Box -> Box -> Box
141+ keepSingleLinesOr f b1 b2
142+ | rows b1 > 1 || rows b2 > 1 = vcat left [ b1, f b2 ]
143+ | otherwise = hcat top [ b1, text " ", b2]
144+
139145forall_ :: Pattern () Type ([String], Type)
140146forall_ = mkPattern match
141147 where
src/Language/PureScript/Pretty/Values.hs+1
@@ -160,6 +160,7 @@ prettyPrintBinderAtom (ArrayBinder bs) =
160160 ++ " ]"
161161prettyPrintBinderAtom (NamedBinder ident binder) = showIdent ident ++ "@" ++ prettyPrintBinder binder
162162prettyPrintBinderAtom (PositionedBinder _ _ binder) = prettyPrintBinderAtom binder
163+prettyPrintBinderAtom (TypedBinder _ binder) = prettyPrintBinderAtom binder
163164prettyPrintBinderAtom b = parens (prettyPrintBinder b)
164165
165166-- |