@@ -2639,34 +2639,29 @@ defmodule Macro do
2639
2639
# Pipelines.
2640
2640
defp dbg_ast_to_debuggable ( { :|> , _meta , _args } = pipe_ast , _env ) do
2641
2641
value_var = unique_var ( :value , __MODULE__ )
2642
- values_acc_var = unique_var ( :values , __MODULE__ )
2643
2642
2644
- [ start_ast | rest_asts ] = asts = for { ast , 0 } <- unpipe ( pipe_ast ) , do: ast
2645
- rest_asts = Enum . map ( rest_asts , & pipe ( value_var , & 1 , 0 ) )
2643
+ [ start_ast | rest_asts ] = for { ast , 0 } <- unpipe ( pipe_ast ) , do: ast
2644
+ piped_rest_asts = Enum . map ( rest_asts , & { & 1 , pipe ( value_var , & 1 , 0 ) } )
2646
2645
2647
- initial_acc =
2646
+ first_entry =
2648
2647
quote do
2649
2648
unquote ( value_var ) = unquote ( start_ast )
2650
- unquote ( values_acc_var ) = [ unquote ( value_var ) ]
2649
+ { :multi_value , unquote ( escape ( start_ast ) ) , unquote ( value_var ) }
2651
2650
end
2652
2651
2653
- values_ast =
2654
- for step_ast <- rest_asts , reduce: initial_acc do
2655
- ast_acc ->
2656
- quote do
2657
- unquote ( ast_acc )
2658
- unquote ( value_var ) = unquote ( step_ast )
2659
- unquote ( values_acc_var ) = [ unquote ( value_var ) | unquote ( values_acc_var ) ]
2660
- end
2661
- end
2652
+ len = length ( piped_rest_asts )
2662
2653
2663
- [
2664
- quote do
2665
- unquote ( values_ast )
2654
+ pipe_entries =
2655
+ Enum . with_index ( piped_rest_asts , fn { original_ast , step_ast } , i ->
2656
+ tag = if i + 1 == len , do: :pipe_end , else: :pipe
2666
2657
2667
- { :pipe , unquote ( escape ( asts ) ) , Enum . reverse ( unquote ( values_acc_var ) ) }
2668
- end
2669
- ]
2658
+ quote do
2659
+ unquote ( value_var ) = unquote ( step_ast )
2660
+ { unquote ( tag ) , unquote ( escape ( original_ast ) ) , unquote ( value_var ) }
2661
+ end
2662
+ end )
2663
+
2664
+ [ first_entry | pipe_entries ]
2670
2665
end
2671
2666
2672
2667
dbg_decomposed_binary_operators = [ :&& , :|| , :and , :or ]
@@ -2886,18 +2881,19 @@ defmodule Macro do
2886
2881
result
2887
2882
end
2888
2883
2889
- defp dbg_format_ast_to_debug ( { :pipe , code_asts , values } , options ) do
2890
- result = List . last ( values )
2891
- code_strings = Enum . map ( code_asts , & to_string_with_colors ( & 1 , options ) )
2892
- [ { first_ast , first_value } | asts_with_values ] = Enum . zip ( code_strings , values )
2893
- first_formatted = [ dbg_format_ast ( first_ast ) , " " , inspect ( first_value , options ) , ?\n ]
2884
+ defp dbg_format_ast_to_debug ( { :pipe , code_ast , value } , options ) do
2885
+ formatted = [
2886
+ [ :faint , "|> " , :reset ] ,
2887
+ dbg_format_ast_with_value_no_newline ( code_ast , value , options )
2888
+ ]
2889
+
2890
+ { formatted , value }
2891
+ end
2894
2892
2895
- rest_formatted =
2896
- Enum . map ( asts_with_values , fn { code_ast , value } ->
2897
- [ :faint , "|> " , :reset , dbg_format_ast ( code_ast ) , " " , inspect ( value , options ) , ?\n ]
2898
- end )
2893
+ defp dbg_format_ast_to_debug ( { :pipe_end , code_ast , value } , options ) do
2894
+ { formatted , value } = dbg_format_ast_to_debug ( { :pipe , code_ast , value } , options )
2899
2895
2900
- { [ first_formatted | rest_formatted ] , result }
2896
+ { [ formatted , ?\n ] , value }
2901
2897
end
2902
2898
2903
2899
defp dbg_format_ast_to_debug ( { :case_argument , expr_ast , expr_value } , options ) do
0 commit comments