jamesrhester / Lerche.jl

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

MethodError: no method matching length(::Lerche.Tree) #3

Closed kskyten closed 4 years ago

kskyten commented 4 years ago

I'm trying to make a strace parser based on this grammar, but when I run

using Lerche

const grammar = read(joinpath(@__DIR__, "grammar.lark"), String)
const parser = Lark(grammar, parser="lalr", lexer="standard")

I get the following error message:

ERROR: LoadError: MethodError: no method matching length(::Lerche.Tree)
Closest candidates are:
  length(::Core.SimpleVector) at essentials.jl:593
  length(::Base.MethodList) at reflection.jl:849
  length(::Core.MethodTable) at reflection.jl:923
  ...
Stacktrace:
 [1] _append!(::Array{Any,1}, ::Base.HasLength, ::Lerche.Tree) at ./array.jl:921
 [2] append!(::Array{Any,1}, ::Lerche.Tree) at ./array.jl:915
 [3] alias(::Lerche.SimplifyRule_Visitor, ::Lerche.Tree) at ~/.julia/packages/Lerche/hwaIs/src/load_grammar.jl:221
 [4] _call_userfunc(::Lerche.SimplifyRule_Visitor, ::Lerche.Tree) at ~/.julia/packages/Lerche/hwaIs/src/visitors.jl:149
 [5] visit(::Lerche.SimplifyRule_Visitor, ::Lerche.Tree) at ~/.julia/packages/Lerche/hwaIs/src/visitors.jl:160
 [6] compile(::Lerche.Grammar) at ~/.julia/packages/Lerche/hwaIs/src/load_grammar.jl:544
 [7] Lerche.Lark(::String, ::Dict{String,Any}, ::String, ::String) at ~/.julia/packages/Lerche/hwaIs/src/lark.jl:112
 [8] #Lark#257(::Base.Iterators.Pairs{Symbol,String,Tuple{Symbol,Symbol},NamedTuple{(:parser, :lexer),Tuple{String,String}}}, ::Type{Lerche.Lark}, ::String) at ~/.julia/packages/Lerche/hwaIs/src/lark.jl:75
 [9] (::Core.var"#kw#Type")(::NamedTuple{(:parser, :lexer),Tuple{String,String}}, ::Type{Lerche.Lark}, ::String) at ./none:0
 [10] top-level scope at ~/src/github.uio.no/StraceParser/src/StraceParser.jl:5
 [11] include at ./boot.jl:328 [inlined]
 [12] include_relative(::Module, ::String) at ./loading.jl:1105
 [13] include(::Module, ::String) at ./Base.jl:31
 [14] top-level scope at none:2
 [15] eval at ./boot.jl:330 [inlined]
 [16] eval(::Expr) at ./client.jl:425
 [17] top-level scope at ./none:3
in expression starting at ~/src/github.uio.no/StraceParser/src/StraceParser.jl:5
ERROR: Failed to precompile StraceParser [91173181-eabb-40f1-87ea-f7b8bbc25fb1] to ~/.julia/compiled/v1.3/StraceParser/bvIko_7ute1.ji.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1283
 [3] _require(::Base.PkgId) at ./loading.jl:1024
 [4] require(::Base.PkgId) at ./loading.jl:922
 [5] require(::Module, ::Symbol) at ./loading.jl:917
jamesrhester commented 4 years ago

This was caused by an append inherited from Python which I didn't catch. The equivalent is push! in Julia. The latest commit has a fix for this as well as a fix for using Lerche from other modules which unfortunately involves adding a couple of macros to files containing Transformer/Visitor types. Please see the updated README.md for instructions. If you do not want to update, the fix is to change the append in line 222 of load_grammar.jl to push!.

kskyten commented 4 years ago

Thanks!