Skip to content

Handle instance context in haskell-indentation #708

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
Jun 7, 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
8 changes: 4 additions & 4 deletions haskell-indentation.el
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ the current buffer."
;; tokens in type declarations
(defconst haskell-indentation-type-list
'(("::" . (lambda () (haskell-indentation-with-starter
(lambda () (haskell-indentation-separated #'haskell-indentation-type '("->" "=>"))))))
(lambda () (haskell-indentation-separated #'haskell-indentation-type "->")))))
("(" . (lambda () (haskell-indentation-list #'haskell-indentation-type ")" ",")))
("[" . (lambda () (haskell-indentation-list #'haskell-indentation-type "]" ",")))
("{" . (lambda () (haskell-indentation-list #'haskell-indentation-type "}" ",")))))
Expand Down Expand Up @@ -637,7 +637,7 @@ the current buffer."
("where" . (lambda () (haskell-indentation-with-starter
#'haskell-indentation-declaration-layout nil t)))
("::" . (lambda () (haskell-indentation-with-starter
(lambda () (haskell-indentation-separated #'haskell-indentation-type '("->" "=>"))))))
(lambda () (haskell-indentation-separated #'haskell-indentation-type "->")))))
("=" . (lambda () (haskell-indentation-statement-right #'haskell-indentation-expression)))
("<-" . (lambda () (haskell-indentation-statement-right #'haskell-indentation-expression)))
("(" . (lambda () (haskell-indentation-list #'haskell-indentation-expression ")" '(list "," "->"))))
Expand Down Expand Up @@ -702,7 +702,7 @@ the current buffer."
((eq current-token 'end-tokens)
(when (member following-token
'(value operator no-following-token
"(" "[" "{" "::"))
"->" "(" "[" "{" "::"))
(haskell-indentation-add-indentation current-indent))
(throw 'return nil))
(t (let ((parser (assoc current-token haskell-indentation-type-list)))
Expand Down Expand Up @@ -1167,7 +1167,7 @@ the current buffer."
(match-string-no-properties 1))
((looking-at "[][(){}[,;]")
(match-string-no-properties 0))
((looking-at "\\(\\\\\\|->\\|=>\\|→\\|<-\\|←\\|::\\|∷\\|=\\||\\)\\([^-:!#$%&*+./<=>?@\\\\^|~]\\|$\\)")
((looking-at "\\(\\\\\\|->\\|→\\|<-\\|←\\|::\\|∷\\|=\\||\\)\\([^-:!#$%&*+./<=>?@\\\\^|~]\\|$\\)")
(match-string-no-properties 1))
((looking-at "\\(→\\|←\\|∷\\)\\([^-:!#$%&*+./<=>?@\\\\^|~]\\|$\\)")
(let ((tok (match-string-no-properties 1)))
Expand Down
96 changes: 96 additions & 0 deletions tests/haskell-indentation-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -198,29 +198,125 @@ Example of lines:

(ert-deftest haskell-indentation-check-17a ()
"A type for a function"
:expected-result :failed
(haskell-indentation-check
"fun :: Int"
" -> Int"
" ^"))

(ert-deftest haskell-indentation-check-17b ()
"A type for a function with context"
:expected-result :failed
(haskell-indentation-check
"fun :: Monad m"
" => Int"
" ^"))

(ert-deftest haskell-indentation-check-17c ()
"A type for a function with complicated context"
:expected-result :failed
(haskell-indentation-check
"fun :: (Monad m, MonadBaseControl IO m, MyMonad (A v) m)"
" => MyMonad (A v) m"
" ^"))

(ert-deftest haskell-indentation-check-17d ()
"A type for a function with param and a complicated context"
:expected-result :failed
(haskell-indentation-check
"fun :: (Monad m, MonadBaseControl IO m, MyMonad (A v) m)"
" => MyMonad (A v) m"
" -> m (Maybe a)"
" ^"))

(ert-deftest haskell-indentation-check-18a ()
"if then else indentation: then"
(haskell-indentation-check
"x = if flag"
" then 1"
" ^"))

(ert-deftest haskell-indentation-check-18b ()
"if then else indentation: else"
(haskell-indentation-check
"x = if flag"
" then 1"
" else 0"
" ^"))

(ert-deftest haskell-indentation-check-18c ()
"do and if then else indentation: then"
(haskell-indentation-check
"x = do"
" if flag"
" then 1"
" ^"))

(ert-deftest haskell-indentation-check-18d ()
"do and if then else indentation: else"
(haskell-indentation-check
"x = do"
" if flag"
" then 1"
" else 0"
" ^"))

(ert-deftest haskell-indentation-check-18e ()
"do and if then else indentation: else"
:expected-result :failed
(haskell-indentation-check
"x = do"
" if flag"
" then do"
" return ()"
" ^"))

(ert-deftest haskell-indentation-check-18f ()
"do and if then else indentation: else"
:expected-result :failed
(haskell-indentation-check
"x = do"
" if flag"
" then do"
" return ()"
" else do"
" return ()"
" ^"))

(ert-deftest haskell-indentation-check-19a ()
"let and in"
(haskell-indentation-check
"x = let"
" y"
" ^"))

(ert-deftest haskell-indentation-check-19b ()
"let and in"
(haskell-indentation-check
"x = let y"
" in "
" z "
" ^"))

(ert-deftest haskell-indentation-check-19c ()
"let in a do"
(haskell-indentation-check
"x = do"
" thing"
" let "
" z = 5"
" ^"))

(ert-deftest haskell-indentation-check-instance-20a ()
"instance declaration"
(haskell-indentation-check
"instance C a where"
" c = undefined"
" ^"))

(ert-deftest haskell-indentation-check-instance-20b ()
"instance declaration"
(haskell-indentation-check
"instance (Monad m) => C m a where"
" c = undefined"
" ^"))