@@ -36,11 +36,13 @@ Base.propertynames(x::Metadata) = propertynames(_data(x))
3636@unstable @inline Base. getproperty (x:: Metadata , f:: Symbol ) = getproperty (_data (x), f)
3737Base. show (io:: IO , x:: Metadata ) = print (io, " Metadata(" , _data (x), " )" )
3838@inline _copy (x) = copy (x)
39+ @inline _copy (x:: NamedTuple ) = copy_named_tuple (x)
3940@inline _copy (x:: Nothing ) = nothing
41+ @inline function copy_named_tuple (nt:: NamedTuple )
42+ return NamedTuple {keys(nt)} (map (_copy, values (nt)))
43+ end
4044@inline function Base. copy (metadata:: Metadata )
41- nt = _data (metadata)
42- copied_nt = NamedTuple {keys(nt)} (map (_copy, values (nt)))
43- return Metadata (copied_nt)
45+ return Metadata (_copy (_data (metadata)))
4446end
4547@inline Base.:(== )(x:: Metadata , y:: Metadata ) = _data (x) == _data (y)
4648@inline Base. hash (x:: Metadata , h:: UInt ) = hash (_data (x), h)
@@ -101,26 +103,11 @@ default_node_type(::Type{<:AbstractExpression{T}}) where {T} = Node{T}
101103# #######################################################
102104# Abstract interface ###################################
103105# #######################################################
104- """
105- get_operators(ex::AbstractExpression, operators::Union{Nothing,Any})
106-
107- which will return the operators to be passed to internal functions
108- such as `eval_tree_array` or `string_tree`, either from the expression itself,
109- or `cur_operators` if it is not `nothing`. If left as default,
110- it requires `cur_operators` to not be `nothing`.
111- `cur_operators` would typically be an `OperatorEnum`.
112- """
113106function get_operators (
114107 ex:: AbstractExpression , operators:: Union{AbstractOperatorEnum,Nothing} = nothing
115108)
116109 return error (" `get_operators` function must be implemented for $(typeof (ex)) types." )
117110end
118-
119- """
120- get_variable_names(ex::AbstractExpression, variable_names::Union{Nothing,AbstractVector{<:AbstractString}})
121-
122- The same as `operators`, but for variable names.
123- """
124111function get_variable_names (
125112 ex:: AbstractExpression ,
126113 variable_names:: Union{Nothing,AbstractVector{<:AbstractString}} = nothing ,
@@ -130,12 +117,6 @@ function get_variable_names(
130117 )
131118end
132119
133- """
134- get_tree(ex::AbstractExpression)
135-
136- A method that extracts the expression tree from `AbstractExpression`
137- and should return an `AbstractExpressionNode`.
138- """
139120function get_tree (ex:: AbstractExpression )
140121 return error (" `get_tree` function must be implemented for $(typeof (ex)) types." )
141122end
@@ -167,6 +148,50 @@ function get_metadata(ex::AbstractExpression)
167148end
168149# #######################################################
169150
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+
170195"""
171196 with_contents(ex::AbstractExpression, tree::AbstractExpressionNode)
172197 with_contents(ex::AbstractExpression, tree::AbstractExpression)
@@ -317,7 +342,7 @@ for io in ((), (:(io::IO),))
317342 end
318343end
319344
320- function Base. show (io:: IO , :: MIME"text/plain" , ex:: AbstractExpression )
345+ function Base. show (io:: IO , ex:: AbstractExpression )
321346 return print (io, string_tree (ex))
322347end
323348
0 commit comments