forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.jl
33 lines (25 loc) · 1.08 KB
/
core.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# This file is a part of Julia. License is MIT: https://julialang.org/license
module CoreDocs
import ..esc, ..push!, ..getindex, ..unsafe_load, ..Csize_t, ..@nospecialize
@nospecialize # don't specialize on any arguments of the methods declared herein
function doc!(source::LineNumberNode, mod::Module, str, ex)
push!(DOCS, Core.svec(mod, ex, str, source.file, source.line))
nothing
end
const DOCS = Array{Core.SimpleVector,1}()
isexpr(x, h::Symbol) = isa(x, Expr) && x.head === h
lazy_iterpolate(s::AbstractString) = Expr(:call, Core.svec, s)
lazy_iterpolate(x) = isexpr(x, :string) ? Expr(:call, Core.svec, x.args...) : x
function docm(source::LineNumberNode, mod::Module, str, x)
out = Expr(:call, doc!, QuoteNode(source), mod, lazy_iterpolate(str), QuoteNode(x))
if isexpr(x, :module)
out = Expr(:toplevel, out, x)
elseif isexpr(x, :call)
else
out = Expr(:block, x, out)
end
return esc(out)
end
docm(source::LineNumberNode, mod::Module, x) =
isexpr(x, :->) ? docm(source, mod, x.args[1], x.args[2].args[2]) : error("invalid '@doc'.")
end