diff --git a/src/HerbGrammar.jl b/src/HerbGrammar.jl index 65d68d1..32b27d3 100644 --- a/src/HerbGrammar.jl +++ b/src/HerbGrammar.jl @@ -67,9 +67,6 @@ export read_pcsg, add_rule!, remove_rule!, - cleanup_removed_rules!, - empty_children, - rulenode_with_empty_children, - uniform_hole_with_empty_children + cleanup_removed_rules! end # module HerbGrammar diff --git a/src/rulenode_operators.jl b/src/rulenode_operators.jl index b11ada7..6e6e321 100644 --- a/src/rulenode_operators.jl +++ b/src/rulenode_operators.jl @@ -1,89 +1,3 @@ -""" - empty_children(index::Integer, grammar::ContextSensitiveGrammar) - -Given the `index` of a rule in a `grammar`, create a vector of [`Hole`](@ref)s -corresponding to the children of the rule at `index`. - -# Examples -```jldoctest -julia> g = @csgrammar begin - A = 1 | 2 | 3 - B = A + A - end -1: A = 1 -2: A = 2 -3: A = 3 -4: B = A + A - - -julia> empty_children(4, g) -2-element Vector{Hole}: - hole[Bool[1, 1, 1, 0]] - hole[Bool[1, 1, 1, 0]]``` -""" -function empty_children(index::Integer, grammar::ContextSensitiveGrammar) - return [Hole(get_domain(grammar, type)) for type in grammar.childtypes[index]] -end - -""" - RuleNode(ind::Int, grammar::ContextSensitiveGrammar) - -Create a [`RuleNode`](@ref) with [`Hole`](@ref)s as children. The holes -are initialized with the types of the children of the rule at `ind`. - -# Examples -```jldoctest -julia> g = @csgrammar begin - A = 1 | 2 | 3 - B = A + A - end -1: A = 1 -2: A = 2 -3: A = 3 -4: B = A + A - - -julia> rulenode_with_empty_children(4, g) -4{hole[Bool[1, 1, 1, 0]],hole[Bool[1, 1, 1, 0]]} -``` -""" -function rulenode_with_empty_children(ind::Int, _val::Union{Any,Nothing}, grammar::ContextSensitiveGrammar) - child_holes = empty_children(ind, grammar) - return RuleNode(ind, _val, child_holes) -end - -function rulenode_with_empty_children(ind::Int, grammar::ContextSensitiveGrammar) - return rulenode_with_empty_children(ind, nothing, grammar) -end - -""" - uniform_hole_with_empty_children(domain::BitVector, grammar::AbstractGrammar) - -Create a [`UniformHole`](@ref) with [`Hole`](@ref)s as children. The holes -are initialized with the types of the children of the rule at `ind`. - -# Examples -```jldoctest -julia> g = @csgrammar begin - A = 1 | 2 | 3 - B = (A + A) | (A - A) - end -1: A = 1 -2: A = 2 -3: A = 3 -4: B = A + A -5: B = A - A - - -julia> uniform_hole_with_empty_children(BitVector([0, 0, 0, 1, 1]), g) -fshole[Bool[0, 0, 0, 1, 1]]{hole[Bool[1, 1, 1, 0, 0]],hole[Bool[1, 1, 1, 0, 0]]} -``` -""" -function uniform_hole_with_empty_children(domain::BitVector, grammar::AbstractGrammar) - child_holes = empty_children(findfirst(domain), grammar) - return UniformHole(domain, child_holes) -end - rulesoftype(::Hole, ::Set{Int}) = Set{Int}() """ diff --git a/test/test_rulenode_operators.jl b/test/test_rulenode_operators.jl index fd52ea6..dee0c14 100644 --- a/test/test_rulenode_operators.jl +++ b/test/test_rulenode_operators.jl @@ -15,27 +15,4 @@ end @test !isvariable(g₁, RuleNode(7, g₁), SomeDefinitions) @test isvariable(g₁, RuleNode(7, g₁)) end - - @testset "Create `RuleNode`s with `Hole`s for children" begin - g = @csgrammar begin - A = 1 | 2 | 3 - B = A + A - end - - r = rulenode_with_empty_children(4, g) - - @test get_children(r)[1].domain == [1, 1, 1, 0] - @test get_children(r)[2].domain == [1, 1, 1, 0] - end - - @testset "Create `UniformHole`s with `Hole`s for children" begin - g = @csgrammar begin - A = 1 | 2 | 3 - B = (A + A) | (A - A) - end - h = uniform_hole_with_empty_children(BitVector([0, 0, 0, 1, 1]), g) - - @test get_children(h)[1].domain == [1, 1, 1, 0, 0] - @test get_children(h)[2].domain == [1, 1, 1, 0, 0] - end end