Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty grammar creation #54

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/csg/csg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ function expr2csgrammar(ex::Expr)::ContextSensitiveGrammar
end
end
alltypes = collect(keys(bytype))
is_terminal = [isterminal(rule, alltypes) for rule ∈ rules]
is_eval = [iseval(rule) for rule ∈ rules]
childtypes = [get_childtypes(rule, alltypes) for rule ∈ rules]
is_terminal::Vector{Bool} = [isterminal(rule, alltypes) for rule ∈ rules]
is_eval::Vector{Bool} = [iseval(rule) for rule ∈ rules]
childtypes::Vector{Vector{Symbol}} = [get_childtypes(rule, alltypes) for rule ∈ rules]
domains = Dict(type => BitArray(r ∈ bytype[type] for r ∈ 1:length(rules)) for type ∈ alltypes)
return ContextSensitiveGrammar(rules, types, is_terminal, is_eval, bytype, domains, childtypes, nothing)
end
Expand Down
12 changes: 12 additions & 0 deletions test/test_csg.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
@testset verbose=true "CSGs" begin
@testset "Create empty grammar" begin
g = @csgrammar begin end
@test isempty(g.rules)
@test isempty(g.types)
@test isempty(g.isterminal)
@test isempty(g.iseval)
@test isempty(g.bytype)
@test isempty(g.domains)
@test isempty(g.childtypes)
@test isnothing(g.log_probabilities)
end

@testset "Creating grammars" begin
g₁ = @cfgrammar begin
Real = |(1:9)
Expand Down
Loading