branch: elpa/haskell-tng-mode commit 08a394606dbbdb158a861ed737b5378e73fde41a Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
records indentation --- haskell-tng-smie.el | 12 ++++++++---- test/haskell-tng-indent-test.el | 2 +- test/src/indentation.hs | 10 ++++++++++ test/src/indentation.hs.append.indent | 20 ++++++++++++++++++++ test/src/indentation.hs.insert.indent | 20 ++++++++++++++++++++ test/src/indentation.hs.layout | 10 ++++++++++ test/src/indentation.hs.lexer | 10 ++++++++++ test/src/indentation.hs.reindent | 22 +++++++++++++++++++++- test/src/indentation.hs.sexps | 10 ++++++++++ test/src/indentation.hs.syntax | 10 ++++++++++ 10 files changed, 120 insertions(+), 6 deletions(-) diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el index 5e86037..ee622db 100644 --- a/haskell-tng-smie.el +++ b/haskell-tng-smie.el @@ -176,7 +176,10 @@ information, to aid in the creation of new rules." parent grand))))) (cond - ((smie-rule-parent-p "[" "(") ",") + ((or (smie-rule-parent-p "[" "(") + (and (smie-rule-parent-p "{") + (smie-rule-grandparent-p "="))) + ",") ((or (smie-rule-parent-p "|") (and (smie-rule-parent-p "=") @@ -209,9 +212,10 @@ information, to aid in the creation of new rules." (:after (pcase arg - ((or "let" "do" "of" "=" "in" "->" "\\") 2) + ((or "let" "do" "of" "in" "->" "\\") 2) + ("=" (when (not (smie-rule-parent-p "data")) 2)) ("\\case" 2) ;; LambdaCase - ("where" (if (smie-rule-parent-p "module") 0 2)) + ("where" (when (not (smie-rule-parent-p "module")) 2)) ((or "[" "(") 2) ("{" (when (not (smie-rule-prev-p "\\case" ;; LambdaCase @@ -234,7 +238,7 @@ information, to aid in the creation of new rules." ;; ;; blah = bloo where ;; bloo = blu - ((or "where" "let" "do" "case" "->" "SYMID") + ((or "where" "let" "do" "case" "=" "->" "SYMID") (smie-rule-parent)) ("\\case" ;; LambdaCase (smie-rule-parent)) diff --git a/test/haskell-tng-indent-test.el b/test/haskell-tng-indent-test.el index 7733261..11a14ca 100644 --- a/test/haskell-tng-indent-test.el +++ b/test/haskell-tng-indent-test.el @@ -14,9 +14,9 @@ ;; FIXME implement more indentation rules ;; -;; TODO records (resolve WLDO ambiguity) ;; TODO multiline type signatures ;; TODO if/then/else +;; TODO data: one conid ~> record, multi ~> coproduct ;; Three indentation regression tests are possible: ;; diff --git a/test/src/indentation.hs b/test/src/indentation.hs index 488d17e..b2de628 100644 --- a/test/src/indentation.hs +++ b/test/src/indentation.hs @@ -77,6 +77,16 @@ data Wibble = Wibble Int | Wobble Int | Vibble Int +data Record1 = Record1 { + fieldA :: String +, fieldB :: String +} + +data Record2 = Record2 + { fieldA :: String + , fieldB :: String + } + lists1 = [ foo , bar , [ blah diff --git a/test/src/indentation.hs.append.indent b/test/src/indentation.hs.append.indent index 8732e21..d1240f4 100644 --- a/test/src/indentation.hs.append.indent +++ b/test/src/indentation.hs.append.indent @@ -156,6 +156,26 @@ v 1 v v 1 +data Record1 = Record1 { +1 v + fieldA :: String +v 1 +, fieldB :: String +v +} +v + +v +data Record2 = Record2 +v + { fieldA :: String +1 v + , fieldB :: String +1 v + } +v 1 + +v 1 lists1 = [ foo 1 v , bar diff --git a/test/src/indentation.hs.insert.indent b/test/src/indentation.hs.insert.indent index 380ef7b..dc63d4c 100644 --- a/test/src/indentation.hs.insert.indent +++ b/test/src/indentation.hs.insert.indent @@ -156,6 +156,26 @@ data Wibble = Wibble Int 1 v v 1 +data Record1 = Record1 { +1 v + fieldA :: String +1 v +, fieldB :: String +v +} +v + +v +data Record2 = Record2 +1 2 v + { fieldA :: String +1 v + , fieldB :: String +2 1 v + } +v 1 + +v 1 lists1 = [ foo 1 v , bar diff --git a/test/src/indentation.hs.layout b/test/src/indentation.hs.layout index a85ba62..c181fdf 100644 --- a/test/src/indentation.hs.layout +++ b/test/src/indentation.hs.layout @@ -77,6 +77,16 @@ module Indentation where | Wobble Int | Vibble Int +;data Record1 = Record1 { + fieldA :: String +;, fieldB :: String +;} + +;data Record2 = Record2 + { fieldA :: String + , fieldB :: String + } + ;lists1 = [ foo , bar , [ blah diff --git a/test/src/indentation.hs.lexer b/test/src/indentation.hs.lexer index 97aadd9..b4eddbc 100644 --- a/test/src/indentation.hs.lexer +++ b/test/src/indentation.hs.lexer @@ -77,6 +77,16 @@ VARID | CONID CONID | CONID CONID +; data CONID = CONID « +VARID :: CONID +; , VARID :: CONID +; » + +; data CONID = CONID +« VARID :: CONID +, VARID :: CONID +» + ; VARID = « VARID , VARID , « VARID diff --git a/test/src/indentation.hs.reindent b/test/src/indentation.hs.reindent index 5f54fa1..f764170 100644 --- a/test/src/indentation.hs.reindent +++ b/test/src/indentation.hs.reindent @@ -156,7 +156,27 @@ data Wibble = Wibble Int | Vibble Int v 1 -v 1 2 +v 1 2 +data Record1 = Record1 { +1 v + fieldA :: String +v 1 +, fieldB :: String +v +} +v + +v 1 +data Record2 = Record2 +1 2 v + { fieldA :: String +1 v + , fieldB :: String +1 v + } +v 1 + +v 2 1 lists1 = [ foo 1 v , bar diff --git a/test/src/indentation.hs.sexps b/test/src/indentation.hs.sexps index 35c2bcf..e149595 100644 --- a/test/src/indentation.hs.sexps +++ b/test/src/indentation.hs.sexps @@ -77,6 +77,16 @@ | (Wobble) (Int) | (Vibble) (Int) +(data (Record1) = (Record1) ({ + (fieldA) (::) (String) +((, (fieldB) (::) (String)) +)})) + +(data (Record2) = (Record2) + ({ (fieldA) (::) (String) + , (fieldB) (::) (String) + })) + ((lists1) = ([ (foo) , (bar) , ([ (blah) diff --git a/test/src/indentation.hs.syntax b/test/src/indentation.hs.syntax index ce0322d..4fbb203 100644 --- a/test/src/indentation.hs.syntax +++ b/test/src/indentation.hs.syntax @@ -77,6 +77,16 @@ wwww wwwwww _ wwwwww www> _ wwwwww www> _ wwwwww www> > +wwww wwwwwww _ wwwwwww (> + wwwwww __ wwwwww> +. wwwwww __ wwwwww> +)> +> +wwww wwwwwww _ wwwwwww> + ( wwwwww __ wwwwww> + . wwwwww __ wwwwww> + )> +> wwwwww _ ( www> . www> . ( wwww>