Skip to content

Commit 6cd1b85

Browse files
committed
fixup! Clean up and document syntax tree child access API
1 parent 74ef94e commit 6cd1b85

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/hooks.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@ function _incomplete_tag(n::SyntaxNode, codelen)
4545
return :none
4646
end
4747
end
48-
if kind(c) == K"error" && begin
49-
cs = children(c)
50-
length(cs) > 0
51-
end
52-
for cc in cs
48+
if kind(c) == K"error" && numchildren(c) > 0
49+
for cc in children(c)
5350
if kind(cc) == K"error"
5451
return :other
5552
end

src/syntax_tree.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,12 @@ function Base.copy(node::TreeNode)
223223
# copy the container but not the data (ie, deep copy the tree, shallow copy the data). copy(::Expr) is similar
224224
# copy "un-parents" the top-level `node` that you're copying
225225
newnode = typeof(node)(nothing, is_leaf(node) ? nothing : typeof(node)[], copy(node.data))
226-
for child in children(node)
227-
newchild = copy(child)
228-
newchild.parent = newnode
229-
push!(newnode, newchild)
226+
if !is_leaf(node)
227+
for child in children(node)
228+
newchild = copy(child)
229+
newchild.parent = newnode
230+
push!(newnode, newchild)
231+
end
230232
end
231233
return newnode
232234
end

0 commit comments

Comments
 (0)