@@ -6437,29 +6437,37 @@ defmodule Kernel do
6437
6437
"""
6438
6438
defmacro sigil_r ( term , modifiers )
6439
6439
6440
- defmacro sigil_r ( { :<<>> , _meta , [ string ] } , options ) when is_binary ( string ) do
6441
- binary = :elixir_interpolation . unescape_string ( string , & regex_unescape_map / 1 )
6442
- regex = Regex . compile! ( binary , :binary . list_to_bin ( options ) )
6443
- Macro . escape ( regex )
6440
+ defmacro sigil_r ( { :<<>> , _meta , [ binary ] } , options ) when is_binary ( binary ) do
6441
+ binary = :elixir_interpolation . unescape_string ( binary , & regex_unescape_map / 1 )
6442
+ compile_regex ( binary , options )
6444
6443
end
6445
6444
6446
6445
defmacro sigil_r ( { :<<>> , meta , pieces } , options ) do
6447
- binary = { :<<>> , meta , unescape_tokens ( pieces , & regex_unescape_map / 1 ) }
6448
- quote ( do: Regex . compile! ( unquote ( binary ) , unquote ( :binary . list_to_bin ( options ) ) ) )
6446
+ tuple = { :<<>> , meta , unescape_tokens ( pieces , & regex_unescape_map / 1 ) }
6447
+ compile_regex ( tuple , options )
6449
6448
end
6450
6449
6451
6450
defp regex_unescape_map ( :newline ) , do: true
6452
6451
defp regex_unescape_map ( _ ) , do: false
6453
6452
6454
6453
@ doc false
6455
- defmacro sigil_R ( { :<<>> , _meta , [ string ] } , options ) when is_binary ( string ) do
6454
+ defmacro sigil_R ( { :<<>> , _meta , [ binary ] } , options ) when is_binary ( binary ) do
6456
6455
IO . warn (
6457
6456
"~R/.../ is deprecated, use ~r/.../ instead" ,
6458
6457
Macro.Env . stacktrace ( __CALLER__ )
6459
6458
)
6460
6459
6461
- regex = Regex . compile! ( string , :binary . list_to_bin ( options ) )
6462
- Macro . escape ( regex )
6460
+ compile_regex ( binary , options )
6461
+ end
6462
+
6463
+ defp compile_regex ( binary_or_tuple , options ) do
6464
+ case is_binary ( binary_or_tuple ) and :erlang . system_info ( :otp_release ) < [ ?2 , ?8 ] do
6465
+ true ->
6466
+ Macro . escape ( Regex . compile! ( binary_or_tuple , :binary . list_to_bin ( options ) ) )
6467
+
6468
+ false ->
6469
+ quote ( do: Regex . compile! ( unquote ( binary_or_tuple ) , unquote ( :binary . list_to_bin ( options ) ) ) )
6470
+ end
6463
6471
end
6464
6472
6465
6473
@ doc ~S"""
0 commit comments