Skip to content

Commit 7933ca9

Browse files
committed
Merge pull request #1011 from gracjan/pr-non-recursive-rest
Non-recursive haskell-indentation-phrase-rest
2 parents 37e20e2 + c44356c commit 7933ca9

File tree

2 files changed

+57
-90
lines changed

2 files changed

+57
-90
lines changed

haskell-indentation.el

+55-52
Original file line numberDiff line numberDiff line change
@@ -969,60 +969,63 @@ layout starts."
969969
(apply-partially #'haskell-indentation-phrase-rest phrase)
970970
nil))
971971

972-
(defun haskell-indentation-phrase-rest (phrase)
972+
(defun haskell-indentation-phrase-rest (phrase1)
973973
"" ; FIXME
974-
(let ((starter-line parse-line-number))
975-
(let ((current-indent (current-column)))
976-
(funcall (car phrase)))
977-
(cond
978-
((eq current-token 'end-tokens)
979-
(cond ((null (cdr phrase))) ;; fallthrough
980-
((equal following-token (cadr phrase))
981-
(haskell-indentation-add-indentation starter-indent)
982-
(throw 'parse-end nil))
983-
((string= (cadr phrase) "in")
984-
(when (= left-indent layout-indent)
985-
(haskell-indentation-add-layout-indent)
986-
(throw 'parse-end nil)))
987-
(t (throw 'parse-end nil))))
988-
((null (cdr phrase)))
989-
((equal (cadr phrase) current-token)
990-
(let* ((on-new-line (= (current-column)
991-
(haskell-indentation-current-indentation)))
992-
(lines-between (- parse-line-number starter-line))
993-
(left-indent (if (<= lines-between 0)
994-
left-indent
995-
starter-indent)))
996-
(haskell-indentation-read-next-token)
997-
(when (eq current-token 'end-tokens)
998-
(cond ((member (cadr phrase) '("then" "else"))
999-
(haskell-indentation-add-indentation
1000-
(+ starter-indent haskell-indentation-ifte-offset)))
1001-
1002-
((member (cadr phrase) '("in" "->"))
1003-
;; expression ending in another expression
1004-
(when (or (not haskell-indentation-indent-leftmost)
1005-
(eq haskell-indentation-indent-leftmost 'both))
1006-
(haskell-indentation-add-indentation
1007-
(+ starter-indent haskell-indentation-starter-offset)))
1008-
(when haskell-indentation-indent-leftmost
1009-
(haskell-indentation-add-indentation
1010-
(if on-new-line
1011-
(+ left-indent haskell-indentation-starter-offset)
1012-
left-indent))))
1013-
(t
1014-
(when (or (not haskell-indentation-indent-leftmost)
1015-
(eq haskell-indentation-indent-leftmost 'both))
1016-
(haskell-indentation-add-indentation
1017-
(+ starter-indent haskell-indentation-starter-offset)))
1018-
(when haskell-indentation-indent-leftmost
974+
(while phrase1
975+
(let ((starter-line parse-line-number)
976+
(phrase phrase1))
977+
(setq phrase1 nil)
978+
(let ((current-indent (current-column)))
979+
(funcall (car phrase)))
980+
(cond
981+
((eq current-token 'end-tokens)
982+
(cond ((null (cdr phrase))) ;; fallthrough
983+
((equal following-token (cadr phrase))
984+
(haskell-indentation-add-indentation starter-indent)
985+
(throw 'parse-end nil))
986+
((string= (cadr phrase) "in")
987+
(when (= left-indent layout-indent)
988+
(haskell-indentation-add-layout-indent)
989+
(throw 'parse-end nil)))
990+
(t (throw 'parse-end nil))))
991+
((null (cdr phrase)))
992+
((equal (cadr phrase) current-token)
993+
(let* ((on-new-line (= (current-column)
994+
(haskell-indentation-current-indentation)))
995+
(lines-between (- parse-line-number starter-line))
996+
(left-indent (if (<= lines-between 0)
997+
left-indent
998+
starter-indent)))
999+
(haskell-indentation-read-next-token)
1000+
(when (eq current-token 'end-tokens)
1001+
(cond ((member (cadr phrase) '("then" "else"))
10191002
(haskell-indentation-add-indentation
1020-
(if on-new-line
1021-
(+ left-indent haskell-indentation-starter-offset)
1022-
left-indent)))))
1023-
(throw 'parse-end nil))
1024-
(haskell-indentation-phrase-rest (cddr phrase))))
1025-
((string= (cadr phrase) "in")))))
1003+
(+ starter-indent haskell-indentation-ifte-offset)))
1004+
1005+
((member (cadr phrase) '("in" "->"))
1006+
;; expression ending in another expression
1007+
(when (or (not haskell-indentation-indent-leftmost)
1008+
(eq haskell-indentation-indent-leftmost 'both))
1009+
(haskell-indentation-add-indentation
1010+
(+ starter-indent haskell-indentation-starter-offset)))
1011+
(when haskell-indentation-indent-leftmost
1012+
(haskell-indentation-add-indentation
1013+
(if on-new-line
1014+
(+ left-indent haskell-indentation-starter-offset)
1015+
left-indent))))
1016+
(t
1017+
(when (or (not haskell-indentation-indent-leftmost)
1018+
(eq haskell-indentation-indent-leftmost 'both))
1019+
(haskell-indentation-add-indentation
1020+
(+ starter-indent haskell-indentation-starter-offset)))
1021+
(when haskell-indentation-indent-leftmost
1022+
(haskell-indentation-add-indentation
1023+
(if on-new-line
1024+
(+ left-indent haskell-indentation-starter-offset)
1025+
left-indent)))))
1026+
(throw 'parse-end nil))
1027+
(setq phrase1 (cddr phrase))))
1028+
((string= (cadr phrase) "in"))))))
10261029

10271030
(defun haskell-indentation-add-indentation (indent)
10281031
"" ; FIXME

tests/haskell-indentation-tests.el

+2-38
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ function = abc
764764
xyz"
765765
((3 0) 0 7))
766766

767-
(hindent-test "45* phrase should not eat whole stack" "
767+
(hindent-test "45 phrase should not eat whole stack" "
768768
function =
769769
if True
770770
then True
@@ -847,44 +847,8 @@ function =
847847
if True
848848
then True
849849
else
850-
if True
851-
then True
852-
else
853-
if True
854-
then True
855-
else
856-
if True
857-
then True
858-
else
859-
if True
860-
then True
861-
else
862-
if True
863-
then True
864-
else
865-
if True
866-
then True
867-
else
868-
if True
869-
then True
870-
else
871-
if True
872-
then True
873-
else
874-
if True
875-
then True
876-
else
877-
if True
878-
then True
879-
else
880-
if True
881-
then True
882-
else
883-
if True
884-
then True
885-
else
886850
"
887-
((118 0) 0 4))
851+
((84 0) 4))
888852

889853

890854
(ert-deftest haskell-indentation-ret-indents ()

0 commit comments

Comments
 (0)