Skip to content

Commit 192d01e

Browse files
committed
support list and tuple pattern matching (close #21)
1 parent a6142bc commit 192d01e

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

indent/haskell.vim

Lines changed: 10 additions & 6 deletions
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: 2021/08/04 19:27:55.
5+
" Last Change: 2021/08/07 07:21:36.
66
" =============================================================================
77

88
if exists('b:did_indent')
@@ -91,7 +91,11 @@ function! GetHaskellIndent() abort
9191
return 0
9292
endif
9393

94-
if line =~# '\v^\s*,([^()[\]{}]*|\([^()[\]{}]*\)|\[[^()[\]{}]*\])*(\s*--.*)?$' && nonblankline =~# '\v^\s*,'
94+
let noparen = '[^()[\]{}]'
95+
let noparen = '%(' . noparen . '+|\(' . noparen . '*\)|\[' . noparen . '*\])'
96+
let noparen = '%(' . noparen . '+|\(' . noparen . '*\)|\[' . noparen . '*\])*'
97+
98+
if line =~# '\v^\s*,' . noparen . '(\s*--.*)?$' && nonblankline =~# '\v^\s*,'
9599
return match(nonblankline, '^\s*\zs,')
96100
endif
97101

@@ -106,15 +110,15 @@ function! GetHaskellIndent() abort
106110
return match(nonblankline, '^\s*\zs--')
107111
endif
108112

109-
if nonblankline =~# '\v^\s*}?[^()[\]{}]*[([{]([^()[\]{}]*|\([^()[\]{}]*\)|\[[^()[\]{}]*\])*[-+/*\$&<>,]?(\s*--.*)?$'
113+
if nonblankline =~# '\v^\s*}?' . noparen . '[([{]' . noparen . '[-+/*\$&<>,]?(\s*--.*)?$'
110114
if nonblankline =~# '\v[([{](\s*--.*)?$'
111115
return match(nonblankline, '\v^\s*(<where>|.*<let>)?\s*\zs') + &shiftwidth
112116
elseif nonblankline =~# '\v[-+/*\$&<>,](\s*--.*)?$'
113-
return match(nonblankline, '\v^\s*}?[^()[\]{}]*(\[.*\|\s*\zs|[([{]\s*\zs)')
117+
return match(nonblankline, '\v^\s*}?' . noparen . '(\[.*\|\s*\zs|[([{]\s*\zs)')
114118
elseif nonblankline =~# '\v^[^[\]]*\[([^[\]]*|\[[^[\]]*\])*\|([^[\]]*|\[[^[\]]*\])*(\s*--.*)?$'
115119
return match(nonblankline, '\v^[^[\]]*\[([^[\]]*|\[[^[\]]*\])*\zs\|')
116120
else
117-
return match(nonblankline, '\v^\s*}?[^()[\]{}]*\zs[([{]')
121+
return match(nonblankline, '\v^\s*}?' . noparen . '\zs[([{]')
118122
endif
119123
endif
120124

@@ -187,7 +191,7 @@ function! GetHaskellIndent() abort
187191
return match(nonblankline, '\S')
188192
else
189193
return match(nonblankline, '\v^\s*(<where>|.*<let>)?\s*\zs') +
190-
\ (nonblankline =~# '\v(<where>|<let>)|^\s*\k+\s*\=.*([-+/*\$&<>]|`\k+`)(\s*--.*)?$|(\=|-\>)(\s*--.*)?$' ? &shiftwidth : 0)
194+
\ (nonblankline =~# '\v(<where>|<let>)|^\s*\k+\s*'. noparen .'\=.*([-+/*\$&<>]|`\k+`)(\s*--.*)?$|(\=|-\>)(\s*--.*)?$' ? &shiftwidth : 0)
191195
endif
192196
endif
193197

test/list/arg_list.in.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
f [x, y, [z, w]] = [
2+
x, y,
3+
[
4+
z,
5+
w,
6+
]]
7+
8+
g [x, y] = x `div`
9+
y

test/list/arg_list.out.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
f [x, y, [z, w]] = [
2+
x, y,
3+
[
4+
z,
5+
w,
6+
]]
7+
8+
g [x, y] = x `div`
9+
y

test/list/arg_tuple.in.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
f (x, y, (z, w)) = [
2+
x, (
3+
y
4+
),
5+
(
6+
z,
7+
w
8+
)]
9+
10+
g (x, y) = x +
11+
y

test/list/arg_tuple.out.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
f (x, y, (z, w)) = [
2+
x, (
3+
y
4+
),
5+
(
6+
z,
7+
w
8+
)]
9+
10+
g (x, y) = x +
11+
y

0 commit comments

Comments
 (0)