jamesrhester / Lerche.jl

A Julia port of the Lark parser
MIT License
45 stars 3 forks source link

Type parameters in @rule are not supported #15

Closed guyvdbroeck closed 3 years ago

guyvdbroeck commented 3 years ago
julia> @rule test(t::Transformer, x::Vector{Int}) = 0

julia> @rule test(t::Transformer, x::Vector{T}) where T = 0
ERROR: LoadError: A rule must be a function definition
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] var"@rule"(__source__::LineNumberNode, __module__::Module, s::Any)
   @ Lerche ~/.julia/packages/Lerche/rO9vr/src/utils.jl:182
in expression starting at REPL[8]:1
jamesrhester commented 3 years ago

Yes, the macro forgets about type parameters. I should have a fix today.

guyvdbroeck commented 3 years ago

somewhat related, i noticed that anonymous arguments like test(::Transformer, x) also trip up the macro

jamesrhester commented 3 years ago

somewhat related, i noticed that anonymous arguments like test(::Transformer, x) also trip up the macro

The macro checks that it is applied to a function definition. How should @rule test(::Transformer,x) (without a definition) behave?

jamesrhester commented 3 years ago

96271a9 (version 0.4.3) fixes original bug.

guyvdbroeck commented 3 years ago

Awesome, thanks! With the other error I mean:


julia> @rule test(::Transformer,x) =0
ERROR: LoadError: BoundsError: attempt to access 1-element Vector{Any} at index [2]
Stacktrace:
 [1] getindex(A::Vector{Any}, i1::Int64)
   @ Base ./array.jl:801
 [2] var"@rule"(__source__::LineNumberNode, __module__::Module, s::Any)
   @ Lerche ~/.julia/packages/Lerche/hvADG/src/utils.jl:188
in expression starting at REPL[3]:1```
jamesrhester commented 3 years ago

It looks like both issues have been fixed by the latest update.