Skip to content

Commit 32dae29

Browse files
committed
enable julia syntax highlights where possible
1 parent 2be3fd8 commit 32dae29

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

docs/src/utilities.md

Lines changed: 1 addition & 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)

src/examples/threading.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
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
810
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
1519
See also [`@>>`](@ref), [`@as`](@ref).
1620
"""
@@ -30,9 +34,11 @@ end
3034
"""
3135
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: 29 additions & 17 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)]...);)
@@ -138,7 +139,9 @@ replace(ex, s, s′) = prewalk(x -> x == s ? s′ : x, ex)
138139
Simple expression match; will return `true` if the expression `x` can be found
139140
inside `expr`.
140141
141-
inexpr(:(2+2), 2) == true
142+
```julia
143+
inexpr(:(2+2), 2) == true
144+
```
142145
"""
143146
function inexpr(ex, x)
144147
result = false
@@ -167,11 +170,13 @@ end
167170
168171
Replaces gensyms with unique ids (deterministically).
169172
170-
julia> x, y = gensym("x"), gensym("y")
171-
(Symbol("##x#363"), Symbol("##y#364"))
173+
```julia
174+
julia> x, y = gensym("x"), gensym("y")
175+
(Symbol("##x#363"), Symbol("##y#364"))
172176
173-
julia> MacroTools.gensym_ids(:(\$x+\$y))
174-
:(x_1 + y_2)
177+
julia> MacroTools.gensym_ids(:(\$x+\$y))
178+
:(x_1 + y_2)
179+
```
175180
"""
176181
function gensym_ids(ex)
177182
counter = 0
@@ -189,11 +194,13 @@ end
189194
Replaces gensyms with animal names.
190195
This makes gensym'd code far easier to follow.
191196
192-
julia> x, y = gensym("x"), gensym("y")
193-
(Symbol("##x#363"), Symbol("##y#364"))
197+
```julia
198+
julia> x, y = gensym("x"), gensym("y")
199+
(Symbol("##x#363"), Symbol("##y#364"))
194200
195-
julia> MacroTools.alias_gensyms(:(\$x+\$y))
196-
:(porcupine + gull)
201+
julia> MacroTools.alias_gensyms(:(\$x+\$y))
202+
:(porcupine + gull)
203+
```
197204
"""
198205
function alias_gensyms(ex)
199206
left = copy(animals)
@@ -206,7 +213,9 @@ end
206213
"""
207214
More convenient macro expansion, e.g.
208215
209-
@expand @time foo()
216+
```julia
217+
@expand @time foo()
218+
```
210219
"""
211220
@static if VERSION <= v"0.7.0-DEV.484"
212221
macro expand(ex)
@@ -255,7 +264,10 @@ function shortdef1(ex)
255264
end
256265
shortdef(ex) = prewalk(shortdef1, ex)
257266

258-
""" `gatherwheres(:(f(x::T, y::U) where T where U)) => (:(f(x::T, y::U)), (:U, :T))`
267+
"""
268+
```julia
269+
gatherwheres(:(f(x::T, y::U) where T where U)) == (:(f(x::T, y::U)), (:U, :T))
270+
```
259271
"""
260272
function gatherwheres(ex)
261273
if @capture(ex, (f_ where {params1__}))
@@ -279,7 +291,7 @@ end
279291
and return `Dict(:name=>..., :args=>..., etc.)`. The definition can be rebuilt by
280292
calling `MacroTools.combinedef(dict)`, or explicitly with
281293
282-
```
294+
```julia
283295
rtype = get(dict, :rtype, :Any)
284296
all_params = [get(dict, :params, [])..., get(dict, :whereparams, [])...]
285297
:(function \$(dict[:name]){\$(all_params...)}(\$(dict[:args]...);
@@ -378,7 +390,7 @@ Match function arguments (whether from a definition or a function call) such as
378390
`default` are `nothing` when they are absent. For example:
379391
380392
```julia
381-
> map(splitarg, (:(f(a=2, x::Int=nothing, y, args...))).args[2:end])
393+
julia> map(splitarg, (:(f(a=2, x::Int=nothing, y, args...))).args[2:end])
382394
4-element Array{Tuple{Symbol,Symbol,Bool,Any},1}:
383395
(:a, :Any, false, 2)
384396
(:x, :Int, false, :nothing)

0 commit comments

Comments
 (0)