Skip to content

Commit dc8b3af

Browse files
authored
Improve lambda case (#25)
* improve lambda case correctly indent further cases for a lambda case expression where the first pattern is on the same line as `\case` * add tests for lambda case on the same line * update date of last change * allow space between lambda and case `\ case`, `\ case`, etc. are allowed in LambdaCase syntax. Also update test to reflect this. * include `-` in case pattern * recognise literal string, character, list
1 parent a7423fe commit dc8b3af

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

indent/haskell.vim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Filename: indent/haskell.vim
33
" Author: itchyny
44
" License: MIT License
5-
" Last Change: 2023/11/07 19:40:39.
5+
" Last Change: 2024/08/04 15:46:49.
66
" =============================================================================
77

88
if exists('b:did_indent')
@@ -178,6 +178,10 @@ function! GetHaskellIndent() abort
178178
return match(line, '\v^\s*%(<where>|.*<let>)?\s*\zs') + &shiftwidth
179179
endif
180180

181+
if line =~# '\v\\\s*<case>\s*[[:alnum:](\-\"''\[]'
182+
return match(line, '\v\\\s*<case>\s*\zs\S')
183+
endif
184+
181185
if nonblankline =~# '\v^.*[^|]\|[^|].*\='
182186
return s:after_guard()
183187
endif

test/case/lambda_case_literal.in.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
f = \case [] -> 0
2+
"one" -> 1
3+
'0':_ -> 0
4+
xs@('-':_) -> g $ read xs
5+
where g = \case -1 -> -100
6+
_ -> -1

test/case/lambda_case_literal.out.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
f = \case [] -> 0
2+
"one" -> 1
3+
'0':_ -> 0
4+
xs@('-':_) -> g $ read xs
5+
where g = \case -1 -> -100
6+
_ -> -1

test/case/lambda_case_same_line.in.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
f = \case 1 -> 0
2+
2 -> 1
3+
x -> g x
4+
where g = \ case -1 -> -1
5+
_ -> 3
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
f = \case 1 -> 0
2+
2 -> 1
3+
x -> g x
4+
where g = \ case -1 -> -1
5+
_ -> 3

0 commit comments

Comments
 (0)