From dafa7bd75b8d5911beba3820a1121566ba572322 Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Sun, 13 Sep 2015 22:33:17 +0200 Subject: [PATCH 1/2] Parse scoped types in indentation --- haskell-indentation.el | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/haskell-indentation.el b/haskell-indentation.el index 57dab0baf..e19c74620 100644 --- a/haskell-indentation.el +++ b/haskell-indentation.el @@ -740,10 +740,7 @@ the current buffer." ("where" . ,(apply-partially 'haskell-indentation-with-starter 'haskell-indentation-declaration-layout nil t)) - ("::" . - ,(apply-partially 'haskell-indentation-with-starter - (apply-partially #'haskell-indentation-separated - #'haskell-indentation-type "->"))) + ("::" . haskell-indentation-scoped-type) ("=" . ,(apply-partially 'haskell-indentation-statement-right 'haskell-indentation-expression)) @@ -834,6 +831,17 @@ After a lambda (backslash) there are two possible cases: (throw 'return nil) (funcall (cdr parser)))))))))) +(defun haskell-indentation-scoped-type () + "Parse scoped type declaration. + +For example + let x :: Int = 12 + do x :: Int <- return 12" + (haskell-indentation-with-starter + (apply-partially #'haskell-indentation-separated #'haskell-indentation-type "->")) + (when (member current-token '("<-" "=")) + (haskell-indentation-statement-right #'haskell-indentation-expression))) + (defun haskell-indentation-data () "Parse data or type declaration." (haskell-indentation-with-starter From f94a9545ef8aa58c38f2d21a5dfd978bbfc214b8 Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Sun, 13 Sep 2015 22:33:44 +0200 Subject: [PATCH 2/2] Parse scoped types in indentation - tests --- tests/haskell-indentation-tests.el | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/haskell-indentation-tests.el b/tests/haskell-indentation-tests.el index 360138da0..bb5309d3b 100644 --- a/tests/haskell-indentation-tests.el +++ b/tests/haskell-indentation-tests.el @@ -524,15 +524,37 @@ func = 1234 -}" ((3 2) 0)) -(hindent-test "24* should parse inline type signatures properly" " +(hindent-test "24 should parse inline type signatures properly" " foo = do _ :: String <- undefined _ :: String <- undefined return ()" ((1 0) 0) ((2 0) 2) - ((3 0) 2 17) - ((4 0) 2 17)) + ((3 0) 0 2 17) + ((4 0) 0 2 17)) + +(hindent-test "25a* support scoped type declarations" " +foo = do + bar :: String + -> String + <- undefined" + ((1 0) 0) + ((2 0) 2) + ((3 0) 6 9) + ;; here it brakes, it would like to put '<-' on same line with 'bar' + ;; the culprit is the 'do' keyword + ((4 0) 4)) + +(hindent-test "25b support scoped type declarations" " +foo = let + bar :: String + -> String + = undefined" + ((1 0) 0) + ((2 0) 2) + ((3 0) 6 9) + ((4 0) 4)) ;;; haskell-indentation-tests.el ends here