Skip to content

Commit

Permalink
automatic macrocall match
Browse files Browse the repository at this point in the history
  • Loading branch information
thautwarm committed Mar 13, 2021
1 parent 84847ee commit f541b6f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
10 changes: 8 additions & 2 deletions src/MatchImpl.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module MatchImpl
export is_enum,
pattern_uncall, pattern_unref, @switch, @match, Where, gen_match, gen_switch
pattern_uncall, pattern_unref, pattern_unmacrocall, @switch, @match, Where, gen_match, gen_switch
export Q
import MLStyle
using MLStyle: mlstyle_report_deprecation_msg!
Expand All @@ -15,6 +15,12 @@ OptionalLn = Union{LineNumberNode, Nothing}
is_enum(_)::Bool = false
function pattern_uncall end
function pattern_unref end
function pattern_unmacrocall(macro_func, self::Function, args::AbstractArray)
@sswitch args begin
@case [ln, m::Module, args...]
return self(macro_func(ln, m, args...))
end
end

struct Where
value::Any
Expand Down Expand Up @@ -254,7 +260,7 @@ function ex2tf(m::Module, ex::Expr)

@case Expr(:macrocall, [macro_expr, ln::LineNumberNode, args...])
macro_func = m.eval(macro_expr)
return pattern_uncall(macro_func, rec, [], [], Any[ln, m, args...])
return pattern_unmacrocall(macro_func, rec, Any[ln, m, args...])

@case a
error("unknown pattern syntax $(repr(a))")
Expand Down
17 changes: 1 addition & 16 deletions src/Pervasives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,9 @@ function MLStyle.pattern_uncall(
MLStyle.pattern_unref(Many, self, args)
end

function MLStyle.pattern_uncall(
::typeof(@eval $(Symbol("@", "raw_str"))),
self::Function,
_::AbstractArray,
_::AbstractArray,
args::AbstractArray,
)
@switch args begin
@case [ln, m, s::String]
end
self(s)
end

function MLStyle.pattern_uncall(
function MLStyle.pattern_unmacrocall(
r_str::typeof(@eval $(Symbol("@", "r_str"))),
self::Function,
_::AbstractArray,
_::AbstractArray,
args::AbstractArray,
)
@switch args begin
Expand Down

0 comments on commit f541b6f

Please sign in to comment.