branch: elpa/haskell-tng-mode commit 269be9193e4d77ce9f6acd729bd90f7f37b8645a Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
revert broken grammar rules --- haskell-tng-smie.el | 84 +++++++++++++++++++++++++------------------ test/haskell-tng-sexp-test.el | 6 ++-- test/src/layout.hs.sexps | 28 +++++++-------- 3 files changed, 68 insertions(+), 50 deletions(-) diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el index 67de3f2..08bfe71 100644 --- a/haskell-tng-smie.el +++ b/haskell-tng-smie.el @@ -36,9 +36,10 @@ (infixexp "::" type) (infixexp)) - ;; TODO update the lexer to provide a virtual token for infix + ;; TODO update the lexer to provide a virtual token for infix but keep + ;; popular operators with important fixity. (infixexp - (lexp "$" infixexp) ;; TODO arrange by fixity + (lexp "$" infixexp) (lexp "+" infixexp) (lexp "-" infixexp) (lexp "*" infixexp) @@ -48,40 +49,55 @@ (lexp ">>=" infixexp) (lexp "`should`" infixexp) (lexp "&" infixexp) - ("-" infixexp) - (lexp)) - - (lexp - ;; TODO apats, it is hard to formalise... - ;;("\\" apats "->" exp) - ("let" "{" decls "}" "in" exp) - ("if" exp "then" exp "else" exp) - ("case" exp "of" "{" alts "}") - ("do" "{" stmts "}") - ;; TODO fexp + ;;("-" infixexp) ;; can't be opener and neither + ;;(lexp) ) - ;; TODO formal decls definition - (decls - (decls ";" decls) - (decl)) - (decl - (id "=" exp)) - ;; TODO formal alts definition - (alts - (alts ";" alts) - (alt)) - (alt - (id "->" exp)) - ;; TODO formal stmts definition - (stmts - (stmts ";" stmts) - (stmt)) - (stmt - (id "<-" exp)) - - ;; TODO operator precedences - )))) + ;; ;; FIXME these seem to break everything + ;; (lexp + ;; ;; TODO apats + ;; ;;("let" decls "in" exp) + ;; ;;("if" exp "then" exp "else" exp) + ;; ;;("case" exp "of" alts) + ;; ;;("do" stmts) + ;; ;; TODO where? + ;; ;; TODO fexp + ;; ) + + ;; (decls + ;; ;;("{" decls "}") + ;; (decls ";" decls) + ;; (decl)) + ;; (decl + ;; (id "=" exp)) + ;; (alts + ;; ;;("{" alts "}") + ;; (alts ";" alts) + ;; (alt)) + ;; (alt + ;; (id "->" exp)) + ;; (stmts + ;; ;;("{" stmts "}") + ;; (stmts ";" stmts) + ;; (stmt)) + ;; (stmt + ;; (id "<-" exp)) + + ) + + ;; operator precedences + ;; TODO arrange by fixity + '((left "$")) + '((left "+")) + '((left "-")) + '((left "*")) + '((left "/")) + '((left "<$>")) + '((left "<*>")) + '((left ">>=")) + '((left "&")) + + ))) ;; TODO indentation rules ;; https://www.gnu.org/software/emacs/manual/html_mono/elisp.html#SMIE-Indentation diff --git a/test/haskell-tng-sexp-test.el b/test/haskell-tng-sexp-test.el index a496606..dc3a15f 100644 --- a/test/haskell-tng-sexp-test.el +++ b/test/haskell-tng-sexp-test.el @@ -45,7 +45,8 @@ (forward-sexp) (let ((forward (point))) (backward-sexp) - (cons (point) forward))))) + (unless (= (point) forward) + (cons (point) forward)))))) (backward-forward (ignore-errors (save-excursion @@ -53,7 +54,8 @@ (backward-sexp) (let ((backward (point))) (forward-sexp) - (cons backward (point))))))) + (unless (= backward (point)) + (cons backward (point)))))))) (when forward-backward (push forward-backward sexps)) (when backward-forward diff --git a/test/src/layout.hs.sexps b/test/src/layout.hs.sexps index a3b077a..a412dc4 100644 --- a/test/src/layout.hs.sexps +++ b/test/src/layout.hs.sexps @@ -1,20 +1,20 @@ (-- Figure 2.1 from the Haskell2010 report -((module)) (AStack()( (Stack(),) (push(),) (pop(),) (top(),) (size) )) (where) -(((data) (Stack) (a) = (Empty) +(((((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)) +(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) +(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) +(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) -)) \ No newline at end of file +(top)) (::) (Stack) (a) (->) (a) +(top) (((MkStack) (x) (s))) (=) (x) -- (top Empty) is an error +) \ No newline at end of file