Skip to content

Commit

Permalink
Clarify new empty_children method
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenJ committed Dec 2, 2024
1 parent 9cc532c commit 44146c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/HerbGrammar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export
add_rule!,
remove_rule!,
cleanup_removed_rules!,
holes_from_child_types,
empty_children,
rulenode_with_empty_children,
uniform_hole_with_empty_children

Expand Down
25 changes: 21 additions & 4 deletions src/rulenode_operators.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
"""
holes_from_child_types(index::Integer, grammar::ContextSensitiveGrammar)
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 holes_from_child_types(index::Integer, grammar::ContextSensitiveGrammar)
function empty_children(index::Integer, grammar::ContextSensitiveGrammar)
return [Hole(get_domain(grammar, type)) for type in grammar.childtypes[index]]
end

Expand All @@ -31,7 +48,7 @@ julia> rulenode_with_empty_children(4, g)
```
"""
function rulenode_with_empty_children(ind::Int, _val::Union{Any,Nothing}, grammar::ContextSensitiveGrammar)
child_holes = holes_from_child_types(ind, grammar)
child_holes = empty_children(ind, grammar)
return RuleNode(ind, _val, child_holes)
end

Expand Down Expand Up @@ -63,7 +80,7 @@ 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 = holes_from_child_types(findfirst(domain), grammar)
child_holes = empty_children(findfirst(domain), grammar)
return UniformHole(domain, child_holes)
end

Expand Down

0 comments on commit 44146c3

Please sign in to comment.