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