haskell / haskell/haskell-mode
Parse error for Haskell sections
- Dominant language
- Emacs Lisp
- Stars
- 1.4k
- Forks
- 354
- Avg merge
- 5d 10h
- Merged PRs (30d)
- 2
Description
Consider the program:
```
main = print $ (`div` 2) 3
```
If you put the cursor inside the brackets anywhere *except* on the first back-tick character and hit `C-M-u` (`backward-up-list`) the cursor is placed at the beginning of the current buffer and a scan error is echoed to the `*Messages*` buffer:
```
up-list: Scan error: "Unbalanced parentheses", 1, 1
```
I tried to debug this, but I'm not great with lisp. I *think* it has to do with the fact that "plain" `backward-sexp` and `haskell-backward-sexp` don't agree on where to go when cursor is on the `d` in `div`. There is a comment in `haskell-forward-sexp` saying that:
> Navigate backwards using plain `backward-sexp', assume that it skipped over at least one Haskell expression
If I switch to `fundamental-mode` I can see that this assumption doesn't hold if you call `backward-sexp` with the cursor on the `d` in `div`.
I would love to provide the patch, but I'm afraid I need help digging to locate the bug.
The bug is present in at least versions 20231115.1812 and 20240116.1718.
Contributor guide
Research direction
Reproduce the example in haskell-mode and start by reading haskell-forward-sexp, haskell-backward-sexp, and the interaction with plain backward-sexp at the d in div. Done means C-M-u correctly navigates from every position inside the Haskell section without reporting an unbalanced-parentheses scan error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- emacs-lisp, haskell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100