Skip to content

Commit 9df921d

Browse files
committed
Change export -> reexport to fix parsing issue, update version
1 parent 12f6c4e commit 9df921d

File tree

2 files changed

+36
-40
lines changed

2 files changed

+36
-40
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ keywords = ["Packages", "API", "Modules"]
44
license = "MIT"
55
desc = "Macro to help manage module and package APIs"
66
authors = ["ScottPJones <scottjones@alum.mit.edu>"]
7-
version = "0.2.0"
7+
version = "0.2.1"
88

99
[deps]
1010

src/ModuleInterfaceTools.jl

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ __precompile__(true)
22
"""
33
API Tools package
44
5-
Copyright 2018 Gandalf Software, Inc., Scott P. Jones
5+
Copyright 2018-2019 Gandalf Software, Inc., Scott P. Jones
66
77
Licensed under MIT License, see LICENSE.md
88
@@ -16,8 +16,8 @@ const showeval = Ref(false)
1616
const V6_COMPAT = VERSION < v"0.7-"
1717
const BIG_ENDIAN = (ENDIAN_BOM == 0x01020304)
1818

19-
_stdout() = @static V6_COMPAT ? STDOUT : stdout
20-
_stderr() = @static V6_COMPAT ? STDERR : stderr
19+
_stdout() = stdout
20+
_stderr() = stderr
2121

2222
Base.parse(::Type{Expr}, args...; kwargs...) =
2323
Meta.parse(args...; kwargs...)
@@ -91,34 +91,34 @@ end
9191
"""
9292
@api <cmd> [<symbols>...]
9393
94-
* freeze # use at end of module to freeze API
94+
* freeze # use at end of module to freeze API
9595
96-
* list <modules>... # list API(s) of given modules (or current if none given)
96+
* list <modules>... # list API(s) of given modules (or current if none given)
9797
98-
* use <modules>... # use, without importing (i.e. can't extend)
99-
* use! <modules>... # use, without importing (i.e. can't extend), "export"
100-
* test <modules>... # using public and develop APIs, for testing purposes
101-
* extend <modules>... # for development, imports api & dev, use api & dev definitions
102-
* extend! <modules>... # for development, imports api & dev, use api & dev definitions, "export"
103-
* export <modules>... # export public definitions
98+
* use <modules>... # use, without importing (i.e. can't extend)
99+
* use! <modules>... # use, without importing (i.e. can't extend), "export"
100+
* test <modules>... # using public and develop APIs, for testing purposes
101+
* extend <modules>... # for development, imports api & dev, use api & dev definitions
102+
* extend! <modules>... # for development, imports api & dev, use api & dev definitions, "export"
103+
* reexport <modules>... # export public definitions from those modules
104104
105-
* base <names...> # Add functions from Base that are part of the API (extendible)
106-
* base! <names...> # Add functions from Base or define them if not in Base
107-
* public <names...> # Add other symbols that are part of the public API (structs, consts)
108-
* public! <names...> # Add functions that are part of the public API (extendible)
109-
* develop <names...> # Add other symbols that are part of the development API
110-
* develop! <names...> # Add functions that are part of the development API (extendible)
111-
* define! <names...> # Define functions to be extended, public API
112-
* defdev! <names...> # Define functions to be extended, develop API
113-
* modules <names...> # Add submodule names that are part of the API
105+
* base <names...> # Add functions from Base that are part of the API (extendible)
106+
* base! <names...> # Add functions from Base or define them if not in Base
107+
* public <names...> # Add other symbols that are part of the public API (structs, consts)
108+
* public! <names...> # Add functions that are part of the public API (extendible)
109+
* develop <names...> # Add other symbols that are part of the development API
110+
* develop! <names...> # Add functions that are part of the development API (extendible)
111+
* define! <names...> # Define functions to be extended, public API
112+
* defdev! <names...> # Define functions to be extended, develop API
113+
* modules <names...> # Add submodule names that are part of the API
114114
115115
* path <paths...> # Add paths to LOAD_PATH
116116
117117
* def <name> <expr> # Same as the @def macro, creates a macro with the given name
118118
119119
"""
120120
macro api(cmd::Symbol)
121-
mod = @static V6_COMPAT ? current_module() : __module__
121+
mod = __module__
122122
cmd == :list ? _api_list(mod) :
123123
cmd == :freeze ? _api_freeze(mod) :
124124
cmd == :test ? _api_test(mod) :
@@ -163,12 +163,11 @@ function _api_path(curmod, exprs)
163163
nothing
164164
end
165165

166-
const _cmduse = (:use, :use!, :test, :extend, :extend!, :export, :list)
166+
const _cmduse = (:use, :use!, :test, :extend, :extend!, :reexport, :list)
167167
const _cmdadd =
168168
(:modules, :public, :develop, :public!, :develop!, :base, :base!, :define!, :defdev!)
169169

170-
@static V6_COMPAT ? (const _ff = findfirst) :
171-
(_ff(lst, val) = (ret = findfirst(isequal(val), lst); ret === nothing ? 0 : ret))
170+
_ff(lst, val) = (ret = findfirst(isequal(val), lst); ret === nothing ? 0 : ret)
172171

173172
function _add_def!(curmod, grp, exp)
174173
debug[] && print("_add_def!($curmod, $grp, $exp::$(typeof(exp))")
@@ -287,14 +286,16 @@ function _api_use(curmod, modules, cpy::Bool)
287286
nothing
288287
end
289288

290-
function _api_export(curmod, modules)
289+
function _api_reexport(curmod, modules)
291290
for nam in modules
292291
mod = m_eval(curmod, nam)
293292
if has_api(mod)
294293
api = get_api(curmod, mod)
295-
m_eval(curmod, Expr( :export, getfield(api, :modules)...))
296-
m_eval(curmod, Expr( :export, getfield(api, :public)...))
297-
m_eval(curmod, Expr( :export, getfield(api, :public!)...))
294+
l1, l2, l3 = getfield(api, :modules), getfield(api, :public), getfield(api, :public!)
295+
if !(isempty(l1) && isempty(l2) && isempty(l3))
296+
println("Reexport: api = $api:$l1,$l2,$l3")
297+
m_eval(curmod, Expr( :export, l1..., l2..., l3... ))
298+
end
298299
end
299300
end
300301
nothing
@@ -307,7 +308,7 @@ function _api_list(curmod, modules)
307308
nothing
308309
end
309310

310-
_api_test(mod) = m_eval(mod, V6_COMPAT ? :(using Base.Test) : :(using Test))
311+
_api_test(mod) = m_eval(mod, :(using Test))
311312

312313
function _api(curmod::Module, cmd::Symbol, exprs)
313314
cmd == :def && return _api_def(exprs...)
@@ -346,7 +347,7 @@ function _api(curmod::Module, cmd::Symbol, exprs)
346347
end
347348
debug[] && println(" => $modules")
348349

349-
cmd == :export && return _api_export(curmod, modules)
350+
cmd == :reexport && return _api_reexport(curmod, modules)
350351
cmd == :list && return _api_list(curmod, modules)
351352

352353
cpy = (cmd == :use!) || (cmd == :extend!)
@@ -373,13 +374,9 @@ function _api(curmod::Module, cmd::Symbol, exprs)
373374
end
374375

375376
function makecmd(cmd, nam, sym)
376-
@static if V6_COMPAT
377-
Expr(cmd, nam, sym)
378-
else
379-
(cmd == :using
380-
? Expr(cmd, Expr(:(:), Expr(:., nam), Expr(:., sym)))
381-
: Expr(cmd, Expr(:., nam, sym)))
382-
end
377+
(cmd == :using
378+
? Expr(cmd, Expr(:(:), Expr(:., nam), Expr(:., sym)))
379+
: Expr(cmd, Expr(:., nam, sym)))
383380
end
384381

385382
_do_list(curmod, cpy, cmd, mod, nam, grp, api::API) =
@@ -398,8 +395,7 @@ function _do_list(curmod, cpy, cmd, mod, nam, grp, lst)
398395
end
399396

400397
macro api(cmd::Symbol, exprs...)
401-
mod = @static V6_COMPAT ? current_module() : __module__
402-
_api(mod, cmd, exprs)
398+
_api(__module__, cmd, exprs)
403399
end
404400

405401
end # module ModuleInterfaceTools

0 commit comments

Comments
 (0)