Skip to content

Commit

Permalink
Remove empty-child RuleNode and UniformHole constructors
Browse files Browse the repository at this point in the history
They don't seem to be used at the point in time, and their utility
seems fairly vague anyway.
  • Loading branch information
ReubenJ committed Dec 12, 2024
1 parent db9e65e commit 588e13a
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 113 deletions.
5 changes: 1 addition & 4 deletions src/HerbGrammar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
86 changes: 0 additions & 86 deletions src/rulenode_operators.jl
Original file line number Diff line number Diff line change
@@ -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}()

"""
Expand Down
23 changes: 0 additions & 23 deletions test/test_rulenode_operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 588e13a

Please sign in to comment.