Skip to content

Commit 0c57f27

Browse files
committed
Add doc_str and doc macros, to support Base.Docs/Docile syntax.
Add tests for doc-syntax.
1 parent e324d63 commit 0c57f27

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Currently, the `@compat` macro supports the following syntaxes:
116116

117117
* `@inline` and `@noinline` have been added. On 0.3, these are "no-ops," meaning they don't actually do anything.
118118

119+
* `@doc`, `@doc_str` and `@doc_mstr` have been added. On 0.3 if Docile is available it will use its definitions, else these are no-ops.
120+
119121
## Other changes
120122

121123
* `Dict(ks, vs)` is now `Dict(zip(ks, vs))` [#8521](https://github.com/JuliaLang/julia/pull/8521)

src/Compat.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ if VERSION < v"0.4.0-dev+412"
4545
eval(Base, :(const IPAddr = IpAddr))
4646
end
4747

48+
if VERSION < v"0.4.0-dev+1501"
49+
try
50+
import Docile: @doc_str, @doc_mstr, @doc
51+
catch
52+
macro doc_str(x) x end
53+
macro doc_mstr(x) x end
54+
macro doc(ex) esc(ex.args[end]) end
55+
end
56+
export @doc_str, @doc_mstr, @doc
57+
end
58+
4859
if VERSION < v"0.4.0-dev+2197"
4960
Base.IPv4(ipstr::AbstractString) = Base.parseipv4(ipstr)
5061
Base.IPv6(ipstr::AbstractString) = Base.parseipv6(ipstr)

test/runtests.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ ns = length(d.slots)
6363
@test @compat rsplit("a,b,,c", ',', keep=false) == ["a", "b", "c"]
6464
@test @compat rsplit("a,b,,c", ',', keep=true) == ["a", "b", "", "c"]
6565

66+
# We test that the following doc-syntax does not raise in 0.3.
67+
# and that the methods are still defined.
68+
doc"foo $latex$"
69+
function foo_doc() end
70+
71+
doc"""multi-line"""
72+
function foo_mdoc() end
73+
74+
@doc "docstring" ->
75+
function foo_macrodoc() end
76+
77+
@test foo_doc() == nothing
78+
@test foo_mdoc() == nothing
79+
@test foo_macrodoc() == nothing
80+
6681
if VERSION < v"0.4.0-dev+1387"
6782
@test isdefined(Main, :AbstractString)
6883
end

0 commit comments

Comments
 (0)