Skip to content

Commit e51cfc1

Browse files
author
José Valim
committed
Merge pull request #2516 from alco/sigil-docs
Make sigil docs more readable in the source
2 parents b259e79 + 45c6fba commit e51cfc1

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,7 +3354,7 @@ defmodule Kernel do
33543354

33553355
## Sigils
33563356

3357-
@doc """
3357+
@doc ~S"""
33583358
Handles the sigil ~S. It simply returns a string
33593359
without escaping characters and without interpolations.
33603360
@@ -3363,15 +3363,15 @@ defmodule Kernel do
33633363
iex> ~S(foo)
33643364
"foo"
33653365
3366-
iex> ~S(f\#{o}o)
3367-
"f\\\#{o}o"
3366+
iex> ~S(f#{o}o)
3367+
"f\#{o}o"
33683368
33693369
"""
33703370
defmacro sigil_S(string, []) do
33713371
string
33723372
end
33733373

3374-
@doc """
3374+
@doc ~S"""
33753375
Handles the sigil ~s. It returns a string as if it was double quoted
33763376
string, unescaping characters and replacing interpolations.
33773377
@@ -3380,15 +3380,18 @@ defmodule Kernel do
33803380
iex> ~s(foo)
33813381
"foo"
33823382
3383-
iex> ~s(f\#{:o}o)
3383+
iex> ~s(f#{:o}o)
33843384
"foo"
33853385
3386+
iex> ~s(f\#{:o}o)
3387+
"f\#{:o}o"
3388+
33863389
"""
33873390
defmacro sigil_s({:<<>>, line, pieces}, []) do
33883391
{:<<>>, line, Macro.unescape_tokens(pieces)}
33893392
end
33903393

3391-
@doc """
3394+
@doc ~S"""
33923395
Handles the sigil ~C. It simply returns a char list
33933396
without escaping characters and without interpolations.
33943397
@@ -3397,15 +3400,15 @@ defmodule Kernel do
33973400
iex> ~C(foo)
33983401
'foo'
33993402
3400-
iex> ~C(f\#{o}o)
3401-
'f\\\#{o}o'
3403+
iex> ~C(f#{o}o)
3404+
'f\#{o}o'
34023405
34033406
"""
34043407
defmacro sigil_C({:<<>>, _line, [string]}, []) when is_binary(string) do
34053408
String.to_char_list(string)
34063409
end
34073410

3408-
@doc """
3411+
@doc ~S"""
34093412
Handles the sigil ~c. It returns a char list as if it were a single
34103413
quoted string, unescaping characters and replacing interpolations.
34113414
@@ -3414,9 +3417,12 @@ defmodule Kernel do
34143417
iex> ~c(foo)
34153418
'foo'
34163419
3417-
iex> ~c(f\#{:o}o)
3420+
iex> ~c(f#{:o}o)
34183421
'foo'
34193422
3423+
iex> ~c(f\#{:o}o)
3424+
'f\#{:o}o'
3425+
34203426
"""
34213427

34223428
# We can skip the runtime conversion if we are
@@ -3450,13 +3456,13 @@ defmodule Kernel do
34503456
quote do: Regex.compile!(unquote(binary), unquote(:binary.list_to_bin(options)))
34513457
end
34523458

3453-
@doc """
3459+
@doc ~S"""
34543460
Handles the sigil ~R. It returns a Regex pattern without escaping
34553461
nor interpreting interpolations.
34563462
34573463
## Examples
34583464
3459-
iex> Regex.match?(~R(f\#{1,3}o), "f\#o")
3465+
iex> Regex.match?(~R(f#{1,3}o), "f#o")
34603466
true
34613467
34623468
"""
@@ -3465,7 +3471,7 @@ defmodule Kernel do
34653471
Macro.escape(regex)
34663472
end
34673473

3468-
@doc """
3474+
@doc ~S"""
34693475
Handles the sigil ~w. It returns a list of "words" split by whitespace.
34703476
34713477
## Modifiers
@@ -3476,7 +3482,7 @@ defmodule Kernel do
34763482
34773483
## Examples
34783484
3479-
iex> ~w(foo \#{:bar} baz)
3485+
iex> ~w(foo #{:bar} baz)
34803486
["foo", "bar", "baz"]
34813487
34823488
iex> ~w(--source test/enum_test.exs)
@@ -3496,7 +3502,7 @@ defmodule Kernel do
34963502
split_words(binary, modifiers)
34973503
end
34983504

3499-
@doc """
3505+
@doc ~S"""
35003506
Handles the sigil ~W. It returns a list of "words" split by whitespace
35013507
without escaping nor interpreting interpolations.
35023508
@@ -3508,8 +3514,8 @@ defmodule Kernel do
35083514
35093515
## Examples
35103516
3511-
iex> ~W(foo \#{bar} baz)
3512-
["foo", "\\\#{bar}", "baz"]
3517+
iex> ~W(foo #{bar} baz)
3518+
["foo", "\#{bar}", "baz"]
35133519
35143520
"""
35153521
defmacro sigil_W({:<<>>, _line, [string]}, modifiers) when is_binary(string) do

0 commit comments

Comments
 (0)