Skip to content

Commit b2706d8

Browse files
committed
Merge pull request #708 from gracjan/pr-instance-context
Handle instance context in haskell-indentation
2 parents 4291cb9 + 69562d3 commit b2706d8

File tree

2 files changed

+100
-4
lines changed

2 files changed

+100
-4
lines changed

haskell-indentation.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ the current buffer."
606606
;; tokens in type declarations
607607
(defconst haskell-indentation-type-list
608608
'(("::" . (lambda () (haskell-indentation-with-starter
609-
(lambda () (haskell-indentation-separated #'haskell-indentation-type '("->" "=>"))))))
609+
(lambda () (haskell-indentation-separated #'haskell-indentation-type "->")))))
610610
("(" . (lambda () (haskell-indentation-list #'haskell-indentation-type ")" ",")))
611611
("[" . (lambda () (haskell-indentation-list #'haskell-indentation-type "]" ",")))
612612
("{" . (lambda () (haskell-indentation-list #'haskell-indentation-type "}" ",")))))
@@ -637,7 +637,7 @@ the current buffer."
637637
("where" . (lambda () (haskell-indentation-with-starter
638638
#'haskell-indentation-declaration-layout nil t)))
639639
("::" . (lambda () (haskell-indentation-with-starter
640-
(lambda () (haskell-indentation-separated #'haskell-indentation-type '("->" "=>"))))))
640+
(lambda () (haskell-indentation-separated #'haskell-indentation-type "->")))))
641641
("=" . (lambda () (haskell-indentation-statement-right #'haskell-indentation-expression)))
642642
("<-" . (lambda () (haskell-indentation-statement-right #'haskell-indentation-expression)))
643643
("(" . (lambda () (haskell-indentation-list #'haskell-indentation-expression ")" '(list "," "->"))))
@@ -702,7 +702,7 @@ the current buffer."
702702
((eq current-token 'end-tokens)
703703
(when (member following-token
704704
'(value operator no-following-token
705-
"(" "[" "{" "::"))
705+
"->" "(" "[" "{" "::"))
706706
(haskell-indentation-add-indentation current-indent))
707707
(throw 'return nil))
708708
(t (let ((parser (assoc current-token haskell-indentation-type-list)))
@@ -1167,7 +1167,7 @@ the current buffer."
11671167
(match-string-no-properties 1))
11681168
((looking-at "[][(){}[,;]")
11691169
(match-string-no-properties 0))
1170-
((looking-at "\\(\\\\\\|->\\|=>\\|\\|<-\\|←\\|::\\|∷\\|=\\||\\)\\([^-:!#$%&*+./<=>?@\\\\^|~]\\|$\\)")
1170+
((looking-at "\\(\\\\\\|->\\|→\\|<-\\|←\\|::\\|∷\\|=\\||\\)\\([^-:!#$%&*+./<=>?@\\\\^|~]\\|$\\)")
11711171
(match-string-no-properties 1))
11721172
((looking-at "\\(→\\|←\\|∷\\)\\([^-:!#$%&*+./<=>?@\\\\^|~]\\|$\\)")
11731173
(let ((tok (match-string-no-properties 1)))

tests/haskell-indentation-tests.el

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,29 +198,125 @@ Example of lines:
198198

199199
(ert-deftest haskell-indentation-check-17a ()
200200
"A type for a function"
201+
:expected-result :failed
201202
(haskell-indentation-check
202203
"fun :: Int"
203204
" -> Int"
204205
" ^"))
205206

206207
(ert-deftest haskell-indentation-check-17b ()
207208
"A type for a function with context"
209+
:expected-result :failed
208210
(haskell-indentation-check
209211
"fun :: Monad m"
210212
" => Int"
211213
" ^"))
212214

213215
(ert-deftest haskell-indentation-check-17c ()
214216
"A type for a function with complicated context"
217+
:expected-result :failed
215218
(haskell-indentation-check
216219
"fun :: (Monad m, MonadBaseControl IO m, MyMonad (A v) m)"
217220
" => MyMonad (A v) m"
218221
" ^"))
219222

220223
(ert-deftest haskell-indentation-check-17d ()
221224
"A type for a function with param and a complicated context"
225+
:expected-result :failed
222226
(haskell-indentation-check
223227
"fun :: (Monad m, MonadBaseControl IO m, MyMonad (A v) m)"
224228
" => MyMonad (A v) m"
225229
" -> m (Maybe a)"
226230
" ^"))
231+
232+
(ert-deftest haskell-indentation-check-18a ()
233+
"if then else indentation: then"
234+
(haskell-indentation-check
235+
"x = if flag"
236+
" then 1"
237+
" ^"))
238+
239+
(ert-deftest haskell-indentation-check-18b ()
240+
"if then else indentation: else"
241+
(haskell-indentation-check
242+
"x = if flag"
243+
" then 1"
244+
" else 0"
245+
" ^"))
246+
247+
(ert-deftest haskell-indentation-check-18c ()
248+
"do and if then else indentation: then"
249+
(haskell-indentation-check
250+
"x = do"
251+
" if flag"
252+
" then 1"
253+
" ^"))
254+
255+
(ert-deftest haskell-indentation-check-18d ()
256+
"do and if then else indentation: else"
257+
(haskell-indentation-check
258+
"x = do"
259+
" if flag"
260+
" then 1"
261+
" else 0"
262+
" ^"))
263+
264+
(ert-deftest haskell-indentation-check-18e ()
265+
"do and if then else indentation: else"
266+
:expected-result :failed
267+
(haskell-indentation-check
268+
"x = do"
269+
" if flag"
270+
" then do"
271+
" return ()"
272+
" ^"))
273+
274+
(ert-deftest haskell-indentation-check-18f ()
275+
"do and if then else indentation: else"
276+
:expected-result :failed
277+
(haskell-indentation-check
278+
"x = do"
279+
" if flag"
280+
" then do"
281+
" return ()"
282+
" else do"
283+
" return ()"
284+
" ^"))
285+
286+
(ert-deftest haskell-indentation-check-19a ()
287+
"let and in"
288+
(haskell-indentation-check
289+
"x = let"
290+
" y"
291+
" ^"))
292+
293+
(ert-deftest haskell-indentation-check-19b ()
294+
"let and in"
295+
(haskell-indentation-check
296+
"x = let y"
297+
" in "
298+
" z "
299+
" ^"))
300+
301+
(ert-deftest haskell-indentation-check-19c ()
302+
"let in a do"
303+
(haskell-indentation-check
304+
"x = do"
305+
" thing"
306+
" let "
307+
" z = 5"
308+
" ^"))
309+
310+
(ert-deftest haskell-indentation-check-instance-20a ()
311+
"instance declaration"
312+
(haskell-indentation-check
313+
"instance C a where"
314+
" c = undefined"
315+
" ^"))
316+
317+
(ert-deftest haskell-indentation-check-instance-20b ()
318+
"instance declaration"
319+
(haskell-indentation-check
320+
"instance (Monad m) => C m a where"
321+
" c = undefined"
322+
" ^"))

0 commit comments

Comments
 (0)