Skip to content

Support scoped types in indentation #874

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

Merged
merged 2 commits into from
Sep 14, 2015
Merged
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
16 changes: 12 additions & 4 deletions haskell-indentation.el
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,7 @@ the current buffer."
("where" .
,(apply-partially 'haskell-indentation-with-starter
'haskell-indentation-declaration-layout nil t))
("::" .
,(apply-partially 'haskell-indentation-with-starter
(apply-partially #'haskell-indentation-separated
#'haskell-indentation-type "->")))
("::" . haskell-indentation-scoped-type)
("=" .
,(apply-partially 'haskell-indentation-statement-right
'haskell-indentation-expression))
Expand Down Expand Up @@ -834,6 +831,17 @@ After a lambda (backslash) there are two possible cases:
(throw 'return nil)
(funcall (cdr parser))))))))))

(defun haskell-indentation-scoped-type ()
"Parse scoped type declaration.

For example
let x :: Int = 12
do x :: Int <- return 12"
(haskell-indentation-with-starter
(apply-partially #'haskell-indentation-separated #'haskell-indentation-type "->"))
(when (member current-token '("<-" "="))
(haskell-indentation-statement-right #'haskell-indentation-expression)))

(defun haskell-indentation-data ()
"Parse data or type declaration."
(haskell-indentation-with-starter
Expand Down
28 changes: 25 additions & 3 deletions tests/haskell-indentation-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -524,15 +524,37 @@ func = 1234
-}"
((3 2) 0))

(hindent-test "24* should parse inline type signatures properly" "
(hindent-test "24 should parse inline type signatures properly" "
foo = do
_ :: String <- undefined
_ :: String <- undefined
return ()"
((1 0) 0)
((2 0) 2)
((3 0) 2 17)
((4 0) 2 17))
((3 0) 0 2 17)
((4 0) 0 2 17))

(hindent-test "25a* support scoped type declarations" "
foo = do
bar :: String
-> String
<- undefined"
((1 0) 0)
((2 0) 2)
((3 0) 6 9)
;; here it brakes, it would like to put '<-' on same line with 'bar'
;; the culprit is the 'do' keyword
((4 0) 4))

(hindent-test "25b support scoped type declarations" "
foo = let
bar :: String
-> String
= undefined"
((1 0) 0)
((2 0) 2)
((3 0) 6 9)
((4 0) 4))


;;; haskell-indentation-tests.el ends here