You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following function is a nice example of matching expressions. It is used in VideoIO.jl to extract the names of expressions generated by Clang.jl, for later filtering and rewriting.:
extract_name(x) =string(x)
functionextract_name(e::Expr)
@match e beginExpr(:type, [_, name, _], _) => name
Expr(:typealias, [name, _], _) => name
Expr(:call, [name, _...], _) => name
Expr(:function, [sig, _...], _) =>extract_name(sig)
Expr(:const, [assn, _...], _) =>extract_name(assn)
Expr(:(=), [fn, body, _...], _) =>extract_name(fn)
Expr(expr_type, _...) =>error("Can't extract name from ",
expr_type, " expression:\n",
"$e\n")
endend
However, this doesn't work in Match, Rematch, or Rematch2. It would be nice if it did. Doing so would require recognizing treating Expr specially:
julia>methods(Expr)
# 1 method for type constructor:
[1] Expr(args...) in Core at boot.jl:263
julia>fieldnames(Expr)
(:head, :args)
julia>fieldtypes(Expr)
(Symbol, Vector{Any})
The text was updated successfully, but these errors were encountered:
gafter
transferred this issue from JuliaServices/Rematch2.jl
Aug 3, 2023
From the
Match.jl
documentation we have:However, this doesn't work in
Match
,Rematch
, orRematch2
. It would be nice if it did. Doing so would require recognizing treatingExpr
specially:The text was updated successfully, but these errors were encountered: