Metatheory.jl icon indicating copy to clipboard operation
Metatheory.jl copied to clipboard

Matching on fully qualified function call in 3.0

Open HectorPeeters opened this issue 1 year ago • 2 comments

When creating a rule with a fully qualified function call in the ale/3.0 branch, Metatheory fails to compile the pattern.

A rule defined like so:

@rule Main.identity(~a) --> ~a

Results in the following error:

ERROR: LoadError: MethodError: no method matching match_term_op(::PatExpr, ::Symbol, ::PatExpr)
The function `match_term_op` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  match_term_op(::AbstractPat, ::Any, ::PatVar)
   @ Metatheory ~/.julia/packages/Metatheory/Wu6kK/src/match_compiler.jl:208
  match_term_op(::Any, ::Any, ::Union{Expr, Symbol})
   @ Metatheory ~/.julia/packages/Metatheory/Wu6kK/src/match_compiler.jl:205
  match_term_op(::Any, ::Any, ::Union{DataType, Function})
   @ Metatheory ~/.julia/packages/Metatheory/Wu6kK/src/match_compiler.jl:200

Stacktrace:
 [1] match_term_expr(pattern::PatExpr, coordinate::Vector{Int64}, segments_so_far::Vector{Symbol})
   @ Metatheory ~/.julia/packages/Metatheory/Wu6kK/src/match_compiler.jl:217
 [2] match_compile!(pattern::PatExpr, state::Metatheory.MatchCompilerState, coordinate::Vector{Int64}, parent_segments::Vector{Symbol})
   @ Metatheory ~/.julia/packages/Metatheory/Wu6kK/src/match_compiler.jl:137
 [3] match_compile(p::PatExpr, pvars::Vector{Symbol})
   @ Metatheory ~/.julia/packages/Metatheory/Wu6kK/src/match_compiler.jl:34

HectorPeeters avatar May 26 '24 14:05 HectorPeeters

Added support for it in #185 - the function must be defined though

0x0f0f0f avatar Jun 02 '24 13:06 0x0f0f0f

Checked yesterday night. This is now supported.

julia> r = @rule Main.identity(~a) --> ~a
Main.identity(~a) --> ~a

julia> r(:($(identity)(a)))
:a

julia> r(:(identity(a)))

julia> r(:(Main.identity(a)))
:a

julia> module Foo
           identity(x) = 1
       end
Main.Foo

julia> Foo.identity == identity
false

julia> r(:($(Foo.identity)(a)))

julia> r(:(Foo.identity(a)))

0x0f0f0f avatar Jan 22 '25 09:01 0x0f0f0f