From 91b51ad44bde244e9529eb387b810acdc1aa8581 Mon Sep 17 00:00:00 2001 From: Reuben Gardos Reid <5456207+ReubenJ@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:55:52 +0300 Subject: [PATCH] Remove empty-child RuleNode and UniformHole constructors They don't seem to be used at the point in time, and their utility seems fairly vague anyway. --- src/HerbGrammar.jl | 5 +- src/rulenode_operators.jl | 86 --------------------------------- test/test_rulenode_operators.jl | 23 --------- 3 files changed, 1 insertion(+), 113 deletions(-) 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 5a6d0c0..4c2e6db 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