@@ -127,15 +127,23 @@ function _model_macro(mod, name, expr, isconnector)
127127    isconnector &&  push! (exprs. args,
128128        :($ Setfield. @set! (var"#___sys___" . connector_type= $ connector_type (var"#___sys___" ))))
129129
130-     ! isempty (c_evts) &&  push! (exprs. args,
131-         :($ Setfield. @set! (var"#___sys___" . continuous_events= $ SymbolicContinuousCallback .([
132-             $ (c_evts... )
133-         ]))))
130+     push! (exprs. args, :(alg_eqs =  $ (alg_equations)(var"#___sys___" )))
131+     d_evt_exs =  map (d_evts) do  evt
132+         length (evt. args) ==  2  ?  
133+         :($ SymbolicDiscreteCallback ($ (evt. args[1 ]); iv =  $ iv, alg_eqs, $ (evt. args[2 ]. .. ))) : 
134+         :($ SymbolicDiscreteCallback ($ (evt. args[1 ]); iv =  $ iv, alg_eqs))
135+     end 
134136
135137    ! isempty (d_evts) &&  push! (exprs. args,
136-         :($ Setfield. @set! (var"#___sys___" . discrete_events= $ SymbolicDiscreteCallback .([
137-             $ (d_evts... )
138-         ]))))
138+         :($ Setfield. @set! (var"#___sys___" . discrete_events= [$ (d_evt_exs... )])))
139+ 
140+     c_evt_exs =  map (c_evts) do  evt
141+         length (evt. args) ==  2  ?  
142+         :($ SymbolicContinuousCallback ($ (evt. args[1 ]); iv =  $ iv, alg_eqs, $ (evt. args[2 ]. .. ))) : 
143+         :($ SymbolicContinuousCallback ($ (evt. args[1 ]); iv =  $ iv, alg_eqs))
144+     end 
145+     ! isempty (c_evts) &&  push! (exprs. args,
146+         :($ Setfield. @set! (var"#___sys___" . continuous_events= [$ (c_evt_exs... )])))
139147
140148    f =  if  length (where_types) ==  0 
141149        :($ (Symbol (:__ , name, :__ ))(; name, $ (kwargs... )) =  $ exprs)
@@ -1124,21 +1132,47 @@ end
11241132function  parse_continuous_events! (c_evts, dict, body)
11251133    dict[:continuous_events ] =  []
11261134    Base. remove_linenums! (body)
1127-     for  arg in  body. args
1128-         push! (c_evts, arg)
1135+     for  line in  body. args
1136+         if  length (line. args) ==  3  &&  line. args[1 ] ==  :(=> ) 
1137+             push! (c_evts, :(($ line,)))
1138+         elseif  length (line. args) ==  2  
1139+             event =  line. args[1 ]
1140+             kwargs =  parse_event_kwargs (line. args[2 ])
1141+             push! (c_evts, :(($ event, $ kwargs)))
1142+         else 
1143+             error (" Malformed continuous event $line ."  )
1144+         end 
11291145        push! (dict[:continuous_events ], readable_code .(c_evts)... )
11301146    end 
11311147end 
11321148
11331149function  parse_discrete_events! (d_evts, dict, body)
11341150    dict[:discrete_events ] =  []
11351151    Base. remove_linenums! (body)
1136-     for  arg in  body. args
1137-         push! (d_evts, arg)
1152+     for  line in  body. args
1153+         if  length (line. args) ==  3  &&  line. args[1 ] ==  :(=> ) 
1154+             push! (d_evts, :(($ line,)))
1155+         elseif  length (line. args) ==  2  
1156+             event =  line. args[1 ]
1157+             kwargs =  parse_event_kwargs (line. args[2 ])
1158+             push! (d_evts, :(($ event, $ kwargs)))
1159+         else 
1160+             error (" Malformed discrete event $line ."  )
1161+         end 
11381162        push! (dict[:discrete_events ], readable_code .(d_evts)... )
11391163    end 
11401164end 
11411165
1166+ function  parse_event_kwargs (disc_expr)
1167+     kwargs =  :([])
1168+     for  arg in  disc_expr. args
1169+         (arg. head !=  :(= )) &&  error (" Malformed event kwarg $arg ."  )
1170+         (arg. args[1 ] isa  Symbol) ||  error (" Invalid keyword argument name $(arg. args[1 ]) ."  )
1171+         push! (kwargs. args, arg)
1172+     end 
1173+     kwargs
1174+ end 
1175+ 
11421176function  parse_icon! (body:: String , dict, icon, mod)
11431177    icon_dir =  get (ENV , " MTK_ICONS_DIR"  , joinpath (DEPOT_PATH [1 ], " mtk_icons"  ))
11441178    dict[:icon ] =  icon[] =  if  isfile (body)
0 commit comments