@@ -22,15 +22,13 @@ function _model_macro(mod, name, expr, isconnector)
22
22
ext = Ref {Any} (nothing )
23
23
eqs = Expr[]
24
24
icon = Ref {Union{String, URI}} ()
25
- vs = []
26
- ps = []
27
- kwargs = []
25
+ kwargs, ps, sps, vs, = [], [], [], []
28
26
29
27
for arg in expr. args
30
28
arg isa LineNumberNode && continue
31
29
if arg. head == :macrocall
32
30
parse_model! (exprs. args, comps, ext, eqs, icon, vs, ps,
33
- dict, mod, arg, kwargs)
31
+ sps, dict, mod, arg, kwargs)
34
32
elseif arg. head == :block
35
33
push! (exprs. args, arg)
36
34
elseif isconnector
@@ -213,8 +211,8 @@ function get_var(mod::Module, b)
213
211
end
214
212
end
215
213
216
- function parse_model! (exprs, comps, ext, eqs, icon, vs, ps, dict ,
217
- mod, arg, kwargs)
214
+ function parse_model! (exprs, comps, ext, eqs, icon, vs, ps, sps ,
215
+ dict, mod, arg, kwargs)
218
216
mname = arg. args[1 ]
219
217
body = arg. args[end ]
220
218
if mname == Symbol (" @components" )
@@ -225,6 +223,8 @@ function parse_model!(exprs, comps, ext, eqs, icon, vs, ps, dict,
225
223
parse_variables! (exprs, vs, dict, mod, body, :variables , kwargs)
226
224
elseif mname == Symbol (" @parameters" )
227
225
parse_variables! (exprs, ps, dict, mod, body, :parameters , kwargs)
226
+ elseif mname == Symbol (" @structural_parameters" )
227
+ parse_structural_parameters! (exprs, sps, dict, mod, body, kwargs)
228
228
elseif mname == Symbol (" @equations" )
229
229
parse_equations! (exprs, eqs, dict, body)
230
230
elseif mname == Symbol (" @icon" )
@@ -234,6 +234,24 @@ function parse_model!(exprs, comps, ext, eqs, icon, vs, ps, dict,
234
234
end
235
235
end
236
236
237
+ function parse_structural_parameters! (exprs, sps, dict, mod, body, kwargs)
238
+ Base. remove_linenums! (body)
239
+ for arg in body. args
240
+ MLStyle. @match arg begin
241
+ Expr (:(= ), a, b) => begin
242
+ push! (sps, a)
243
+ push! (kwargs, Expr (:kw , a, b))
244
+ dict[:kwargs ][a] = b
245
+ end
246
+ a => begin
247
+ push! (sps, a)
248
+ push! (kwargs, a)
249
+ dict[:kwargs ][a] = nothing
250
+ end
251
+ end
252
+ end
253
+ end
254
+
237
255
function parse_components! (exprs, cs, dict, body, kwargs)
238
256
expr = Expr (:block )
239
257
varexpr = Expr (:block )
0 commit comments