Skip to content

Commit cfc1e96

Browse files
committed
Add graph utils: unfreeze_attrs, attrtypes
Missing utilities in line with existing ones (`freeze_attrs`, `attrnames`)
1 parent 1d57a38 commit cfc1e96

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/syntax_graph.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ function freeze_attrs(graph::SyntaxGraph)
2222
SyntaxGraph(graph.edge_ranges, graph.edges, frozen_attrs)
2323
end
2424

25+
function unfreeze_attrs(graph::SyntaxGraph)
26+
SyntaxGraph(graph.edge_ranges, graph.edges, Dict(pairs(graph.attributes)...))
27+
end
28+
2529
function _show_attrs(io, attributes::Dict)
2630
show(io, MIME("text/plain"), attributes)
2731
end
@@ -33,6 +37,10 @@ function attrnames(graph::SyntaxGraph)
3337
keys(graph.attributes)
3438
end
3539

40+
function attrtypes(graph::SyntaxGraph)
41+
[(k, typeof(v).parameters[2]) for (k, v) in pairs(graph.attributes)]
42+
end
43+
3644
function Base.show(io::IO, ::MIME"text/plain", graph::SyntaxGraph)
3745
print(io, typeof(graph),
3846
" with $(length(graph.edge_ranges)) vertices, $(length(graph.edges)) edges, and attributes:\n")
@@ -54,7 +62,7 @@ function ensure_attributes!(graph::SyntaxGraph{<:Dict}; kws...)
5462
end
5563

5664
function ensure_attributes(graph::SyntaxGraph; kws...)
57-
g = SyntaxGraph(graph.edge_ranges, graph.edges, Dict(pairs(graph.attributes)...))
65+
g = unfreeze_attrs(graph)
5866
ensure_attributes!(g; kws...)
5967
freeze_attrs(g)
6068
end

0 commit comments

Comments
 (0)