Skip to content

Commit 969c960

Browse files
committed
doc about the field name conflict
1 parent 3d71cc2 commit 969c960

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

src/AcuteML.jl

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ export Node, Document
2424
@aml
2525
2626
# Type Definition
27-
Use `@aml` macro to define a Julia type, and then the package automatically creates a xml or html associated with the defined type.
27+
Use `@aml` macro to define a Julia type, and then the package automatically creates a xml or html associated with the defined type. The general syntax would look like this:
28+
```julia
29+
@aml mutable struct mybody "body"
30+
myh1, "h1"
31+
p::Vector{String}, "~"
32+
end
33+
```
34+
Now, we go into the details:
2835
2936
### Document Definition
3037
* Use doc literal before the root name to define a HTML or XML document. For HTML documents root should always be "html".
@@ -40,7 +47,7 @@ end
4047
```
4148
4249
### Nodes (Elements) Definition
43-
* Specify the html/xml struct name as a string after the struct name after a space
50+
* Specify the html/xml name of struct as a string after the struct name (after a space)
4451
```julia
4552
@aml mutable struct Person "person"
4653
# add fields (elements) here
@@ -63,6 +70,29 @@ field, "study-field"
6370
age::UInt, "~"
6471
```
6572
73+
!!! warning
74+
The field names of a struct should not be the same as other defined types. This error happens when you use the same name of a type for a field name. For example, the follwing is an **error**:
75+
```julia
76+
@aml struct person "~"
77+
name, "~"
78+
end
79+
@aml struct myxml doc"~"
80+
person::person, "~"
81+
end
82+
```
83+
Another example of this error:
84+
```julia
85+
@aml struct myxml doc"~"
86+
Int, "myint"
87+
end
88+
```
89+
However, you can choose any xml/html name. The xml/html name of the fields isn't related to the types defined in Julia. So the following is a **valid** syntax:
90+
```julia
91+
@aml struct myxml doc"~"
92+
myint, "Int"
93+
end
94+
```
95+
6696
### Attributes
6797
* If the value is going to be an attribute put `att` before its name
6898
```julia
@@ -381,7 +411,8 @@ macro aml(expr)
381411
# check if the field name is a defined type
382412
for arg_var in args_var
383413
if isdefined(__module__, arg_var) && isa(getfield(__module__, arg_var), Type)
384-
@error "Change the field name $arg_var in struct $T to something else. The name conflicts with an already defined type name."
414+
f, l = __source__.file, __source__.line
415+
@error "Change the field name `$arg_var` in struct `$T` to something else. The name conflicts with an already defined type name. \n Happens at $f:$l"
385416
end
386417
end
387418

0 commit comments

Comments
 (0)