Skip to content

Commit eb45514

Browse files
committed
rename addelm! -> addnode! / initialize_node -> createnode
1 parent a75bcb3 commit eb45514

File tree

7 files changed

+102
-102
lines changed

7 files changed

+102
-102
lines changed

deps/SnoopCompile/precompile/precompile_AcuteML.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ function _precompile_()
1111
precompile(Tuple{typeof(AcuteML.multiString),Float64})
1212
precompile(Tuple{typeof(AcuteML.multiString),Int64})
1313
precompile(Tuple{typeof(AcuteML.multiString),String})
14-
precompile(Tuple{typeof(addelm!),Document,String,Nothing,Type{AbsAttribute}})
15-
precompile(Tuple{typeof(addelm!),Node,String,Array{Any,1},Type{AbsNormal}})
16-
precompile(Tuple{typeof(addelm!),Node,String,Array{Float64,1},Type{AbsNormal}})
17-
precompile(Tuple{typeof(addelm!),Node,String,Array{Int64,1},Type{AbsNormal}})
18-
precompile(Tuple{typeof(addelm!),Node,String,Array{String,1},Type{AbsNormal}})
19-
precompile(Tuple{typeof(addelm!),Node,String,Float64,Type{AbsNormal}})
20-
precompile(Tuple{typeof(addelm!),Node,String,Int64,Type{AbsNormal}})
21-
precompile(Tuple{typeof(addelm!),Node,String,Nothing,Type{AbsAttribute}})
22-
precompile(Tuple{typeof(addelm!),Node,String,Nothing,Type{AbsNormal}})
23-
precompile(Tuple{typeof(addelm!),Node,String,String,Type{AbsAttribute}})
24-
precompile(Tuple{typeof(addelm!),Node,String,String,Type{AbsNormal}})
14+
precompile(Tuple{typeof(addnode!),Document,String,Nothing,Type{AbsAttribute}})
15+
precompile(Tuple{typeof(addnode!),Node,String,Array{Any,1},Type{AbsNormal}})
16+
precompile(Tuple{typeof(addnode!),Node,String,Array{Float64,1},Type{AbsNormal}})
17+
precompile(Tuple{typeof(addnode!),Node,String,Array{Int64,1},Type{AbsNormal}})
18+
precompile(Tuple{typeof(addnode!),Node,String,Array{String,1},Type{AbsNormal}})
19+
precompile(Tuple{typeof(addnode!),Node,String,Float64,Type{AbsNormal}})
20+
precompile(Tuple{typeof(addnode!),Node,String,Int64,Type{AbsNormal}})
21+
precompile(Tuple{typeof(addnode!),Node,String,Nothing,Type{AbsAttribute}})
22+
precompile(Tuple{typeof(addnode!),Node,String,Nothing,Type{AbsNormal}})
23+
precompile(Tuple{typeof(addnode!),Node,String,String,Type{AbsAttribute}})
24+
precompile(Tuple{typeof(addnode!),Node,String,String,Type{AbsNormal}})
2525
precompile(Tuple{typeof(findcontent),String,Node,Type{AbsNormal}})
2626
precompile(Tuple{typeof(findcontent),Type{Array{Any,1}},String,Node,Type{AbsNormal}})
2727
precompile(Tuple{typeof(findcontent),Type{Array{Float64,1}},String,Node,Type{AbsNormal}})
@@ -31,10 +31,10 @@ function _precompile_()
3131
precompile(Tuple{typeof(findcontent),Type{String},String,Node,Type{AbsAttribute}})
3232
precompile(Tuple{typeof(findcontent),Type{String},String,Node,Type{AbsNormal}})
3333
precompile(Tuple{typeof(findcontent),Type{Union{Nothing, String}},String,Node,Type{AbsAttribute}})
34-
precompile(Tuple{typeof(initialize_node),Type{AbsEmpty},String})
35-
precompile(Tuple{typeof(initialize_node),Type{AbsHtml},String})
36-
precompile(Tuple{typeof(initialize_node),Type{AbsNormal},String})
37-
precompile(Tuple{typeof(initialize_node),Type{AbsXml},String})
34+
precompile(Tuple{typeof(createnode),Type{AbsEmpty},String})
35+
precompile(Tuple{typeof(createnode),Type{AbsHtml},String})
36+
precompile(Tuple{typeof(createnode),Type{AbsNormal},String})
37+
precompile(Tuple{typeof(createnode),Type{AbsXml},String})
3838
precompile(Tuple{typeof(newTemplate),String,Symbol})
3939
precompile(Tuple{typeof(newTemplate),String})
4040
precompile(Tuple{typeof(updatecontent!),Array{Any,1},String,Node,Type{AbsNormal}})

src/@aml/@aml_create.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function aml_create(expr::Expr, args_param, args_defaultvalue, args_type, args_v
9494
error("Invalid usage of @aml")
9595
end
9696
################################################################
97-
node_initializer = :( aml = initialize_node($struct_nodetype, $struct_name) )
97+
node_initializer = :( aml = createnode($struct_nodetype, $struct_name) )
9898

9999
struct_definition =:($expr)
100100

src/@aml/@aml_create/get_arg_xml_.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ function get_arg_xmlcreator(argcustomcreator, has_arg_xmlchecker::Bool, argtype,
99
if !has_arg_xmlchecker
1010
arg_creator = quote
1111
$(esc(argcustomcreator))
12-
addelm!(aml, $argname, $esc_argvar, $argliteraltype)
12+
addnode!(aml, $argname, $esc_argvar, $argliteraltype)
1313
end
1414
else
1515
arg_creator=quote
1616
$(esc(argcustomcreator))
1717
if isnothing($esc_argvar) || ($esc_argfunction)($esc_argvar)
18-
addelm!(aml, $argname, $esc_argvar, $argliteraltype)
18+
addnode!(aml, $argname, $esc_argvar, $argliteraltype)
1919
else
2020
error("$($argname) doesn't meet criteria function")
2121
end

src/xmlutils/addnode.jl

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
export addelm!
1+
export addnode!
22
################################################################
33
# Add node
44
################################################################
55
# Document
66
################################################################
77
# Any
88
"""
9-
addelm!(node, name, value, argAmlType)
9+
addnode!(node, name, value, argAmlType)
1010
11-
Add one element to a node/document
11+
To add nodes (single or a vector of nodes) as a child of given a node/document.
1212
"""
13-
function addelm!(aml::Document, name::String, value::T, argAmlType::Type{<:AbsDocOrNode}) where {T}
13+
function addnode!(aml::Document, name::String, value::T, argAmlType::Type{<:AbsDocOrNode}) where {T}
1414

1515
if hasroot(aml)
1616
amlNode = root(aml)
17-
elm = addelm!(amlNode, name, value, argAmlType)
17+
elm = addnode!(amlNode, name, value, argAmlType)
1818
return elm
1919
elseif hasfield(T, :aml)
2020
elm = setroot!(aml, value.aml)
@@ -26,22 +26,22 @@ function addelm!(aml::Document, name::String, value::T, argAmlType::Type{<:AbsDo
2626
end
2727

2828
# Nothing
29-
function addelm!(aml::Document, name::String, value::Nothing, argAmlType::Type{<:AbsDocOrNode})
29+
function addnode!(aml::Document, name::String, value::Nothing, argAmlType::Type{<:AbsDocOrNode})
3030
# do nothing if value is nothing
3131
end
3232
################################################################
3333
# Vector
3434
"""
35-
addelm!(node, name, value, argAmlType)
35+
addnode!(node, name, value, argAmlType)
3636
3737
Add a vector to a node/document
3838
```
3939
"""
40-
function addelm!(aml::Document, name::String, value::Vector, argAmlType::Type{<:AbsDocOrNode})
40+
function addnode!(aml::Document, name::String, value::Vector, argAmlType::Type{<:AbsDocOrNode})
4141

4242
if hasroot(aml)
4343
amlNode = root(aml)
44-
elm = addelm!(amlNode, name, value, argAmlType)
44+
elm = addnode!(amlNode, name, value, argAmlType)
4545
return elm
4646
else
4747
error("You cannot insert a vector in the document directly. Define a @aml defined field for xml or html document struct")
@@ -53,21 +53,21 @@ end
5353
# Nodes
5454
################################################################
5555
# String
56-
@transform function addelm!(aml::Node, name::String,value::AbstractString, argAmlType::Type{allsubtypes(AbsNormal)})
56+
@transform function addnode!(aml::Node, name::String,value::AbstractString, argAmlType::Type{allsubtypes(AbsNormal)})
5757
if !isnothing(value) # do nothing if value is nothing
5858
elm = addelement!(aml, name, value)
5959
return elm
6060
end
6161
end
6262

63-
function addelm!(aml::Node, name::String,value::AbstractString, argAmlType::Type{AbsAttribute})
63+
function addnode!(aml::Node, name::String,value::AbstractString, argAmlType::Type{AbsAttribute})
6464
if !isnothing(value) # do nothing if value is nothing
6565
elm = link!(aml, AttributeNode(name, value))
6666
return elm
6767
end
6868
end
6969

70-
function addelm!(aml::Node, indexstr::String,value::AbstractString, argAmlType::Type{AbsText})
70+
function addnode!(aml::Node, indexstr::String,value::AbstractString, argAmlType::Type{AbsText})
7171
index = parse_textindex(indexstr)
7272
if index < length(elements(aml))
7373
desired_node = elements(aml)[index]
@@ -85,21 +85,21 @@ function addelm!(aml::Node, indexstr::String,value::AbstractString, argAmlType::
8585
end
8686

8787
# Number (and also Bool <:Number)
88-
@transform function addelm!(aml::Node, name::String, value::Number, argAmlType::Type{allsubtypes(AbsNormal)})
88+
@transform function addnode!(aml::Node, name::String, value::Number, argAmlType::Type{allsubtypes(AbsNormal)})
8989
if !isnothing(value) # do nothing if value is nothing
9090
elm = addelement!(aml, name, string(value))
9191
return elm
9292
end
9393
end
9494

95-
function addelm!(aml::Node, name::String, value::Number, argAmlType::Type{AbsAttribute})
95+
function addnode!(aml::Node, name::String, value::Number, argAmlType::Type{AbsAttribute})
9696
if !isnothing(value) # do nothing if value is nothing
9797
elm = link!(aml, AttributeNode(name, string(value)))
9898
return elm
9999
end
100100
end
101101

102-
function addelm!(aml::Node, indexstr::String, value::Number, argAmlType::Type{AbsText})
102+
function addnode!(aml::Node, indexstr::String, value::Number, argAmlType::Type{AbsText})
103103
index = parse_textindex(indexstr)
104104
if index < length(elements(aml))
105105
desired_node = elements(aml)[index]
@@ -117,7 +117,7 @@ function addelm!(aml::Node, indexstr::String, value::Number, argAmlType::Type{Ab
117117
end
118118

119119
# Other
120-
function addelm!(aml::Node, name::String, value::T, argAmlType::Type{<:AbsNormal}) where {T}
120+
function addnode!(aml::Node, name::String, value::T, argAmlType::Type{<:AbsNormal}) where {T}
121121
if hasfield(T, :aml)
122122
elm = link!(aml,value.aml)
123123
return elm
@@ -137,7 +137,7 @@ function addelm!(aml::Node, name::String, value::T, argAmlType::Type{<:AbsNormal
137137
end
138138
end
139139

140-
function addelm!(aml::Node, name::String, value::T, argAmlType::Type{AbsAttribute}) where {T}
140+
function addnode!(aml::Node, name::String, value::T, argAmlType::Type{AbsAttribute}) where {T}
141141
if hasfield(T, :aml)
142142
elm = link!(aml, AttributeNode(name, value.aml))
143143
return elm
@@ -157,7 +157,7 @@ function addelm!(aml::Node, name::String, value::T, argAmlType::Type{AbsAttribut
157157
end
158158
end
159159

160-
function addelm!(aml::Node, indexstr::String, value::T, argAmlType::Type{AbsText}) where {T}
160+
function addnode!(aml::Node, indexstr::String, value::T, argAmlType::Type{AbsText}) where {T}
161161
index = parse_textindex(indexstr)
162162
if index < length(elements(aml))
163163

@@ -203,31 +203,31 @@ function addelm!(aml::Node, indexstr::String, value::T, argAmlType::Type{AbsText
203203
end
204204

205205
# Nothing
206-
@transform function addelm!(aml::Node, name::String, value::Nothing, argAmlType::Type{allsubtypes(AbsDocOrNode)})
206+
@transform function addnode!(aml::Node, name::String, value::Nothing, argAmlType::Type{allsubtypes(AbsDocOrNode)})
207207
# do nothing
208208
end
209209
################################################################
210210
# Vector
211211

212212
allsubtypes_butAbsText(t) = setdiff(allsubtypes(AbsDocOrNode), [AbsText])
213213

214-
@transform function addelm!(aml::Node, name::String, values::Vector, argAmlType::Type{allsubtypes_butAbsText(AbsDocOrNode)})
214+
@transform function addnode!(aml::Node, name::String, values::Vector, argAmlType::Type{allsubtypes_butAbsText(AbsDocOrNode)})
215215
elms = Vector{Union{Node, Nothing}}(undef, length(values))
216216
for (ielm, value) in enumerate(values)
217-
elms[ielm] = addelm!(aml, name, value, argAmlType)
217+
elms[ielm] = addnode!(aml, name, value, argAmlType)
218218
end
219219
return elms
220220
end
221221

222-
function addelm!(aml::Node, indicesstr::String, values::Vector, argAmlType::Type{AbsText})
222+
function addnode!(aml::Node, indicesstr::String, values::Vector, argAmlType::Type{AbsText})
223223
indices = parse_textindices(indicesstr)
224224
if indices isa Colon
225225
indices = 1:length(elements(aml))
226226
end
227227
elms = Vector{Union{Node, Nothing}}(undef, length(indices))
228228
ielm = 1
229229
for (value, index) in zip(values, indices)
230-
elms[ielm] = addelm!(aml, string(index), value, argAmlType)
230+
elms[ielm] = addnode!(aml, string(index), value, argAmlType)
231231
ielm += 1
232232
end
233233
return elms
@@ -236,14 +236,14 @@ end
236236
################################################################
237237
# Dict
238238

239-
@transform function addelm!(aml::Node, name::String, values::AbstractDict, argAmlType::Type{allsubtypes(AbsDocOrNode)})
239+
@transform function addnode!(aml::Node, name::String, values::AbstractDict, argAmlType::Type{allsubtypes(AbsDocOrNode)})
240240
# name is discarded now: actual names are stored in the Dict itself
241241
# elements are added directly
242242
# for AbsText, v_name is considered as the text index
243243
elms = Vector{Union{Node, Nothing}}(undef, length(values))
244244
ielm = 1
245245
for (v_name, v_value) in values
246-
elms[ielm] = addelm!(aml, v_name, v_value, argAmlType)
246+
elms[ielm] = addnode!(aml, v_name, v_value, argAmlType)
247247
ielm += 1
248248
end
249249
end

src/xmlutils/initializer.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
export initialize_node
1+
export createnode
22

33
################################################################
44
# Init
55
################################################################
66
# doc or element initialize
77
"""
8-
initialize_node(struct_nodetype)
8+
createnode(struct_nodetype)
99
1010
Function to initialize the aml
1111
"""
12-
function initialize_node(::Type{AbsHtml}, struct_name::String = "html")
12+
function createnode(::Type{AbsHtml}, struct_name::String = "html")
1313
out = HTMLDocument() # no URI and external id
1414
htmlNode = ElementNode(struct_name)
1515
setroot!(out, htmlNode) # adding html node
1616
return out
1717
end
1818

19-
function initialize_node(::Type{AbsXml}, struct_name::String = "xml_root")
19+
function createnode(::Type{AbsXml}, struct_name::String = "xml_root")
2020
out = XMLDocument() # version 1
2121
xmlNode = ElementNode(struct_name)
2222
setroot!(out, xmlNode) # adding html node
2323
return out
2424
end
2525

26-
function initialize_node(::Type{<:AbsNormal}, struct_name::String)
26+
function createnode(::Type{<:AbsNormal}, struct_name::String)
2727
out = ElementNode(struct_name) # element node
2828
return out
2929
end
3030

31-
function initialize_node(::Type{AbsText}, struct_name::String)
31+
function createnode(::Type{AbsText}, struct_name::String)
3232
out = TextNode(struct_name) # text node
3333
return out
3434
end
3535

3636
# no type method
37-
function initialize_node(struct_name::String)
37+
function createnode(struct_name::String)
3838
out = ElementNode(struct_name) # element node
3939
return out
4040
end

src/xmlutils/updater.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ function updatecontent!(value, name::String, node::Node, argAmlType::Type{<:Unio
8080
if !isnothing(elm)
8181
updatecontent!(value, elm, node, argAmlType)
8282
else
83-
# addelm! if nothing is found
84-
addelm!(node, name, value, argAmlType)
83+
# addnode! if nothing is found
84+
addnode!(node, name, value, argAmlType)
8585
end
8686
end
8787

@@ -90,8 +90,8 @@ function updatecontent!(value, name::String, node::Node, argAmlType::Type{<:AbsA
9090
if haskey(node, name)
9191
node[name] = value
9292
else
93-
# addelm! if nothing is found
94-
addelm!(node, name, value, argAmlType)
93+
# addnode! if nothing is found
94+
addnode!(node, name, value, argAmlType)
9595
end
9696
end
9797

@@ -104,8 +104,8 @@ function updatecontent!(values::Vector, name::String, node::Node, argAmlType::Ty
104104
if !isnothing(elms)
105105
updatecontent!(values, elms, node, argAmlType)
106106
else
107-
# addelm! if nothing is found
108-
addelm!(node, name, values, argAmlType)
107+
# addnode! if nothing is found
108+
addnode!(node, name, values, argAmlType)
109109
end
110110
end
111111

@@ -114,8 +114,8 @@ function updatecontent!(values::Vector, name::String, node::Node, argAmlType::Ty
114114
if haskey(node, name)
115115
node[name] .= values
116116
else
117-
# addelm! if nothing is found
118-
addelm!(node, name, values, argAmlType)
117+
# addnode! if nothing is found
118+
addnode!(node, name, values, argAmlType)
119119
end
120120
end
121121

0 commit comments

Comments
 (0)