Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor additions and test fixes #18

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/HIndent/Styles/Gibiansky.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ gibiansky =
, Extender typ
, Extender exprs
, Extender rhss
, Extender guardedRhs
, Extender decls
, Extender condecls
, Extender guardedAlts
Expand Down Expand Up @@ -176,6 +177,7 @@ exprs _ exp@(InfixApp _ _ (QVarOp _ (UnQual _ (Symbol _ "$"))) _) = dollarExpr e
exprs _ exp@(InfixApp _ _ (QVarOp _ (UnQual _ (Symbol _ "<*>"))) _) = applicativeExpr exp
exprs _ exp@Lambda{} = lambdaExpr exp
exprs _ exp@Case{} = caseExpr exp
exprs _ (Tuple _ _ exps) = parens $ inter (write ", ") $ map pretty exps
exprs _ exp = prettyNoExt exp

letExpr :: Exp NodeInfo -> Printer ()
Expand Down Expand Up @@ -358,6 +360,12 @@ rhss _ (UnGuardedRhs _ exp) = do
pretty exp
rhss _ rhs = prettyNoExt rhs

guardedRhs :: Extend GuardedRhs
guardedRhs _ (GuardedRhs _ stmts exp) = do
indented 1 $ prefixedLined "," (map (\p -> space >> pretty p) stmts)
write " = "
pretty exp

decls :: Extend Decl
decls _ (DataDecl _ dataOrNew Nothing declHead constructors mayDeriving) = do
pretty dataOrNew
Expand All @@ -383,8 +391,7 @@ decls _ (DataDecl _ dataOrNew Nothing declHead constructors mayDeriving) = do

decls _ (PatBind _ pat Nothing rhs mbinds) = funBody [pat] rhs mbinds
decls _ (FunBind _ matches) =
forM_ matches $ \match -> do

inter (write "\n") $ flip map matches $ \match -> do
(name, pat, rhs, mbinds) <-
case match of
Match _ name pat rhs mbinds -> return (name, pat, rhs, mbinds)
Expand Down Expand Up @@ -418,10 +425,7 @@ writeWhereBinds ds@(BDecls _ binds@(first:rest)) = do
printComments Before ds
pretty first
forM_ (zip binds rest) $ \(prev, cur) -> do
let prevLine = srcSpanEndLine . srcInfoSpan . nodeInfoSpan . ann $ prev
curLine = astStartLine cur
emptyLines = curLine - prevLine
replicateM_ emptyLines newline
replicateM_ (lineDelta cur prev) newline
pretty cur
writeWhereBinds binds = prettyNoExt binds

Expand Down Expand Up @@ -512,13 +516,18 @@ exportList _ (ExportSpecList _ exports) = do
write ","

forM_ (zip rest exports) $ \(cur, prev) -> do
let prevLine = srcSpanEndLine . srcInfoSpan . nodeInfoSpan . ann $ prev
curLine = astStartLine cur
emptyLines = curLine - prevLine
replicateM_ (max 1 emptyLines) newline
replicateM_ (max 1 $ lineDelta cur prev) newline
pretty cur
write ","
newline
write ")"
where
indentSpaces' = 2 * indentSpaces

lineDelta :: Annotated ast => ast NodeInfo -> ast NodeInfo -> Int
lineDelta cur prev = emptyLines
where
prevLine = srcSpanEndLine . srcInfoSpan . nodeInfoSpan . ann $ prev
curLine = astStartLine cur
emptyLines = curLine - prevLine

10 changes: 10 additions & 0 deletions test/gibiansky/expected/14.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
x = \y -> y

(1, 2)

f x = 3
f x = 3

f x
| x == y = 3
| x == y = 3
10 changes: 10 additions & 0 deletions test/gibiansky/tests/14.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
x = \y -> y

(1, 2)

f x = 3
f x = 3

f x
| x == y = 3
| x == y = 3