purescript-mode icon indicating copy to clipboard operation
purescript-mode copied to clipboard

matching with record syntax in `let` and `case` expressions breaks indentation

Open gomain opened this issue 4 years ago • 5 comments

In let and case expressions

test1 a
  = let { x } = a
    in x -- parse error from here

test2 a
  = let { x: y } = a
    in y -- parse error from here

test3 a
  = case a of
    { x }
      -> x -- parse error from here

test4 a 
  = case a of
    { x: y }
      -> y -- parse error from here

In function argument it works fine

test { x }
  = x -- this works

gomain avatar Jun 27 '21 14:06 gomain

I investigated this today and figured this seems to be leftover from haskell-mode's layouts code. I've only tested this patch minimally but it eliminates said parse errors.

diff --git a/purescript-indentation.el b/purescript-indentation.el
index 1040964..257c19e 100644
--- a/purescript-indentation.el
+++ b/purescript-indentation.el
@@ -765,9 +765,7 @@ autofill-mode."
            (throw 'parse-end nil)))))
 
 (defun purescript-indentation-layout (parser)
-  (if (string= current-token "{")
-      (purescript-indentation-list parser "}" ";" nil)
-    (purescript-indentation-implicit-layout-list parser)))
+  (purescript-indentation-implicit-layout-list parser))
 
 (defun purescript-indentation-expression-token (token)
   (member token '("if" "let" "do" "case" "\\" "(" "[" "{" "::"

purefunctor avatar Nov 01 '21 14:11 purefunctor

The patch above fixes the issue for me.

@kritzcreek , any chance of this getting landed in the repo?

umanwizard avatar Mar 08 '23 14:03 umanwizard

Sure I can merge, I just can't test it on my own at the moment, I'll rely on your judgement then ;)

kritzcreek avatar Mar 09 '23 13:03 kritzcreek

Actually looks like the PR I merged fixes a separate syntax issue with indentation. If you can open a PR for the patch above I'm happy to merge that as well.

kritzcreek avatar Mar 09 '23 13:03 kritzcreek

Though not fixed, but should be much better with this PR https://github.com/purescript-emacs/purescript-mode/pull/21

Hi-Angel avatar Oct 02 '24 15:10 Hi-Angel