branch: elpa/haskell-tng-mode commit 20f4091711c2ca22e871f91793816430ea751bed Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
support dollars in indentation --- .python-version | 2 +- haskell-tng-lexer.el | 5 +++++ haskell-tng-smie.el | 7 ++++--- test/haskell-tng-indent-test.el | 2 ++ test/src/indentation.hs | 6 ++++++ test/src/indentation.hs.append.indent | 14 +++++++++++++- test/src/indentation.hs.insert.indent | 14 +++++++++++++- test/src/indentation.hs.layout | 8 +++++++- test/src/indentation.hs.lexer | 8 +++++++- test/src/indentation.hs.reindent | 14 +++++++++++++- test/src/indentation.hs.sexps | 8 +++++++- test/src/medley.hs | 4 ++-- test/src/medley.hs.faceup | 4 ++-- test/src/medley.hs.layout | 6 +++--- test/src/medley.hs.lexer | 6 +++--- test/src/medley.hs.syntax | 4 ++-- 16 files changed, 90 insertions(+), 22 deletions(-) diff --git a/.python-version b/.python-version index 0f44168..c1e43e6 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.6.4 +3.7.3 diff --git a/haskell-tng-lexer.el b/haskell-tng-lexer.el index 8ea1a68..158b9bf 100644 --- a/haskell-tng-lexer.el +++ b/haskell-tng-lexer.el @@ -113,6 +113,9 @@ the lexer." ((looking-at (rx "'[")) ;; DataKinds (null (goto-char (+ (point) 1)))) + ((looking-at (rx symbol-start "$" symbol-end)) + ;; special handling of these operators + (haskell-tng-lexer:last-match)) ((looking-at haskell-tng:regexp:kindsym) ;; caveat: doesn't include typelevel lists, see fast-syntax (haskell-tng-lexer:last-match nil "KINDSYM")) @@ -176,6 +179,8 @@ the lexer." ;; non-trivial inversion (goto-char (- (point) 1)) (haskell-tng-lexer:backward-token)) + ((looking-back (rx symbol-start "$" symbol-end) lbp 't) + (haskell-tng-lexer:last-match 'reverse)) ((looking-back haskell-tng:regexp:kindsym lbp 't) (haskell-tng-lexer:last-match 'reverse "KINDSYM")) ((looking-back haskell-tng:regexp:kindid lbp 't) diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el index 476e837..ea4a01b 100644 --- a/haskell-tng-smie.el +++ b/haskell-tng-smie.el @@ -67,6 +67,7 @@ (infixexp (id ":" infixexp) ;; keyword infix (id "':" infixexp) ;; DataKinds + (id "$" infixexp) ;; special case (id "SYMID" infixexp)) ;; WLDOs @@ -159,12 +160,12 @@ information, to aid in the creation of new rules." ;; get called with `:list-intro "HEAD"` when indenting positions A and B. (:list-intro (pcase arg - ((or "<-" "=") t) + ((or "<-" "=" "$") t) )) (:after (pcase arg - ((or "let" "do" "of" "=" "in") 2) + ((or "let" "do" "of" "=" "in" "$" "->") 2) ("\\case" 2) ;; LambdaCase ("where" (if (smie-rule-parent-p "module") 0 2)) )) @@ -181,7 +182,7 @@ information, to aid in the creation of new rules." ;; ;; blah = bloo where ;; bloo = blu - ((or "{" "where" "let" "do" "case") + ((or "{" "where" "let" "do" "case" "$" "->") (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 3ed324b..e8643e6 100644 --- a/test/haskell-tng-indent-test.el +++ b/test/haskell-tng-indent-test.el @@ -16,6 +16,8 @@ ;; TODO lists, records, tuples ;; TODO long type signatures vs definitions ;; TODO if/then/else +;; TODO following opening bracket in a record defn, shouldn't indent so much +;; TODO ImplicitParams in let ;; Three indentation regression tests are possible: ;; diff --git a/test/src/indentation.hs b/test/src/indentation.hs index 278ad20..74df4bd 100644 --- a/test/src/indentation.hs +++ b/test/src/indentation.hs @@ -54,3 +54,9 @@ case_of wibble = case wibble of lambda_case = \case Nothing -> "" Just fish -> fish + +dollars f Nothing = f $ + "" "" + "" +dollars f (Just a) = f $ \s -> + a diff --git a/test/src/indentation.hs.append.indent b/test/src/indentation.hs.append.indent index e671bed..4d7ad5c 100644 --- a/test/src/indentation.hs.append.indent +++ b/test/src/indentation.hs.append.indent @@ -111,4 +111,16 @@ lambda_case = \case Just fish -> fish 1 v -1 v \ No newline at end of file +1 v +dollars f Nothing = f $ +1 v + "" "" +1 v + "" +1 v +dollars f (Just a) = f $ \s -> +1 v + a +2 1 v + +1 2 v \ No newline at end of file diff --git a/test/src/indentation.hs.insert.indent b/test/src/indentation.hs.insert.indent index 7d32101..57835ab 100644 --- a/test/src/indentation.hs.insert.indent +++ b/test/src/indentation.hs.insert.indent @@ -109,4 +109,16 @@ lambda_case = \case Nothing -> "" 1 v Just fish -> fish -1 v \ No newline at end of file +1 v + +1 v +dollars f Nothing = f $ +1 v + "" "" +1 v + "" +1 v +dollars f (Just a) = f $ \s -> +1 v + a +v 1 \ No newline at end of file diff --git a/test/src/indentation.hs.layout b/test/src/indentation.hs.layout index a142e23..93e42c6 100644 --- a/test/src/indentation.hs.layout +++ b/test/src/indentation.hs.layout @@ -54,4 +54,10 @@ module Indentation where };lambda_case = \case {Nothing -> "" ;Just fish -> fish -}} \ No newline at end of file + +};dollars f Nothing = f $ + "" "" + "" +;dollars f (Just a) = f $ \s -> + a +} \ No newline at end of file diff --git a/test/src/indentation.hs.lexer b/test/src/indentation.hs.lexer index 00f4e22..1e34f64 100644 --- a/test/src/indentation.hs.lexer +++ b/test/src/indentation.hs.lexer @@ -54,4 +54,10 @@ VARID VARID } ; VARID = \case { CONID -> § ; CONID VARID -> VARID -} } + +} ; VARID VARID CONID = VARID $ +§ § +§ +; VARID VARID « CONID VARID » = VARID $ \ VARID -> +VARID +} diff --git a/test/src/indentation.hs.reindent b/test/src/indentation.hs.reindent index 8695185..8383795 100644 --- a/test/src/indentation.hs.reindent +++ b/test/src/indentation.hs.reindent @@ -109,4 +109,16 @@ lambda_case = \case 1 v Nothing -> "" v 1 - Just fish -> fish \ No newline at end of file + Just fish -> fish +1 v + +v 1 +dollars f Nothing = f $ +1 v + "" "" +1 v + "" +v 1 +dollars f (Just a) = f $ \s -> +1 v + a \ No newline at end of file diff --git a/test/src/indentation.hs.sexps b/test/src/indentation.hs.sexps index e503f2e..f07a653 100644 --- a/test/src/indentation.hs.sexps +++ b/test/src/indentation.hs.sexps @@ -54,4 +54,10 @@ )(lambda_case) = (\(case ((Nothing) -> ("") ((Just) (fish) -> (fish)) -))))))))))))) \ No newline at end of file + +))(dollars) (f) (Nothing) = (f) $ + ("") ("") + ("") +((dollars) (f) ((Just) (a)) = (f) $ (\)(s) -> + (a)))))))))) +))) \ No newline at end of file diff --git a/test/src/medley.hs b/test/src/medley.hs index 7c76ec4..d55706a 100644 --- a/test/src/medley.hs +++ b/test/src/medley.hs @@ -146,7 +146,7 @@ foo = do test = 1 `shouldBe` 1 cases = \case - Nothing -> "no" - Just _ -> "yes" + Nothing -> "no" & toUpper + Just _ -> toUpper $ "yes" bar = do -- an incomplete do block diff --git a/test/src/medley.hs.faceup b/test/src/medley.hs.faceup index ec46a15..9eb0f6c 100644 --- a/test/src/medley.hs.faceup +++ b/test/src/medley.hs.faceup @@ -146,8 +146,8 @@ «:haskell-tng:toplevel:test» «:haskell-tng:keyword:=» 1 `shouldBe` 1 «:haskell-tng:toplevel:cases» «:haskell-tng:keyword:=» «:haskell-tng:keyword:\case» - «:haskell-tng:constructor:Nothing» «:haskell-tng:keyword:->» «s:"no"» - «:haskell-tng:constructor:Just» «:haskell-tng:keyword:_» «:haskell-tng:keyword:->» «s:"yes"» + «:haskell-tng:constructor:Nothing» «:haskell-tng:keyword:->» «s:"no"» & toUpper + «:haskell-tng:constructor:Just» «:haskell-tng:keyword:_» «:haskell-tng:keyword:->» toUpper $ «s:"yes"» «:haskell-tng:toplevel:bar» «:haskell-tng:keyword:=» «:haskell-tng:keyword:do» «m:-- »«x:an incomplete do block » \ No newline at end of file diff --git a/test/src/medley.hs.layout b/test/src/medley.hs.layout index c5ad093..178e162 100644 --- a/test/src/medley.hs.layout +++ b/test/src/medley.hs.layout @@ -146,8 +146,8 @@ module Foo.Bar.Main }};test = 1 `shouldBe` 1 ;cases = \case - Nothing -> "no" - Just _ -> "yes" + {Nothing -> "no" & toUpper + ;Just _ -> toUpper $ "yes" -;bar = do -- an incomplete do block +};bar = do -- an incomplete do block {}} \ No newline at end of file diff --git a/test/src/medley.hs.lexer b/test/src/medley.hs.lexer index 53f2eba..2943d14 100644 --- a/test/src/medley.hs.lexer +++ b/test/src/medley.hs.lexer @@ -146,8 +146,8 @@ CONSYM CONID « CONID » « CONID CONID » } } ; VARID = 1 SYMID 1 ; VARID = \case -CONID -> § -CONID _ -> § +{ CONID -> § SYMID VARID +; CONID _ -> VARID $ § -; VARID = do +} ; VARID = do { } } diff --git a/test/src/medley.hs.syntax b/test/src/medley.hs.syntax index 496dba9..fe3ab6f 100644 --- a/test/src/medley.hs.syntax +++ b/test/src/medley.hs.syntax @@ -146,7 +146,7 @@ www _ ww> wwww _ w $wwwwwwww$ w> > wwwww _ _wwww> - wwwwwww __ "ww"> - wwww w __ "www"> + wwwwwww __ "ww" _ wwwwwww> + wwww w __ wwwwwww _ "www"> > www _ ww __ ww wwwwwwwwww ww wwwww>