Skip to content

Grammar with action is broken when defined in another package #9

@Kolaru

Description

@Kolaru

Assume I have a simple package with StringParserPEG (master branch) as dependency, and containing the following

module TestPEG

using StringParserPEG

greet() = print("Hello World!")

const g = Grammar("""
    start => 'a' {(r,v,f,l,c) -> v}
""")

end # module

then after activating the package and trying to import it I get the following

(@v1.5) pkg> activate TestPEG/
 Activating environment at `~/Documents/TestPEG/Project.toml`

julia> using TestPEG
[ Info: Precompiling TestPEG [958ec1b8-d9f0-43ac-bfa4-8d89bc9a0955]
ERROR: LoadError: Evaluation into the closed module `StringParserPEG` breaks incremental compilation because the side effects will not be permanent. This is likely due to some other module mutating `StringParserPEG` with `eval` during precompilation - don't do this.
Stacktrace:
 [1] eval at ./boot.jl:331 [inlined]
 [2] eval at /home/benoit/.julia/dev/StringParserPEG/src/StringParserPEG.jl:1 [inlined]
 [3] togrammar(::StringParserPEG.Node, ::Array{Any,1}, ::StringParserPEG.MatchRule{:SINGLE}) at /home/benoit/.julia/dev/StringParserPEG/src/grammarparsing.jl:82
 [4] transform(::typeof(StringParserPEG.togrammar), ::StringParserPEG.Node) at /home/benoit/.julia/dev/StringParserPEG/src/transform.jl:20
 [5] (::StringParserPEG.var"#4#5"{typeof(StringParserPEG.togrammar)})(::StringParserPEG.Node) at ./none:0
 [6] iterate at ./generator.jl:47 [inlined]
 [7] collect_to!(::Array{Symbol,1}, ::Base.Generator{Array{Any,1},StringParserPEG.var"#4#5"{typeof(StringParserPEG.togrammar)}}, ::Int64, ::Int64) at ./array.jl:732
 [8] collect_to_with_first!(::Array{Symbol,1}, ::Symbol, ::Base.Generator{Array{Any,1},StringParserPEG.var"#4#5"{typeof(StringParserPEG.togrammar)}}, ::Int64) at ./array.jl:710
 [9] collect(::Base.Generator{Array{Any,1},StringParserPEG.var"#4#5"{typeof(StringParserPEG.togrammar)}}) at ./array.jl:691
 [10] transform(::typeof(StringParserPEG.togrammar), ::StringParserPEG.Node) at /home/benoit/.julia/dev/StringParserPEG/src/transform.jl:10
 [11] (::StringParserPEG.var"#4#5"{typeof(StringParserPEG.togrammar)})(::StringParserPEG.Node) at ./none:0
 [12] iterate at ./generator.jl:47 [inlined]
 [13] collect(::Base.Generator{Array{Any,1},StringParserPEG.var"#4#5"{typeof(StringParserPEG.togrammar)}}) at ./array.jl:686
 [14] transform(::typeof(StringParserPEG.togrammar), ::StringParserPEG.Node) at /home/benoit/.julia/dev/StringParserPEG/src/transform.jl:10
 [15] StringParserPEG.Grammar(::String) at /home/benoit/.julia/dev/StringParserPEG/src/grammar.jl:18
 [16] top-level scope at /home/benoit/Documents/TestPEG/src/TestPEG.jl:7
 [17] include(::Function, ::Module, ::String) at ./Base.jl:380
 [18] include(::Module, ::String) at ./Base.jl:368
 [19] top-level scope at none:2
 [20] eval at ./boot.jl:331 [inlined]
 [21] eval(::Expr) at ./client.jl:467
 [22] top-level scope at ./none:3
in expression starting at /home/benoit/Documents/TestPEG/src/TestPEG.jl:7
ERROR: Failed to precompile TestPEG [958ec1b8-d9f0-43ac-bfa4-8d89bc9a0955] to /home/benoit/.julia/compiled/v1.5/TestPEG/zafuC_oC3oL.ji.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1290
 [3] _require(::Base.PkgId) at ./loading.jl:1030
 [4] require(::Base.PkgId) at ./loading.jl:928
 [5] require(::Module, ::Symbol) at ./loading.jl:923

Everything works fine however when I'm simply running a file with the grammar, instead of including it in a module.
Also I get no error if I don't define an action in the grammar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions