Skip to content

Commit 51ded2a

Browse files
committed
docs: more key docstrings
1 parent 949b7fc commit 51ded2a

File tree

2 files changed

+54
-21
lines changed

2 files changed

+54
-21
lines changed

docs/src/api.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ You may use operators directly on `AbstractExpression` objects to create a new o
177177
containing the combined expression tree, so long as those objects have identical operators
178178
in their metadata.
179179

180+
You can extract and set contents and metadata with a few utility functions, including:
181+
182+
```@docs
183+
get_contents
184+
with_contents
185+
get_metadata
186+
with_metadata
187+
get_tree
188+
```
189+
180190
To declare a new operator for expressions, you may use:
181191

182192
```@docs

src/Expression.jl

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,11 @@ default_node_type(::Type{<:AbstractExpression{T}}) where {T} = Node{T}
103103
########################################################
104104
# Abstract interface ###################################
105105
########################################################
106-
"""
107-
get_operators(ex::AbstractExpression, operators::Union{Nothing,Any})
108-
109-
which will return the operators to be passed to internal functions
110-
such as `eval_tree_array` or `string_tree`, either from the expression itself,
111-
or `cur_operators` if it is not `nothing`. If left as default,
112-
it requires `cur_operators` to not be `nothing`.
113-
`cur_operators` would typically be an `OperatorEnum`.
114-
"""
115106
function get_operators(
116107
ex::AbstractExpression, operators::Union{AbstractOperatorEnum,Nothing}=nothing
117108
)
118109
return error("`get_operators` function must be implemented for $(typeof(ex)) types.")
119110
end
120-
121-
"""
122-
get_variable_names(ex::AbstractExpression, variable_names::Union{Nothing,AbstractVector{<:AbstractString}})
123-
124-
The same as `operators`, but for variable names.
125-
"""
126111
function get_variable_names(
127112
ex::AbstractExpression,
128113
variable_names::Union{Nothing,AbstractVector{<:AbstractString}}=nothing,
@@ -132,12 +117,6 @@ function get_variable_names(
132117
)
133118
end
134119

135-
"""
136-
get_tree(ex::AbstractExpression)
137-
138-
A method that extracts the expression tree from `AbstractExpression`
139-
and should return an `AbstractExpressionNode`.
140-
"""
141120
function get_tree(ex::AbstractExpression)
142121
return error("`get_tree` function must be implemented for $(typeof(ex)) types.")
143122
end
@@ -169,6 +148,50 @@ function get_metadata(ex::AbstractExpression)
169148
end
170149
########################################################
171150

151+
"""
152+
get_operators(ex::AbstractExpression, operators::Union{Nothing,Any})
153+
154+
which will return the operators to be passed to internal functions
155+
such as `eval_tree_array` or `string_tree`, either from the expression itself,
156+
or `cur_operators` if it is not `nothing`. If left as default,
157+
it requires `cur_operators` to not be `nothing`.
158+
`cur_operators` would typically be an `OperatorEnum`.
159+
"""
160+
get_operators
161+
162+
"""
163+
get_variable_names(ex::AbstractExpression, variable_names::Union{Nothing,AbstractVector{<:AbstractString}})
164+
165+
The same as `operators`, but for variable names.
166+
"""
167+
get_variable_names
168+
169+
"""
170+
get_tree(ex::AbstractExpression)
171+
172+
A method that extracts the expression tree from `AbstractExpression`
173+
and should return an `AbstractExpressionNode`.
174+
"""
175+
get_tree
176+
177+
"""
178+
get_contents(ex::AbstractExpression)
179+
180+
Get the contents of the expression, which might be a plain
181+
`AbstractExpressionNode`, or some combination of them, or other data.
182+
This should include everything other than that returned by [`get_metadata`](@ref).
183+
"""
184+
get_contents
185+
186+
"""
187+
get_metadata(ex::AbstractExpression)
188+
189+
Get the metadata of the expression, which might be a plain
190+
`NamedTuple`, or some combination of them, or other data.
191+
This should include everything other than that returned by [`get_contents`](@ref).
192+
"""
193+
get_metadata
194+
172195
"""
173196
with_contents(ex::AbstractExpression, tree::AbstractExpressionNode)
174197
with_contents(ex::AbstractExpression, tree::AbstractExpression)

0 commit comments

Comments
 (0)