Skip to content

Commit

Permalink
Merge pull request #27 from aminya/mutability
Browse files Browse the repository at this point in the history
Mutability
  • Loading branch information
aminya authored Nov 3, 2019
2 parents 8b732ef + 92e3413 commit 1100d9f
Show file tree
Hide file tree
Showing 7 changed files with 422 additions and 79 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ Use `@aml` macro to define a Julia type, and then the package automatically crea
### Document Defnition
* Use `xd""` or `hd""` to define a XML or HTML document:
```julia
@aml struct Doc xd""
@aml mutable struct Doc xd""
# add fields (elements) here
end
```

### Nodes (Elements) Defnition
* Specify the html/xml struct name as a string after the struct name after a space
```julia
@aml struct Person "person"
@aml mutable struct Person "person"
# add fields (elements) here
end
```
* If the html/xml name is the same as struct name, you can use `"~"` instead
```julia
@aml struct person "~"
@aml mutable struct person "~"
# add fields (elements) here
end
```
Expand Down Expand Up @@ -98,7 +98,7 @@ GPA::Float64, "~", GPAcheck

* To define any restrictions for multiple values of a struct, define a function that gets all the variables and checks a criteria and returns Bool, and put its name after a `,` after the struct name:
```julia
@aml struct Person "person", courseCheck
@aml mutable struct Person "person", courseCheck
# ...
end
```
Expand Down Expand Up @@ -129,22 +129,23 @@ using AcuteML
# Types definition

# Person Type
@aml struct Person "person", courseCheck
age::UInt, "~"
@aml mutable struct Person "person", courseCheck
age::UInt64, "~"
field, "study-field"
GPA::Float64 = 4.5, "~", GPAcheck
courses::Vector{String}, "taken-courses"
id::Int64, a"~"
end

@aml struct University "university"
@aml mutable struct University "university"
name, a"university-name"
people::Vector{Person}, "person"
end

@aml struct Doc xd""
@aml mutable struct Doc xd""
university::University, "~"
end

```

```julia
Expand Down Expand Up @@ -173,6 +174,8 @@ end
P1 = Person(age=24, field="Mechanical Engineering", courses=["Artificial Intelligence", "Robotics"], id = 1)
P2 = Person(age=18, field="Computer Engineering", GPA=4, courses=["Julia"], id = 2)

P2.GPA=4.2 # mutability support

U = University(name="Julia University", people=[P1, P2])

D = Doc(university = U)
Expand Down Expand Up @@ -207,7 +210,7 @@ julia> print(U.aml)
<person id="2">
<age>18</age>
<study-field>Computer Engineering</study-field>
<GPA>4</GPA>
<GPA>4.2</GPA>
<taken-courses>Julia</taken-courses>
</person>
</university>
Expand All @@ -225,12 +228,11 @@ julia> print(D.aml)
<person id="2">
<age>18</age>
<study-field>Computer Engineering</study-field>
<GPA>4</GPA>
<GPA>4.2</GPA>
<taken-courses>Julia</taken-courses>
</person>
</university>
```

-------------------------------------------------------

# Example - Extractor
Expand Down
8 changes: 4 additions & 4 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ Use `@aml` macro to define a Julia type, and then the package automatically crea
### Document Defnition
* Use `xd""` or `hd""` to define a XML or HTML document:
```julia
@aml struct Doc xd""
@aml mutable struct Doc xd""
# add fields (elements) here
end
```

### Nodes (Elements) Defnition
* Specify the html/xml struct name as a string after the struct name after a space
```julia
@aml struct Person "person"
@aml mutable struct Person "person"
# add fields (elements) here
end
```
* If the html/xml name is the same as struct name, you can use `"~"` instead
```julia
@aml struct person "~"
@aml mutable struct person "~"
# add fields (elements) here
end
```
Expand Down Expand Up @@ -95,7 +95,7 @@ GPA::Float64, "~", GPAcheck

* To define any restrictions for multiple values of a struct, define a function that gets all the variables and checks a criteria and returns Bool, and put its name after a `,` after the struct name:
```julia
@aml struct Person "person", courseCheck
@aml mutable struct Person "person", courseCheck
# ...
end
```
Expand Down
32 changes: 20 additions & 12 deletions examples/constructor.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
using AcuteML

# Type Definition
@aml struct Person "person", courseCheck
age::UInt, "~"

@aml mutable struct Person "person", courseCheck
age::UInt64, "~"
field, "study-field"
GPA::Float64 = 4.5, "~", GPAcheck
courses::Vector{String}, "taken-courses"
id::Int64, a"~"
end

@aml struct University "university"
@aml mutable struct University "university"
name, a"university-name"
people::Vector{Person}, "person"
end

@aml struct Doc xd""
@aml mutable struct Doc xd""
university::University, "~"
end

Expand All @@ -38,18 +39,25 @@ end
# Constructor

P1 = Person(age=24, field="Mechanical Engineering", courses=["Artificial Intelligence", "Robotics"], id = 1)
P2 = Person(age=18, field="Computer Engineering", GPA=4, courses=["Julia"], id = 2)

U = University(name="Julia University", people=[P1, P2])
P2 = Person(age=18, field="Computer Engineering", GPA=4, courses=["Julia"], id = 2)

D = Doc(university = U)
P2.GPA=4.2 # mutability support

# An example that doesn't meet the critertia function for GPA because GPA is more than 4.5
# Two examples that doesn't meet the critertia function for GPA because GPA is more than 4.5
#=
P3 = Person(age=99, field="Macro Wizard", GPA=10, courses=["Julia Magic"], id = 3)
#GPA doesn't meet criteria function
# GPA doesn't meet criteria function
P1.GPA=5.0
# GPA doesn't meet criteria function
=#

U = University(name="Julia University", people=[P1, P2])

D = Doc(university = U)


print(P1.aml)
#=
<person id="1">
Expand All @@ -66,7 +74,7 @@ print(P2.aml)
<person id="2">
<age>18</age>
<study-field>Computer Engineering</study-field>
<GPA>4</GPA>
<GPA>4.2</GPA>
<taken-courses>Julia</taken-courses>
</person>
=#
Expand All @@ -84,7 +92,7 @@ print(U.aml)
<person id="2">
<age>18</age>
<study-field>Computer Engineering</study-field>
<GPA>4</GPA>
<GPA>4.2</GPA>
<taken-courses>Julia</taken-courses>
</person>
</university>
Expand All @@ -104,7 +112,7 @@ print(D.aml)
<person id="2">
<age>18</age>
<study-field>Computer Engineering</study-field>
<GPA>4</GPA>
<GPA>4.2</GPA>
<taken-courses>Julia</taken-courses>
</person>
</university>
Expand Down
9 changes: 5 additions & 4 deletions examples/extractor.jl
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
using AcuteML

# Type Definition
@aml struct Person "person", courseCheck
age::UInt, "~"
@aml mutable struct Person "person", courseCheck
age::UInt64, "~"
field, "study-field"
GPA::Float64 = 4.5, "~", GPAcheck
courses::Vector{String}, "taken-courses"
id::Int64, a"~"
end

@aml struct University "university"
@aml mutable struct University "university"
name, a"university-name"
people::Vector{Person}, "person"
end

@aml struct Doc xd""
@aml mutable struct Doc xd""
university::University, "~"
end


# Value Checking Functions
GPAcheck(x) = x <= 4.5 && x >= 0

Expand Down
Loading

2 comments on commit 1100d9f

@aminya
Copy link
Owner Author

@aminya aminya commented on 1100d9f Nov 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/4859

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" 1100d9fe210c3d7abe6639708c395164a816a859
git push origin v0.1.0

Please sign in to comment.