Skip to content

Commit

Permalink
fixup! Clean up and document syntax tree child access API
Browse files Browse the repository at this point in the history
  • Loading branch information
c42f committed Aug 7, 2024
1 parent 74ef94e commit 6cd1b85
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/hooks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ function _incomplete_tag(n::SyntaxNode, codelen)
return :none
end
end
if kind(c) == K"error" && begin
cs = children(c)
length(cs) > 0
end
for cc in cs
if kind(c) == K"error" && numchildren(c) > 0
for cc in children(c)
if kind(cc) == K"error"
return :other
end
Expand Down
10 changes: 6 additions & 4 deletions src/syntax_tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ function Base.copy(node::TreeNode)
# copy the container but not the data (ie, deep copy the tree, shallow copy the data). copy(::Expr) is similar
# copy "un-parents" the top-level `node` that you're copying
newnode = typeof(node)(nothing, is_leaf(node) ? nothing : typeof(node)[], copy(node.data))
for child in children(node)
newchild = copy(child)
newchild.parent = newnode
push!(newnode, newchild)
if !is_leaf(node)
for child in children(node)
newchild = copy(child)
newchild.parent = newnode
push!(newnode, newchild)
end
end
return newnode
end
Expand Down

0 comments on commit 6cd1b85

Please sign in to comment.