Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/porcelain/green_node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ function Base.show(io::IO, ::MIME"text/plain", node::GreenNode, str::AbstractStr
_show_green_node(io, node, "", 1, str, show_trivia)
end

function _show_green_node_sexpr(io, node::GreenNode, position)
if is_leaf(node)
print(io, position, "-", position+node.span-1, "::", untokenize(head(node); unique=false))
else
print(io, "(", untokenize(head(node); unique=false))
p = position
for n in children(node)
print(io, ' ')
_show_green_node_sexpr(io, n, p)
p += n.span
end
print(io, ')')
end
end

function Base.show(io::IO, node::GreenNode)
_show_green_node_sexpr(io, node, 1)
end

function GreenNode(cursor::GreenTreeCursor)
chead = head(cursor)
T = typeof(chead)
Expand Down
2 changes: 0 additions & 2 deletions src/porcelain/syntax_tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,9 @@ function _show_syntax_node_sexpr(io, node::AbstractSyntaxNode, show_kind)
end
else
print(io, "(", untokenize(head(node)))
first = true
for n in children(node)
print(io, ' ')
_show_syntax_node_sexpr(io, n, show_kind)
first = false
end
print(io, ')')
end
Expand Down
3 changes: 3 additions & 0 deletions test/green_node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@
10:10 │ Identifier ✔ "z"
11:11 │ ) ")"
"""

@test sprint(show, parsestmt(GreenNode, "a + bb - f(ccc)")) ==
"(call-i (call-i 1-1::Identifier 2-2::Whitespace-t 3-3::Identifier 4-4::Whitespace-t 5-6::Identifier) 7-7::Whitespace-t 8-8::Identifier 9-9::Whitespace-t (call 10-10::Identifier 11-11::(-t 12-14::Identifier 15-15::)-t))"
end
Loading