-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathallow_patterns.jl
More file actions
34 lines (30 loc) · 844 Bytes
/
allow_patterns.jl
File metadata and controls
34 lines (30 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using MLStyle
function allow_patterns(node)
@match node begin
:(case($(targets...)) do
$(cases...)
end) => let target = length(targets) === 1 ? targets[1] : Expr(:tuple, targets...),
cases = map(allow_patterns, cases)
quote
$MLStyle.@match $target begin
$(cases...)
end
end
end
Expr(hd, tl...) => Expr(hd, map(allow_patterns, tl)...)
a => a
end
end
macro allow_patterns(node)
allow_patterns(node) |> esc
end
# @allow_patterns module SyntaxExtended
# case(1) do
# 2 => error(1)
# 5:10 => error(2)
# 1:4 && a =>
# case(a + 1) do
# a => 5a
# end
# end |> println
# end