@@ -6471,29 +6471,37 @@ defmodule Kernel do
6471
6471
"""
6472
6472
defmacro sigil_r ( term , modifiers )
6473
6473
6474
- defmacro sigil_r ( { :<<>> , _meta , [ string ] } , options ) when is_binary ( string ) do
6475
- binary = :elixir_interpolation . unescape_string ( string , & regex_unescape_map / 1 )
6476
- regex = Regex . compile! ( binary , :binary . list_to_bin ( options ) )
6477
- Macro . escape ( regex )
6474
+ defmacro sigil_r ( { :<<>> , _meta , [ binary ] } , options ) when is_binary ( binary ) do
6475
+ binary = :elixir_interpolation . unescape_string ( binary , & regex_unescape_map / 1 )
6476
+ compile_regex ( binary , options )
6478
6477
end
6479
6478
6480
6479
defmacro sigil_r ( { :<<>> , meta , pieces } , options ) do
6481
- binary = { :<<>> , meta , unescape_tokens ( pieces , & regex_unescape_map / 1 ) }
6482
- quote ( do: Regex . compile! ( unquote ( binary ) , unquote ( :binary . list_to_bin ( options ) ) ) )
6480
+ tuple = { :<<>> , meta , unescape_tokens ( pieces , & regex_unescape_map / 1 ) }
6481
+ compile_regex ( tuple , options )
6483
6482
end
6484
6483
6485
6484
defp regex_unescape_map ( :newline ) , do: true
6486
6485
defp regex_unescape_map ( _ ) , do: false
6487
6486
6488
6487
@ doc false
6489
- defmacro sigil_R ( { :<<>> , _meta , [ string ] } , options ) when is_binary ( string ) do
6488
+ defmacro sigil_R ( { :<<>> , _meta , [ binary ] } , options ) when is_binary ( binary ) do
6490
6489
IO . warn (
6491
6490
"~R/.../ is deprecated, use ~r/.../ instead" ,
6492
6491
Macro.Env . stacktrace ( __CALLER__ )
6493
6492
)
6494
6493
6495
- regex = Regex . compile! ( string , :binary . list_to_bin ( options ) )
6496
- Macro . escape ( regex )
6494
+ compile_regex ( binary , options )
6495
+ end
6496
+
6497
+ defp compile_regex ( binary_or_tuple , options ) do
6498
+ case is_binary ( binary_or_tuple ) and :erlang . system_info ( :otp_release ) < [ ?2 , ?8 ] do
6499
+ true ->
6500
+ Macro . escape ( Regex . compile! ( binary_or_tuple , :binary . list_to_bin ( options ) ) )
6501
+
6502
+ false ->
6503
+ quote ( do: Regex . compile! ( unquote ( binary_or_tuple ) , unquote ( :binary . list_to_bin ( options ) ) ) )
6504
+ end
6497
6505
end
6498
6506
6499
6507
@ doc ~S"""
0 commit comments