@@ -11,22 +11,6 @@ function is_stringchunk(node)
1111 return k == K " String" || k == K " CmdString"
1212end
1313
14- function lower_underscores (args, skiparg= - 1 )
15- g = nothing
16- for i in 1 : length (args)
17- if i == skiparg
18- continue
19- end
20- if args[i] == :_
21- if isnothing (g)
22- g = gensym ()
23- end
24- args[i] = g
25- end
26- end
27- return g
28- end
29-
3014function reorder_parameters! (args, params_pos)
3115 p = 0
3216 for i = length (args): - 1 : 1
@@ -206,7 +190,6 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
206190 headsym = Symbol (" '" )
207191 end
208192 # Move parameters blocks to args[2]
209- g = lower_underscores (args, 1 )
210193 reorder_parameters! (args, 2 )
211194 if headsym === :dotcall
212195 if is_prefix_call (node)
@@ -217,17 +200,9 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
217200 args[1 ] = Symbol (" ." , args[1 ])
218201 end
219202 end
220- if ! isnothing (g)
221- return Expr (:-> , g, Expr (:call , args... ))
222- end
223203 elseif headsym in (:ref , :curly )
224204 # Move parameters blocks to args[2]
225205 reorder_parameters! (args, 2 )
226- elseif headsym == :.
227- g = lower_underscores (args)
228- if ! isnothing (g)
229- return Expr (:-> , g, Expr (:., args... ))
230- end
231206 elseif headsym in (:tuple , :vect , :braces )
232207 # Move parameters blocks to args[1]
233208 reorder_parameters! (args, 1 )
@@ -352,13 +327,37 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
352327 headsym = :const
353328 end
354329 elseif headsym == Symbol (" />" ) || headsym == Symbol (" \\ >" )
355- freearg = gensym ()
356330 callex = only (args)
357331 @assert Meta. isexpr (callex, :call )
358332 args = callex. args
359333 func = headsym == Symbol (" />" ) ?
360334 :(JuliaSyntax. fixbutfirst) :
361335 :(JuliaSyntax. fixbutlast)
336+
337+ # Automatic underscore lowering within pipes
338+ for i = 2 : length (args)
339+ anon_args = Symbol[]
340+ if i == 2 && Meta. isexpr (args[i], :parameters )
341+ kws = args[i]. args
342+ for j = 1 : length (kws)
343+ kw = kws[j]
344+ if Meta. isexpr (kw, :kw )
345+ as = Any[kw. args[2 ]]
346+ lower_underscores! (anon_args, as)
347+ if ! isempty (anon_args)
348+ kw. args[2 ] = Expr (:-> , Expr (:tuple , anon_args... ), as[1 ])
349+ end
350+ end
351+ end
352+ else
353+ as = Any[args[i]]
354+ lower_underscores! (anon_args, as)
355+ if ! isempty (anon_args)
356+ args[i] = Expr (:-> , Expr (:tuple , anon_args... ), as[1 ])
357+ end
358+ end
359+ end
360+
362361 if length (args) >= 2 && Meta. isexpr (args[2 ], :parameters )
363362 return Expr (:call , func, args[2 ], args[1 ], args[3 : end ]. .. )
364363 else
0 commit comments