Permalink
Browse files

Implement new bitstring syntax, closes #421

  • Loading branch information...
1 parent c63a07f commit 26204441bbe705b2b984397d70c6080657461d16 @josevalim josevalim committed Sep 10, 2012
View
@@ -23,6 +23,7 @@
* deprecations
* [Code] `Code.require_file` and `Code.load_file` now expect the full name as argument
* [GenServer] Rename `GenServer.Behavior` to `GenServer.Behaviour`
+ * [Kernel] Bitstring syntax now uses `::` instead of `|`
# v0.6.0 (2012-08-01)
@@ -1082,7 +1082,7 @@ defmodule Enum do
end
defp do_join([h|t], joiner, acc) do
- acc = << acc | :binary, joiner | :binary, to_binary(h) | :binary >>
+ acc = << acc :: binary, joiner :: binary, to_binary(h) :: binary >>
do_join(t, joiner, acc)
end
@@ -1095,7 +1095,7 @@ defmodule Enum do
end
defp do_join({ h, next }, iterator, joiner, acc) do
- acc = << acc | :binary, joiner | :binary, to_binary(h) | :binary >>
+ acc = << acc :: binary, joiner :: binary, to_binary(h) :: binary >>
do_join(iterator.(next), iterator, joiner, acc)
end
@@ -1110,7 +1110,7 @@ defmodule Enum do
end
defp do_map_join([h|t], mapper, joiner, acc) do
- acc = << acc | :binary, joiner | :binary, to_binary(mapper.(h)) | :binary >>
+ acc = << acc :: binary, joiner :: binary, to_binary(mapper.(h)) :: binary >>
do_map_join(t, mapper, joiner, acc)
end
@@ -1123,7 +1123,7 @@ defmodule Enum do
end
defp do_map_join({ h, next }, iterator, mapper, joiner, acc) do
- acc = << acc | :binary, joiner | :binary, to_binary(mapper.(h)) | :binary >>
+ acc = << acc :: binary, joiner :: binary, to_binary(mapper.(h)) :: binary >>
do_map_join(iterator.(next), iterator, mapper, joiner, acc)
end
@@ -71,7 +71,7 @@ defmodule Exception do
"""
def format_module_fun_arity(module, fun, arity) do
case inspect(fun) do
- << ?:, fun | :binary >> -> :ok
+ << ?:, fun :: binary >> -> :ok
fun -> :ok
end
@@ -1175,8 +1175,8 @@ defmodule File do
defp strip_ending("\n"), do: <<>>
defp strip_ending(""), do: <<>>
- defp strip_ending(<< h, t | :binary >>) do
- << h, strip_ending(t) | :binary >>
+ defp strip_ending(<< h, t :: binary >>) do
+ << h, strip_ending(t) :: binary >>
end
@doc """
@@ -2764,7 +2764,7 @@ defmodule Kernel do
end
defp wrap_concatenation(other) do
- { :|, 0, [other, :binary] }
+ { :::, 0, [other, { :binary, 0, nil }] }
end
# Builds cond clauses by nesting them recursively.
@@ -286,7 +286,7 @@ defmodule Macro do
<< case x == ?\n do
true -> replacement
false -> <<x>>
- end | :binary >>
+ end :: binary >>
end
end
@@ -111,7 +111,7 @@ defmodule OptionParser do
Keyword.put dict, option, value
end
- defp normalize_option(<<?-, option|:binary>>, aliases) do
+ defp normalize_option(<<?-, option :: binary>>, aliases) do
normalize_option(option, aliases)
end
@@ -303,14 +303,14 @@ defmodule Regex do
defp return_for(element) when is_binary(element), do: :binary
defp return_for(element) when is_list(element), do: :list
- defp translate_options(<<?u, t|:binary>>), do: [:unicode|translate_options(t)]
- defp translate_options(<<?i, t|:binary>>), do: [:caseless|translate_options(t)]
- defp translate_options(<<?x, t|:binary>>), do: [:extended|translate_options(t)]
- defp translate_options(<<?f, t|:binary>>), do: [:firstline|translate_options(t)]
- defp translate_options(<<?r, t|:binary>>), do: [:ungreedy|translate_options(t)]
- defp translate_options(<<?s, t|:binary>>), do: [:dotall,{:newline,:anycrlf}|translate_options(t)]
- defp translate_options(<<?m, t|:binary>>), do: [:multiline|translate_options(t)]
- defp translate_options(<<?g, t|:binary>>), do: [:groups|translate_options(t)]
+ defp translate_options(<<?u, t :: binary>>), do: [:unicode|translate_options(t)]
+ defp translate_options(<<?i, t :: binary>>), do: [:caseless|translate_options(t)]
+ defp translate_options(<<?x, t :: binary>>), do: [:extended|translate_options(t)]
+ defp translate_options(<<?f, t :: binary>>), do: [:firstline|translate_options(t)]
+ defp translate_options(<<?r, t :: binary>>), do: [:ungreedy|translate_options(t)]
+ defp translate_options(<<?s, t :: binary>>), do: [:dotall,{:newline,:anycrlf}|translate_options(t)]
+ defp translate_options(<<?m, t :: binary>>), do: [:multiline|translate_options(t)]
+ defp translate_options(<<?g, t :: binary>>), do: [:groups|translate_options(t)]
defp translate_options(<<>>), do: []
defp flatten_result(results) do
@@ -19,28 +19,28 @@ defmodule String do
"""
# Allow basic ascii chars
- def printable?(<<c, t|:binary>>) when c in ?\s..?~ do
+ def printable?(<<c, t :: binary>>) when c in ?\s..?~ do
printable?(t)
end
# From 16#A0 to 16#BF
- def printable?(<<194, c, t|:binary>>) when c in 160..191 do
+ def printable?(<<194, c, t :: binary>>) when c in 160..191 do
printable?(t)
end
# From 16#C0 to 16#7FF
- def printable?(<<m, o1, t|:binary>>) when m in 195..223 and o1 in 128..191 do
+ def printable?(<<m, o1, t :: binary>>) when m in 195..223 and o1 in 128..191 do
printable?(t)
end
# From 16#800 to 16#CFFF
- def printable?(<<m, o1, o2, t|:binary>>) when m in 224..236 and
+ def printable?(<<m, o1, o2, t :: binary>>) when m in 224..236 and
o1 >= 128 and o1 < 192 and o2 >= 128 and o2 < 192 do
printable?(t)
end
# From 16#D000 to 16#D7FF
- def printable?(<<237, o1, o2, t|:binary>>) when
+ def printable?(<<237, o1, o2, t :: binary>>) when
o1 >= 128 and o1 < 160 and o2 >= 128 and o2 < 192 do
printable?(t)
end
@@ -51,41 +51,41 @@ defmodule String do
end
# From 16#E000 to 16#EFFF
- def printable?(<<m, o1, o2, t|:binary>>) when (m == 238 or m == 239) and
+ def printable?(<<m, o1, o2, t :: binary>>) when (m == 238 or m == 239) and
o1 in 128..191 and o2 in 128..191 do
printable?(t)
end
# From 16#F000 to 16#FFFD
- def printable?(<<239, o1, o2, t|:binary>>) when
+ def printable?(<<239, o1, o2, t :: binary>>) when
o1 in 128..191 and o2 in 128..191 do
printable?(t)
end
# From 16#10000 to 16#3FFFF
- def printable?(<<240, o1, o2, o3, t|:binary>>) when
+ def printable?(<<240, o1, o2, o3, t :: binary>>) when
o1 in 144..191 and o2 in 128..191 and o3 in 128..191 do
printable?(t)
end
# Reject 16#110000 onwards
- def printable?(<<244, o1, _, _, _|:binary>>) when o1 >= 144 do
+ def printable?(<<244, o1, _, _, _ :: binary>>) when o1 >= 144 do
false
end
# From 16#4000 to 16#10FFFF
- def printable?(<<m, o1, o2, o3, t|:binary>>) when m in 241..244 and
+ def printable?(<<m, o1, o2, o3, t :: binary>>) when m in 241..244 and
o1 in 128..191 and o2 in 128..191 and o3 in 128..191 do
printable?(t)
end
- def printable?(<<?\n, t|:binary>>), do: printable?(t)
- def printable?(<<?\r, t|:binary>>), do: printable?(t)
- def printable?(<<?\t, t|:binary>>), do: printable?(t)
- def printable?(<<?\v, t|:binary>>), do: printable?(t)
- def printable?(<<?\b, t|:binary>>), do: printable?(t)
- def printable?(<<?\f, t|:binary>>), do: printable?(t)
- def printable?(<<?\e, t|:binary>>), do: printable?(t)
+ def printable?(<<?\n, t :: binary>>), do: printable?(t)
+ def printable?(<<?\r, t :: binary>>), do: printable?(t)
+ def printable?(<<?\t, t :: binary>>), do: printable?(t)
+ def printable?(<<?\v, t :: binary>>), do: printable?(t)
+ def printable?(<<?\b, t :: binary>>), do: printable?(t)
+ def printable?(<<?\f, t :: binary>>), do: printable?(t)
+ def printable?(<<?\e, t :: binary>>), do: printable?(t)
def printable?(<<>>), do: true
def printable?(_), do: false
@@ -144,16 +144,16 @@ defmodule String do
"""
def upcase(<<>>), do: <<>>
- def upcase(<<195, c, t | :binary>>) when c in 160..191 do
- <<195, c - 32, upcase(t) | :binary>>
+ def upcase(<<195, c, t :: binary>>) when c in 160..191 do
+ <<195, c - 32, upcase(t) :: binary>>
end
- def upcase(<<c, t | :binary>>) when c in ?a..?z do
- <<c - 32, upcase(t) | :binary>>
+ def upcase(<<c, t :: binary>>) when c in ?a..?z do
+ <<c - 32, upcase(t) :: binary>>
end
- def upcase(<<c, t | :binary>>) do
- <<c , upcase(t) | :binary>>
+ def upcase(<<c, t :: binary>>) do
+ <<c , upcase(t) :: binary>>
end
@doc """
@@ -168,16 +168,16 @@ defmodule String do
"""
def downcase(<<>>), do: <<>>
- def downcase(<<195, c, t | :binary>>) when c in 128..159 do
- <<195, c + 32, downcase(t) | :binary>>
+ def downcase(<<195, c, t :: binary>>) when c in 128..159 do
+ <<195, c + 32, downcase(t) :: binary>>
end
- def downcase(<<c, t | :binary>>) when c in ?A..?Z do
- <<c + 32, downcase(t) | :binary>>
+ def downcase(<<c, t :: binary>>) when c in ?A..?Z do
+ <<c + 32, downcase(t) :: binary>>
end
- def downcase(<<c, t | :binary>>) do
- <<c , downcase(t) | :binary>>
+ def downcase(<<c, t :: binary>>) do
+ <<c , downcase(t) :: binary>>
end
@doc """
@@ -44,21 +44,21 @@ defmodule String.Inspect.Utils do
<<char>> <> do_escape(other, char)
end
- defp do_escape(<<char, t|:binary>>, char) do
- <<?\\, char, do_escape(t, char)|:binary>>
+ defp do_escape(<<char, t :: binary>>, char) do
+ <<?\\, char, do_escape(t, char) :: binary>>
end
- defp do_escape(<<h, t|:binary>>, char) when
+ defp do_escape(<<h, t :: binary>>, char) when
h == ?# or h == ?\b or
h == ?\d or h == ?\e or
h == ?\f or h == ?\n or
h == ?\r or h == ?\\ or
h == ?\t or h == ?\v do
- <<?\\, escape_map(h), do_escape(t, char)|:binary>>
+ <<?\\, escape_map(h), do_escape(t, char) :: binary>>
end
- defp do_escape(<<h, t|:binary>>, char) do
- <<h, do_escape(t,char)|:binary>>
+ defp do_escape(<<h, t :: binary>>, char) do
+ <<h, do_escape(t,char) :: binary>>
end
defp do_escape(<<>>, char) do
@@ -129,7 +129,7 @@ defimpl String.Inspect, for: Atom do
defp valid_ref_identifier?(_), do: false
- defp valid_ref_piece?(<<?-, h, t|:binary>>) when h in ?A..?Z do
+ defp valid_ref_piece?(<<?-, h, t :: binary>>) when h in ?A..?Z do
valid_ref_piece? valid_identifier?(t)
end
@@ -138,7 +138,7 @@ defimpl String.Inspect, for: Atom do
# Detect if atom
- defp valid_atom_identifier?(<<h, t|:binary>>) when h in ?a..?z or h in ?A..?Z or h == ?_ do
+ defp valid_atom_identifier?(<<h, t :: binary>>) when h in ?a..?z or h in ?A..?Z or h == ?_ do
case valid_identifier?(t) do
<<>> -> true
<<??>> -> true
@@ -149,7 +149,7 @@ defimpl String.Inspect, for: Atom do
defp valid_atom_identifier?(_), do: false
- defp valid_identifier?(<<h, t|:binary>>)
+ defp valid_identifier?(<<h, t :: binary>>)
when h in ?a..?z
when h in ?A..?Z
when h in ?0..?9
@@ -191,11 +191,11 @@ defimpl String.Inspect, for: BitString do
"<<" <> each_bit(bitstring) <> ">>"
end
- defp each_bit(<<h, t | :bitstring>>) when t != <<>> do
+ defp each_bit(<<h, t :: bitstring>>) when t != <<>> do
integer_to_binary(h) <> "," <> each_bit(t)
end
- defp each_bit(<<h | 8>>) do
+ defp each_bit(<<h :: size(8)>>) do
integer_to_binary(h)
end
@@ -205,7 +205,7 @@ defimpl String.Inspect, for: BitString do
defp each_bit(bitstring) do
size = bit_size(bitstring)
- <<h|size>> = bitstring
+ <<h :: size(size)>> = bitstring
integer_to_binary(h) <> "|" <> integer_to_binary(size)
end
@@ -67,7 +67,7 @@ defmodule URI do
@doc """
Percent (URL) encodes a URI.
"""
- def encode(s), do: bc <<c>> inbits s, do: <<percent(c)|:binary>>
+ def encode(s), do: bc <<c>> inbits s, do: <<percent(c) :: binary>>
defp percent(32), do: <<?+>>
defp percent(?-), do: <<?->>
@@ -94,11 +94,11 @@ defmodule URI do
@doc """
Unpercent (URL) decodes a URI.
"""
- def decode(<<?%, hex1, hex2, tail |:binary >>) do
+ def decode(<<?%, hex1, hex2, tail :: binary >>) do
<< bsl(hex2dec(hex1), 4) + hex2dec(hex2) >> <> decode(tail)
end
- def decode(<<head, tail |:binary >>) do
+ def decode(<<head, tail :: binary >>) do
<<check_plus(head)>> <> decode(tail)
end
@@ -147,7 +147,7 @@ wrap_interpol(_Line, Form) when is_binary(Form) ->
Form;
wrap_interpol(Line, Form) ->
- { '|', Line, [{ { '.', Line, ['Elixir.Binary.Chars', to_binary] }, Line, [Form]}, binary]}.
+ { '::', Line, [{ { '.', Line, ['Elixir.Binary.Chars', to_binary] }, Line, [Form]}, { binary, Line, nil }]}.
forms(String, StartLine, File) ->
case elixir_translator:raw_forms(String, StartLine, File) of
Oops, something went wrong. Retry.

0 comments on commit 2620444

Please sign in to comment.