Skip to content

Commit c628455

Browse files
author
José Valim
committed
Rename sigils from __ to sigil_$, closes #1301
1 parent a8a2f86 commit c628455

File tree

8 files changed

+34
-42
lines changed

8 files changed

+34
-42
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* [Mix] Implement `Mix.Version` for basic versioniong semantics
1313
* [Mix] Support creation and installation of archives (.ez files)
1414
* [Mix] `github: ...` shortcut now uses the faster `git` schema instead of `https`
15-
* [Record] Allow types to be given to `defrecordp`
15+
* [Record] Allow types to be given to `defrecord` and `defrecordp`
1616

1717
* bug fix
1818
* [Kernel] The elixir executable on Windows now supports the same options as the UNIX one
@@ -32,7 +32,8 @@
3232
* [Bitwise] Precedence of operators used by the Bitwise module were changed. Check `elixir_parser.yrl` for more information.
3333
* [File] `rm_rf` and `cp_r` now returns a tuple with three elements on failures
3434
* [Kernel] The quoted representation for `->` clauses changed from a tuple with two elements to a tuple with three elements to support metadata
35-
* [Macro] `Macro.expand/2` now expands until final form. Although this is backwards incompatible, it is **very** likely your code should expand the node until its final form, particularly if you are expecting an atom out of it
35+
* [Kernel] Sigils now dispatch to `sigil_$` instead of `__$__` where `$` is the sigil caracter
36+
* [Macro] `Macro.expand/2` now expands until final form. Although this is backwards incompatible, it is very likely you do not need to change your code, since expansion until its final form is recommended, particularly if you are expecting an atom out of it
3637
* [Mix] No longer support beam files on `mix local`
3738

3839
# v0.9.2 (2013-06-13)

lib/elixir/lib/kernel.ex

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,7 +3323,7 @@ defmodule Kernel do
33233323
"f\\\#{o}o"
33243324
33253325
"""
3326-
defmacro __B__(string, []) do
3326+
defmacro sigil_B(string, []) do
33273327
string
33283328
end
33293329

@@ -3339,7 +3339,7 @@ defmodule Kernel do
33393339
"foo"
33403340
33413341
"""
3342-
defmacro __b__({ :<<>>, line, pieces }, []) do
3342+
defmacro sigil_b({ :<<>>, line, pieces }, []) do
33433343
{ :<<>>, line, Macro.unescape_tokens(pieces) }
33443344
end
33453345

@@ -3355,7 +3355,7 @@ defmodule Kernel do
33553355
'f\\\#{o}o'
33563356
33573357
"""
3358-
defmacro __C__({ :<<>>, _line, [string] }, []) when is_binary(string) do
3358+
defmacro sigil_C({ :<<>>, _line, [string] }, []) when is_binary(string) do
33593359
binary_to_list(string)
33603360
end
33613361

@@ -3374,11 +3374,11 @@ defmodule Kernel do
33743374

33753375
# We can skip the runtime conversion if we are
33763376
# creating a binary made solely of series of chars.
3377-
defmacro __c__({ :<<>>, _line, [string] }, []) when is_binary(string) do
3377+
defmacro sigil_c({ :<<>>, _line, [string] }, []) when is_binary(string) do
33783378
:unicode.characters_to_list(Macro.unescape_binary(string))
33793379
end
33803380

3381-
defmacro __c__({ :<<>>, line, pieces }, []) do
3381+
defmacro sigil_c({ :<<>>, line, pieces }, []) do
33823382
binary = { :<<>>, line, Macro.unescape_tokens(pieces) }
33833383
quote do: :unicode.characters_to_list(unquote(binary))
33843384
end
@@ -3392,13 +3392,13 @@ defmodule Kernel do
33923392
true
33933393
33943394
"""
3395-
defmacro __r__({ :<<>>, _line, [string] }, options) when is_binary(string) do
3395+
defmacro sigil_r({ :<<>>, _line, [string] }, options) when is_binary(string) do
33963396
binary = Macro.unescape_binary(string, Regex.unescape_map(&1))
33973397
regex = Regex.compile!(binary, options)
33983398
Macro.escape(regex)
33993399
end
34003400

3401-
defmacro __r__({ :<<>>, line, pieces }, options) do
3401+
defmacro sigil_r({ :<<>>, line, pieces }, options) do
34023402
binary = { :<<>>, line, Macro.unescape_tokens(pieces, Regex.unescape_map(&1)) }
34033403
quote do: Regex.compile!(unquote(binary), unquote(options))
34043404
end
@@ -3413,7 +3413,7 @@ defmodule Kernel do
34133413
true
34143414
34153415
"""
3416-
defmacro __R__({ :<<>>, _line, [string] }, options) when is_binary(string) do
3416+
defmacro sigil_R({ :<<>>, _line, [string] }, options) when is_binary(string) do
34173417
regex = Regex.compile!(string, options)
34183418
Macro.escape(regex)
34193419
end
@@ -3438,11 +3438,11 @@ defmodule Kernel do
34383438
34393439
"""
34403440

3441-
defmacro __w__({ :<<>>, _line, [string] }, modifiers) when is_binary(string) do
3441+
defmacro sigil_w({ :<<>>, _line, [string] }, modifiers) when is_binary(string) do
34423442
split_words(Macro.unescape_binary(string), modifiers)
34433443
end
34443444

3445-
defmacro __w__({ :<<>>, line, pieces }, modifiers) do
3445+
defmacro sigil_w({ :<<>>, line, pieces }, modifiers) do
34463446
binary = { :<<>>, line, Macro.unescape_tokens(pieces) }
34473447
split_words(binary, modifiers)
34483448
end
@@ -3463,7 +3463,7 @@ defmodule Kernel do
34633463
["foo", "\\\#{bar}", "baz"]
34643464
34653465
"""
3466-
defmacro __W__({ :<<>>, _line, [string] }, modifiers) when is_binary(string) do
3466+
defmacro sigil_W({ :<<>>, _line, [string] }, modifiers) when is_binary(string) do
34673467
split_words(string, modifiers)
34683468
end
34693469

lib/elixir/lib/macro.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ defmodule Macro do
153153
154154
Only tokens that are binaries are unescaped, all others are
155155
ignored. This function is useful when implementing your own
156-
sigils. Check the implementation of `Kernel.__b__`
156+
sigils. Check the implementation of `Kernel.sigil_b`
157157
for examples.
158158
"""
159159
def unescape_tokens(tokens) do

lib/elixir/src/elixir_import.erl

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,15 @@ intersection([], _All) -> [].
196196

197197
%% Internal funs that are never imported etc.
198198

199-
remove_underscored(default, List) -> remove_underscored(List);
200-
remove_underscored(_, List) -> List.
201-
202-
remove_underscored([{ Name, _ } = H|T]) when Name < a ->
203-
case atom_to_list(Name) of
204-
[$_, $_, _, $_, $_] -> [H|remove_underscored(T)];
205-
"_" ++ _ -> remove_underscored(T);
206-
_ -> [H|remove_underscored(T)]
207-
end;
208-
209-
remove_underscored(T) ->
210-
T.
199+
remove_underscored(default, List) ->
200+
lists:filter(fun({ Name, _ }) ->
201+
case atom_to_list(Name) of
202+
"_" ++ _ -> false;
203+
_ -> true
204+
end
205+
end, List);
206+
207+
remove_underscored(_, List) -> List.
211208

212209
remove_internals(Set) ->
213210
ordsets:del_element({ module_info, 1 },

lib/elixir/src/elixir_parser.yrl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ build_access(Expr, Access) ->
514514

515515
build_sigil({ sigil, Line, Sigil, Parts, Modifiers }) ->
516516
Meta = [{line,Line}],
517-
{ list_to_atom([$_,$_,Sigil,$_,$_]), Meta, [ { '<<>>', Meta, Parts }, Modifiers ] }.
517+
{ list_to_atom("sigil_" ++ [Sigil]), Meta, [ { '<<>>', Meta, Parts }, Modifiers ] }.
518518

519519
build_bin_string({ bin_string, _Line, [H] }) when is_binary(H) -> H;
520520
build_bin_string({ bin_string, Line, Args }) -> { '<<>>', [{line,Line}], Args }.

lib/elixir/test/elixir/kernel/import_test.exs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ end
6161
defmodule Kernel.Underscored do
6262
def hello(x), do: x
6363
def __underscore__(x), do: x
64-
def __s__(x), do: x
6564
end
6665

6766
defmodule Kernel.ExplicitUnderscored do
@@ -87,11 +86,6 @@ defmodule Kernel.ImportUnderscoreTest do
8786
import Kernel.Underscored
8887
assert hello(2) == 2
8988
end
90-
91-
test :includes_sigil_like do
92-
import Kernel.Underscored
93-
assert __s__(3) == 3
94-
end
9589
end
9690

9791
defmodule Kernel.ImportMacrosTest do

lib/elixir/test/elixir/kernel/sigils_test.exs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ Code.require_file "../test_helper.exs", __DIR__
33
defmodule Kernel.SigilsTest do
44
use ExUnit.Case, async: true
55

6-
test :__b__ do
6+
test :sigil_b do
77
assert %b(foo) == "foo"
88
assert %b(f#{:o}o) == "foo"
99
assert %b(f\no) == "f\no"
1010
end
1111

12-
test :__b__with_heredoc do
12+
test :sigil_b_with_heredoc do
1313
assert " foo\n\n" == %b"""
1414
f#{:o}o\n
1515
"""
1616
end
1717

18-
test :__B__ do
18+
test :sigil_B do
1919
assert %B(foo) == "foo"
2020
assert %B[foo] == "foo"
2121
assert %B{foo} == "foo"
@@ -26,19 +26,19 @@ defmodule Kernel.SigilsTest do
2626
assert %B(f\no) == "f\\no"
2727
end
2828
29-
test :__B__with_heredoc do
29+
test :sigil_B_with_heredoc do
3030
assert " f\#{o}o\\n\n" == %B"""
3131
f#{o}o\n
3232
"""
3333
end
3434
35-
test :__c__ do
35+
test :sigil_c do
3636
assert %c(foo) == 'foo'
3737
assert %c(f#{:o}o) == 'foo'
3838
assert %c(f\no) == 'f\no'
3939
end
4040
41-
test :__C__ do
41+
test :sigil_C do
4242
assert %C(foo) == 'foo'
4343
assert %C[foo] == 'foo'
4444
assert %C{foo} == 'foo'
@@ -49,7 +49,7 @@ defmodule Kernel.SigilsTest do
4949
assert %C(f\no) == 'f\\no'
5050
end
5151
52-
test :__w__ do
52+
test :sigil_w do
5353
assert %w(foo bar baz) == ["foo", "bar", "baz"]
5454
assert %w(foo #{:bar} baz) == ["foo", "bar", "baz"]
5555
@@ -72,7 +72,7 @@ defmodule Kernel.SigilsTest do
7272
assert %w(Foo.#{Bar})c == ['Foo.Elixir.Bar']
7373
end
7474

75-
test :__W__ do
75+
test :sigil_W do
7676
assert %W(foo #{bar} baz) == ["foo", "\#{bar}", "baz"]
7777

7878
assert %W(

lib/elixir/test/elixir/regex_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ defmodule Regex.BinaryTest do
7171
assert Regex.captures(%r/c(.)/g, 'cat') == []
7272
end
7373
74-
test :__R__ do
74+
test :sigil_R do
7575
assert Regex.match?(%R/f#{1,3}o/, "f#o")
7676
end
7777

0 commit comments

Comments
 (0)