Skip to content

Commit 9013d7f

Browse files
author
Anant Thazhemadam
committed
feat: support components with fully-qualified names with @mtkmodel
With the `@named` macro, we could use fully-qualified names for components. However, trying to do the same with `@mtkmodel`, ``` @mtkmodel Model begin @components begin resistor = ModelingToolkitStandardLibrary.Electrical.Resistor(R = 1) ... end ... end ``` throws the following error. ``` ERROR: LoadError: MethodError: Cannot `convert` an object of type Expr to an object of type Symbol Closest candidates are: convert(::Type{T}, ::T) where T @ Base Base.jl:84 Symbol(::Any...) @ Base strings/basic.jl:229 ``` Fix this and support fully qualified names by considering the fully-qualifed name's Expr while parsing components.
1 parent df0bd9a commit 9013d7f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/systems/model_parsing.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,15 @@ function parse_components!(exprs, cs, dict, body, kwargs)
275275
expr = Expr(:block)
276276
varexpr = Expr(:block)
277277
push!(exprs, varexpr)
278-
comps = Vector{Symbol}[]
278+
comps = Vector{Union{Symbol, Expr}}[]
279279
for arg in body.args
280280
arg isa LineNumberNode && continue
281281
MLStyle.@match arg begin
282282
Expr(:(=), a, b) => begin
283283
push!(cs, a)
284-
push!(comps, [a, b.args[1]])
284+
if(isa(b.args[1], Symbol) || Meta.isexpr(b.args[1], :.))
285+
push!(comps, [a, b.args[1]])
286+
end
285287
arg = deepcopy(arg)
286288
b = deepcopy(arg.args[2])
287289

0 commit comments

Comments
 (0)