diff --git a/src/differentials.jl b/src/differentials.jl index 25a0498e76..24c762c33e 100644 --- a/src/differentials.jl +++ b/src/differentials.jl @@ -61,9 +61,10 @@ _repeat_apply(f, n) = n == 1 ? f : f ∘ _repeat_apply(f, n-1) function _differential_macro(x) ex = Expr(:block) lhss = Symbol[] + x = x isa Tuple && first(x).head == :tuple ? first(x).args : x # tuple handling x = flatten_expr!(x) for di in x - @assert di isa Expr && di.args[1] == :~ "@derivatives expects a form that looks like `@derivatives D''~t E'~t`" + @assert di isa Expr && di.args[1] == :~ "@derivatives expects a form that looks like `@derivatives D''~t E'~t` or `@derivatives (D''~t), (E'~t)`" lhs = di.args[2] rhs = di.args[3] order, lhs = count_order(lhs) diff --git a/src/variables.jl b/src/variables.jl index 4777eed673..d1dd42d32e 100644 --- a/src/variables.jl +++ b/src/variables.jl @@ -49,11 +49,12 @@ function _parse_vars(macroname, known, x) # y # z # end + x = x isa Tuple && first(x) isa Expr && first(x).head == :tuple ? first(x).args : x # tuple handling x = flatten_expr!(x) for _var in x iscall = isa(_var, Expr) && _var.head == :call issym = _var isa Symbol - @assert iscall || issym "@$macroname expects a tuple of expressions (`@$macroname x y z(t)`)" + @assert iscall || issym "@$macroname expects a tuple of expressions or an expression of a tuple (`@$macroname x y z(t)` or `@$macroname x, y, z(t)`)" if iscall dependents = :(Variable[$(_var.args[2:end]...)]) @@ -71,8 +72,8 @@ function _parse_vars(macroname, known, x) return ex end macro variables(xs...) - esc(_parse_vars(:Variable, false, xs)) + esc(_parse_vars(:variables, false, xs)) end macro parameters(xs...) - esc(_parse_vars(:Param, true, xs)) + esc(_parse_vars(:parameters, true, xs)) end diff --git a/test/derivatives.jl b/test/derivatives.jl index 999cad9a70..f475f9209a 100644 --- a/test/derivatives.jl +++ b/test/derivatives.jl @@ -6,6 +6,8 @@ using Test @variables x(t) y(t) z(t) @derivatives D'~t D2''~t +@test @macroexpand(@derivatives D'~t D2''~t) == @macroexpand(@derivatives (D'~t), (D2''~t)) + @test isequal(expand_derivatives(D(t)), 1) @test isequal(expand_derivatives(D(D(t))), 0) diff --git a/test/variable_parsing.jl b/test/variable_parsing.jl index 759652f110..842a5632d8 100644 --- a/test/variable_parsing.jl +++ b/test/variable_parsing.jl @@ -2,9 +2,8 @@ using ModelingToolkit using Test @parameters t -@variables x(t) -@variables y(t) -@variables z(t) +@variables x(t) y(t) # test multi-arg +@variables z(t) # test single-arg x1 = Variable(:x, [t]) y1 = Variable(:y, [t]) z1 = Variable(:z, [t]) @@ -33,3 +32,6 @@ D1 = Differential(t) @test convert(Expr, D) == D @test isequal(x ≤ y + 1, (x < y + 1) | (x == y + 1)) + +@test @macroexpand(@parameters x, y, z(t)) == @macroexpand(@parameters x y z(t)) +@test @macroexpand(@variables x, y, z(t)) == @macroexpand(@variables x y z(t))