Skip to content

Commit

Permalink
rulenode2expr for Holes
Browse files Browse the repository at this point in the history
  • Loading branch information
THinnerichs committed Dec 14, 2023
1 parent c84d34c commit 338a71a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/rulenode_operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,21 @@ function rulenode2expr(rulenode::RuleNode, grammar::Grammar)
end


function _rulenode2expr(rulenode::Hole, grammar::Grammar)
# Find the index of the first element that is true
index = findfirst(==(true), rulenode.domain)
return isnothing(index) ? :Nothing : grammar.types[index]
end
rulenode2expr(rulenode::Hole, grammar::Grammar) = _rulenode2expr(rulenode::Hole, grammar::Grammar)

function _rulenode2expr(expr::Expr, rulenode::RuleNode, grammar::Grammar, j=0)
for (k,arg) in enumerate(expr.args)
if isa(arg, Expr)
expr.args[k],j = _rulenode2expr(arg, rulenode, grammar, j)
elseif haskey(grammar.bytype, arg)
child = rulenode.children[j+=1]
if isa(child, Hole)
# Find the index of the first element that is true
index = findfirst(==(true), child.domain)
expr.args[k] = isnothing(index) ? :Nothing : grammar.types[index]
expr.args[k] = _rulenode2expr(child, grammar)
continue
end
expr.args[k] = (child._val !== nothing) ?
Expand Down

0 comments on commit 338a71a

Please sign in to comment.