Skip to content

Implement tree interface #7

Description

@kovariance

Right now, there is no way to easily traverse the org-mode syntax tree. I recommend a function be implemented to query the child elements of an OrgComponent in a generic way, e.g.

children(o::OrgComponent) = OrgComponent[]
children(o::FootnoteReference) = begin
    isnothing(o.definition) && return OrgComponent[]
    o.definition
end
# ,,,

Such an interface would allow one to do a DFS of the syntax tree. If bringin in dependencies is acceptable, implementing the AbstractTrees.jl traits would be convenient.

Some type definitions may need to be adjusted, e.g. from

mutable struct CitationReference <: Object
    prefix::Vector{Object}
    key::AbstractString
    suffix::Vector{Object}
end

to

mutable struct CitationReference <: Object
    prefix::CitationReferencePrefix
    key::AbstractString
    suffix::CitationReferenceSuffix
end

struct CitationReferencePrefix <: Object
    contents::Vector{Object}
end

struct CitationReferenceSuffix <: Object
    contents::Vector{Object}
end

children(o::CitationReference) = [o.prefix, o.suffix]
children(o::CitrationReferencePrefix) = o.contents
children(o::CitrationReferencePrefix) = o.contents

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions