Skip to content

Commit

Permalink
Merge pull request #54 from Herb-AI/bug/empty-grammar
Browse files Browse the repository at this point in the history
Fix empty grammar creation
THinnerichs authored Feb 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents c7bb3e7 + 014731e commit d6d79c7
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/csg/csg.jl
Original file line number Diff line number Diff line change
@@ -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
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)

0 comments on commit d6d79c7

Please sign in to comment.