Skip to content

Commit 254230a

Browse files
authored
Merge pull request #131 from aviatesk/updates
fix some doc syntax and add some references
2 parents a31fa90 + 5342fd2 commit 254230a

File tree

5 files changed

+74
-54
lines changed

5 files changed

+74
-54
lines changed

docs/Manifest.toml

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
[[Base64]]
44
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
55

6-
[[DataStructures]]
7-
deps = ["InteractiveUtils", "OrderedCollections"]
8-
git-tree-sha1 = "1fe8fad5fc84686dcbc674aa255bc867a64f8132"
9-
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
10-
version = "0.17.5"
11-
126
[[Dates]]
137
deps = ["Printf"]
148
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
@@ -24,10 +18,10 @@ uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
2418
version = "0.8.1"
2519

2620
[[Documenter]]
27-
deps = ["Base64", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "Pkg", "REPL", "Random", "Test", "Unicode"]
28-
git-tree-sha1 = "04d40966cddd2ea5d227e7130484b57ac4718596"
21+
deps = ["Base64", "Dates", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"]
22+
git-tree-sha1 = "646ebc3db49889ffeb4c36f89e5d82c6a26295ff"
2923
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
30-
version = "0.22.1"
24+
version = "0.24.7"
3125

3226
[[InteractiveUtils]]
3327
deps = ["Markdown"]
@@ -40,6 +34,7 @@ uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
4034
version = "0.21.0"
4135

4236
[[LibGit2]]
37+
deps = ["Printf"]
4338
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
4439

4540
[[Libdl]]
@@ -49,10 +44,10 @@ uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
4944
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
5045

5146
[[MacroTools]]
52-
deps = ["DataStructures", "Markdown", "Random", "Test"]
47+
deps = ["Markdown", "Random"]
5348
path = ".."
5449
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
55-
version = "0.5.2"
50+
version = "0.5.5"
5651

5752
[[Markdown]]
5853
deps = ["Base64"]
@@ -61,17 +56,11 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
6156
[[Mmap]]
6257
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
6358

64-
[[OrderedCollections]]
65-
deps = ["Random", "Serialization", "Test"]
66-
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1"
67-
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
68-
version = "1.1.0"
69-
7059
[[Parsers]]
7160
deps = ["Dates", "Test"]
72-
git-tree-sha1 = "a23968e107c0544aca91bfab6f7dd34de1206a54"
61+
git-tree-sha1 = "0c16b3179190d3046c073440d94172cfc3bb0553"
7362
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
74-
version = "0.3.9"
63+
version = "0.3.12"
7564

7665
[[Pkg]]
7766
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ makedocs(
99
format = Documenter.HTML(prettyurls = haskey(ENV, "CI")))
1010

1111
deploydocs(
12-
repo = "github.com/MikeInnes/MacroTools.jl.git",)
12+
repo = "github.com/MikeInnes/MacroTools.jl.git",
13+
push_preview = true)

docs/src/utilities.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ such as `x::Int=2` and returns `(arg_name, arg_type, slurp, default)`. `default`
5656
`nothing` when there is none. For example:
5757

5858
```julia
59-
> map(splitarg, (:(f(y, a=2, x::Int=nothing, args...))).args[2:end])
59+
julia> map(splitarg, (:(f(y, a=2, x::Int=nothing, args...))).args[2:end])
6060
4-element Array{Tuple{Symbol,Symbol,Bool,Any},1}:
6161
(:y, :Any, false, nothing)
6262
(:a, :Any, false, 2)
@@ -67,6 +67,7 @@ such as `x::Int=2` and returns `(arg_name, arg_type, slurp, default)`. `default`
6767
## Other Utilities
6868

6969
```@docs
70+
MacroTools.@q
7071
MacroTools.isexpr
7172
MacroTools.rmlines
7273
MacroTools.unblock

src/examples/threading.jl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
"""
22
The threading macro is like a more flexible version of the `|>` operator.
33
4-
@> x f = f(x)
5-
@> x g f == f(g(x))
6-
@> x a b c d e == e(d(c(b(a(x)))))
4+
```julia
5+
@> x f = f(x)
6+
@> x g f == f(g(x))
7+
@> x a b c d e == e(d(c(b(a(x)))))
8+
```
79
8-
Unlike |>, functions can have arguments - the value
10+
Unlike `|>`, functions can have arguments - the value
911
preceding a function will be treated as its first argument
1012
11-
@> x g(y, z) f == f(g(x, y, z))
13+
```julia
14+
@> x g(y, z) f == f(g(x, y, z))
1215
13-
@> x g f(y, z) == f(g(x), y, z)
16+
@> x g f(y, z) == f(g(x), y, z)
17+
```
1418
15-
See also `@>>`, `@as`.
19+
See also [`@>>`](@ref), [`@as`](@ref).
1620
"""
1721
macro >(exs...)
1822
thread(x) = isexpr(x, :block) ? thread(rmlines(x).args...) : x
@@ -28,11 +32,13 @@ macro >(exs...)
2832
end
2933

3034
"""
31-
Same as `@>`, but threads the last argument.
35+
Same as [`@>`](@ref), but threads the last argument.
3236
33-
@>> x g(y, z) f == f(g(y, z, x))
37+
```julia
38+
@>> x g(y, z) f == f(g(y, z, x))
3439
35-
@>> x g f(y, z) == f(y, z, g(x))
40+
@>> x g f(y, z) == f(y, z, g(x))
41+
```
3642
"""
3743
macro >>(exs...)
3844
thread(x) = isexpr(x, :block) ? thread(rmlines(x).args...) : x

src/utils.jl

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ assoc!(d, k, v) = (d[k] = v; d)
1111
"""
1212
@esc x y
1313
14-
is the same as
15-
16-
x = esc(x)
17-
y = esc(y)
14+
is the same as:
15+
```julia
16+
x = esc(x)
17+
y = esc(y)
18+
```
1819
"""
1920
macro esc(xs...)
2021
:($([:($x = esc($x)) for x in map(esc, xs)]...);)
@@ -26,6 +27,8 @@ end
2627
Like the `quote` keyword but doesn't insert line numbers from the construction
2728
site. e.g. compare `@q begin end` with `quote end`. Line numbers of interpolated
2829
expressions are preserverd.
30+
31+
See also: [`rmlines`](@ref)
2932
"""
3033
macro q(ex)
3134
Expr(:quote, striplines(ex))
@@ -65,6 +68,8 @@ To work with nested blocks:
6568
```julia
6669
prewalk(rmlines, ex)
6770
```
71+
72+
See also: [`@q`](@ref)
6873
"""
6974
rmlines(x) = x
7075
function rmlines(x::Expr)
@@ -108,8 +113,9 @@ walk(x::Expr, inner, outer) = outer(Expr(x.head, map(inner, x.args)...))
108113
postwalk(f, expr)
109114
110115
Applies `f` to each node in the given expression tree, returning the result.
111-
`f` sees expressions *after* they have been transformed by the walk. See also
112-
`prewalk`.
116+
`f` sees expressions *after* they have been transformed by the walk.
117+
118+
See also: [`prewalk`](@ref).
113119
"""
114120
postwalk(f, x) = walk(x, x -> postwalk(f, x), f)
115121

@@ -121,7 +127,7 @@ Applies `f` to each node in the given expression tree, returning the result.
121127
walk will be applied to whatever `f` returns.
122128
123129
This makes `prewalk` somewhat prone to infinite loops; you probably want to try
124-
`postwalk` first.
130+
[`postwalk`](@ref) first.
125131
"""
126132
prewalk(f, x) = walk(f(x), x -> prewalk(f, x), identity)
127133

@@ -133,7 +139,9 @@ replace(ex, s, s′) = prewalk(x -> x == s ? s′ : x, ex)
133139
Simple expression match; will return `true` if the expression `x` can be found
134140
inside `expr`.
135141
136-
inexpr(:(2+2), 2) == true
142+
```julia
143+
inexpr(:(2+2), 2) == true
144+
```
137145
"""
138146
function inexpr(ex, x)
139147
result = false
@@ -162,11 +170,13 @@ end
162170
163171
Replaces gensyms with unique ids (deterministically).
164172
165-
julia> x, y = gensym("x"), gensym("y")
166-
(Symbol("##x#363"), Symbol("##y#364"))
173+
```julia
174+
julia> x, y = gensym("x"), gensym("y")
175+
(Symbol("##x#363"), Symbol("##y#364"))
167176
168-
julia> MacroTools.gensym_ids(:(\$x+\$y))
169-
:(x_1 + y_2)
177+
julia> MacroTools.gensym_ids(:(\$x+\$y))
178+
:(x_1 + y_2)
179+
```
170180
"""
171181
function gensym_ids(ex)
172182
counter = 0
@@ -184,11 +194,13 @@ end
184194
Replaces gensyms with animal names.
185195
This makes gensym'd code far easier to follow.
186196
187-
julia> x, y = gensym("x"), gensym("y")
188-
(Symbol("##x#363"), Symbol("##y#364"))
197+
```julia
198+
julia> x, y = gensym("x"), gensym("y")
199+
(Symbol("##x#363"), Symbol("##y#364"))
189200
190-
julia> MacroTools.alias_gensyms(:(\$x+\$y))
191-
:(porcupine + gull)
201+
julia> MacroTools.alias_gensyms(:(\$x+\$y))
202+
:(porcupine + gull)
203+
```
192204
"""
193205
function alias_gensyms(ex)
194206
left = copy(animals)
@@ -201,7 +213,9 @@ end
201213
"""
202214
More convenient macro expansion, e.g.
203215
204-
@expand @time foo()
216+
```julia
217+
@expand @time foo()
218+
```
205219
"""
206220
@static if VERSION <= v"0.7.0-DEV.484"
207221
macro expand(ex)
@@ -248,7 +262,10 @@ function shortdef1(ex)
248262
end
249263
shortdef(ex) = prewalk(shortdef1, ex)
250264

251-
""" `gatherwheres(:(f(x::T, y::U) where T where U)) => (:(f(x::T, y::U)), (:U, :T))`
265+
"""
266+
```julia
267+
gatherwheres(:(f(x::T, y::U) where T where U)) == (:(f(x::T, y::U)), (:U, :T))
268+
```
252269
"""
253270
function gatherwheres(ex)
254271
if @capture(ex, (f_ where {params1__}))
@@ -272,14 +289,16 @@ end
272289
and return `Dict(:name=>..., :args=>..., etc.)`. The definition can be rebuilt by
273290
calling `MacroTools.combinedef(dict)`, or explicitly with
274291
275-
```
292+
```julia
276293
rtype = get(dict, :rtype, :Any)
277294
all_params = [get(dict, :params, [])..., get(dict, :whereparams, [])...]
278295
:(function \$(dict[:name]){\$(all_params...)}(\$(dict[:args]...);
279296
\$(dict[:kwargs]...))::\$rtype
280297
\$(dict[:body])
281298
end)
282299
```
300+
301+
See also: [`combinedef`](@ref)
283302
"""
284303
function splitdef(fdef)
285304
error_msg = "Not a function definition: $(repr(fdef))"
@@ -321,8 +340,9 @@ end
321340
"""
322341
combinedef(dict::Dict)
323342
324-
`combinedef` is the inverse of `splitdef`. It takes a splitdef-like Dict
325-
and returns a function definition. """
343+
`combinedef` is the inverse of [`splitdef`](@ref). It takes a `splitdef`-like Dict
344+
and returns a function definition.
345+
"""
326346
function combinedef(dict::Dict)
327347
rtype = get(dict, :rtype, nothing)
328348
params = get(dict, :params, [])
@@ -383,7 +403,8 @@ end
383403
"""
384404
combinearg(arg_name, arg_type, is_splat, default)
385405
386-
`combinearg` is the inverse of `splitarg`. """
406+
`combinearg` is the inverse of [`splitarg`](@ref).
407+
"""
387408
function combinearg(arg_name, arg_type, is_splat, default)
388409
a = arg_name===nothing ? :(::$arg_type) : :($arg_name::$arg_type)
389410
a2 = is_splat ? Expr(:..., a) : a
@@ -405,13 +426,15 @@ Match function arguments (whether from a definition or a function call) such as
405426
`default` are `nothing` when they are absent. For example:
406427
407428
```julia
408-
> map(splitarg, (:(f(a=2, x::Int=nothing, y, args...))).args[2:end])
429+
julia> map(splitarg, (:(f(a=2, x::Int=nothing, y, args...))).args[2:end])
409430
4-element Array{Tuple{Symbol,Symbol,Bool,Any},1}:
410431
(:a, :Any, false, 2)
411432
(:x, :Int, false, :nothing)
412433
(:y, :Any, false, nothing)
413434
(:args, :Any, true, nothing)
414435
```
436+
437+
See also: [`combinearg`](@ref)
415438
"""
416439
function splitarg(arg_expr)
417440
splitvar(arg) =

0 commit comments

Comments
 (0)