Merge pull request #77 from domenkozar/prettyprinter-fixes
Prettyprinter fixes
This commit is contained in:
commit
a28a8397cd
|
@ -81,16 +81,16 @@ prettyParams (ParamSet s mname) = prettyParamSet s <> case mname of
|
||||||
Just name -> text "@" <> text (unpack name)
|
Just name -> text "@" <> text (unpack name)
|
||||||
|
|
||||||
prettyParamSet :: ParamSet NixDoc -> Doc
|
prettyParamSet :: ParamSet NixDoc -> Doc
|
||||||
prettyParamSet params = lbrace <+> middle <+> rbrace
|
prettyParamSet params = encloseSep (lbrace <> space) (align rbrace) sep prettyArgs
|
||||||
where
|
where
|
||||||
|
prettySetArg (n, maybeDef) = case maybeDef of
|
||||||
|
Nothing -> text (unpack n)
|
||||||
|
Just v -> text (unpack n) <+> text "?" <+> withoutParens v
|
||||||
prettyArgs = case params of
|
prettyArgs = case params of
|
||||||
FixedParamSet args -> map prettySetArg (toList args)
|
FixedParamSet args -> map prettySetArg (toList args)
|
||||||
|
|
||||||
VariadicParamSet args -> map prettySetArg (toList args) ++ [text "..."]
|
VariadicParamSet args -> map prettySetArg (toList args) ++ [text "..."]
|
||||||
middle = hcat $ punctuate (comma <> space) prettyArgs
|
sep = align (comma <> space)
|
||||||
prettySetArg (n, maybeDef) = case maybeDef of
|
|
||||||
Nothing -> text (unpack n)
|
|
||||||
Just v -> text (unpack n) <+> text "?" <+> withoutParens v
|
|
||||||
|
|
||||||
prettyBind :: Binding NixDoc -> Doc
|
prettyBind :: Binding NixDoc -> Doc
|
||||||
prettyBind (NamedVar n v) = prettySelector n <+> equals <+> withoutParens v <> semi
|
prettyBind (NamedVar n v) = prettySelector n <+> equals <+> withoutParens v <> semi
|
||||||
|
@ -125,7 +125,7 @@ prettyNix = withoutParens . cata phi where
|
||||||
phi (NRecSet xs) = simpleExpr $ group $
|
phi (NRecSet xs) = simpleExpr $ group $
|
||||||
nest 2 (vsep $ recPrefix <> lbrace : map prettyBind xs) <$> rbrace
|
nest 2 (vsep $ recPrefix <> lbrace : map prettyBind xs) <$> rbrace
|
||||||
phi (NAbs args body) = leastPrecedence $
|
phi (NAbs args body) = leastPrecedence $
|
||||||
(prettyParams args <> colon) </> (nest 2 $ withoutParens body)
|
(prettyParams args <> colon) </> (indent 2 (withoutParens body))
|
||||||
phi (NBinary op r1 r2) = flip NixDoc opInfo $ hsep
|
phi (NBinary op r1 r2) = flip NixDoc opInfo $ hsep
|
||||||
[ wrapParens (f NAssocLeft) r1
|
[ wrapParens (f NAssocLeft) r1
|
||||||
, text $ operatorName opInfo
|
, text $ operatorName opInfo
|
||||||
|
@ -156,17 +156,17 @@ prettyNix = withoutParens . cata phi where
|
||||||
| "../" `isPrefixOf` txt -> txt
|
| "../" `isPrefixOf` txt -> txt
|
||||||
| otherwise -> "./" ++ txt
|
| otherwise -> "./" ++ txt
|
||||||
phi (NSym name) = simpleExpr $ text (unpack name)
|
phi (NSym name) = simpleExpr $ text (unpack name)
|
||||||
phi (NLet binds body) = leastPrecedence $ group $ nest 2 $
|
phi (NLet binds body) = leastPrecedence $ group $ text "let" <$> indent 2 (
|
||||||
vsep (text "let" : map prettyBind binds) <$> text "in" <+> withoutParens body
|
vsep (map prettyBind binds)) <$> text "in" <+> withoutParens body
|
||||||
phi (NIf cond trueBody falseBody) = leastPrecedence $
|
phi (NIf cond trueBody falseBody) = leastPrecedence $
|
||||||
group $ nest 2 $ (text "if" <+> withoutParens cond) <$>
|
group $ nest 2 $ (text "if" <+> withoutParens cond) <$>
|
||||||
( align (text "then" <+> withoutParens trueBody)
|
( align (text "then" <+> withoutParens trueBody)
|
||||||
<$> align (text "else" <+> withoutParens falseBody)
|
<$> align (text "else" <+> withoutParens falseBody)
|
||||||
)
|
)
|
||||||
phi (NWith scope body) = leastPrecedence $
|
phi (NWith scope body) = leastPrecedence $
|
||||||
text "with" <+> withoutParens scope <> semi <+> withoutParens body
|
text "with" <+> withoutParens scope <> semi <$> align (withoutParens body)
|
||||||
phi (NAssert cond body) = leastPrecedence $
|
phi (NAssert cond body) = leastPrecedence $
|
||||||
text "assert" <+> withoutParens cond <> semi <+> withoutParens body
|
text "assert" <+> withoutParens cond <> semi <$> align (withoutParens body)
|
||||||
|
|
||||||
recPrefix = text "rec" <> space
|
recPrefix = text "rec" <> space
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue