Skip to content

Commit f8b8f22

Browse files
authored
Merge pull request #134 from aminya/refactor
2 parents 8591893 + a352e7b commit f8b8f22

22 files changed

+1028
-1144
lines changed

benchmark/bench.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ P1, P2, U = creation();
8484
#=
8585
Benchmark Result
8686
87+
v 0.10
88+
# small bump in extraction is because of two additional hasmethod check in nodeparse. Using traits this will be fixed
89+
90+
8.899 μs (100 allocations: 3.61 KiB)
91+
3.938 μs (66 allocations: 3.17 KiB)
92+
308.500 μs (403 allocations: 16.33 KiB)
93+
8794
V 0.9.2 - julia 1.4
8895
8996
10.000 μs (99 allocations: 3.39 KiB)

deps/SnoopCompile/precompile/precompile_AcuteML.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
function _precompile_()
22
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
3-
isdefined(AcuteML, Symbol("#8#17")) && precompile(Tuple{getfield(AcuteML, Symbol("#8#17")),Nothing})
43
precompile(Tuple{Core.kwftype(typeof(AcuteML.render2file)),NamedTuple{(:id, :age, :field, :GPA, :courses),Tuple{Int64,Int64,String,Float64,Array{String,1}}},typeof(render2file),String,Bool})
54
precompile(Tuple{typeof(AcuteML.aml_create),Expr,Array{Union{Expr, Symbol},1},Array{Any,1},Array{Union{Expr, Symbol, Type},1},Array{Union{Expr, Symbol},1},Array{Union{Missing, String},1},Array{Union{Missing, Function, Symbol},1},Array{Union{Missing, Type},1},String,Type{T} where T,Array{Union{Missing, Function, Symbol},0},Bool,Array{Union{Nothing, Expr},1},Array{Union{Nothing, Expr},1},Array{Union{Nothing, Expr},1},Symbol})
65
precompile(Tuple{typeof(AcuteML.aml_parse),Expr})
@@ -11,17 +10,19 @@ function _precompile_()
1110
precompile(Tuple{typeof(AcuteML.multiString),Float64})
1211
precompile(Tuple{typeof(AcuteML.multiString),Int64})
1312
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}})
13+
precompile(Tuple{typeof(AcuteML.nodeparse),Type{T} where T,Node})
14+
precompile(Tuple{typeof(addnode!),Node,String,Array{Any,1},Type{AbsNormal}})
15+
precompile(Tuple{typeof(addnode!),Node,String,Array{Float64,1},Type{AbsNormal}})
16+
precompile(Tuple{typeof(addnode!),Node,String,Array{Int64,1},Type{AbsNormal}})
17+
precompile(Tuple{typeof(addnode!),Node,String,Array{String,1},Type{AbsNormal}})
18+
precompile(Tuple{typeof(addnode!),Node,String,Nothing,Type{AbsAttribute}})
19+
precompile(Tuple{typeof(addnode!),Node,String,Nothing,Type{AbsNormal}})
20+
precompile(Tuple{typeof(addnode!),Node,String,String,Type{AbsAttribute}})
21+
precompile(Tuple{typeof(addnode!),Node,String,String,Type{AbsNormal}})
22+
precompile(Tuple{typeof(createnode),Type{AbsEmpty},String})
23+
precompile(Tuple{typeof(createnode),Type{AbsHtml},String})
24+
precompile(Tuple{typeof(createnode),Type{AbsNormal},String})
25+
precompile(Tuple{typeof(createnode),Type{AbsXml},String})
2526
precompile(Tuple{typeof(findcontent),String,Node,Type{AbsNormal}})
2627
precompile(Tuple{typeof(findcontent),Type{Array{Any,1}},String,Node,Type{AbsNormal}})
2728
precompile(Tuple{typeof(findcontent),Type{Array{Float64,1}},String,Node,Type{AbsNormal}})
@@ -31,14 +32,13 @@ function _precompile_()
3132
precompile(Tuple{typeof(findcontent),Type{String},String,Node,Type{AbsAttribute}})
3233
precompile(Tuple{typeof(findcontent),Type{String},String,Node,Type{AbsNormal}})
3334
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})
3835
precompile(Tuple{typeof(newTemplate),String,Symbol})
3936
precompile(Tuple{typeof(newTemplate),String})
37+
precompile(Tuple{typeof(updatecontent!),Array{Any,1},Array{Node,1},Node,Type{T} where T})
4038
precompile(Tuple{typeof(updatecontent!),Array{Any,1},String,Node,Type{AbsNormal}})
39+
precompile(Tuple{typeof(updatecontent!),Array{Float64,1},Array{Node,1},Node,Type{T} where T})
4140
precompile(Tuple{typeof(updatecontent!),Array{Float64,1},String,Node,Type{AbsNormal}})
41+
precompile(Tuple{typeof(updatecontent!),Array{Int64,1},Array{Node,1},Node,Type{T} where T})
4242
precompile(Tuple{typeof(updatecontent!),Array{Int64,1},String,Node,Type{AbsNormal}})
4343
precompile(Tuple{typeof(updatecontent!),Array{String,1},String,Node,Type{AbsNormal}})
4444
precompile(Tuple{typeof(updatecontent!),String,String,Node,Type{AbsAttribute}})

docs/make.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ makedocs(;
1313
),
1414
pages=[
1515
"Home" => "index.md",
16-
17-
"Value Checking" => "valueChecking.md",
1816
"Supported Value Types" => "supportedValueTypes.md",
17+
"Value Checking" => "valueChecking.md",
1918
"Extra Contructors" => "extraConstructors.md",
20-
2119
"Custom Value Types" => "customValueTypes.md",
22-
"Custom Contructors - AcuteML Backend" => "customConstructors.md",
23-
20+
"Custom Contructors" => "customConstructors.md",
21+
"DOM/XPath API" => "domxpath.md",
2422
"Templating" => "templating.md",
2523
"Syntax Reference" => "SyntaxReference.md"
2624
],

docs/src/customConstructors.md

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -110,62 +110,3 @@ mathclass = MathClass(xml)
110110

111111
mathclass.students[2].log # "A genius with a GPA of 5.0 is found"
112112
```
113-
114-
## Making a Type and constructor from scratch using AcuteML Backend
115-
116-
You can use AcuteML utilities to define custom type constructors from scratch or to override `@aml` defined constructors.
117-
118-
Notice that if you don't use `@aml`, you should include `aml::Node` as one of your fields.
119-
120-
Functions to use for custom html/xml constructor:
121-
- [initialize_node](@ref): function to initialize the aml
122-
- [addelm!](@ref) : to add elements (single or a vector of elements)
123-
Use these functions, to make a method that calculates the `aml` inside the function and returns all of the fields.
124-
125-
Functions to use for custom html/xml extractor:
126-
- [findcontent](@ref) : to extract elements
127-
Use these functions, to make a method that gets the `aml::Node` and calculates and returns all of the fields.
128-
129-
Functions to support mutability:
130-
- [updatecontent!](@ref): Finds all the elements with the address of string in the node, and updates the content.
131-
132-
# Example:
133-
In this example we define `Identity` with custom constructors:
134-
```julia
135-
using AcuteML
136-
137-
mutable struct Identity
138-
pitch::UN{Pitch}
139-
rest::UN{Rest}
140-
unpitched::UN{Unpitched}
141-
aml::Node
142-
end
143-
144-
function Identity(;pitch = nothing, rest = nothing, unpitched = nothing)
145-
146-
# This constructor only allows one the fields to exist - similar to choice element in XS
147-
148-
aml = initialize_node(AbsNormal, "identity")
149-
150-
if pitch != nothing
151-
addelm!(aml, "pitch", pitch, AbsNormal)
152-
elseif rest != nothing
153-
addelm!(aml, "rest", rest, AbsNormal)
154-
elseif unpitched != nothing
155-
addelm!(aml, "unpitched", unpitched, AbsNormal)
156-
else
157-
error("one of the pitch, rest or unpitched should be given")
158-
end
159-
160-
return Identity(pitch, rest, unpitched, aml)
161-
end
162-
163-
function Identity(;aml)
164-
165-
pitch = findcontent(Pitch, "pitch", aml, AbsNormal)
166-
rest = findcontent(Rest, "rest", aml, AbsNormal)
167-
unpitched = findcontent(Unpitched, "unpitched", aml, AbsNormal)
168-
169-
return Identity(pitch, rest, unpitched, aml)
170-
end
171-
```

docs/src/domxpath.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# AcuteML DOM/Xpath API
2+
3+
AcuteML provides a DOM/Xpath API that you can use to do lower level XML/HTML manipulation if needed.
4+
5+
You can use AcuteML utilities to define custom type constructors from scratch or to override `@aml` defined constructors.
6+
7+
Notice that if you don't use `@aml`, you should include `aml::Node` as one of your fields.
8+
9+
Functions to use for custom html/xml constructor:
10+
- [createnode](@ref): function to create a node/document
11+
- [addnode!](@ref) : To add nodes (single or a vector of nodes) as a child of given a node/document.
12+
Use these functions, to make a method that calculates the `aml` inside the function and returns all of the fields.
13+
14+
Functions to use for custom html/xml extractor:
15+
- [findfirst](@ref): to find the first node based on the given node name
16+
- [findall](@ref): to find all of the nodes based on the given node name
17+
- [findcontent](@ref) : to get the content of a node based on the given name
18+
Use these functions, to make a method that gets the `aml::Node` and calculates and returns all of the fields.
19+
20+
Functions to support mutability:
21+
- [updatecontent!](@ref): Finds all the elements with the address of string in the node, and updates the content.
22+
23+
## Making a Type and constructor from scratch using AcuteML Backend
24+
25+
# Example:
26+
In this example we define `Identity` with custom constructors:
27+
```julia
28+
using AcuteML
29+
30+
mutable struct Identity
31+
pitch::UN{Pitch}
32+
rest::UN{Rest}
33+
unpitched::UN{Unpitched}
34+
aml::Node
35+
end
36+
37+
function Identity(;pitch = nothing, rest = nothing, unpitched = nothing)
38+
39+
# This constructor only allows one the fields to exist - similar to choice element in XS
40+
41+
aml = createnode(AbsNormal, "identity")
42+
43+
if pitch != nothing
44+
addnode!(aml, "pitch", pitch, AbsNormal)
45+
elseif rest != nothing
46+
addnode!(aml, "rest", rest, AbsNormal)
47+
elseif unpitched != nothing
48+
addnode!(aml, "unpitched", unpitched, AbsNormal)
49+
else
50+
error("one of the pitch, rest or unpitched should be given")
51+
end
52+
53+
return Identity(pitch, rest, unpitched, aml)
54+
end
55+
56+
function Identity(;aml)
57+
58+
pitch = findcontent(Pitch, "pitch", aml, AbsNormal)
59+
rest = findcontent(Rest, "rest", aml, AbsNormal)
60+
unpitched = findcontent(Unpitched, "unpitched", aml, AbsNormal)
61+
62+
return Identity(pitch, rest, unpitched, aml)
63+
end
64+
```

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/@aml/@aml_parse.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function aml_parse(expr::Expr)
1818
argsexpr = expr.args[3] # arguments of the type
1919

2020
# TODO: optimize and fuse these
21-
areargs_inds = findall(x->!(isa(x, LineNumberNode)), argsexpr.args)
21+
areargs_inds = Base.findall(x->!(isa(x, LineNumberNode)), argsexpr.args)
2222
macronum = count(x-> isa(x, Tuple{Symbol, Expr}), argsexpr.args)
2323

2424
data = argsexpr.args[areargs_inds]

src/xmlutils.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ import EzXML: Document, Node
1717
################################################################
1818
import Tables
1919
# DataTypesSupport
20-
include("xmlutils/aml_type_support.jl")
20+
include("xmlutils/TypesSupport/amlTables.jl")
2121
################################################################
2222
include("xmlutils/initializer.jl")
23-
include("xmlutils/creators.jl")
24-
include("xmlutils/extractor_utils.jl")
25-
include("xmlutils/extractors.jl")
26-
include("xmlutils/updaters.jl")
23+
include("xmlutils/addnode.jl")
24+
include("xmlutils/nodeparse.jl")
25+
include("xmlutils/findnode.jl")
26+
include("xmlutils/findcontent.jl")
27+
include("xmlutils/updater.jl")
2728
################################################################
29+
30+
@deprecate addelm!(args...) addnode!(args...)
31+
@deprecate initialize_node(args...) createnode(args...)

src/xmlutils/TypesSupport/amlTables.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function amlTable(x)
66
pretty_table(io, x, backend = :html, standalone = false)
77
str = String(resize!(io.data, io.size))
88

9-
html = findfirst("html/body/table",parsehtml(str))
9+
html = Base.findfirst("html/body/table",parsehtml(str))
1010
unlink!(html)
1111
return html
1212
end

0 commit comments

Comments
 (0)