Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove/rename internal properties for Node types #23

Open
mortenpi opened this issue Oct 6, 2023 · 0 comments
Open

Remove/rename internal properties for Node types #23

mortenpi opened this issue Oct 6, 2023 · 0 comments
Milestone

Comments

@mortenpi
Copy link
Member

mortenpi commented Oct 6, 2023

We have these internal fields like .nxt and .first_child, and we do some unnecessary get/setproperty stuff:

MarkdownAST.jl/src/node.jl

Lines 103 to 137 in 99e0f82

function Base.getproperty(node::Node{T}, name::Symbol) where T
if name === :element
getfield(node, :t)
elseif name === :children
NodeChildren(node)
elseif name === :next
getfield(node, :nxt)
elseif name === :previous
getfield(node, :prv)
elseif name === :parent
getfield(node, :parent)
elseif name === :meta
getfield(node, :meta)
else
# TODO: error("type Node does not have property $(name)")
@debug "Accessing private field $(name) of Node" stacktrace()
getfield(node, name)
end
end
function Base.setproperty!(node::Node, name::Symbol, x)
if name === :element
setfield!(node, :t, x)
elseif name === :meta
setfield!(node, :meta, x)
elseif name in propertynames(node)
# TODO: error("Unable to set property $(name) for Node")
@debug "Setting private field :$(name) of Node" stacktrace()
setfield!(node, name, x)
else
# TODO: error("type Node does not have property $(name)")
@debug "Accessing private field :$(name) of Node" stacktrace()
setfield!(node, name, x)
end
end

We should clean that up and make sure that you can only access documented fields. Internally, we can use getfield and setfield! where necessary. But let's do that in 0.2.0.

X-ref: #19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant