@@ -525,11 +525,15 @@ defmodule Macro do
525525
526526 # All other calls
527527 def to_string ( { target , _ , args } = ast , fun ) when is_list ( args ) do
528- { list , last } = :elixir_utils . split_last ( args )
529- fun . ( ast , case kw_blocks? ( last ) do
530- true -> call_to_string_with_args ( target , list , fun ) <> kw_blocks_to_string ( last , fun )
531- false -> call_to_string_with_args ( target , args , fun )
532- end )
528+ if sigil = sigil_call ( ast , fun ) do
529+ sigil
530+ else
531+ { list , last } = :elixir_utils . split_last ( args )
532+ fun . ( ast , case kw_blocks? ( last ) do
533+ true -> call_to_string_with_args ( target , list , fun ) <> kw_blocks_to_string ( last , fun )
534+ false -> call_to_string_with_args ( target , args , fun )
535+ end )
536+ end
533537 end
534538
535539 # Two-item tuples
@@ -565,6 +569,26 @@ defmodule Macro do
565569 defp module_to_string ( atom , _fun ) when is_atom ( atom ) , do: inspect ( atom , [ ] )
566570 defp module_to_string ( other , fun ) , do: call_to_string ( other , fun )
567571
572+ defp sigil_call ( { func , _ , [ { :<<>> , _ , [ string ] } , args ] } = ast , fun ) when is_list ( args ) do
573+ sigil =
574+ case Atom . to_string ( func ) do
575+ << "sigil_" , name >> ->
576+ "~" <> << name >> <>
577+ fun . ( string , inspect ( string , [ ] ) ) <>
578+ sigil_args ( args , fun )
579+ _ ->
580+ nil
581+ end
582+ fun . ( ast , sigil )
583+ end
584+
585+ defp sigil_call ( _other , _fun ) do
586+ nil
587+ end
588+
589+ defp sigil_args ( [ ] , _fun ) , do: ""
590+ defp sigil_args ( args , fun ) , do: fun . ( args , List . to_string ( args ) )
591+
568592 defp call_to_string ( atom , _fun ) when is_atom ( atom ) , do: Atom . to_string ( atom )
569593 defp call_to_string ( { :. , _ , [ arg ] } , fun ) , do: module_to_string ( arg , fun ) <> "."
570594 defp call_to_string ( { :. , _ , [ left , right ] } , fun ) , do: module_to_string ( left , fun ) <> "." <> call_to_string ( right , fun )
0 commit comments