@@ -494,7 +494,8 @@ fixes up only indentation."
494
494
(" newtype" . haskell-indentation-data)
495
495
(" import" . haskell-indentation-import)
496
496
(" class" . haskell-indentation-class-declaration)
497
- (" instance" . haskell-indentation-class-declaration))
497
+ (" instance" . haskell-indentation-class-declaration)
498
+ (" deriving" . haskell-indentation-deriving))
498
499
" Alist of toplevel keywords with associated parsers." )
499
500
500
501
(defconst haskell-indentation-type-list
@@ -633,6 +634,25 @@ After a lambda (backslash) there are two possible cases:
633
634
(throw 'return nil )
634
635
(funcall (cdr parser))))))))))
635
636
637
+ (defun haskell-indentation-type-1 ()
638
+ " Parse a single type declaration."
639
+ (let ((current-indent (current-column )))
640
+ (catch 'return
641
+ (cond
642
+ ((member current-token '(value operator " ->" ))
643
+ (haskell-indentation-read-next-token))
644
+
645
+ ((eq current-token 'end-tokens )
646
+ (when (member following-token
647
+ '(value operator no-following-token
648
+ " ->" " (" " [" " {" " ::" ))
649
+ (haskell-indentation-add-indentation current-indent))
650
+ (throw 'return nil ))
651
+ (t (let ((parser (assoc current-token haskell-indentation-type-list)))
652
+ (if (not parser)
653
+ (throw 'return nil )
654
+ (funcall (cdr parser)))))))))
655
+
636
656
(defun haskell-indentation-scoped-type ()
637
657
" Parse scoped type declaration.
638
658
@@ -655,13 +675,30 @@ For example
655
675
(haskell-indentation-add-indentation current-indent)
656
676
(throw 'parse-end nil )))
657
677
((string= current-token " =" )
658
- (haskell-indentation-with-starter
659
- (lambda ()
660
- (haskell-indentation-separated
661
- #'haskell-indentation-expression " |" " deriving" ))))
678
+ (let ((starter-indent-inside (current-column )))
679
+ (haskell-indentation-with-starter
680
+ (lambda ()
681
+ (haskell-indentation-separated
682
+ #'haskell-indentation-expression " |" )))
683
+ (cond
684
+ ((equal current-token 'end-tokens )
685
+ (when (string= following-token " deriving" )
686
+ (haskell-indentation-push-indentation starter-indent-inside)
687
+ (haskell-indentation-add-left-indent)))
688
+ ((equal current-token " deriving" )
689
+ (haskell-indentation-with-starter
690
+ #'haskell-indentation-type-1 )))))
662
691
((string= current-token " where" )
663
- (haskell-indentation-with-starter
664
- #'haskell-indentation-expression-layout nil ))))
692
+ (let ((starter-indent-inside (current-column )))
693
+ (haskell-indentation-with-starter
694
+ #'haskell-indentation-expression-layout nil )
695
+ (cond
696
+ ((equal current-token 'end-tokens )
697
+ (when (string= following-token " deriving" )
698
+ (haskell-indentation-add-left-indent)))
699
+ ((equal current-token " deriving" )
700
+ (haskell-indentation-with-starter
701
+ #'haskell-indentation-type-1 )))))))
665
702
666
703
(defun haskell-indentation-import ()
667
704
" Parse import declaration."
@@ -678,6 +715,19 @@ For example
678
715
(haskell-indentation-with-starter
679
716
#'haskell-indentation-declaration-layout nil )))))
680
717
718
+ (defun haskell-indentation-deriving ()
719
+ " Parse standalone declaration."
720
+ (haskell-indentation-with-starter
721
+ (lambda ()
722
+ (when (string= " instance" current-token)
723
+ (haskell-indentation-read-next-token))
724
+ (when (equal current-token 'end-tokens )
725
+ (haskell-indentation-add-left-indent)
726
+ (throw 'parse-end nil ))
727
+ (haskell-indentation-type)
728
+ (when (string= current-token " |" )
729
+ (haskell-indentation-fundep)))))
730
+
681
731
(defun haskell-indentation-module ()
682
732
" Parse module declaration."
683
733
(haskell-indentation-with-starter
0 commit comments