branch: elpa/haskell-tng-mode commit 71cf9457cba13230a35d348a50099d056b9b7579 Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
lexer test based on Haskell2010 --- README.md | 1 + haskell-tng-smie.el | 7 ++ test/faces/{medley.hs.forward => medley.hs.lexer} | 0 test/haskell-tng-smie-test.el | 7 +- test/lexer/layout.hs | 19 +++ test/lexer/layout.hs.lexer | 142 ++++++++++++++++++++++ 6 files changed, 174 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 72d68b8..5e84623 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ Some blue sky features are being considered but may be best as independent proje - `:type` at point - `:browse` `company-backend` - `:doc` at point + - expand type definitions (e.g. to show full ADT) - [`flycheck`](http://www.flycheck.org/en/latest/) integration with `haskell-compile` - `ghc` / `cabal v2-exec ghc --` for red squiggles, getting the correct info from [`cabal-helper`](http://hackage.haskell.org/package/cabal-helper) - and [`hlint`](https://github.com/ndmitchell/hlint) diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el index c08b252..ce8d614 100644 --- a/haskell-tng-smie.el +++ b/haskell-tng-smie.el @@ -19,6 +19,11 @@ ;; Users may consult the SMIE manual to customise their indentation rules: ;; https://www.gnu.org/software/emacs/manual/html_mono/elisp.html#SMIE ;; +;; The Haskell2010 report's sections 2.7 and 10.3 are particularly pertinent: +;; +;; https://www.haskell.org/onlinereport/haskell2010/haskellch2.html +;; https://www.haskell.org/onlinereport/haskell2010/haskellch10.html +;; ;;; Code: (require 'smie) @@ -48,6 +53,8 @@ (progn (skip-syntax-forward "w_") (point)))))) +;; + ;; TODO a haskell grammar ;; https://www.gnu.org/software/emacs/manual/html_mono/elisp.html#SMIE-Grammar (defvar haskell-tng-smie:grammar diff --git a/test/faces/medley.hs.forward b/test/faces/medley.hs.lexer similarity index 100% rename from test/faces/medley.hs.forward rename to test/faces/medley.hs.lexer diff --git a/test/haskell-tng-smie-test.el b/test/haskell-tng-smie-test.el index f5253f6..005ed0e 100644 --- a/test/haskell-tng-smie-test.el +++ b/test/haskell-tng-smie-test.el @@ -41,7 +41,7 @@ (filename (expand-file-name file (haskell-tng-smie:this-lisp-directory))) - (golden (concat filename ".forward")) + (golden (concat filename ".lexer")) (expected (with-temp-buffer (insert-file-contents golden) (buffer-string))) @@ -61,8 +61,11 @@ nil)) (kill-buffer lexed)))) +;; TODO the backwards test should simply assert consistency + (ert-deftest haskell-tng-smie-file-tests () - (should (have-expected-forward-lex "faces/medley.hs"))) + (should (have-expected-forward-lex "faces/medley.hs")) + (should (have-expected-forward-lex "lexer/layout.hs"))) ;; ideas for an indentation tester ;; https://github.com/elixir-editors/emacs-elixir/blob/master/test/test-helper.el#L52-L63 diff --git a/test/lexer/layout.hs b/test/lexer/layout.hs new file mode 100644 index 0000000..749b05d --- /dev/null +++ b/test/lexer/layout.hs @@ -0,0 +1,19 @@ +-- Figure 2.1 from the Haskell2010 report +module AStack( Stack, push, pop, top, size ) where +data Stack a = Empty + | MkStack a (Stack a) + +push :: a -> Stack a -> Stack a +push x s = MkStack x s + +size :: Stack a -> Int +size s = length (stkToLst s) where + stkToLst Empty = [] + stkToLst (MkStack x s) = x:xs where xs = stkToLst s + +pop :: Stack a -> (a, Stack a) +pop (MkStack x s) + = (x, case s of r -> i r where i x = x) -- (pop Empty) is an error + +top :: Stack a -> a +top (MkStack x s) = x -- (top Empty) is an error diff --git a/test/lexer/layout.hs.lexer b/test/lexer/layout.hs.lexer new file mode 100644 index 0000000..10ac6b0 --- /dev/null +++ b/test/lexer/layout.hs.lexer @@ -0,0 +1,142 @@ +module +AStack +( +Stack +, +; +push +, +pop +, +top +, +size +) +where +{ +data +Stack +a += +Empty +| +MkStack +a +( +Stack +a +) +; +push +:: +a +-> +Stack +a +-> +Stack +a +push +x +s += +MkStack +x +s +; +size +:: +Stack +a +-> +Int +; +size +s += +length +( +stkToLst +s +) +where +{ +stkToLst +Empty += +[ +] +; +stkToLst +( +MkStack +x +s +) += +x:xs +where +{ +xs += +stkToLst +s +} +} +; +pop +:: +Stack +a +-> +( +a +, +Stack +a +) +; +pop +( +MkStack +x +s +) += +( +x +, +case +s +of +{ +r +-> +i +r +where +{ +i +x += +x +} +} +) +; +top +:: +Stack +a +-> +a +; +top +( +MkStack +x +s +) += +x +}