@@ -282,50 +282,46 @@ end
282282 evaluate_on:: Union{Nothing,AbstractVector} ;
283283 kws... ,
284284):: N where {F<: Function ,N<: AbstractExpressionNode ,E<: AbstractExpression }
285- if length (args) == 2 && func ∈ operators . unaops
286- # Regular unary operator
287- op = findfirst (== (func), operators. unaops) :: Int
285+ degree = length (args) - 1
286+ if degree <= length (operators . ops) && func ∈ operators[degree]
287+ op_idx = findfirst (== (func), operators[degree])
288288 return N (;
289- op= op:: Int ,
290- l= _parse_expression (
291- args[2 ], operators, variable_names, N, E, evaluate_on; kws...
292- ),
293- )
294- elseif length (args) == 3 && func ∈ operators. binops
295- # Regular binary operator
296- op = findfirst (== (func), operators. binops):: Int
297- return N (;
298- op= op:: Int ,
299- l= _parse_expression (
300- args[2 ], operators, variable_names, N, E, evaluate_on; kws...
301- ),
302- r= _parse_expression (
303- args[3 ], operators, variable_names, N, E, evaluate_on; kws...
289+ op= op_idx:: Int ,
290+ children= map (
291+ arg -> _parse_expression (
292+ arg, operators, variable_names, N, E, evaluate_on; kws...
293+ ),
294+ (args[2 : end ]. .. ,),
304295 ),
305296 )
306- elseif length (args) > 3 && func in (+ , - , * ) && func ∈ operators. binops
307- # Either + or - but used with more than two arguments
308- op = findfirst (== (func), operators. binops):: Int
297+ elseif degree > 2 && func ∈ (+ , - , * ) && func ∈ operators[2 ]
298+ op_idx = findfirst (== (func), operators[2 ]):: Int
309299 inner = N (;
310- op= op:: Int ,
311- l= _parse_expression (
312- args[2 ], operators, variable_names, N, E, evaluate_on; kws...
313- ),
314- r= _parse_expression (
315- args[3 ], operators, variable_names, N, E, evaluate_on; kws...
300+ op= op_idx:: Int ,
301+ children= (
302+ _parse_expression (
303+ args[2 ], operators, variable_names, N, E, evaluate_on; kws...
304+ ),
305+ _parse_expression (
306+ args[3 ], operators, variable_names, N, E, evaluate_on; kws...
307+ ),
316308 ),
317309 )
318310 for arg in args[4 : end ]
319311 inner = N (;
320- op= op:: Int ,
321- l= inner,
322- r= _parse_expression (
323- arg, operators, variable_names, N, E, evaluate_on; kws...
312+ op= op_idx:: Int ,
313+ children= (
314+ inner,
315+ _parse_expression (
316+ arg, operators, variable_names, N, E, evaluate_on; kws...
317+ ),
324318 ),
325319 )
326320 end
327321 return inner
328- elseif evaluate_on != = nothing && func in evaluate_on
322+ end
323+
324+ if evaluate_on != = nothing && func in evaluate_on
329325 # External function
330326 func (
331327 map (
337333 )
338334 else
339335 matching_s = let
340- s = if length (args) == 2
341- " `" * string (operators. unaops) * " `"
342- elseif length (args) == 3
343- " `" * string (operators. binops) * " `"
336+ s = if degree <= length (operators. ops)
337+ join ((' `' , operators[degree], ' `' ))
344338 else
345339 " "
346340 end
0 commit comments