Skip to content

Commit 973c09a

Browse files
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 493e695 commit 973c09a

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
@@ -673,7 +673,7 @@ function _parse_components!(exprs, body, kwargs)
673673
expr = Expr(:block)
674674
varexpr = Expr(:block)
675675
# push!(exprs, varexpr)
676-
comps = Vector{Symbol}[]
676+
comps = Vector{Union{Symbol, Expr}}[]
677677
comp_names = []
678678

679679
for arg in body.args
@@ -692,7 +692,9 @@ function _parse_components!(exprs, body, kwargs)
692692
arg.args[2] = b
693693
push!(expr.args, arg)
694694
push!(comp_names, a)
695-
push!(comps, [a, b.args[1]])
695+
if(isa(b.args[1], Symbol) || Meta.isexpr(b.args[1], :.))
696+
push!(comps, [a, b.args[1]])
697+
end
696698
end
697699
_ => error("Couldn't parse the component body: $arg")
698700
end

0 commit comments

Comments
 (0)