Skip to content

Remove/rename internal properties for Node types #23

@mortenpi

Description

@mortenpi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions