@@ -120,7 +120,7 @@ function _api_freeze(mod::Module)
120
120
nothing
121
121
end
122
122
123
- const _cmduse = (:use , :test , :extend , :export )
123
+ const _cmduse = (:use , :test , :extend , :export , :list )
124
124
const _cmdadd =
125
125
(:define_module , :define_public , :define_develop , :public , :develop , :base , :maybe_public )
126
126
@@ -178,29 +178,24 @@ function _add_symbols(curmod, grp, exprs)
178
178
nothing
179
179
end
180
180
181
- function _make_modules (curmod, cmd, exprs)
182
- modlst = SymSet ()
181
+ function _api (curmod:: Module , cmd:: Symbol , exprs)
182
+ ind = _ff (_cmdadd, cmd)
183
+ ind == 0 || return _add_symbols (curmod, cmd, exprs)
184
+
185
+ _ff (_cmduse, cmd) == 0 && error (" Syntax error: @api $cmd $exprs " )
186
+
187
+ modules = SymSet ()
183
188
for ex in exprs
184
189
if isa (ex, Expr) && ex. head == :tuple
185
- push! (modlst , ex. args... )
190
+ push! (modules , ex. args... )
186
191
for sym in ex. args ; eval (curmod, :(import $ sym)) ; end
187
192
elseif isa (ex, Symbol)
188
- push! (modlst , ex)
193
+ push! (modules , ex)
189
194
eval (curmod, :(import $ ex))
190
195
else
191
196
error (" @api $cmd : syntax error $ex " )
192
197
end
193
198
end
194
- modlst
195
- end
196
-
197
- function _api (curmod:: Module , cmd:: Symbol , exprs)
198
- ind = _ff (_cmdadd, cmd)
199
- ind == 0 || return _add_symbols (curmod, cmd, exprs)
200
-
201
- ind = _ff (_cmduse, cmd)
202
-
203
- modules = _make_modules (curmod, cmd, exprs)
204
199
205
200
cmd == :export &&
206
201
return esc (Expr (:toplevel ,
@@ -212,50 +207,66 @@ function _api(curmod::Module, cmd::Symbol, exprs)
212
207
[:(eval (APITools. _api_display ($ mod))) for mod in modules]. .. ,
213
208
nothing )
214
209
215
- lst = Expr[]
216
- for mod in modules
217
- exp = " APITools._make_module_list($(QuoteNode (mod)) , $mod .__api__.define_module)"
218
- push! (lst, :(eval ($ (Meta. parse (exp)))))
210
+ for nam in modules
211
+ mod = eval (curmod, nam)
212
+ api = eval (mod, :__api__ )
213
+ lst = getfield (api, :define_module )
214
+ for sym in lst
215
+ eval (curmod, :(using $ mod.$ sym))
216
+ end
219
217
end
220
218
221
- if cmd == :use
222
- grplst = (:public , :define_public )
223
- elseif cmd == :test
224
- grplst = (:public , :develop , :define_public , :define_develop )
225
- push! (lst, V6_COMPAT ? :(using Base. Test) : :(using Test))
226
- elseif cmd == :extend
227
- grplst = (:define_public , :define_develop )
228
- for mod in modules, grp in (:base , :public , :develop )
229
- push! (lst, _make_exprs (:import , mod, grp))
219
+ if cmd == :extend
220
+ for nam in modules
221
+ mod = eval (curmod, nam)
222
+ if isdefined (mod, :__api__ )
223
+ api = eval (mod, :__api__ )
224
+ _import_list (curmod, api, :Base , :base )
225
+ _import_list (curmod, api, nam, :public )
226
+ _import_list (curmod, api, nam, :develop )
227
+ _using_list (curmod, api, nam, :define_public )
228
+ _using_list (curmod, api, nam, :define_develop )
229
+ else
230
+ println (" API not found for module: $mod " )
231
+ end
230
232
end
231
- else
232
- error (" @api unrecognized command: $cmd " )
233
+ return nothing
233
234
end
234
- for mod in modules, grp in grplst
235
- push! (lst, _make_exprs (:using , mod, grp))
235
+
236
+ # Be nice and set up standard Test
237
+ cmd == :test && eval (curmod, V6_COMPAT ? :(using Base. Test) : :(using Test))
238
+
239
+ for nam in modules
240
+ mod = eval (curmod, nam)
241
+ if isdefined (mod, :__api__ )
242
+ api = eval (mod, :__api__ )
243
+ _using_list (curmod, api, nam, :public )
244
+ _using_list (curmod, api, nam, :define_public )
245
+ if cmd == :test
246
+ _using_list (curmod, api, nam, :public )
247
+ _using_list (curmod, api, nam, :define_public )
248
+ end
249
+ end
236
250
end
237
- esc (Expr (:toplevel , lst... , nothing ))
238
- end
239
251
240
- macro api (cmd:: Symbol , exprs... )
241
- @static V6_COMPAT ? _api (current_module (), cmd, exprs) : _api (__module__, cmd, exprs)
252
+ nothing
242
253
end
243
254
244
- function _make_module_list (mod, lst)
245
- isempty (lst) && return nothing
246
- length (lst) == 1 ? :(import $ mod.$ (lst[1 ])) :
247
- Expr (:toplevel , [:(import $ mod.$ nam) for nam in lst]. .. , nothing )
255
+ function _using_list (curmod, api, mod, grp)
256
+ lst = getfield (api, grp)
257
+ for sym in lst
258
+ eval (curmod, :(using $ mod.$ sym))
259
+ end
248
260
end
249
-
250
- function _make_list (cmd, mod, lst)
251
- isempty (lst) && return nothing
252
- length (lst) > 1 ?
253
- Expr ( :toplevel , [ Expr (cmd, mod, nam) for nam in lst] . .. ) : Expr (cmd, mod, lst[ 1 ])
261
+ function _import_list (curmod, api, mod, grp)
262
+ lst = getfield (api, grp )
263
+ for sym in lst
264
+ eval (curmod, :( import $ mod. $ sym))
265
+ end
254
266
end
255
267
256
- function _make_exprs (cmd, mod, grp)
257
- from = QuoteNode (grp == :base ? :Base : mod)
258
- :(eval ($ (Meta. parse (" APITools._make_list($(QuoteNode (cmd)) , $from , $mod .__api__.$grp )" ))))
268
+ macro api (cmd:: Symbol , exprs... )
269
+ @static V6_COMPAT ? _api (current_module (), cmd, exprs) : _api (__module__, cmd, exprs)
259
270
end
260
271
261
272
end # module APITools
0 commit comments