diff --git a/lib/eex/lib/eex/compiler.ex b/lib/eex/lib/eex/compiler.ex index 5b832547a96..b4bc4488761 100644 --- a/lib/eex/lib/eex/compiler.ex +++ b/lib/eex/lib/eex/compiler.ex @@ -25,38 +25,38 @@ defmodule EEx.Compiler do # Generates the buffers by handling each expression from the tokenizer - defp generate_buffer([{:text, chars}|t], buffer, scope, state) do + defp generate_buffer([{:text, chars} | t], buffer, scope, state) do buffer = state.engine.handle_text(buffer, IO.chardata_to_string(chars)) generate_buffer(t, buffer, scope, state) end - defp generate_buffer([{:expr, line, mark, chars}|t], buffer, scope, state) do + defp generate_buffer([{:expr, line, mark, chars} | t], buffer, scope, state) do expr = Code.string_to_quoted!(chars, [line: line, file: state.file]) buffer = state.engine.handle_expr(buffer, IO.chardata_to_string(mark), expr) generate_buffer(t, buffer, scope, state) end - defp generate_buffer([{:start_expr, start_line, mark, chars}|t], buffer, scope, state) do + defp generate_buffer([{:start_expr, start_line, mark, chars} | t], buffer, scope, state) do {contents, line, t} = look_ahead_text(t, start_line, chars) - {contents, t} = generate_buffer(t, "", [contents|scope], + {contents, t} = generate_buffer(t, "", [contents | scope], %{state | quoted: [], line: line, start_line: start_line}) buffer = state.engine.handle_expr(buffer, IO.chardata_to_string(mark), contents) generate_buffer(t, buffer, scope, state) end - defp generate_buffer([{:middle_expr, line, _, chars}|t], buffer, [current|scope], state) do + defp generate_buffer([{:middle_expr, line, _, chars} | t], buffer, [current | scope], state) do {wrapped, state} = wrap_expr(current, line, buffer, chars, state) - generate_buffer(t, "", [wrapped|scope], %{state | line: line}) + generate_buffer(t, "", [wrapped | scope], %{state | line: line}) end - defp generate_buffer([{:end_expr, line, _, chars}|t], buffer, [current|_], state) do + defp generate_buffer([{:end_expr, line, _, chars} | t], buffer, [current | _], state) do {wrapped, state} = wrap_expr(current, line, buffer, chars, state) tuples = Code.string_to_quoted!(wrapped, [line: state.start_line, file: state.file]) buffer = insert_quoted(tuples, state.quoted) {buffer, t} end - defp generate_buffer([{:end_expr, line, _, chars}|_], _buffer, [], state) do + defp generate_buffer([{:end_expr, line, _, chars} | _], _buffer, [], state) do raise EEx.SyntaxError, message: "unexpected token #{inspect chars}", file: state.file, line: line end @@ -76,12 +76,12 @@ defmodule EEx.Compiler do key = length(state.quoted) placeholder = '__EEX__(' ++ Integer.to_char_list(key) ++ ');' {current ++ placeholder ++ new_lines ++ chars, - %{state | quoted: [{key, buffer}|state.quoted]}} + %{state | quoted: [{key, buffer} | state.quoted]}} end # Look text ahead on expressions - defp look_ahead_text([{:text, text}, {:middle_expr, line, _, chars}|t]=list, start, contents) do + defp look_ahead_text([{:text, text}, {:middle_expr, line, _, chars} | t]=list, start, contents) do if only_spaces?(text) do {contents ++ text ++ chars, line, t} else diff --git a/lib/eex/lib/eex/tokenizer.ex b/lib/eex/lib/eex/tokenizer.ex index 949b18b65e2..7c9a7684a61 100644 --- a/lib/eex/lib/eex/tokenizer.ex +++ b/lib/eex/lib/eex/tokenizer.ex @@ -25,7 +25,7 @@ defmodule EEx.Tokenizer do end defp tokenize('<%%' ++ t, line, opts, buffer, acc) do - tokenize t, line, opts, [?%, ?<|buffer], acc + tokenize t, line, opts, [?%, ?< | buffer], acc end defp tokenize('<%#' ++ t, line, opts, buffer, acc) do @@ -52,11 +52,11 @@ defmodule EEx.Tokenizer do end defp tokenize('\n' ++ t, line, opts, buffer, acc) do - tokenize t, line + 1, opts, [?\n|buffer], acc + tokenize t, line + 1, opts, [?\n | buffer], acc end - defp tokenize([h|t], line, opts, buffer, acc) do - tokenize t, line, opts, [h|buffer], acc + defp tokenize([h | t], line, opts, buffer, acc) do + tokenize t, line, opts, [h | buffer], acc end defp tokenize([], _line, _opts, buffer, acc) do @@ -75,16 +75,16 @@ defmodule EEx.Tokenizer do # Tokenize an expression until we find %> - defp expr([?%, ?>|t], line, buffer) do + defp expr([?%, ?> | t], line, buffer) do {:ok, buffer, line, t} end defp expr('\n' ++ t, line, buffer) do - expr t, line + 1, [?\n|buffer] + expr t, line + 1, [?\n | buffer] end - defp expr([h|t], line, buffer) do - expr t, line, [h|buffer] + defp expr([h | t], line, buffer) do + expr t, line, [h | buffer] end defp expr([], line, _buffer) do @@ -98,11 +98,11 @@ defmodule EEx.Tokenizer do # Middle tokens are marked with "->" or keywords # End tokens contain only the end word and optionally ")" - defp token_name([h|t]) when h in [?\s, ?\t, ?)] do + defp token_name([h | t]) when h in [?\s, ?\t, ?)] do token_name(t) end - defp token_name('od' ++ [h|_]) when h in [?\s, ?\t, ?)] do + defp token_name('od' ++ [h | _]) when h in [?\s, ?\t, ?)] do :start_expr end @@ -190,7 +190,7 @@ defmodule EEx.Tokenizer do defp trim_left(buffer, acc) do case {trim_whitespace(buffer), acc} do - {[?\n|_] = trimmed_buffer, _} -> {true, trimmed_buffer} + {[?\n | _] = trimmed_buffer, _} -> {true, trimmed_buffer} {[], []} -> {true, []} _ -> {false, buffer} end @@ -198,14 +198,14 @@ defmodule EEx.Tokenizer do defp trim_right(rest, line) do case trim_whitespace(rest) do - [?\r, ?\n|trimmed_rest] -> {true, trimmed_rest, line + 1} - [?\n|trimmed_rest] -> {true, trimmed_rest, line + 1} + [?\r, ?\n | trimmed_rest] -> {true, trimmed_rest, line + 1} + [?\n | trimmed_rest] -> {true, trimmed_rest, line + 1} [] -> {true, [], line} _ -> {false, rest, line} end end - defp trim_whitespace([h|t]) when h == ?\s or h == ?\t do + defp trim_whitespace([h | t]) when h == ?\s or h == ?\t do trim_whitespace(t) end diff --git a/lib/elixir/lib/access.ex b/lib/elixir/lib/access.ex index 1f4a3364df2..832c3bd4662 100644 --- a/lib/elixir/lib/access.ex +++ b/lib/elixir/lib/access.ex @@ -117,7 +117,7 @@ defmodule Access do stacktrace = System.stacktrace e = case stacktrace do - [unquote(top)|_] -> + [unquote(top) | _] -> %{unquote(e) | reason: "#{inspect unquote(struct)} does not implement the Access behaviour"} _ -> unquote(e) diff --git a/lib/elixir/lib/application.ex b/lib/elixir/lib/application.ex index b3d31fe4628..f5887ab4e8c 100644 --- a/lib/elixir/lib/application.ex +++ b/lib/elixir/lib/application.ex @@ -381,7 +381,7 @@ defmodule Application do Path.join(app_dir(app), path) end def app_dir(app, path) when is_list(path) do - Path.join([app_dir(app)|path]) + Path.join([app_dir(app) | path]) end @doc """ diff --git a/lib/elixir/lib/code.ex b/lib/elixir/lib/code.ex index b318f8354a8..1325fdf852a 100644 --- a/lib/elixir/lib/code.ex +++ b/lib/elixir/lib/code.ex @@ -594,7 +594,7 @@ defmodule Code do ## Examples # Get the documentation for the first function listed - iex> [fun|_] = Code.get_docs(Atom, :docs) |> Enum.sort() + iex> [fun | _] = Code.get_docs(Atom, :docs) |> Enum.sort() iex> {{_function, _arity}, _line, _kind, _signature, text} = fun iex> String.split(text, "\n") |> Enum.at(0) "Converts an atom to a char list." diff --git a/lib/elixir/lib/collectable.ex b/lib/elixir/lib/collectable.ex index a326b2e4f0d..6bcc8607626 100644 --- a/lib/elixir/lib/collectable.ex +++ b/lib/elixir/lib/collectable.ex @@ -49,7 +49,7 @@ end defimpl Collectable, for: List do def into(original) do {[], fn - list, {:cont, x} -> [x|list] + list, {:cont, x} -> [x | list] list, :done -> original ++ :lists.reverse(list) _, :halt -> :ok end} @@ -59,7 +59,7 @@ end defimpl Collectable, for: BitString do def into(original) do {original, fn - acc, {:cont, x} when is_bitstring(x) -> [acc|x] + acc, {:cont, x} when is_bitstring(x) -> [acc | x] acc, :done -> IO.iodata_to_binary(acc) _, :halt -> :ok end} diff --git a/lib/elixir/lib/dict.ex b/lib/elixir/lib/dict.ex index 6991a7affd1..819b4fe7481 100644 --- a/lib/elixir/lib/dict.ex +++ b/lib/elixir/lib/dict.ex @@ -82,19 +82,19 @@ defmodule Dict do def to_list(dict) do reduce(dict, {:cont, []}, fn - kv, acc -> {:cont, [kv|acc]} + kv, acc -> {:cont, [kv | acc]} end) |> elem(1) |> :lists.reverse end def keys(dict) do reduce(dict, {:cont, []}, fn - {k, _}, acc -> {:cont, [k|acc]} + {k, _}, acc -> {:cont, [k | acc]} end) |> elem(1) |> :lists.reverse end def values(dict) do reduce(dict, {:cont, []}, fn - {_, v}, acc -> {:cont, [v|acc]} + {_, v}, acc -> {:cont, [v | acc]} end) |> elem(1) |> :lists.reverse end diff --git a/lib/elixir/lib/enum.ex b/lib/elixir/lib/enum.ex index 89f6746fa57..4e4155f0a07 100644 --- a/lib/elixir/lib/enum.ex +++ b/lib/elixir/lib/enum.ex @@ -16,7 +16,7 @@ defprotocol Enumerable do Internally, `Enum.map/2` is implemented as follows: def map(enum, fun) do - reducer = fn x, acc -> {:cont, [fun.(x)|acc]} end + reducer = fn x, acc -> {:cont, [fun.(x) | acc]} end Enumerable.reduce(enum, {:cont, []}, reducer) |> elem(1) |> :lists.reverse() end @@ -106,10 +106,10 @@ defprotocol Enumerable do As an example, here is the implementation of `reduce` for lists: - def reduce(_, {:halt, acc}, _fun), do: {:halted, acc} - def reduce(list, {:suspend, acc}, fun), do: {:suspended, acc, &reduce(list, &1, fun)} - def reduce([], {:cont, acc}, _fun), do: {:done, acc} - def reduce([h|t], {:cont, acc}, fun), do: reduce(t, fun.(h, acc), fun) + def reduce(_, {:halt, acc}, _fun), do: {:halted, acc} + def reduce(list, {:suspend, acc}, fun), do: {:suspended, acc, &reduce(list, &1, fun)} + def reduce([], {:cont, acc}, _fun), do: {:done, acc} + def reduce([h | t], {:cont, acc}, fun), do: reduce(t, fun.(h, acc), fun) """ @spec reduce(t, acc, reducer) :: result @@ -191,7 +191,7 @@ defmodule Enum do end defmacrop next(_, entry, acc) do - quote do: [unquote(entry)|unquote(acc)] + quote do: [unquote(entry) | unquote(acc)] end defmacrop acc(h, n, _) do @@ -200,7 +200,7 @@ defmodule Enum do defmacrop next_with_acc(f, entry, h, n, _) do quote do - {[unquote(entry)|unquote(h)], unquote(n)} + {[unquote(entry) | unquote(h)], unquote(n)} end end @@ -367,7 +367,7 @@ defmodule Enum do :lists.reverse(acc) else buffer = :lists.reverse(buffer, take(pad, count - i)) - :lists.reverse([buffer|acc]) + :lists.reverse([buffer | acc]) end end @@ -439,7 +439,7 @@ defmodule Enum do end defp do_concat(enumerable) do - fun = &[&1|&2] + fun = &[&1 | &2] reduce(enumerable, [], &reduce(&1, &2, fun)) |> :lists.reverse end @@ -561,7 +561,7 @@ defmodule Enum do def drop(enumerable, n) when n >= 0 do res = reduce(enumerable, n, fn - x, acc when is_list(acc) -> [x|acc] + x, acc when is_list(acc) -> [x | acc] x, 0 -> [x] _, acc when acc > 0 -> acc - 1 end) @@ -876,7 +876,7 @@ defmodule Enum do @spec flat_map(t, (element -> t)) :: list def flat_map(enumerable, fun) do reduce(enumerable, [], fn(entry, acc) -> - reduce(fun.(entry), acc, &[&1|&2]) + reduce(fun.(entry), acc, &[&1 | &2]) end) |> :lists.reverse end @@ -911,9 +911,9 @@ defmodule Enum do {[], acc} -> {:cont, {list, acc}} {[entry], acc} -> - {:cont, {[entry|list], acc}} + {:cont, {[entry | list], acc}} {entries, acc} -> - {:cont, {reduce(entries, list, &[&1|&2]), acc}} + {:cont, {reduce(entries, list, &[&1 | &2]), acc}} end end) @@ -945,8 +945,8 @@ defmodule Enum do end) |> :lists.reverse() case list do - [] -> [] - [_|t] -> t # Head is a superfluous intersperser element + [] -> [] + [_ | t] -> t # Head is a superfluous intersperser element end end @@ -1069,7 +1069,7 @@ defmodule Enum do def join(enumerable, joiner) when is_binary(joiner) do reduced = reduce(enumerable, :first, fn entry, :first -> enum_to_string(entry) - entry, acc -> [acc, joiner|enum_to_string(entry)] + entry, acc -> [acc, joiner | enum_to_string(entry)] end) if reduced == :first do "" @@ -1129,7 +1129,7 @@ defmodule Enum do def map_join(enumerable, joiner, mapper) when is_binary(joiner) do reduced = reduce(enumerable, :first, fn entry, :first -> enum_to_string(mapper.(entry)) - entry, acc -> [acc, joiner|enum_to_string(mapper.(entry))] + entry, acc -> [acc, joiner | enum_to_string(mapper.(entry))] end) if reduced == :first do @@ -1167,7 +1167,7 @@ defmodule Enum do {list, acc} = reduce(enumerable, {[], acc}, fn(entry, {list, acc}) -> {new_entry, acc} = fun.(entry, acc) - {[new_entry|list], acc} + {[new_entry | list], acc} end) {:lists.reverse(list), acc} end @@ -1208,7 +1208,7 @@ defmodule Enum do """ @spec max_by(t, (element -> any)) :: element | no_return - def max_by([h|t], fun) do + def max_by([h | t], fun) do reduce(t, {h, fun.(h)}, fn(entry, {_, fun_max} = old) -> fun_entry = fun.(entry) if(fun_entry > fun_max, do: {entry, fun_entry}, else: old) @@ -1309,7 +1309,7 @@ defmodule Enum do """ @spec min_by(t, (element -> any)) :: element | no_return - def min_by([h|t], fun) do + def min_by([h | t], fun) do reduce(t, {h, fun.(h)}, fn(entry, {_, fun_min} = old) -> fun_entry = fun.(entry) if(fun_entry < fun_min, do: {entry, fun_entry}, else: old) @@ -1448,9 +1448,9 @@ defmodule Enum do {acc1, acc2} = reduce(enumerable, {[], []}, fn(entry, {acc1, acc2}) -> if fun.(entry) do - {[entry|acc1], acc2} + {[entry | acc1], acc2} else - {acc1, [entry|acc2]} + {acc1, [entry | acc2]} end end) @@ -1479,7 +1479,7 @@ defmodule Enum do def group_by(enumerable, map, fun) when is_map(map) do reduce(reverse(enumerable), map, fn entry, categories -> - Map.update(categories, fun.(entry), [entry], &[entry|&1]) + Map.update(categories, fun.(entry), [entry], &[entry | &1]) end) end @@ -1491,7 +1491,7 @@ defmodule Enum do IO.write :stderr, "warning: Enum.group_by/3 with a dictionary is deprecated, please use a map instead\n" <> Exception.format_stacktrace reduce(reverse(enumerable), dict, fn(entry, categories) -> - Dict.update(categories, fun.(entry), [entry], &[entry|&1]) + Dict.update(categories, fun.(entry), [entry], &[entry | &1]) end) end @@ -1554,7 +1554,7 @@ defmodule Enum do @spec reduce(t, (element, any -> any)) :: any def reduce(enumerable, fun) - def reduce([h|t], fun) do + def reduce([h | t], fun) do reduce(t, h, fun) end @@ -1655,7 +1655,7 @@ defmodule Enum do def reverse(enumerable, tail) do reduce(enumerable, to_list(tail), fn(entry, acc) -> - [entry|acc] + [entry | acc] end) end @@ -1773,7 +1773,7 @@ defmodule Enum do @spec shuffle(t) :: list def shuffle(enumerable) do randomized = reduce(enumerable, [], fn x, acc -> - [{:rand.uniform, x}|acc] + [{:rand.uniform, x} | acc] end) unwrap(:lists.keysort(1, randomized), []) end @@ -1824,9 +1824,9 @@ defmodule Enum do _entry, {start, count, _list} when start > 0 -> {:cont, {start-1, count, []}} entry, {start, count, list} when count > 1 -> - {:cont, {start, count-1, [entry|list]}} + {:cont, {start, count-1, [entry | list]}} entry, {start, count, list} -> - {:halt, {start, count, [entry|list]}} + {:halt, {start, count, [entry | list]}} end) |> elem(1) :lists.reverse(list) @@ -2026,9 +2026,9 @@ defmodule Enum do reduce(enumerable, {count, [], []}, fn(entry, {counter, acc1, acc2}) -> if counter > 0 do - {counter - 1, [entry|acc1], acc2} + {counter - 1, [entry | acc1], acc2} else - {counter, acc1, [entry|acc2]} + {counter, acc1, [entry | acc2]} end end) @@ -2058,9 +2058,9 @@ defmodule Enum do {list1, list2} = reduce(enumerable, {[], []}, fn entry, {acc1, []} -> - if(fun.(entry), do: {[entry|acc1], []}, else: {acc1, [entry]}) + if(fun.(entry), do: {[entry | acc1], []}, else: {acc1, [entry]}) entry, {acc1, acc2} -> - {acc1, [entry|acc2]} + {acc1, [entry | acc2]} end) {:lists.reverse(list1), :lists.reverse(list2)} @@ -2107,8 +2107,8 @@ defmodule Enum do fn(entry, {list, n}) -> case n do 0 -> {:halt, {list, n}} - 1 -> {:halt, {[entry|list], n - 1}} - _ -> {:cont, {[entry|list], n - 1}} + 1 -> {:halt, {[entry | list], n - 1}} + _ -> {:cont, {[entry | list], n - 1}} end end) :lists.reverse(res) @@ -2119,7 +2119,7 @@ defmodule Enum do {_count, buf1, buf2} = reduce(enumerable, {0, [], []}, fn entry, {n, buf1, buf2} -> - buf1 = [entry|buf1] + buf1 = [entry | buf1] n = n + 1 if n == count do {0, [], buf1} @@ -2135,10 +2135,10 @@ defmodule Enum do do: acc defp do_take_last([], [], _, acc), do: acc - defp do_take_last([], [h|t], count, acc), - do: do_take_last([], t, count-1, [h|acc]) - defp do_take_last([h|t], buf2, count, acc), - do: do_take_last(t, buf2, count-1, [h|acc]) + defp do_take_last([], [h | t], count, acc), + do: do_take_last([], t, count-1, [h | acc]) + defp do_take_last([h | t], buf2, count, acc), + do: do_take_last(t, buf2, count-1, [h | acc]) @doc """ Returns a list of every `nth` item in the enumerable, @@ -2267,7 +2267,7 @@ defmodule Enum do {_, res} = Enumerable.reduce(enumerable, {:cont, []}, fn(entry, acc) -> if fun.(entry) do - {:cont, [entry|acc]} + {:cont, [entry | acc]} else {:halt, acc} end @@ -2364,7 +2364,7 @@ defmodule Enum do def unzip(enumerable) do {list1, list2} = reduce(enumerable, {[], []}, fn({el1, el2}, {list1, list2}) -> - {[el1|list1], [el2|list2]} + {[el1 | list1], [el2 | list2]} end) {:lists.reverse(list1), :lists.reverse(list2)} @@ -2392,7 +2392,7 @@ defmodule Enum do end def zip(enumerable1, enumerable2) do - Stream.zip(enumerable1, enumerable2).({:cont, []}, &{:cont, [&1|&2]}) + Stream.zip(enumerable1, enumerable2).({:cont, []}, &{:cont, [&1 | &2]}) |> elem(1) |> :lists.reverse end @@ -2441,7 +2441,7 @@ defmodule Enum do ## all? - defp do_all?([h|t], fun) do + defp do_all?([h | t], fun) do if fun.(h) do do_all?(t, fun) else @@ -2455,7 +2455,7 @@ defmodule Enum do ## any? - defp do_any?([h|t], fun) do + defp do_any?([h | t], fun) do if fun.(h) do true else @@ -2469,13 +2469,13 @@ defmodule Enum do ## fetch - defp do_fetch([h|_], 0), do: {:ok, h} - defp do_fetch([_|t], n), do: do_fetch(t, n - 1) - defp do_fetch([], _), do: :error + defp do_fetch([h | _], 0), do: {:ok, h} + defp do_fetch([_ | t], n), do: do_fetch(t, n - 1) + defp do_fetch([], _), do: :error ## drop - defp do_drop([_|t], counter) when counter > 0 do + defp do_drop([_ | t], counter) when counter > 0 do do_drop(t, counter - 1) end @@ -2489,11 +2489,11 @@ defmodule Enum do ## drop_while - defp do_drop_while([h|t], fun) do + defp do_drop_while([h | t], fun) do if fun.(h) do do_drop_while(t, fun) else - [h|t] + [h | t] end end @@ -2503,7 +2503,7 @@ defmodule Enum do ## find - defp do_find([h|t], default, fun) do + defp do_find([h | t], default, fun) do if fun.(h) do h else @@ -2517,7 +2517,7 @@ defmodule Enum do ## find_index - defp do_find_index([h|t], counter, fun) do + defp do_find_index([h | t], counter, fun) do if fun.(h) do counter else @@ -2531,7 +2531,7 @@ defmodule Enum do ## find_value - defp do_find_value([h|t], default, fun) do + defp do_find_value([h | t], default, fun) do fun.(h) || do_find_value(t, default, fun) end @@ -2542,7 +2542,7 @@ defmodule Enum do ## shuffle defp unwrap([{_, h} | enumerable], t) do - unwrap(enumerable, [h|t]) + unwrap(enumerable, [h | t]) end defp unwrap([], t), do: t @@ -2552,9 +2552,9 @@ defmodule Enum do defp sort_reducer(entry, {:split, y, x, r, rs, bool}, fun) do cond do fun.(y, entry) == bool -> - {:split, entry, y, [x|r], rs, bool} + {:split, entry, y, [x | r], rs, bool} fun.(x, entry) == bool -> - {:split, y, entry, [x|r], rs, bool} + {:split, y, entry, [x | r], rs, bool} r == [] -> {:split, y, x, [entry], rs, bool} true -> @@ -2580,7 +2580,7 @@ defmodule Enum do end defp sort_reducer(entry, acc, _fun) do - [entry|acc] + [entry | acc] end defp sort_terminator({:split, y, x, r, rs, bool}, fun) do @@ -2669,8 +2669,8 @@ defmodule Enum do ## split - defp do_split([h|t], counter, acc) when counter > 0 do - do_split(t, counter - 1, [h|acc]) + defp do_split([h | t], counter, acc) when counter > 0 do + do_split(t, counter - 1, [h | acc]) end defp do_split(list, 0, acc) do @@ -2681,8 +2681,8 @@ defmodule Enum do {:lists.reverse(acc), []} end - defp do_split_reverse([h|t], counter, acc) when counter > 0 do - do_split_reverse(t, counter - 1, [h|acc]) + defp do_split_reverse([h | t], counter, acc) when counter > 0 do + do_split_reverse(t, counter - 1, [h | acc]) end defp do_split_reverse(list, 0, acc) do @@ -2695,11 +2695,11 @@ defmodule Enum do ## split_while - defp do_split_while([h|t], fun, acc) do + defp do_split_while([h | t], fun, acc) do if fun.(h) do - do_split_while(t, fun, [h|acc]) + do_split_while(t, fun, [h | acc]) else - {:lists.reverse(acc), [h|t]} + {:lists.reverse(acc), [h | t]} end end @@ -2709,8 +2709,8 @@ defmodule Enum do ## take - defp do_take([h|t], counter) when counter > 0 do - [h|do_take(t, counter - 1)] + defp do_take([h | t], counter) when counter > 0 do + [h | do_take(t, counter - 1)] end defp do_take(_list, 0) do @@ -2723,9 +2723,9 @@ defmodule Enum do ## take_while - defp do_take_while([h|t], fun) do + defp do_take_while([h | t], fun) do if fun.(h) do - [h|do_take_while(t, fun)] + [h | do_take_while(t, fun)] else [] end @@ -2737,12 +2737,12 @@ defmodule Enum do ## uniq - defp do_uniq([h|t], acc, fun) do + defp do_uniq([h | t], acc, fun) do fun_h = fun.(h) if Map.has_key?(acc, fun_h) do do_uniq(t, acc, fun) else - [h|do_uniq(t, Map.put(acc, fun_h, true), fun)] + [h | do_uniq(t, Map.put(acc, fun_h, true), fun)] end end @@ -2752,8 +2752,8 @@ defmodule Enum do ## zip - defp do_zip([h1|next1], [h2|next2]) do - [{h1, h2}|do_zip(next1, next2)] + defp do_zip([h1 | next1], [h2 | next2]) do + [{h1, h2} | do_zip(next1, next2)] end defp do_zip(_, []), do: [] @@ -2769,20 +2769,20 @@ defmodule Enum do [] end - defp do_slice([h|t], 0, count) do - [h|do_slice(t, 0, count-1)] + defp do_slice([h | t], 0, count) do + [h | do_slice(t, 0, count-1)] end - defp do_slice([_|t], start, count) do + defp do_slice([_ | t], start, count) do do_slice(t, start-1, count) end end defimpl Enumerable, for: List do - def reduce(_, {:halt, acc}, _fun), do: {:halted, acc} - def reduce(list, {:suspend, acc}, fun), do: {:suspended, acc, &reduce(list, &1, fun)} - def reduce([], {:cont, acc}, _fun), do: {:done, acc} - def reduce([h|t], {:cont, acc}, fun), do: reduce(t, fun.(h, acc), fun) + def reduce(_, {:halt, acc}, _fun), do: {:halted, acc} + def reduce(list, {:suspend, acc}, fun), do: {:suspended, acc, &reduce(list, &1, fun)} + def reduce([], {:cont, acc}, _fun), do: {:done, acc} + def reduce([h | t], {:cont, acc}, fun), do: reduce(t, fun.(h, acc), fun) def member?(_list, _value), do: {:error, __MODULE__} @@ -2795,10 +2795,10 @@ defimpl Enumerable, for: Map do do_reduce(:maps.to_list(map), acc, fun) end - defp do_reduce(_, {:halt, acc}, _fun), do: {:halted, acc} - defp do_reduce(list, {:suspend, acc}, fun), do: {:suspended, acc, &do_reduce(list, &1, fun)} - defp do_reduce([], {:cont, acc}, _fun), do: {:done, acc} - defp do_reduce([h|t], {:cont, acc}, fun), do: do_reduce(t, fun.(h, acc), fun) + defp do_reduce(_, {:halt, acc}, _fun), do: {:halted, acc} + defp do_reduce(list, {:suspend, acc}, fun), do: {:suspended, acc, &do_reduce(list, &1, fun)} + defp do_reduce([], {:cont, acc}, _fun), do: {:done, acc} + defp do_reduce([h | t], {:cont, acc}, fun), do: do_reduce(t, fun.(h, acc), fun) def member?(map, {key, value}) do {:ok, match?({:ok, ^value}, :maps.find(key, map))} diff --git a/lib/elixir/lib/exception.ex b/lib/elixir/lib/exception.ex index adfd4e3c546..4d8cef98efb 100644 --- a/lib/elixir/lib/exception.ex +++ b/lib/elixir/lib/exception.ex @@ -757,11 +757,11 @@ defmodule UnicodeConversionError do "encoding starting at #{inspect rest}" end - defp detail([h|_]) when is_integer(h) do + defp detail([h | _]) when is_integer(h) do "code point #{h}" end - defp detail([h|_]) do + defp detail([h | _]) do detail(h) end end @@ -841,10 +841,10 @@ defmodule ErlangError do def normalize({:badkey, key}, stacktrace) do term = case stacktrace || :erlang.get_stacktrace do - [{Map, :get_and_update!, [map, _, _], _}|_] -> map - [{Map, :update!, [map, _, _], _}|_] -> map - [{:maps, :update, [_, _, map], _}|_] -> map - [{:maps, :get, [_, map], _}|_] -> map + [{Map, :get_and_update!, [map, _, _], _} | _] -> map + [{Map, :update!, [map, _, _], _} | _] -> map + [{:maps, :update, [_, _, map], _} | _] -> map + [{:maps, :get, [_, map], _} | _] -> map _ -> nil end %KeyError{key: key, term: term} @@ -885,11 +885,11 @@ defmodule ErlangError do %ErlangError{original: other} end - defp from_stacktrace([{module, function, args, _}|_]) when is_list(args) do + defp from_stacktrace([{module, function, args, _} | _]) when is_list(args) do {module, function, length(args)} end - defp from_stacktrace([{module, function, arity, _}|_]) do + defp from_stacktrace([{module, function, arity, _} | _]) do {module, function, arity} end diff --git a/lib/elixir/lib/file.ex b/lib/elixir/lib/file.ex index 81600e3b38d..c2d7aea291d 100644 --- a/lib/elixir/lib/file.ex +++ b/lib/elixir/lib/file.ex @@ -610,7 +610,7 @@ defmodule File do {:ok, files} -> case mkdir(dest) do success when success in [:ok, {:error, :eexist}] -> - Enum.reduce(files, [dest|acc], fn(x, acc) -> + Enum.reduce(files, [dest | acc], fn(x, acc) -> do_cp_r(Path.join(src, x), Path.join(dest, x), callback, acc) end) {:error, reason} -> {:error, reason, dest} @@ -637,13 +637,13 @@ defmodule File do case F.copy(src, {dest, [:exclusive]}) do {:ok, _} -> copy_file_mode!(src, dest) - [dest|acc] + [dest | acc] {:error, :eexist} -> if path_differs?(src, dest) and callback.(src, dest) do case copy(src, dest) do {:ok, _} -> copy_file_mode!(src, dest) - [dest|acc] + [dest | acc] {:error, reason} -> {:error, reason, src} end else @@ -657,13 +657,13 @@ defmodule File do defp do_cp_link(link, src, dest, callback, acc) do case F.make_symlink(link, dest) do :ok -> - [dest|acc] + [dest | acc] {:error, :eexist} -> if path_differs?(src, dest) and callback.(src, dest) do # If rm/1 fails, F.make_symlink/2 will fail _ = rm(dest) case F.make_symlink(link, dest) do - :ok -> [dest|acc] + :ok -> [dest | acc] {:error, reason} -> {:error, reason, src} end else @@ -850,7 +850,7 @@ defmodule File do case res do {:ok, acc} -> case rmdir(path) do - :ok -> {:ok, [path|acc]} + :ok -> {:ok, [path | acc]} {:error, :enoent} -> res {:error, reason} -> {:error, reason, path} end @@ -870,7 +870,7 @@ defmodule File do defp do_rm_regular(path, {:ok, acc} = entry) do case rm(path) do - :ok -> {:ok, [path|acc]} + :ok -> {:ok, [path | acc]} {:error, :enoent} -> entry {:error, reason} -> {:error, reason, path} end @@ -882,7 +882,7 @@ defmodule File do # a file removal. defp do_rm_directory(path, {:ok, acc} = entry) do case rmdir(path) do - :ok -> {:ok, [path|acc]} + :ok -> {:ok, [path | acc]} {:error, :enotdir} -> do_rm_regular(path, entry) {:error, :enoent} -> entry {:error, reason} -> {:error, reason, path} @@ -1318,20 +1318,20 @@ defmodule File do @read_ahead 64*1024 - defp open_defaults([:char_list|t], _add_binary) do + defp open_defaults([:char_list | t], _add_binary) do open_defaults(t, false) end - defp open_defaults([:utf8|t], add_binary) do - open_defaults([{:encoding, :utf8}|t], add_binary) + defp open_defaults([:utf8 | t], add_binary) do + open_defaults([{:encoding, :utf8} | t], add_binary) end - defp open_defaults([:read_ahead|t], add_binary) do - open_defaults([{:read_ahead, @read_ahead}|t], add_binary) + defp open_defaults([:read_ahead | t], add_binary) do + open_defaults([{:read_ahead, @read_ahead} | t], add_binary) end - defp open_defaults([h|t], add_binary) do - [h|open_defaults(t, add_binary)] + defp open_defaults([h | t], add_binary) do + [h | open_defaults(t, add_binary)] end defp open_defaults([], true), do: [:binary] diff --git a/lib/elixir/lib/file/stream.ex b/lib/elixir/lib/file/stream.ex index 9e92274f726..a178466a375 100644 --- a/lib/elixir/lib/file/stream.ex +++ b/lib/elixir/lib/file/stream.ex @@ -22,9 +22,9 @@ defmodule File.Stream do modes = if raw do if :lists.keyfind(:read_ahead, 1, modes) == {:read_ahead, false} do - [:raw|modes] + [:raw | modes] else - [:raw, :read_ahead|modes] + [:raw, :read_ahead | modes] end else modes @@ -37,7 +37,7 @@ defmodule File.Stream do def into(%{path: path, modes: modes, raw: raw} = stream) do modes = for mode <- modes, not mode in [:read], do: mode - case :file.open(path, [:write|modes]) do + case :file.open(path, [:write | modes]) do {:ok, device} -> {:ok, into(device, stream, raw)} {:error, reason} -> diff --git a/lib/elixir/lib/float.ex b/lib/elixir/lib/float.ex index 2234213cbb7..590221487de 100644 --- a/lib/elixir/lib/float.ex +++ b/lib/elixir/lib/float.ex @@ -250,8 +250,8 @@ defmodule Float do :erlang.float_to_binary(float, expand_compact(options)) end - defp expand_compact([{:compact, false}|t]), do: expand_compact(t) - defp expand_compact([{:compact, true}|t]), do: [:compact|expand_compact(t)] - defp expand_compact([h|t]), do: [h|expand_compact(t)] - defp expand_compact([]), do: [] + defp expand_compact([{:compact, false} | t]), do: expand_compact(t) + defp expand_compact([{:compact, true} | t]), do: [:compact | expand_compact(t)] + defp expand_compact([h | t]), do: [h | expand_compact(t)] + defp expand_compact([]), do: [] end diff --git a/lib/elixir/lib/gen_event.ex b/lib/elixir/lib/gen_event.ex index 4a00cf18cba..44961cc2076 100644 --- a/lib/elixir/lib/gen_event.ex +++ b/lib/elixir/lib/gen_event.ex @@ -29,7 +29,7 @@ defmodule GenEvent do # Callbacks def handle_event({:log, x}, messages) do - {:ok, [x|messages]} + {:ok, [x | messages]} end def handle_call(:messages, messages) do @@ -899,13 +899,13 @@ defmodule GenEvent do {hib, server_collect_process_handlers(mode, event, streams, handlers, name)} end - defp server_split_process_handlers(mode, event, [handler|t], handlers, streams) do + defp server_split_process_handlers(mode, event, [handler | t], handlers, streams) do case handler(handler, :id) do {pid, _ref} when is_pid(pid) -> server_process_notify(mode, event, handler) - server_split_process_handlers(mode, event, t, handlers, [handler|streams]) + server_split_process_handlers(mode, event, t, handlers, [handler | streams]) _ -> - server_split_process_handlers(mode, event, t, [handler|handlers], streams) + server_split_process_handlers(mode, event, t, [handler | handlers], streams) end end @@ -921,10 +921,10 @@ defmodule GenEvent do defp mode_to_tag(:sync), do: :sync_notify defp mode_to_tag(:async), do: :notify - defp server_notify(event, fun, [handler|t], name, handlers, acc, hib) do + defp server_notify(event, fun, [handler | t], name, handlers, acc, hib) do case server_update(handler, fun, event, name, handlers) do {new_hib, handler} -> - server_notify(event, fun, t, name, handlers, [handler|acc], hib or new_hib) + server_notify(event, fun, t, name, handlers, [handler | acc], hib or new_hib) :error -> server_notify(event, fun, t, name, handlers, acc, hib) end @@ -958,16 +958,16 @@ defmodule GenEvent do end end - defp server_collect_process_handlers(:async, event, [handler|t], handlers, name) do - server_collect_process_handlers(:async, event, t, [handler|handlers], name) + defp server_collect_process_handlers(:async, event, [handler | t], handlers, name) do + server_collect_process_handlers(:async, event, t, [handler | handlers], name) end - defp server_collect_process_handlers(mode, event, [handler|t], handlers, name) when mode in [:sync, :ack] do + defp server_collect_process_handlers(mode, event, [handler | t], handlers, name) when mode in [:sync, :ack] do handler(ref: ref, id: id) = handler receive do {^ref, :ok} -> - server_collect_process_handlers(mode, event, t, [handler|handlers], name) + server_collect_process_handlers(mode, event, t, [handler | handlers], name) {_from, tag, {:delete_handler, ^id, args}} -> do_terminate(handler, args, :remove, name, :normal) reply(tag, :ok) @@ -1057,9 +1057,9 @@ defmodule GenEvent do {:ok, res} -> case res do {:ok, state} -> - {false, succ, [handler(handler, state: state)|handlers]} + {false, succ, [handler(handler, state: state) | handlers]} {:ok, state, :hibernate} -> - {true, succ, [handler(handler, state: state)|handlers]} + {true, succ, [handler(handler, state: state) | handlers]} {:error, _} = error -> {false, error, handlers} other -> @@ -1122,7 +1122,7 @@ defmodule GenEvent do defp report_error(handler, reason, state, last_in, name) do reason = case reason do - {:undef, [{m, f, a, _}|_]=mfas} -> + {:undef, [{m, f, a, _} | _]=mfas} -> cond do :code.is_loaded(m) === false -> {:"module could not be loaded", mfas} diff --git a/lib/elixir/lib/gen_server.ex b/lib/elixir/lib/gen_server.ex index 9bb5763bd59..134c56b0f88 100644 --- a/lib/elixir/lib/gen_server.ex +++ b/lib/elixir/lib/gen_server.ex @@ -23,12 +23,12 @@ defmodule GenServer do # Callbacks - def handle_call(:pop, _from, [h|t]) do + def handle_call(:pop, _from, [h | t]) do {:reply, h, t} end def handle_cast({:push, item}, state) do - {:noreply, [item|state]} + {:noreply, [item | state]} end end @@ -129,7 +129,7 @@ defmodule GenServer do # Server (callbacks) - def handle_call(:pop, _from, [h|t]) do + def handle_call(:pop, _from, [h | t]) do {:reply, h, t} end @@ -139,7 +139,7 @@ defmodule GenServer do end def handle_cast({:push, item}, state) do - {:noreply, [item|state]} + {:noreply, [item | state]} end def handle_cast(request, state) do @@ -739,6 +739,6 @@ defmodule GenServer do @compile {:inline, [nodes: 0]} defp nodes do - [node()|:erlang.nodes()] + [node() | :erlang.nodes()] end end diff --git a/lib/elixir/lib/hash_dict.ex b/lib/elixir/lib/hash_dict.ex index 6795b7eb211..5ee884628bf 100644 --- a/lib/elixir/lib/hash_dict.ex +++ b/lib/elixir/lib/hash_dict.ex @@ -90,7 +90,7 @@ defmodule HashDict do defp do_fetch(node, key, hash) do index = key_mask(hash) case elem(node, index) do - [^key|v] -> {:ok, v} + [^key | v] -> {:ok, v} {^key, v, _} -> {:ok, v} {_, _, n} -> do_fetch(n, key, key_shift(hash)) _ -> :error @@ -101,11 +101,11 @@ defmodule HashDict do index = key_mask(hash) case elem(node, index) do [] -> - {put_elem(node, index, [key|value]), 1} - [^key|_] -> - {put_elem(node, index, [key|value]), 0} - [k|v] -> - n = put_elem(@node_template, key_mask(key_shift(hash)), [key|value]) + {put_elem(node, index, [key | value]), 1} + [^key | _] -> + {put_elem(node, index, [key | value]), 0} + [k | v] -> + n = put_elem(@node_template, key_mask(key_shift(hash)), [key | value]) {put_elem(node, index, {k, v, n}), 1} {^key, _, n} -> {put_elem(node, index, {key, value, n}), 0} @@ -119,11 +119,11 @@ defmodule HashDict do index = key_mask(hash) case elem(node, index) do [] -> - {put_elem(node, index, [key|initial.()]), 1} - [^key|value] -> - {put_elem(node, index, [key|fun.(value)]), 0} - [k|v] -> - n = put_elem(@node_template, key_mask(key_shift(hash)), [key|initial.()]) + {put_elem(node, index, [key | initial.()]), 1} + [^key | value] -> + {put_elem(node, index, [key | fun.(value)]), 0} + [k | v] -> + n = put_elem(@node_template, key_mask(key_shift(hash)), [key | initial.()]) {put_elem(node, index, {k, v, n}), 1} {^key, value, n} -> {put_elem(node, index, {key, fun.(value), n}), 0} @@ -138,16 +138,16 @@ defmodule HashDict do case elem(node, index) do [] -> :error - [^key|value] -> + [^key | value] -> {put_elem(node, index, []), value} - [_|_] -> + [_ | _] -> :error {^key, value, n} -> {put_elem(node, index, do_compact_node(n)), value} {k, v, n} -> case do_delete(n, key, key_shift(hash)) do {@node_template, value} -> - {put_elem(node, index, [k|v]), value} + {put_elem(node, index, [k | v]), value} {n, value} -> {put_elem(node, index, {k, v, n}), value} :error -> @@ -159,9 +159,9 @@ defmodule HashDict do Enum.each 0..(@node_size - 1), fn index -> defp do_compact_node(node) when elem(node, unquote(index)) != [] do case elem(node, unquote(index)) do - [k|v] -> + [k | v] -> case put_elem(node, unquote(index), []) do - @node_template -> [k|v] + @node_template -> [k | v] n -> {k, v, n} end {k, v, n} -> @@ -184,7 +184,7 @@ defmodule HashDict do next.(acc) end - defp do_reduce_each([k|v], {:cont, acc}, fun, next) do + defp do_reduce_each([k | v], {:cont, acc}, fun, next) do next.(fun.({k, v}, acc)) end diff --git a/lib/elixir/lib/hash_set.ex b/lib/elixir/lib/hash_set.ex index 335ae42dab6..fd07f3c06af 100644 --- a/lib/elixir/lib/hash_set.ex +++ b/lib/elixir/lib/hash_set.ex @@ -42,7 +42,7 @@ defmodule HashSet do end def to_list(set) do - set_fold(set, [], &[&1|&2]) |> :lists.reverse + set_fold(set, [], &[&1 | &2]) |> :lists.reverse end def equal?(%HashSet{size: size1} = set1, %HashSet{size: size2} = set2) do @@ -110,10 +110,10 @@ defmodule HashSet do defp do_member?(node, term, hash) do index = key_mask(hash) case elem(node, index) do - [] -> false - [^term|_] -> true - [_] -> false - [_|n] -> do_member?(n, term, key_shift(hash)) + [] -> false + [^term | _] -> true + [_] -> false + [_ | n] -> do_member?(n, term, key_shift(hash)) end end @@ -122,14 +122,14 @@ defmodule HashSet do case elem(node, index) do [] -> {put_elem(node, index, [term]), 1} - [^term|_] -> + [^term | _] -> {node, 0} [t] -> n = put_elem(@node_template, key_mask(key_shift(hash)), [term]) - {put_elem(node, index, [t|n]), 1} - [t|n] -> + {put_elem(node, index, [t | n]), 1} + [t | n] -> {n, counter} = do_put(n, term, key_shift(hash)) - {put_elem(node, index, [t|n]), counter} + {put_elem(node, index, [t | n]), counter} end end @@ -142,14 +142,14 @@ defmodule HashSet do {:ok, put_elem(node, index, [])} [_] -> :error - [^term|n] -> + [^term | n] -> {:ok, put_elem(node, index, do_compact_node(n))} - [t|n] -> + [t | n] -> case do_delete(n, term, key_shift(hash)) do {:ok, @node_template} -> {:ok, put_elem(node, index, [t])} {:ok, n} -> - {:ok, put_elem(node, index, [t|n])} + {:ok, put_elem(node, index, [t | n])} :error -> :error end @@ -162,19 +162,19 @@ defmodule HashSet do [t] -> case put_elem(node, unquote(index), []) do @node_template -> [t] - n -> [t|n] + n -> [t | n] end - [t|n] -> - [t|put_elem(node, unquote(index), do_compact_node(n))] + [t | n] -> + [t | put_elem(node, unquote(index), do_compact_node(n))] end end end ## Set fold - defp do_fold_each([], acc, _fun), do: acc - defp do_fold_each([t], acc, fun), do: fun.(t, acc) - defp do_fold_each([t|n], acc, fun), do: do_fold(n, fun.(t, acc), fun, @node_size) + defp do_fold_each([], acc, _fun), do: acc + defp do_fold_each([t], acc, fun), do: fun.(t, acc) + defp do_fold_each([t | n], acc, fun), do: do_fold(n, fun.(t, acc), fun, @node_size) defp do_fold(node, acc, fun, count) when count > 0 do acc = do_fold_each(:erlang.element(count, node), acc, fun) @@ -203,7 +203,7 @@ defmodule HashSet do next.(fun.(t, acc)) end - defp do_reduce_each([t|n], {:cont, acc}, fun, next) do + defp do_reduce_each([t | n], {:cont, acc}, fun, next) do do_reduce(n, fun.(t, acc), fun, @node_size, next) end diff --git a/lib/elixir/lib/inspect.ex b/lib/elixir/lib/inspect.ex index 80be71478cb..d66e5dab606 100644 --- a/lib/elixir/lib/inspect.ex +++ b/lib/elixir/lib/inspect.ex @@ -310,15 +310,15 @@ defimpl Inspect, for: List do def keyword?(_other), do: false @doc false - def printable?([c|cs]) when is_integer(c) and c in 32..126, do: printable?(cs) - def printable?([?\n|cs]), do: printable?(cs) - def printable?([?\r|cs]), do: printable?(cs) - def printable?([?\t|cs]), do: printable?(cs) - def printable?([?\v|cs]), do: printable?(cs) - def printable?([?\b|cs]), do: printable?(cs) - def printable?([?\f|cs]), do: printable?(cs) - def printable?([?\e|cs]), do: printable?(cs) - def printable?([?\a|cs]), do: printable?(cs) + def printable?([c | cs]) when is_integer(c) and c in 32..126, do: printable?(cs) + def printable?([?\n | cs]), do: printable?(cs) + def printable?([?\r | cs]), do: printable?(cs) + def printable?([?\t | cs]), do: printable?(cs) + def printable?([?\v | cs]), do: printable?(cs) + def printable?([?\b | cs]), do: printable?(cs) + def printable?([?\f | cs]), do: printable?(cs) + def printable?([?\e | cs]), do: printable?(cs) + def printable?([?\a | cs]), do: printable?(cs) def printable?([]), do: true def printable?(_), do: false diff --git a/lib/elixir/lib/inspect/algebra.ex b/lib/elixir/lib/inspect/algebra.ex index 1746ae8c9dd..49333304376 100644 --- a/lib/elixir/lib/inspect/algebra.ex +++ b/lib/elixir/lib/inspect/algebra.ex @@ -418,7 +418,7 @@ defmodule Inspect.Algebra do def fold_doc(list, fun) def fold_doc([], _), do: empty def fold_doc([doc], _), do: doc - def fold_doc([d|ds], fun), do: fun.(d, fold_doc(ds, fun)) + def fold_doc([d | ds], fun), do: fun.(d, fold_doc(ds, fun)) # Elixir conveniences @@ -490,14 +490,14 @@ defmodule Inspect.Algebra do fun.(h, %{opts | limit: limit}) end - defp do_surround_many([h|t], limit, opts, fun, sep) when is_list(t) do + defp do_surround_many([h | t], limit, opts, fun, sep) when is_list(t) do limit = decrement(limit) h = fun.(h, %{opts | limit: limit}) t = do_surround_many(t, limit, opts, fun, sep) do_join(h, t, sep) end - defp do_surround_many([h|t], limit, opts, fun, _sep) do + defp do_surround_many([h | t], limit, opts, fun, _sep) do limit = decrement(limit) h = fun.(h, %{opts | limit: limit}) t = fun.(t, %{opts | limit: limit}) diff --git a/lib/elixir/lib/io.ex b/lib/elixir/lib/io.ex index e1d4c2eb121..4b5796c3a93 100644 --- a/lib/elixir/lib/io.ex +++ b/lib/elixir/lib/io.ex @@ -369,7 +369,7 @@ defmodule IO do iex> bin1 = <<1, 2, 3>> iex> bin2 = <<4, 5>> iex> bin3 = <<6>> - iex> IO.iodata_to_binary([bin1, 1, [2, 3, bin2], 4|bin3]) + iex> IO.iodata_to_binary([bin1, 1, [2, 3, bin2], 4 | bin3]) <<1, 2, 3, 1, 2, 3, 4, 5, 4, 6>> iex> bin = <<1, 2, 3>> @@ -389,7 +389,7 @@ defmodule IO do ## Examples - iex> IO.iodata_length([1, 2|<<3, 4>>]) + iex> IO.iodata_length([1, 2 | <<3, 4>>]) 4 """ diff --git a/lib/elixir/lib/io/ansi/docs.ex b/lib/elixir/lib/io/ansi/docs.ex index abfe9b59ee5..c067db45869 100644 --- a/lib/elixir/lib/io/ansi/docs.ex +++ b/lib/elixir/lib/io/ansi/docs.ex @@ -197,7 +197,7 @@ defmodule IO.ANSI.Docs do defp write_text(text, indent, options) do case Enum.reverse(text) do - [:no_wrap|rest] -> write_text(rest, indent, options, true) + [:no_wrap | rest] -> write_text(rest, indent, options, true) rest -> write_text(rest, indent, options, false) end end @@ -229,7 +229,7 @@ defmodule IO.ANSI.Docs do end defp process_code([" " <> line | rest], code, indent, options) do - process_code(rest, [line|code], indent, options) + process_code(rest, [line | code], indent, options) end defp process_code(rest, code, indent, options) do @@ -250,7 +250,7 @@ defmodule IO.ANSI.Docs do if line === delimiter do process_code(rest, code, indent, options) else - process_fenced_code(rest, [line|code], indent, options, delimiter) + process_fenced_code(rest, [line | code], indent, options, delimiter) end end @@ -379,13 +379,13 @@ defmodule IO.ANSI.Docs do write_with_wrap(rest, available, indent, false) end - defp take_words([word|words], available, acc) do + defp take_words([word | words], available, acc) do available = available - length_without_escape(word, 0) cond do # It fits, take one for space and continue decreasing available > 0 -> - take_words(words, available - 1, [word|acc]) + take_words(words, available - 1, [word | acc]) # No space but we got no words acc == [] -> @@ -393,7 +393,7 @@ defmodule IO.ANSI.Docs do # Otherwise true -> - {Enum.reverse(acc), [word|words]} + {Enum.reverse(acc), [word | words]} end end @@ -466,80 +466,80 @@ defmodule IO.ANSI.Docs do defp handle_inline(<>, nil, buffer, acc, options) when rest != "" and delimiter in @delimiters do - handle_inline(rest, ?d, ["**"], [delimiter, Enum.reverse(buffer)|acc], options) + handle_inline(rest, ?d, ["**"], [delimiter, Enum.reverse(buffer) | acc], options) end defp handle_inline(<>, nil, buffer, acc, options) when rest != "" and delimiter in @delimiters and mark in @single do - handle_inline(rest, mark, [<>], [delimiter, Enum.reverse(buffer)|acc], options) + handle_inline(rest, mark, [<>], [delimiter, Enum.reverse(buffer) | acc], options) end defp handle_inline(<>, nil, buffer, acc, options) when rest != "" do - handle_inline(rest, ?`, ["`"], [Enum.reverse(buffer)|acc], options) + handle_inline(rest, ?`, ["`"], [Enum.reverse(buffer) | acc], options) end # Clauses for handling escape defp handle_inline(<>, nil, buffer, acc, options) when rest != "" do - handle_inline(rest, ?d, ["**"], [?\\, Enum.reverse(buffer)|acc], options) + handle_inline(rest, ?d, ["**"], [?\\, Enum.reverse(buffer) | acc], options) end defp handle_inline(<>, nil, buffer, acc, options) when rest != "" and mark in @single do - handle_inline(rest, mark, [<>], [?\\, Enum.reverse(buffer)|acc], options) + handle_inline(rest, mark, [<>], [?\\, Enum.reverse(buffer) | acc], options) end defp handle_inline(<>, limit, buffer, acc, options) do - handle_inline(rest, limit, [?\\|buffer], acc, options) + handle_inline(rest, limit, [?\\ | buffer], acc, options) end # An escape is not valid inside ` defp handle_inline(<>, limit, buffer, acc, options) when not(mark == limit and mark == ?`) do - handle_inline(rest, limit, [mark|buffer], acc, options) + handle_inline(rest, limit, [mark | buffer], acc, options) end # Inline end defp handle_inline(<>, ?d, buffer, acc, options) when delimiter in @delimiters do - handle_inline(<>, nil, [], [inline_buffer(buffer, options)|acc], options) + handle_inline(<>, nil, [], [inline_buffer(buffer, options) | acc], options) end defp handle_inline(<>, mark, buffer, acc, options) when delimiter in @delimiters and mark in @single do - handle_inline(<>, nil, [], [inline_buffer(buffer, options)|acc], options) + handle_inline(<>, nil, [], [inline_buffer(buffer, options) | acc], options) end defp handle_inline(<>, ?d, buffer, acc, options) when rest == "" do - handle_inline(<<>>, nil, [], [inline_buffer(buffer, options)|acc], options) + handle_inline(<<>>, nil, [], [inline_buffer(buffer, options) | acc], options) end defp handle_inline(<>, mark, buffer, acc, options) when rest == "" and mark in @single do - handle_inline(<<>>, nil, [], [inline_buffer(buffer, options)|acc], options) + handle_inline(<<>>, nil, [], [inline_buffer(buffer, options) | acc], options) end defp handle_inline(<>, ?`, buffer, acc, options) do - handle_inline(rest, nil, [], [inline_buffer(buffer, options)|acc], options) + handle_inline(rest, nil, [], [inline_buffer(buffer, options) | acc], options) end # Catch all defp handle_inline(<>, mark, buffer, acc, options) do - handle_inline(rest, mark, [char|buffer], acc, options) + handle_inline(rest, mark, [char | buffer], acc, options) end defp handle_inline(<<>>, _mark, buffer, acc, _options) do - IO.iodata_to_binary Enum.reverse([Enum.reverse(buffer)|acc]) + IO.iodata_to_binary Enum.reverse([Enum.reverse(buffer) | acc]) end defp inline_buffer(buffer, options) do - [h|t] = Enum.reverse([IO.ANSI.reset|buffer]) - [color_for(h, options)|t] + [h | t] = Enum.reverse([IO.ANSI.reset | buffer]) + [color_for(h, options) | t] end defp color_for(mark, colors) do diff --git a/lib/elixir/lib/kernel.ex b/lib/elixir/lib/kernel.ex index 1a1ba495e0c..f96d0d85ac6 100644 --- a/lib/elixir/lib/kernel.ex +++ b/lib/elixir/lib/kernel.ex @@ -1288,7 +1288,7 @@ defmodule Kernel do # Extracts concatenations in order to optimize many # concatenations into one single clause. defp extract_concatenations({:<>, _, [left, right]}) do - [wrap_concatenation(left)|extract_concatenations(right)] + [wrap_concatenation(left) | extract_concatenations(right)] end defp extract_concatenations(other) do @@ -1551,7 +1551,7 @@ defmodule Kernel do iex> inspect('bar') "'bar'" - iex> inspect([0|'bar']) + iex> inspect([0 | 'bar']) "[0, 98, 97, 114]" iex> inspect(100, base: :octal) @@ -1704,17 +1704,17 @@ defmodule Kernel do def get_in(data, [h]) when is_function(h), do: h.(:get, data, &(&1)) - def get_in(data, [h|t]) when is_function(h), + def get_in(data, [h | t]) when is_function(h), do: h.(:get, data, &get_in(&1, t)) def get_in(nil, [_]), do: nil - def get_in(nil, [_|t]), + def get_in(nil, [_ | t]), do: get_in(nil, t) def get_in(data, [h]), do: Access.get(data, h) - def get_in(data, [h|t]), + def get_in(data, [h | t]), do: get_in(Access.get(data, h), t) @doc """ @@ -1811,12 +1811,12 @@ defmodule Kernel do def get_and_update_in(data, [h], fun) when is_function(h), do: h.(:get_and_update, data, fun) - def get_and_update_in(data, [h|t], fun) when is_function(h), + def get_and_update_in(data, [h | t], fun) when is_function(h), do: h.(:get_and_update, data, &get_and_update_in(&1, t, fun)) def get_and_update_in(data, [h], fun), do: Access.get_and_update(data, h, fun) - def get_and_update_in(data, [h|t], fun), + def get_and_update_in(data, [h | t], fun), do: Access.get_and_update(data, h, &get_and_update_in(&1, t, fun)) @doc """ @@ -1838,18 +1838,18 @@ defmodule Kernel do """ @spec pop_in(Access.t, nonempty_list(term)) :: Access.t def pop_in(data, keys) - def pop_in(nil, [h|_]), do: Access.pop(nil, h) + def pop_in(nil, [h | _]), do: Access.pop(nil, h) def pop_in(data, keys), do: do_pop_in(data, keys) - defp do_pop_in(nil, [_|_]), + defp do_pop_in(nil, [_ | _]), do: :pop defp do_pop_in(data, [h]) when is_function(h), do: h.(:get_and_update, data, fn _ -> :pop end) - defp do_pop_in(data, [h|t]) when is_function(h), + defp do_pop_in(data, [h | t]) when is_function(h), do: h.(:get_and_update, data, &do_pop_in(&1, t)) defp do_pop_in(data, [h]), do: Access.pop(data, h) - defp do_pop_in(data, [h|t]), + defp do_pop_in(data, [h | t]), do: Access.get_and_update(data, h, &do_pop_in(&1, t)) @doc """ @@ -1881,9 +1881,9 @@ defmodule Kernel do """ defmacro put_in(path, value) do case unnest(path, [], true, "put_in/2") do - {[h|t], true} -> + {[h | t], true} -> nest_update_in(h, t, quote(do: fn _ -> unquote(value) end)) - {[h|t], false} -> + {[h | t], false} -> expr = nest_get_and_update_in(h, t, quote(do: fn _ -> {nil, unquote(value)} end)) quote do: :erlang.element(2, unquote(expr)) end @@ -1919,7 +1919,7 @@ defmodule Kernel do and the deletion will be considered a success. """ defmacro pop_in(path) do - {[h|t], _} = unnest(path, [], true, "pop_in/1") + {[h | t], _} = unnest(path, [], true, "pop_in/1") nest_pop_in(:map, h, t) end @@ -1952,9 +1952,9 @@ defmodule Kernel do """ defmacro update_in(path, fun) do case unnest(path, [], true, "update_in/2") do - {[h|t], true} -> + {[h | t], true} -> nest_update_in(h, t, fun) - {[h|t], false} -> + {[h | t], false} -> expr = nest_get_and_update_in(h, t, quote(do: fn x -> {nil, unquote(fun).(x)} end)) quote do: :erlang.element(2, unquote(expr)) end @@ -2009,7 +2009,7 @@ defmodule Kernel do """ defmacro get_and_update_in(path, fun) do - {[h|t], _} = unnest(path, [], true, "get_and_update_in/2") + {[h | t], _} = unnest(path, [], true, "get_and_update_in/2") nest_get_and_update_in(h, t, fun) end @@ -2019,7 +2019,7 @@ defmodule Kernel do fn x -> unquote(nest_update_in(quote(do: x), list, fun)) end end end - defp nest_update_in(h, [{:map, key}|t], fun) do + defp nest_update_in(h, [{:map, key} | t], fun) do quote do Map.update!(unquote(h), unquote(key), unquote(nest_update_in(t, fun))) end @@ -2031,7 +2031,7 @@ defmodule Kernel do fn x -> unquote(nest_get_and_update_in(quote(do: x), list, fun)) end end end - defp nest_get_and_update_in(h, [{:access, key}|t], fun) do + defp nest_get_and_update_in(h, [{:access, key} | t], fun) do quote do Access.get_and_update( unquote(h), @@ -2040,7 +2040,7 @@ defmodule Kernel do ) end end - defp nest_get_and_update_in(h, [{:map, key}|t], fun) do + defp nest_get_and_update_in(h, [{:map, key} | t], fun) do quote do Map.get_and_update!(unquote(h), unquote(key), unquote(nest_get_and_update_in(t, fun))) end @@ -2065,7 +2065,7 @@ defmodule Kernel do raise ArgumentError, "cannot use pop_in when the last segment is a map/struct field. " <> "This would effectively remove the field #{inspect key} from the map/struct" end - defp nest_pop_in(_, h, [{:map, key}|t]) do + defp nest_pop_in(_, h, [{:map, key} | t]) do quote do Map.get_and_update!(unquote(h), unquote(key), unquote(nest_pop_in(:map, t))) end @@ -2079,21 +2079,21 @@ defmodule Kernel do end end end - defp nest_pop_in(_, h, [{:access, key}|t]) do + defp nest_pop_in(_, h, [{:access, key} | t]) do quote do Access.get_and_update(unquote(h), unquote(key), unquote(nest_pop_in(:access, t))) end end defp unnest({{:., _, [Access, :get]}, _, [expr, key]}, acc, _all_map?, kind) do - unnest(expr, [{:access, key}|acc], false, kind) + unnest(expr, [{:access, key} | acc], false, kind) end defp unnest({{:., _, [expr, key]}, _, []}, acc, all_map?, kind) when is_tuple(expr) and :erlang.element(1, expr) != :__aliases__ and :erlang.element(1, expr) != :__MODULE__ do - unnest(expr, [{:map, key}|acc], all_map?, kind) + unnest(expr, [{:map, key} | acc], all_map?, kind) end defp unnest(other, [], _all_map?, kind) do @@ -2103,7 +2103,7 @@ defmodule Kernel do defp unnest(other, acc, all_map?, kind) do case proper_start?(other) do - true -> {[other|acc], all_map?} + true -> {[other | acc], all_map?} false -> raise ArgumentError, "expression given to #{kind} must start with a variable, local or remote call " <> @@ -2735,7 +2735,7 @@ defmodule Kernel do notation. """ defmacro left |> right do - [{h, _}|t] = Macro.unpipe({:|>, [], [left, right]}) + [{h, _} | t] = Macro.unpipe({:|>, [], [left, right]}) :lists.foldl fn {x, pos}, acc -> # TODO: raise an error in `Macro.pipe` by 1.4 case Macro.pipe_warning(x) do @@ -2837,7 +2837,7 @@ defmodule Kernel do quote do: Elixir.Enum.member?(unquote(right), unquote(left)) [] -> false - [h|t] -> + [h | t] -> :lists.foldr(fn x, acc -> quote do: :erlang.or(unquote(comp(left, x)), unquote(acc)) end, comp(left, h), t) @@ -3074,7 +3074,7 @@ defmodule Kernel do do: raw # defmodule Elixir.Alias - defp expand_module({:__aliases__, _, [:Elixir|t]}, module, _env) when t != [], + defp expand_module({:__aliases__, _, [:Elixir | t]}, module, _env) when t != [], do: module # defmodule Alias in root @@ -3083,14 +3083,14 @@ defmodule Kernel do # defmodule Alias nested defp expand_module({:__aliases__, _, t}, _module, env), - do: :elixir_aliases.concat([env.module|t]) + do: :elixir_aliases.concat([env.module | t]) # defmodule _ defp expand_module(_raw, module, env), do: :elixir_aliases.concat([env.module, module]) # quote vars to be injected into the module definition - defp module_vars([{key, kind}|vars], counter) do + defp module_vars([{key, kind} | vars], counter) do var = case is_atom(kind) do true -> {key, [warn: false], kind} @@ -3099,7 +3099,7 @@ defmodule Kernel do under = String.to_atom(<<"_@", :erlang.integer_to_binary(counter)::binary>>) args = [key, kind, under, var] - [{:{}, [], args}|module_vars(vars, counter+1)] + [{:{}, [], args} | module_vars(vars, counter+1)] end defp module_vars([], _counter) do @@ -3131,17 +3131,17 @@ defmodule Kernel do end end - defp module_nesting([x|t1], [x|t2], acc, full), - do: module_nesting(t1, t2, [x|acc], full) - defp module_nesting([], [h|_], acc, _full), + defp module_nesting([x | t1], [x | t2], acc, full), + do: module_nesting(t1, t2, [x | acc], full) + defp module_nesting([], [h | _], acc, _full), do: {String.to_atom(<<"Elixir.", h::binary>>), - :elixir_aliases.concat(:lists.reverse([h|acc]))} + :elixir_aliases.concat(:lists.reverse([h | acc]))} defp module_nesting(_, _, _acc, full), do: {nil, full} defp split_module(atom) do case :binary.split(Atom.to_string(atom), ".", [:global]) do - ["Elixir"|t] -> t + ["Elixir" | t] -> t _ -> [] end end @@ -3445,7 +3445,7 @@ defmodule Kernel do """ defmacro defexception(fields) do fields = case is_list(fields) do - true -> [{:__exception__, true}|fields] + true -> [{:__exception__, true} | fields] false -> quote(do: [{:__exception__, true}] ++ unquote(fields)) end @@ -4124,7 +4124,7 @@ defmodule Kernel do ## Shared functions defp optimize_boolean({:case, meta, args}) do - {:case, [{:optimize_boolean, true}|meta], args} + {:case, [{:optimize_boolean, true} | meta], args} end # We need this check only for bootstrap purposes. diff --git a/lib/elixir/lib/kernel/cli.ex b/lib/elixir/lib/kernel/cli.ex index bb6e8a4cc70..5e44f7255b9 100644 --- a/lib/elixir/lib/kernel/cli.ex +++ b/lib/elixir/lib/kernel/cli.ex @@ -111,7 +111,7 @@ defmodule Kernel.CLI do defp shared_option?(list, config, callback) do case parse_shared(list, config) do - {[h|hs], _} when h == hd(list) -> + {[h | hs], _} when h == hd(list) -> new_config = %{config | errors: ["#{h} : Unknown option" | config.errors]} callback.(hs, new_config) {new_list, new_config} -> @@ -127,16 +127,16 @@ defmodule Kernel.CLI do :elixir_translator, :elixir_expand, :elixir_lexical, :elixir_exp_clauses, :elixir_def, :elixir_map] - defp prune_stacktrace([{mod, _, _, _}|t]) when mod in @elixir_internals do + defp prune_stacktrace([{mod, _, _, _} | t]) when mod in @elixir_internals do prune_stacktrace(t) end - defp prune_stacktrace([{__MODULE__, :wrapper, 1, _}|_]) do + defp prune_stacktrace([{__MODULE__, :wrapper, 1, _} | _]) do [] end - defp prune_stacktrace([h|t]) do - [h|prune_stacktrace(t)] + defp prune_stacktrace([h | t]) do + [h | prune_stacktrace(t)] end defp prune_stacktrace([]) do @@ -145,7 +145,7 @@ defmodule Kernel.CLI do # Parse shared options - defp parse_shared([opt|_t], _config) when opt in ["-v", "--version"] do + defp parse_shared([opt | _t], _config) when opt in ["-v", "--version"] do if function_exported?(IEx, :started?, 0) and IEx.started? do IO.puts "IEx " <> System.build_info[:build] else @@ -156,43 +156,43 @@ defmodule Kernel.CLI do System.halt 0 end - defp parse_shared(["-pa", h|t], config) do + defp parse_shared(["-pa", h | t], config) do paths = expand_code_path(h) Enum.each(paths, &:code.add_patha/1) parse_shared t, %{config | pa: config.pa ++ paths} end - defp parse_shared(["-pz", h|t], config) do + defp parse_shared(["-pz", h | t], config) do paths = expand_code_path(h) Enum.each(paths, &:code.add_pathz/1) parse_shared t, %{config | pz: config.pz ++ paths} end - defp parse_shared(["--app", h|t], config) do + defp parse_shared(["--app", h | t], config) do parse_shared t, %{config | commands: [{:app, h} | config.commands]} end - defp parse_shared(["--no-halt"|t], config) do + defp parse_shared(["--no-halt" | t], config) do parse_shared t, %{config | halt: false} end - defp parse_shared(["-e", h|t], config) do + defp parse_shared(["-e", h | t], config) do parse_shared t, %{config | commands: [{:eval, h} | config.commands]} end - defp parse_shared(["-r", h|t], config) do + defp parse_shared(["-r", h | t], config) do parse_shared t, %{config | commands: [{:require, h} | config.commands]} end - defp parse_shared(["-pr", h|t], config) do + defp parse_shared(["-pr", h | t], config) do parse_shared t, %{config | commands: [{:parallel_require, h} | config.commands]} end - defp parse_shared([erl, _|t], config) when erl in ["--erl", "--sname", "--name", "--cookie", "--logger-otp-reports", "--logger-sasl-reports"] do + defp parse_shared([erl, _ | t], config) when erl in ["--erl", "--sname", "--name", "--cookie", "--logger-otp-reports", "--logger-sasl-reports"] do parse_shared t, config end - defp parse_shared([erl|t], config) when erl in ["--detached", "--hidden", "--werl"] do + defp parse_shared([erl | t], config) when erl in ["--detached", "--hidden", "--werl"] do parse_shared t, config end @@ -210,23 +210,23 @@ defmodule Kernel.CLI do # Process init options - defp parse_argv(["--"|t], config) do + defp parse_argv(["--" | t], config) do {config, t} end - defp parse_argv(["+elixirc"|t], config) do + defp parse_argv(["+elixirc" | t], config) do parse_compiler t, config end - defp parse_argv(["+iex"|t], config) do + defp parse_argv(["+iex" | t], config) do parse_iex t, config end - defp parse_argv(["-S", h|t], config) do + defp parse_argv(["-S", h | t], config) do {%{config | commands: [{:script, h} | config.commands]}, t} end - defp parse_argv([h|t] = list, config) do + defp parse_argv([h | t] = list, config) do case h do "-" <> _ -> shared_option? list, config, &parse_argv(&1, &2) @@ -245,35 +245,35 @@ defmodule Kernel.CLI do # Parse compiler options - defp parse_compiler(["--"|t], config) do + defp parse_compiler(["--" | t], config) do {config, t} end - defp parse_compiler(["-o", h|t], config) do + defp parse_compiler(["-o", h | t], config) do parse_compiler t, %{config | output: h} end - defp parse_compiler(["--no-docs"|t], config) do + defp parse_compiler(["--no-docs" | t], config) do parse_compiler t, %{config | compiler_options: [{:docs, false} | config.compiler_options]} end - defp parse_compiler(["--no-debug-info"|t], config) do + defp parse_compiler(["--no-debug-info" | t], config) do parse_compiler t, %{config | compiler_options: [{:debug_info, false} | config.compiler_options]} end - defp parse_compiler(["--ignore-module-conflict"|t], config) do + defp parse_compiler(["--ignore-module-conflict" | t], config) do parse_compiler t, %{config | compiler_options: [{:ignore_module_conflict, true} | config.compiler_options]} end - defp parse_compiler(["--warnings-as-errors"|t], config) do + defp parse_compiler(["--warnings-as-errors" | t], config) do parse_compiler t, %{config | compiler_options: [{:warnings_as_errors, true} | config.compiler_options]} end - defp parse_compiler(["--verbose"|t], config) do + defp parse_compiler(["--verbose" | t], config) do parse_compiler t, %{config | verbose_compile: true} end - defp parse_compiler([h|t] = list, config) do + defp parse_compiler([h | t] = list, config) do case h do "-" <> _ -> shared_option? list, config, &parse_compiler(&1, &2) @@ -284,30 +284,30 @@ defmodule Kernel.CLI do end defp parse_compiler([], config) do - {%{config | commands: [{:compile, config.compile}|config.commands]}, []} + {%{config | commands: [{:compile, config.compile} | config.commands]}, []} end # Parse iex options - defp parse_iex(["--"|t], config) do + defp parse_iex(["--" | t], config) do {config, t} end # This clause is here so that Kernel.CLI does not # error out with "unknown option" - defp parse_iex(["--dot-iex", _|t], config) do + defp parse_iex(["--dot-iex", _ | t], config) do parse_iex t, config end - defp parse_iex([opt, _|t], config) when opt in ["--remsh"] do + defp parse_iex([opt, _ | t], config) when opt in ["--remsh"] do parse_iex t, config end - defp parse_iex(["-S", h|t], config) do + defp parse_iex(["-S", h | t], config) do {%{config | commands: [{:script, h} | config.commands]}, t} end - defp parse_iex([h|t] = list, config) do + defp parse_iex([h | t] = list, config) do case h do "-" <> _ -> shared_option? list, config, &parse_iex(&1, &2) diff --git a/lib/elixir/lib/kernel/lexical_tracker.ex b/lib/elixir/lib/kernel/lexical_tracker.ex index f30b798966f..3d0c32cf95a 100644 --- a/lib/elixir/lib/kernel/lexical_tracker.ex +++ b/lib/elixir/lib/kernel/lexical_tracker.ex @@ -20,10 +20,10 @@ defmodule Kernel.LexicalTracker do |> partition([], []) end - defp partition([[remote, :compile]|t], compile, runtime), - do: partition(t, [remote|compile], runtime) - defp partition([[remote, :runtime]|t], compile, runtime), - do: partition(t, compile, [remote|runtime]) + defp partition([[remote, :compile] | t], compile, runtime), + do: partition(t, [remote | compile], runtime) + defp partition([[remote, :runtime] | t], compile, runtime), + do: partition(t, compile, [remote | runtime]) defp partition([], compile, runtime), do: {compile, runtime} diff --git a/lib/elixir/lib/kernel/parallel_compiler.ex b/lib/elixir/lib/kernel/parallel_compiler.ex index 0acddbdfe13..28f05e752e9 100644 --- a/lib/elixir/lib/kernel/parallel_compiler.ex +++ b/lib/elixir/lib/kernel/parallel_compiler.ex @@ -72,7 +72,7 @@ defmodule Kernel.ParallelCompiler do end # Release waiting processes - defp spawn_compilers([{h, kind}|t], original, output, options, waiting, queued, schedulers, result) when is_pid(h) do + defp spawn_compilers([{h, kind} | t], original, output, options, waiting, queued, schedulers, result) when is_pid(h) do waiting = case List.keytake(waiting, h, 1) do {{_kind, ^h, ref, _module, _defining}, waiting} -> @@ -85,7 +85,7 @@ defmodule Kernel.ParallelCompiler do end # Spawn a compiler for each file in the list until we reach the limit - defp spawn_compilers([h|t], original, output, options, waiting, queued, schedulers, result) do + defp spawn_compilers([h | t], original, output, options, waiting, queued, schedulers, result) do parent = self() {pid, ref} = @@ -108,7 +108,7 @@ defmodule Kernel.ParallelCompiler do end spawn_compilers(t, original, output, options, waiting, - [{pid, ref, h}|queued], schedulers, result) + [{pid, ref, h} | queued], schedulers, result) end # No more files, nothing waiting, queue is empty, we are done @@ -147,7 +147,7 @@ defmodule Kernel.ParallelCompiler do do: {pid, :found} spawn_compilers(available ++ entries, original, output, options, - waiting, queued, schedulers, [{:struct, module}|result]) + waiting, queued, schedulers, [{:struct, module} | result]) {:module_available, child, ref, file, module, binary} -> if callback = Keyword.get(options, :each_module) do @@ -162,7 +162,7 @@ defmodule Kernel.ParallelCompiler do do: {pid, :found} spawn_compilers(available ++ entries, original, output, options, - waiting, queued, schedulers, [{:module, module}|result]) + waiting, queued, schedulers, [{:module, module} | result]) {:waiting, kind, child, ref, on, defining} -> defined = fn {k, m} -> on == m and k in [kind, :module] end @@ -173,7 +173,7 @@ defmodule Kernel.ParallelCompiler do send child, {ref, :found} waiting else - [{kind, child, ref, on, defining}|waiting] + [{kind, child, ref, on, defining} | waiting] end spawn_compilers(entries, original, output, options, waiting, queued, schedulers, result) @@ -263,12 +263,12 @@ defmodule Kernel.ParallelCompiler do :elixir_translator, :elixir_expand, :elixir_lexical, :elixir_exp_clauses, :elixir_def, :elixir_map, Kernel.ErrorHandler] - defp prune_stacktrace([{mod, _, _, _}|t]) when mod in @elixir_internals do + defp prune_stacktrace([{mod, _, _, _} | t]) when mod in @elixir_internals do prune_stacktrace(t) end - defp prune_stacktrace([h|t]) do - [h|prune_stacktrace(t)] + defp prune_stacktrace([h | t]) do + [h | prune_stacktrace(t)] end defp prune_stacktrace([]) do diff --git a/lib/elixir/lib/kernel/parallel_require.ex b/lib/elixir/lib/kernel/parallel_require.ex index a30636a1a97..41c281e29ec 100644 --- a/lib/elixir/lib/kernel/parallel_require.ex +++ b/lib/elixir/lib/kernel/parallel_require.ex @@ -38,7 +38,7 @@ defmodule Kernel.ParallelRequire do wait_for_messages(files, waiting, callback, schedulers, result) end - defp spawn_requires([h|t], waiting, callback, schedulers, result) do + defp spawn_requires([h | t], waiting, callback, schedulers, result) do parent = self() {pid, ref} = :erlang.spawn_monitor fn -> :erlang.put(:elixir_compiler_pid, parent) @@ -52,7 +52,7 @@ defmodule Kernel.ParallelRequire do end) end - spawn_requires(t, [{pid, ref}|waiting], callback, schedulers, result) + spawn_requires(t, [{pid, ref} | waiting], callback, schedulers, result) end defp wait_for_messages(files, waiting, callback, schedulers, result) do diff --git a/lib/elixir/lib/kernel/special_forms.ex b/lib/elixir/lib/kernel/special_forms.ex index a4d7cbe4f55..6f274f2466f 100644 --- a/lib/elixir/lib/kernel/special_forms.ex +++ b/lib/elixir/lib/kernel/special_forms.ex @@ -1481,9 +1481,9 @@ defmodule Kernel.SpecialForms do iex> fun.(1, 2) {1, 2} - iex> fun = &[&1|&2] + iex> fun = &[&1 | &2] iex> fun.(1, 2) - [1|2] + [1 | 2] The only restrictions when creating anonymous functions is that at least one placeholder must be present, i.e. it must contain at least diff --git a/lib/elixir/lib/kernel/typespec.ex b/lib/elixir/lib/kernel/typespec.ex index c2a5a46d9d7..00ae5912e04 100644 --- a/lib/elixir/lib/kernel/typespec.ex +++ b/lib/elixir/lib/kernel/typespec.ex @@ -196,7 +196,7 @@ defmodule Kernel.Typespec do def type_to_ast({{:record, record}, fields, args}) when is_atom(record) do fields = for field <- fields, do: typespec_to_ast(field) args = for arg <- args, do: typespec_to_ast(arg) - type = {:{}, [], [record|fields]} + type = {:{}, [], [record | fields]} quote do: unquote(record)(unquote_splicing(args)) :: unquote(type) end @@ -439,7 +439,7 @@ defmodule Kernel.Typespec do defp translate_spec(kind, meta, name, args, return, guard, caller) when is_atom(args), do: translate_spec(kind, meta, name, [], return, guard, caller) defp translate_spec(:macrocallback, meta, name, args, return, guard, caller), - do: translate_spec(:callback, meta, :"MACRO-#{name}", [quote(do: env :: Macro.Env.t)|args], return, guard, caller) + do: translate_spec(:callback, meta, :"MACRO-#{name}", [quote(do: env :: Macro.Env.t) | args], return, guard, caller) defp translate_spec(kind, meta, name, args, return, guard, caller) do ensure_no_defaults!(args) @@ -488,7 +488,7 @@ defmodule Kernel.Typespec do {name, type}, acc -> constraint = [{:atom, line, :is_subtype}, [{:var, line, name}, typespec(type, vars, caller)]] type = {:type, line, :constraint, constraint} - [type|acc] + [type | acc] end, [], guard) |> :lists.reverse end @@ -795,7 +795,7 @@ defmodule Kernel.Typespec do end end, fields) - typespec({:{}, meta, [atom|types]}, vars, caller) + typespec({:{}, meta, [atom | types]}, vars, caller) _ -> compile_error(caller, "unknown record #{inspect atom}") end @@ -827,7 +827,7 @@ defmodule Kernel.Typespec do # Handle type operator defp typespec({:::, meta, [var, expr]}, vars, caller) do - left = typespec(var, [elem(var, 0)|vars], caller) + left = typespec(var, [elem(var, 0) | vars], caller) right = typespec(expr, vars, caller) {:ann_type, line(meta), [left, right]} end @@ -936,7 +936,7 @@ defmodule Kernel.Typespec do end defp typespec(list, vars, caller) when is_list(list) do - [h|t] = :lists.reverse(list) + [h | t] = :lists.reverse(list) union = :lists.foldl(fn(x, acc) -> {:|, [], [validate_kw(x, list, caller), acc]} end, validate_kw(h, list, caller), t) @@ -958,7 +958,7 @@ defmodule Kernel.Typespec do {:remote_type, line(meta), [ remote, name, arguments ]} end - defp collect_union({:|, _, [a, b]}), do: [a|collect_union(b)] + defp collect_union({:|, _, [a, b]}), do: [a | collect_union(b)] defp collect_union(v), do: [v] defp validate_kw({key, _} = t, _, _caller) when is_atom(key), do: t @@ -986,8 +986,8 @@ defmodule Kernel.Typespec do {:var, line(meta), name} end - defp unpack_typespec_kw([{:type, _, :tuple, [{:atom, _, atom}, type]}|t], acc) do - unpack_typespec_kw(t, [{atom, typespec_to_ast(type)}|acc]) + defp unpack_typespec_kw([{:type, _, :tuple, [{:atom, _, atom}, type]} | t], acc) do + unpack_typespec_kw(t, [{atom, typespec_to_ast(type)} | acc]) end defp unpack_typespec_kw([], acc) do diff --git a/lib/elixir/lib/kernel/utils.ex b/lib/elixir/lib/kernel/utils.ex index 8243285ae09..b5e0019762d 100644 --- a/lib/elixir/lib/kernel/utils.ex +++ b/lib/elixir/lib/kernel/utils.ex @@ -8,10 +8,10 @@ defmodule Kernel.Utils do defp destructure_list(_, 0), do: [] defp destructure_list([], count), do: destructure_nil(count) - defp destructure_list([h|t], count), do: [h|destructure_list(t, count - 1)] + defp destructure_list([h | t], count), do: [h | destructure_list(t, count - 1)] defp destructure_nil(0), do: [] - defp destructure_nil(count), do: [nil|destructure_nil(count - 1)] + defp destructure_nil(count), do: [nil | destructure_nil(count - 1)] def defdelegate(fun, opts) do append_first = Keyword.get(opts, :append_first, false) @@ -41,16 +41,16 @@ defmodule Kernel.Utils do defp normalize_args(raw_args) do :lists.foldr(fn - ({:\\, _, [arg, default_arg]}, [as_args|_] = as_args_list) -> - new_as_args = [default_arg|as_args] - [new_as_args|add_arg(as_args_list, arg)] + ({:\\, _, [arg, default_arg]}, [as_args | _] = as_args_list) -> + new_as_args = [default_arg | as_args] + [new_as_args | add_arg(as_args_list, arg)] (arg, as_args_list) -> add_arg(as_args_list, arg) end, [[]], raw_args) end defp add_arg(as_args_list, {name, _, mod} = arg) when is_atom(name) and is_atom(mod), - do: :lists.map(&([arg|&1]), as_args_list) + do: :lists.map(&([arg | &1]), as_args_list) defp add_arg(_, code) do raise ArgumentError, "defdelegate/2 only accepts function parameters, got: #{Macro.to_string(code)}" diff --git a/lib/elixir/lib/keyword.ex b/lib/elixir/lib/keyword.ex index 9b62130ed83..3319a32d133 100644 --- a/lib/elixir/lib/keyword.ex +++ b/lib/elixir/lib/keyword.ex @@ -224,19 +224,19 @@ defmodule Keyword do when is_list(keywords) and is_atom(key), do: get_and_update(keywords, [], key, fun) - defp get_and_update([{key, current}|t], acc, key, fun) do + defp get_and_update([{key, current} | t], acc, key, fun) do case fun.(current) do - {get, value} -> {get, :lists.reverse(acc, [{key, value}|t])} + {get, value} -> {get, :lists.reverse(acc, [{key, value} | t])} :pop -> {current, :lists.reverse(acc, t)} end end - defp get_and_update([h|t], acc, key, fun), - do: get_and_update(t, [h|acc], key, fun) + defp get_and_update([h | t], acc, key, fun), + do: get_and_update(t, [h | acc], key, fun) defp get_and_update([], acc, key, fun) do case fun.(nil) do - {get, update} -> {get, [{key, update}|:lists.reverse(acc)]} + {get, update} -> {get, [{key, update} | :lists.reverse(acc)]} :pop -> {nil, :lists.reverse(acc)} end end @@ -275,17 +275,17 @@ defmodule Keyword do get_and_update!(keywords, key, fun, []) end - defp get_and_update!([{key, value}|keywords], key, fun, acc) do + defp get_and_update!([{key, value} | keywords], key, fun, acc) do case fun.(value) do {get, value} -> - {get, :lists.reverse(acc, [{key, value}|delete(keywords, key)])} + {get, :lists.reverse(acc, [{key, value} | delete(keywords, key)])} :pop -> {value, :lists.reverse(acc, keywords)} end end - defp get_and_update!([{_, _} = e|keywords], key, fun, acc) do - get_and_update!(keywords, key, fun, [e|acc]) + defp get_and_update!([{_, _} = e | keywords], key, fun, acc) do + get_and_update!(keywords, key, fun, [e | acc]) end defp get_and_update!([], key, _fun, acc) when is_atom(key) do @@ -472,7 +472,7 @@ defmodule Keyword do """ @spec put(t, key, value) :: t def put(keywords, key, value) when is_list(keywords) and is_atom(key) do - [{key, value}|delete(keywords, key)] + [{key, value} | delete(keywords, key)] end @doc """ @@ -500,7 +500,7 @@ defmodule Keyword do when is_list(keywords) and is_atom(key) and is_function(fun, 0) do case :lists.keyfind(key, 1, keywords) do {^key, _} -> keywords - false -> [{key, fun.()}|keywords] + false -> [{key, fun.()} | keywords] end end @@ -520,7 +520,7 @@ defmodule Keyword do def put_new(keywords, key, value) when is_list(keywords) and is_atom(key) do case :lists.keyfind(key, 1, keywords) do {^key, _} -> keywords - false -> [{key, value}|keywords] + false -> [{key, value} | keywords] end end @@ -602,13 +602,13 @@ defmodule Keyword do do_merge(keywords2, [], keywords1, keywords1, fun) end - defp do_merge([{k, v2}|t], acc, rest, original, fun) do + defp do_merge([{k, v2} | t], acc, rest, original, fun) do case :lists.keyfind(k, 1, original) do {^k, v1} -> - do_merge(t, [{k, fun.(k, v1, v2)}|acc], + do_merge(t, [{k, fun.(k, v1, v2)} | acc], delete(rest, k), :lists.keydelete(k, 1, original), fun) false -> - do_merge(t, [{k, v2}|acc], rest, original, fun) + do_merge(t, [{k, v2} | acc], rest, original, fun) end end @@ -656,12 +656,12 @@ defmodule Keyword do update!(keywords, key, fun, keywords) end - defp update!([{key, value}|keywords], key, fun, _dict) do - [{key, fun.(value)}|delete(keywords, key)] + defp update!([{key, value} | keywords], key, fun, _dict) do + [{key, fun.(value)} | delete(keywords, key)] end - defp update!([{_, _} = e|keywords], key, fun, dict) do - [e|update!(keywords, key, fun, dict)] + defp update!([{_, _} = e | keywords], key, fun, dict) do + [e | update!(keywords, key, fun, dict)] end defp update!([], key, _fun, dict) when is_atom(key) do @@ -689,12 +689,12 @@ defmodule Keyword do @spec update(t, key, value, (value -> value)) :: t def update(keywords, key, initial, fun) - def update([{key, value}|keywords], key, _initial, fun) do - [{key, fun.(value)}|delete(keywords, key)] + def update([{key, value} | keywords], key, _initial, fun) do + [{key, fun.(value)} | delete(keywords, key)] end - def update([{_, _} = e|keywords], key, initial, fun) do - [e|update(keywords, key, initial, fun)] + def update([{_, _} = e | keywords], key, initial, fun) do + [e | update(keywords, key, initial, fun)] end def update([], key, initial, _fun) when is_atom(key) do @@ -722,8 +722,8 @@ defmodule Keyword do def split(keywords, keys) when is_list(keywords) do fun = fn {k, v}, {take, drop} -> case k in keys do - true -> {[{k, v}|take], drop} - false -> {take, [{k, v}|drop]} + true -> {[{k, v} | take], drop} + false -> {take, [{k, v} | drop]} end end diff --git a/lib/elixir/lib/list.ex b/lib/elixir/lib/list.ex index d9516880f62..8ca25cbc436 100644 --- a/lib/elixir/lib/list.ex +++ b/lib/elixir/lib/list.ex @@ -160,8 +160,8 @@ defmodule List do """ @spec first([elem]) :: nil | elem when elem: var - def first([]), do: nil - def first([h|_]), do: h + def first([]), do: nil + def first([h | _]), do: h @doc """ Returns the last element in `list` or `nil` if `list` is empty. @@ -179,9 +179,9 @@ defmodule List do """ @spec last([elem]) :: nil | elem when elem: var - def last([]), do: nil - def last([h]), do: h - def last([_|t]), do: last(t) + def last([]), do: nil + def last([h]), do: h + def last([_ | t]), do: last(t) @doc """ Receives a list of tuples and returns the first tuple diff --git a/lib/elixir/lib/macro.ex b/lib/elixir/lib/macro.ex index a7328a375ed..b2f76315d98 100644 --- a/lib/elixir/lib/macro.ex +++ b/lib/elixir/lib/macro.ex @@ -136,7 +136,7 @@ defmodule Macro do end defp unpipe(other, acc) do - [{other, 0}|acc] + [{other, 0} | acc] end @doc """ @@ -638,7 +638,7 @@ defmodule Macro do end # left -> right - def to_string([{:->, _, _}|_] = ast, fun) do + def to_string([{:->, _, _} | _] = ast, fun) do fun.(ast, "(" <> arrow_to_string(ast, fun, true) <> ")") end @@ -772,7 +772,7 @@ defmodule Macro do defp kw_blocks?(_), do: false # Check if we have an interpolated string. - defp interpolated?({:<<>>, _, [_|_] = parts}) do + defp interpolated?({:<<>>, _, [_ | _] = parts}) do Enum.all?(parts, fn {:::, _, [{{:., _, [Kernel, :to_string]}, _, [_]}, {:binary, _, _}]} -> true @@ -866,7 +866,7 @@ defmodule Macro do Atom.to_string(key) <> "\n " <> block <> "\n" end - defp block_to_string([{:->, _, _}|_] = block, fun) do + defp block_to_string([{:->, _, _} | _] = block, fun) do Enum.map_join(block, "\n", fn({:->, _, [left, right]}) -> left = comma_join_or_empty_paren(left, fun, false) left <> "->\n " <> adjust_new_lines block_to_string(right, fun), "\n " diff --git a/lib/elixir/lib/module.ex b/lib/elixir/lib/module.ex index 18a9aecd75a..52429a03289 100644 --- a/lib/elixir/lib/module.ex +++ b/lib/elixir/lib/module.ex @@ -659,7 +659,7 @@ defmodule Module do defp simplify_signature(_, acc), do: autogenerated(acc, :arg) defp autogenerated(acc, key) do - {key, [key|acc]} + {key, [key | acc]} end defp expand_signature(key, {all_keys, acc}) when is_atom(key) do @@ -699,8 +699,8 @@ defmodule Module do # Merge - defp merge_signatures([h1|t1], [h2|t2], i) do - [merge_signature(h1, h2, i)|merge_signatures(t1, t2, i + 1)] + defp merge_signatures([h1 | t1], [h2 | t2], i) do + [merge_signature(h1, h2, i) | merge_signatures(t1, t2, i + 1)] end defp merge_signatures([], [], _) do @@ -876,7 +876,7 @@ defmodule Module do new = if :lists.member(key, acc) do case :ets.lookup(table, key) do - [{^key, old}] -> [value|old] + [{^key, old}] -> [value | old] [] -> [value] end else @@ -976,12 +976,12 @@ defmodule Module do if Keyword.get(opts, :persist) do old = :ets.lookup_element(table, {:elixir, :persisted_attributes}, 2) - :ets.insert(table, {{:elixir, :persisted_attributes}, [new|old]}) + :ets.insert(table, {{:elixir, :persisted_attributes}, [new | old]}) end if Keyword.get(opts, :accumulate) do old = :ets.lookup_element(table, {:elixir, :acc_attributes}, 2) - :ets.insert(table, {{:elixir, :acc_attributes}, [new|old]}) + :ets.insert(table, {{:elixir, :acc_attributes}, [new | old]}) end end @@ -1045,7 +1045,7 @@ defmodule Module do new = case :ets.lookup(table, key) do - [{^key, old}] -> [value|old] + [{^key, old}] -> [value | old] [] -> [value] end @@ -1076,7 +1076,7 @@ defmodule Module do end end - defp warn_info([entry|_]) do + defp warn_info([entry | _]) do opts = elem(entry, tuple_size(entry) - 1) Exception.format_file_line(Keyword.get(opts, :file), Keyword.get(opts, :line)) <> " " end diff --git a/lib/elixir/lib/module/locals_tracker.ex b/lib/elixir/lib/module/locals_tracker.ex index 1ab9f10606c..794b0e17ee2 100644 --- a/lib/elixir/lib/module/locals_tracker.ex +++ b/lib/elixir/lib/module/locals_tracker.ex @@ -174,9 +174,9 @@ defmodule Module.LocalsTracker do reduce_unreachable(private, [], :sets.from_list(unreachable)) end - defp reduce_unreachable([{vertex, callers}|t], acc, unreachable) do + defp reduce_unreachable([{vertex, callers} | t], acc, unreachable) do if :sets.is_subset(callers, unreachable) do - reduce_unreachable(t, [{vertex, callers}|acc], unreachable) + reduce_unreachable(t, [{vertex, callers} | acc], unreachable) else reduce_unreachable(acc ++ t, [], :sets.del_element(vertex, unreachable)) end @@ -195,7 +195,7 @@ defmodule Module.LocalsTracker do if :lists.member(tuple, reachable) do acc else - [{:unused_def, tuple, kind}|acc] + [{:unused_def, tuple, kind} | acc] end end @@ -207,12 +207,12 @@ defmodule Module.LocalsTracker do invoked = for {n, a} <- reachable, n == name, a in min..max, do: a if invoked == [] do - [{:unused_def, tuple, kind}|acc] + [{:unused_def, tuple, kind} | acc] else case :lists.min(invoked) - min do 0 -> acc - ^default -> [{:unused_args, tuple}|acc] - unused_args -> [{:unused_args, tuple, unused_args}|acc] + ^default -> [{:unused_args, tuple} | acc] + unused_args -> [{:unused_args, tuple, unused_args} | acc] end end end @@ -244,11 +244,11 @@ defmodule Module.LocalsTracker do @doc false def handle_call({:cache_env, env}, _from, {d, cache}) do case cache do - [{i, ^env}|_] -> + [{i, ^env} | _] -> {:reply, i, {d, cache}} t -> i = length(t) - {:reply, i, {d, [{i, env}|t]}} + {:reply, i, {d, [{i, env} | t]}} end end @@ -353,7 +353,7 @@ defmodule Module.LocalsTracker do defp replace_edge!(d, from, to) do _ = unless :lists.member(to, :digraph.out_neighbours(d, from)) do - [:"$e"|_] = :digraph.add_edge(d, from, to) + [:"$e" | _] = :digraph.add_edge(d, from, to) end :ok end diff --git a/lib/elixir/lib/option_parser.ex b/lib/elixir/lib/option_parser.ex index 065afff53ca..4dc747e5be1 100644 --- a/lib/elixir/lib/option_parser.ex +++ b/lib/elixir/lib/option_parser.ex @@ -151,19 +151,19 @@ defmodule OptionParser do {:invalid, option, value, rest} -> # the option exist but it has wrong value - do_parse(rest, config, opts, args, [{option, value}|invalid], all?) + do_parse(rest, config, opts, args, [{option, value} | invalid], all?) {:undefined, option, _value, rest} -> # the option does not exist (for strict cases) - do_parse(rest, config, opts, args, [{option, nil}|invalid], all?) + do_parse(rest, config, opts, args, [{option, nil} | invalid], all?) - {:error, ["--"|rest]} -> + {:error, ["--" | rest]} -> {Enum.reverse(opts), Enum.reverse(args, rest), Enum.reverse(invalid)} - {:error, [arg|rest]=remaining_args} -> + {:error, [arg | rest]=remaining_args} -> # there is no option if all? do - do_parse(rest, config, opts, [arg|args], invalid, all?) + do_parse(rest, config, opts, [arg | args], invalid, all?) else {Enum.reverse(opts), Enum.reverse(args, remaining_args), Enum.reverse(invalid)} end @@ -205,19 +205,19 @@ defmodule OptionParser do {:error, []} end - defp next(["--"|_]=argv, _aliases, _switches, _strict) do + defp next(["--" | _]=argv, _aliases, _switches, _strict) do {:error, argv} end - defp next(["-"|_]=argv, _aliases, _switches, _strict) do + defp next(["-" | _]=argv, _aliases, _switches, _strict) do {:error, argv} end - defp next(["- " <> _|_]=argv, _aliases, _switches, _strict) do + defp next(["- " <> _ | _]=argv, _aliases, _switches, _strict) do {:error, argv} end - defp next(["-" <> option|rest] = argv, aliases, switches, strict) do + defp next(["-" <> option | rest] = argv, aliases, switches, strict) do {option, value} = split_option(option) opt_name_bin = "-" <> option tagged = tag_option(option, switches, aliases) @@ -305,7 +305,7 @@ defmodule OptionParser do # If we have space and we are outside of a quote, start new segment defp do_split(<>, buffer, acc, nil), - do: do_split(strip_leading_spaces(t), "", [buffer|acc], nil) + do: do_split(strip_leading_spaces(t), "", [buffer | acc], nil) # All other characters are moved to buffer defp do_split(<>, buffer, acc, quote) do @@ -317,7 +317,7 @@ defmodule OptionParser do do: Enum.reverse(acc) defp do_split(<<>>, buffer, acc, nil), - do: Enum.reverse([buffer|acc]) + do: Enum.reverse([buffer | acc]) # Otherwise raise defp do_split(<<>>, _, _acc, marker) do @@ -380,9 +380,9 @@ defmodule OptionParser do defp do_store_option(dict, option, value, kinds) do cond do :keep in kinds -> - [{option, value}|dict] + [{option, value} | dict] true -> - [{option, value}|Keyword.delete(dict, option)] + [{option, value} | Keyword.delete(dict, option)] end end @@ -433,7 +433,7 @@ defmodule OptionParser do :boolean in kinds -> {true, kinds, t} value_in_tail?(t) -> - [h|t] = t + [h | t] = t {h, kinds, t} kinds == [] -> {nil_or_true, kinds, t} @@ -446,9 +446,9 @@ defmodule OptionParser do {value, kinds, t} end - defp value_in_tail?(["-"|_]), do: true - defp value_in_tail?(["- " <> _|_]), do: true - defp value_in_tail?(["-" <> arg|_]), do: negative_number?("-" <> arg) + defp value_in_tail?(["-" | _]), do: true + defp value_in_tail?(["- " <> _ | _]), do: true + defp value_in_tail?(["-" <> arg | _]), do: negative_number?("-" <> arg) defp value_in_tail?([]), do: false defp value_in_tail?(_), do: true diff --git a/lib/elixir/lib/path.ex b/lib/elixir/lib/path.ex index 2669931086a..d5f446449e8 100644 --- a/lib/elixir/lib/path.ex +++ b/lib/elixir/lib/path.ex @@ -69,15 +69,15 @@ defmodule Path do end # Absolute path on current drive - defp absname_vr(["/"|rest], [volume|_], _relative), - do: absname_join([volume|rest]) + defp absname_vr(["/" | rest], [volume | _], _relative), + do: absname_join([volume | rest]) # Relative to current directory on current drive. - defp absname_vr([<>|rest], [<>|_], relative), + defp absname_vr([<> | rest], [<> | _], relative), do: absname(absname_join(rest), relative) # Relative to current directory on another drive. - defp absname_vr([<>|name], _, _relative) do + defp absname_vr([<> | name], _, _relative) do cwd = case :file.get_cwd([x, ?:]) do {:ok, dir} -> IO.chardata_to_string(dir) @@ -87,8 +87,8 @@ defmodule Path do end # Joins a list - defp absname_join([name1, name2|rest]), do: - absname_join([absname_join(name1, name2)|rest]) + defp absname_join([name1, name2 | rest]), do: + absname_join([absname_join(name1, name2) | rest]) defp absname_join([name]), do: do_absname_join(IO.chardata_to_string(name), <<>>, [], major_os_type()) @@ -100,26 +100,26 @@ defmodule Path do do_absname_join(rest, relativename, [?:, uc_letter+?a-?A], :win32) defp do_absname_join(<>, relativename, result, :win32), do: do_absname_join(<>, relativename, result, :win32) - defp do_absname_join(<>, relativename, [?., ?/|result], os_type), do: - do_absname_join(rest, relativename, [?/|result], os_type) - defp do_absname_join(<>, relativename, [?/|result], os_type), do: - do_absname_join(rest, relativename, [?/|result], os_type) + defp do_absname_join(<>, relativename, [?., ?/ | result], os_type), do: + do_absname_join(rest, relativename, [?/ | result], os_type) + defp do_absname_join(<>, relativename, [?/ | result], os_type), do: + do_absname_join(rest, relativename, [?/ | result], os_type) defp do_absname_join(<<>>, <<>>, result, os_type), do: IO.iodata_to_binary(reverse_maybe_remove_dirsep(result, os_type)) - defp do_absname_join(<<>>, relativename, [?:|rest], :win32), do: - do_absname_join(relativename, <<>>, [?:|rest], :win32) - defp do_absname_join(<<>>, relativename, [?/|result], os_type), do: - do_absname_join(relativename, <<>>, [?/|result], os_type) + defp do_absname_join(<<>>, relativename, [?: | rest], :win32), do: + do_absname_join(relativename, <<>>, [?: | rest], :win32) + defp do_absname_join(<<>>, relativename, [?/ | result], os_type), do: + do_absname_join(relativename, <<>>, [?/ | result], os_type) defp do_absname_join(<<>>, relativename, result, os_type), do: - do_absname_join(relativename, <<>>, [?/|result], os_type) + do_absname_join(relativename, <<>>, [?/ | result], os_type) defp do_absname_join(<>, relativename, result, os_type), do: - do_absname_join(rest, relativename, [char|result], os_type) + do_absname_join(rest, relativename, [char | result], os_type) defp reverse_maybe_remove_dirsep([?/, ?:, letter], :win32), do: [letter, ?:, ?/] defp reverse_maybe_remove_dirsep([?/], _), do: [?/] - defp reverse_maybe_remove_dirsep([?/|name], _), do: + defp reverse_maybe_remove_dirsep([?/ | name], _), do: :lists.reverse(name) defp reverse_maybe_remove_dirsep(name, _), do: :lists.reverse(name) @@ -227,19 +227,19 @@ defmodule Path do defp unix_pathtype(<>), do: {:absolute, relative} - defp unix_pathtype([?/|relative]), do: + defp unix_pathtype([?/ | relative]), do: {:absolute, relative} - defp unix_pathtype([list|rest]) when is_list(list), do: + defp unix_pathtype([list | rest]) when is_list(list), do: unix_pathtype(list ++ rest) defp unix_pathtype(relative), do: {:relative, relative} @slash [?/, ?\\] - defp win32_pathtype([list|rest]) when is_list(list), do: + defp win32_pathtype([list | rest]) when is_list(list), do: win32_pathtype(list++rest) - defp win32_pathtype([char, list|rest]) when is_list(list), do: - win32_pathtype([char|list++rest]) + defp win32_pathtype([char, list | rest]) when is_list(list), do: + win32_pathtype([char | list++rest]) defp win32_pathtype(<>) when c1 in @slash and c2 in @slash, do: {:absolute, relative} defp win32_pathtype(<>) when c in @slash, do: @@ -253,8 +253,8 @@ defmodule Path do {:absolute, relative} defp win32_pathtype([c | relative]) when c in @slash, do: {:volumerelative, relative} - defp win32_pathtype([c1, c2, list|rest]) when is_list(list), do: - win32_pathtype([c1, c2|list++rest]) + defp win32_pathtype([c1, c2, list | rest]) when is_list(list), do: + win32_pathtype([c1, c2 | list++rest]) defp win32_pathtype([_letter, ?:, c | relative]) when c in @slash, do: {:absolute, relative} defp win32_pathtype([_letter, ?: | relative]), do: @@ -290,11 +290,11 @@ defmodule Path do relative_to(split(path), split(from), path) end - defp relative_to([h|t1], [h|t2], original) do + defp relative_to([h | t1], [h | t2], original) do relative_to(t1, t2, original) end - defp relative_to([_|_] = l1, [], _original) do + defp relative_to([_ | _] = l1, [], _original) do join(l1) end @@ -446,8 +446,8 @@ defmodule Path do """ @spec join([t]) :: binary - def join([name1, name2|rest]), do: - join([join(name1, name2)|rest]) + def join([name1, name2 | rest]), do: + join([join(name1, name2) | rest]) def join([name]), do: name @@ -640,17 +640,17 @@ defmodule Path do defp do_expand_dot(path), do: do_expand_dot(:binary.split(path, "/", [:global]), []) - defp do_expand_dot([".."|t], [_, _|acc]), + defp do_expand_dot([".." | t], [_, _ | acc]), do: do_expand_dot(t, acc) - defp do_expand_dot([".."|t], []), + defp do_expand_dot([".." | t], []), do: do_expand_dot(t, []) - defp do_expand_dot(["."|t], acc), + defp do_expand_dot(["." | t], acc), do: do_expand_dot(t, acc) - defp do_expand_dot([h|t], acc), - do: do_expand_dot(t, ["/", h|acc]) + defp do_expand_dot([h | t], acc), + do: do_expand_dot(t, ["/", h | acc]) defp do_expand_dot([], []), do: "" - defp do_expand_dot([], ["/"|acc]), + defp do_expand_dot([], ["/" | acc]), do: IO.iodata_to_binary(:lists.reverse(acc)) defp major_os_type do diff --git a/lib/elixir/lib/protocol.ex b/lib/elixir/lib/protocol.ex index 3d1777b1dbe..91e428604e5 100644 --- a/lib/elixir/lib/protocol.ex +++ b/lib/elixir/lib/protocol.ex @@ -31,7 +31,7 @@ defmodule Protocol do name = unquote(name) arity = unquote(arity) - @functions [{name, arity}|@functions] + @functions [{name, arity} | @functions] # Generate a fake definition with the user # signature that will be used by docs @@ -298,7 +298,7 @@ defmodule Protocol do end end - defp change_impl_for([{:function, line, :__protocol__, 1, clauses}|t], protocol, types, structs, _, acc) do + defp change_impl_for([{:function, line, :__protocol__, 1, clauses} | t], protocol, types, structs, _, acc) do clauses = :lists.map(fn {:clause, l, [{:atom, _, :consolidated?}], [], [{:atom, _, _}]} -> {:clause, l, [{:atom, 0, :consolidated?}], [], [{:atom, 0, true}]} @@ -307,34 +307,34 @@ defmodule Protocol do end, clauses) change_impl_for(t, protocol, types, structs, true, - [{:function, line, :__protocol__, 1, clauses}|acc]) + [{:function, line, :__protocol__, 1, clauses} | acc]) end - defp change_impl_for([{:function, line, :impl_for, 1, _}|t], protocol, types, structs, is_protocol, acc) do + defp change_impl_for([{:function, line, :impl_for, 1, _} | t], protocol, types, structs, is_protocol, acc) do fallback = if Any in types, do: load_impl(protocol, Any) clauses = for {guard, mod} <- builtin, mod in types, do: builtin_clause_for(mod, guard, protocol, line) - clauses = [struct_clause_for(line)|clauses] ++ + clauses = [struct_clause_for(line) | clauses] ++ [fallback_clause_for(fallback, protocol, line)] change_impl_for(t, protocol, types, structs, is_protocol, - [{:function, line, :impl_for, 1, clauses}|acc]) + [{:function, line, :impl_for, 1, clauses} | acc]) end - defp change_impl_for([{:function, line, :struct_impl_for, 1, _}|t], protocol, types, structs, is_protocol, acc) do + defp change_impl_for([{:function, line, :struct_impl_for, 1, _} | t], protocol, types, structs, is_protocol, acc) do fallback = if Any in types, do: load_impl(protocol, Any) clauses = for struct <- structs, do: each_struct_clause_for(struct, protocol, line) clauses = clauses ++ [fallback_clause_for(fallback, protocol, line)] change_impl_for(t, protocol, types, structs, is_protocol, - [{:function, line, :struct_impl_for, 1, clauses}|acc]) + [{:function, line, :struct_impl_for, 1, clauses} | acc]) end - defp change_impl_for([h|t], protocol, info, types, is_protocol, acc) do - change_impl_for(t, protocol, info, types, is_protocol, [h|acc]) + defp change_impl_for([h | t], protocol, info, types, is_protocol, acc) do + change_impl_for(t, protocol, info, types, is_protocol, [h | acc]) end defp change_impl_for([], protocol, _info, _types, is_protocol, acc) do @@ -386,7 +386,7 @@ defmodule Protocol do # Finally compile the module and emit its bytecode. defp compile({protocol, code}, docs) do opts = if Code.compiler_options[:debug_info], do: [:debug_info], else: [] - {:ok, ^protocol, binary, _warnings} = :compile.forms(code, [:return|opts]) + {:ok, ^protocol, binary, _warnings} = :compile.forms(code, [:return | opts]) {:ok, case docs do :missing_chunk -> binary @@ -504,7 +504,7 @@ defmodule Protocol do @doc false def __functions_spec__([]), do: [] - def __functions_spec__([h|t]), + def __functions_spec__([h | t]), do: [:lists.foldl(&{:|, [], [&1, &2]}, h, t), quote(do: ...)] @doc false diff --git a/lib/elixir/lib/record.ex b/lib/elixir/lib/record.ex index c5ed0484965..bc00e2b13de 100644 --- a/lib/elixir/lib/record.ex +++ b/lib/elixir/lib/record.ex @@ -260,8 +260,8 @@ defmodule Record do create(atom, fields, args, caller) true -> case Macro.expand(args, caller) do - {:{}, _, [^atom|list]} when length(list) == length(fields) -> - record = List.to_tuple([atom|list]) + {:{}, _, [^atom | list]} when length(list) == length(fields) -> + record = List.to_tuple([atom | list]) Macro.escape(Record.__keyword__(atom, fields, record)) {^atom, arg} when length(fields) == 1 -> Macro.escape(Record.__keyword__(atom, fields, {atom, arg})) @@ -313,7 +313,7 @@ defmodule Record do case remaining do [] -> - {:{}, [], [atom|match]} + {:{}, [], [atom | match]} _ -> keys = for {key, _} <- remaining, do: key raise ArgumentError, "record #{inspect atom} does not have the key: #{inspect hd(keys)}" @@ -352,15 +352,15 @@ defmodule Record do end end - defp find_index([{k, _}|_], k, i), do: i + 2 - defp find_index([{_, _}|t], k, i), do: find_index(t, k, i + 1) + defp find_index([{k, _} | _], k, i), do: i + 2 + defp find_index([{_, _} | t], k, i), do: find_index(t, k, i + 1) defp find_index([], _k, _i), do: nil # Returns a keyword list of the record @doc false def __keyword__(atom, fields, record) do if is_record(record, atom) do - [_tag|values] = Tuple.to_list(record) + [_tag | values] = Tuple.to_list(record) join_keyword(fields, values, []) else msg = "expected argument to be a literal atom, literal keyword or a #{inspect atom} record, got runtime: #{inspect record}" @@ -368,8 +368,8 @@ defmodule Record do end end - defp join_keyword([{field, _default}|fields], [value|values], acc), - do: join_keyword(fields, values, [{field, value}| acc]) + defp join_keyword([{field, _default} | fields], [value | values], acc), + do: join_keyword(fields, values, [{field, value} | acc]) defp join_keyword([], [], acc), do: :lists.reverse(acc) diff --git a/lib/elixir/lib/record/extractor.ex b/lib/elixir/lib/record/extractor.ex index c354890d55a..f1d170f5370 100644 --- a/lib/elixir/lib/record/extractor.ex +++ b/lib/elixir/lib/record/extractor.ex @@ -36,12 +36,12 @@ defmodule Record.Extractor do # Find file using the same lookup as the *include_lib* attribute from Erlang modules. defp from_lib_file(file) do - [app|path] = :filename.split(String.to_char_list(file)) + [app | path] = :filename.split(String.to_char_list(file)) case :code.lib_dir(List.to_atom(app)) do {:error, _} -> raise ArgumentError, "lib file #{file} could not be found" libpath -> - :filename.join([libpath|path]) + :filename.join([libpath | path]) end end diff --git a/lib/elixir/lib/regex.ex b/lib/elixir/lib/regex.ex index 0ff5c861fd0..a26b1a8bff3 100644 --- a/lib/elixir/lib/regex.ex +++ b/lib/elixir/lib/regex.ex @@ -415,38 +415,38 @@ defmodule Regex do defp do_split([], string, offset, _counter, _trim, _with_captures), do: [binary_part(string, offset, byte_size(string) - offset)] - defp do_split([[{pos, _}|h]|t], string, offset, counter, trim, with_captures) when pos - offset < 0, - do: do_split([h|t], string, offset, counter, trim, with_captures) + defp do_split([[{pos, _} | h] | t], string, offset, counter, trim, with_captures) when pos - offset < 0, + do: do_split([h | t], string, offset, counter, trim, with_captures) - defp do_split([[]|t], string, offset, counter, trim, with_captures), + defp do_split([[] | t], string, offset, counter, trim, with_captures), do: do_split(t, string, offset, counter, trim, with_captures) - defp do_split([[{pos, length}|h]|t], string, offset, counter, trim, true) do + defp do_split([[{pos, length} | h] | t], string, offset, counter, trim, true) do new_offset = pos + length keep = pos - offset if keep == 0 and length == 0 do - do_split([h|t], string, new_offset, counter, trim, true) + do_split([h | t], string, new_offset, counter, trim, true) else <<_::binary-size(offset), part::binary-size(keep), match::binary-size(length), _::binary>> = string if keep == 0 and (length == 0 or trim) do - [match | do_split([h|t], string, new_offset, counter - 1, trim, true)] + [match | do_split([h | t], string, new_offset, counter - 1, trim, true)] else - [part, match | do_split([h|t], string, new_offset, counter - 1, trim, true)] + [part, match | do_split([h | t], string, new_offset, counter - 1, trim, true)] end end end - defp do_split([[{pos, length}|h]|t], string, offset, counter, trim, false) do + defp do_split([[{pos, length} | h] | t], string, offset, counter, trim, false) do new_offset = pos + length keep = pos - offset if keep == 0 and (length == 0 or trim) do - do_split([h|t], string, new_offset, counter, trim, false) + do_split([h | t], string, new_offset, counter, trim, false) else <<_::binary-size(offset), part::binary-size(keep), _::binary>> = string - [part | do_split([h|t], string, new_offset, counter - 1, trim, false)] + [part | do_split([h | t], string, new_offset, counter - 1, trim, false)] end end @@ -509,13 +509,13 @@ defmodule Regex do defp do_replace(%Regex{re_pattern: compiled}, string, replacement, options) do opts = if Keyword.get(options, :global) != false, do: [:global], else: [] - opts = [{:capture, :all, :index}|opts] + opts = [{:capture, :all, :index} | opts] case :re.run(string, compiled, opts) do :nomatch -> string - {:match, [mlist|t]} when is_list(mlist) -> - apply_list(string, replacement, [mlist|t]) |> IO.iodata_to_binary + {:match, [mlist | t]} when is_list(mlist) -> + apply_list(string, replacement, [mlist | t]) |> IO.iodata_to_binary {:match, slist} -> apply_list(string, replacement, [slist]) |> IO.iodata_to_binary end @@ -535,7 +535,7 @@ defmodule Regex do defp precompile_replacement(<>) when x in ?0..?9 do {ns, rest} = pick_int(rest) - [List.to_integer([x|ns]) | precompile_replacement(rest)] + [List.to_integer([x | ns]) | precompile_replacement(rest)] end defp precompile_replacement(<>) do @@ -549,7 +549,7 @@ defmodule Regex do defp pick_int(<>) when x in ?0..?9 do {found, rest} = pick_int(rest) - {[x|found], rest} + {[x | found], rest} end defp pick_int(bin) do @@ -617,11 +617,11 @@ defmodule Regex do end defp get_indexes(string, [], arity) do - [""|get_indexes(string, [], arity - 1)] + ["" | get_indexes(string, [], arity - 1)] end - defp get_indexes(string, [h|t], arity) do - [get_index(string, h)|get_indexes(string, t, arity - 1)] + defp get_indexes(string, [h | t], arity) do + [get_index(string, h) | get_indexes(string, t, arity - 1)] end {:ok, pattern} = :re.compile(~S"[.^$*+?()\[\]{}\\\|\s#]", [:unicode]) @@ -658,18 +658,18 @@ defmodule Regex do # Private Helpers - defp translate_options(<>, acc), do: translate_options(t, [:unicode, :ucp|acc]) - defp translate_options(<>, acc), do: translate_options(t, [:caseless|acc]) - defp translate_options(<>, acc), do: translate_options(t, [:extended|acc]) - defp translate_options(<>, acc), do: translate_options(t, [:firstline|acc]) - defp translate_options(<>, acc), do: translate_options(t, [:ungreedy|acc]) - defp translate_options(<>, acc), do: translate_options(t, [:dotall, {:newline, :anycrlf}|acc]) - defp translate_options(<>, acc), do: translate_options(t, [:multiline|acc]) + defp translate_options(<>, acc), do: translate_options(t, [:unicode, :ucp | acc]) + defp translate_options(<>, acc), do: translate_options(t, [:caseless | acc]) + defp translate_options(<>, acc), do: translate_options(t, [:extended | acc]) + defp translate_options(<>, acc), do: translate_options(t, [:firstline | acc]) + defp translate_options(<>, acc), do: translate_options(t, [:ungreedy | acc]) + defp translate_options(<>, acc), do: translate_options(t, [:dotall, {:newline, :anycrlf} | acc]) + defp translate_options(<>, acc), do: translate_options(t, [:multiline | acc]) defp translate_options(<>, acc) do IO.write :stderr, "warning: the /r modifier in regular expressions is deprecated, please use /U instead\n" <> Exception.format_stacktrace - translate_options(t, [:ungreedy|acc]) + translate_options(t, [:ungreedy | acc]) end defp translate_options(<<>>, acc), do: acc diff --git a/lib/elixir/lib/stream.ex b/lib/elixir/lib/stream.ex index a13543c0039..fc3217bf0fc 100644 --- a/lib/elixir/lib/stream.ex +++ b/lib/elixir/lib/stream.ex @@ -110,13 +110,13 @@ defmodule Stream do end defmacrop acc(h, n, t) do - quote do: [unquote(h), unquote(n)|unquote(t)] + quote do: [unquote(h), unquote(n) | unquote(t)] end defmacrop next_with_acc(f, entry, h, n, t) do quote do - {reason, [h|t]} = unquote(f).(unquote(entry), [unquote(h)|unquote(t)]) - {reason, [h, unquote(n)|t]} + {reason, [h | t]} = unquote(f).(unquote(entry), [unquote(h) | unquote(t)]) + {reason, [h, unquote(n) | t]} end end @@ -270,20 +270,20 @@ defmodule Stream do fn entry, [h, {count, buf1, []} | t] -> do_drop(:cont, n, entry, h, count, buf1, [], t) - entry, [h, {count, buf1, [next|buf2]} | t] -> - {reason, [h|t]} = f1.(next, [h|t]) + entry, [h, {count, buf1, [next | buf2]} | t] -> + {reason, [h | t]} = f1.(next, [h | t]) do_drop(reason, n, entry, h, count, buf1, buf2, t) end end end defp do_drop(reason, n, entry, h, count, buf1, buf2, t) do - buf1 = [entry|buf1] + buf1 = [entry | buf1] count = count + 1 if count == n do - {reason, [h, {0, [], :lists.reverse(buf1)}|t]} + {reason, [h, {0, [], :lists.reverse(buf1)} | t]} else - {reason, [h, {count, buf1, buf2}|t]} + {reason, [h, {count, buf1, buf2} | t]} end end @@ -412,26 +412,26 @@ defmodule Stream do defp do_into(enum, collectable, transform, acc, fun) do {initial, into} = Collectable.into(collectable) - composed = fn x, [acc|collectable] -> + composed = fn x, [acc | collectable] -> collectable = into.(collectable, {:cont, transform.(x)}) {reason, acc} = fun.(x, acc) - {reason, [acc|collectable]} + {reason, [acc | collectable]} end do_into(&Enumerable.reduce(enum, &1, composed), initial, into, acc) end defp do_into(reduce, collectable, into, {command, acc}) do try do - reduce.({command, [acc|collectable]}) + reduce.({command, [acc | collectable]}) catch kind, reason -> stacktrace = System.stacktrace into.(collectable, :halt) :erlang.raise(kind, reason, stacktrace) else - {:suspended, [acc|collectable], continuation} -> + {:suspended, [acc | collectable], continuation} -> {:suspended, acc, &do_into(continuation, collectable, into, &1)} - {reason, [acc|collectable]} -> + {reason, [acc | collectable]} -> into.(collectable, :done) {reason, acc} end @@ -697,7 +697,7 @@ defmodule Stream do defp do_transform(user_acc, user, fun, next_acc, next, inner_acc, inner, after_fun) do case next.({:cont, next_acc}) do - {:suspended, [val|next_acc], next} -> + {:suspended, [val | next_acc], next} -> try do user.(val, user_acc) catch @@ -749,7 +749,7 @@ defmodule Stream do defp do_enum_transform(user_acc, user, fun, next_acc, next, {op, inner_acc}, inner, reduce, after_fun) do try do - reduce.({op, [:outer|inner_acc]}) + reduce.({op, [:outer | inner_acc]}) catch kind, reason -> stacktrace = System.stacktrace @@ -759,15 +759,15 @@ defmodule Stream do else # Only take into account outer halts when the op is not halt itself. # Otherwise, we were the ones wishing to halt, so we should just stop. - {:halted, [:outer|acc]} when op != :halt -> + {:halted, [:outer | acc]} when op != :halt -> do_transform(user_acc, user, fun, next_acc, next, {:cont, acc}, inner, after_fun) - {:halted, [_|acc]} -> + {:halted, [_ | acc]} -> next.({:halt, next_acc}) do_after(after_fun, user_acc) {:halted, acc} - {:done, [_|acc]} -> + {:done, [_ | acc]} -> do_transform(user_acc, user, fun, next_acc, next, {:cont, acc}, inner, after_fun) - {:suspended, [_|acc], c} -> + {:suspended, [_ | acc], c} -> {:suspended, acc, &do_enum_transform(user_acc, user, fun, next_acc, next, &1, inner, c, after_fun)} end end @@ -775,15 +775,15 @@ defmodule Stream do defp do_after(nil, _user_acc), do: :ok defp do_after(fun, user_acc), do: fun.(user_acc) - defp do_transform_each(x, [:outer|acc], f) do + defp do_transform_each(x, [:outer | acc], f) do case f.(x, acc) do - {:halt, res} -> {:halt, [:inner|res]} - {op, res} -> {op, [:outer|res]} + {:halt, res} -> {:halt, [:inner | res]} + {op, res} -> {op, [:outer | res]} end end defp do_transform_step(x, acc) do - {:suspend, [x|acc]} + {:suspend, [x | acc]} end @doc """ @@ -916,10 +916,10 @@ defmodule Stream do end end - defp do_zip([{fun, fun_acc}|t], acc, callback, list, buffer) do + defp do_zip([{fun, fun_acc} | t], acc, callback, list, buffer) do case fun.({:cont, fun_acc}) do - {:suspended, [i|fun_acc], fun} -> - do_zip(t, acc, callback, [i|list], [{fun, fun_acc}|buffer]) + {:suspended, [i | fun_acc], fun} -> + do_zip(t, acc, callback, [i | list], [{fun, fun_acc} | buffer]) {_, _} -> do_zip_close(:lists.reverse(buffer, t)) {:done, acc} @@ -932,13 +932,13 @@ defmodule Stream do end defp do_zip_close([]), do: :ok - defp do_zip_close([{fun, acc}|t]) do + defp do_zip_close([{fun, acc} | t]) do fun.({:halt, acc}) do_zip_close(t) end defp do_zip_step(x, acc) do - {:suspend, [x|acc]} + {:suspend, [x | acc]} end ## Sources @@ -1140,28 +1140,28 @@ defmodule Stream do defp do_enum_resource(next_acc, next_fun, {op, acc}, fun, after_fun, reduce) do try do - reduce.({op, [:outer|acc]}) + reduce.({op, [:outer | acc]}) catch kind, reason -> stacktrace = System.stacktrace after_fun.(next_acc) :erlang.raise(kind, reason, stacktrace) else - {:halted, [:outer|acc]} -> + {:halted, [:outer | acc]} -> do_resource(next_acc, next_fun, {:cont, acc}, fun, after_fun) - {:halted, [:inner|acc]} -> + {:halted, [:inner | acc]} -> do_resource(next_acc, next_fun, {:halt, acc}, fun, after_fun) - {:done, [_|acc]} -> + {:done, [_ | acc]} -> do_resource(next_acc, next_fun, {:cont, acc}, fun, after_fun) - {:suspended, [_|acc], c} -> + {:suspended, [_ | acc], c} -> {:suspended, acc, &do_enum_resource(next_acc, next_fun, &1, fun, after_fun, c)} end end - defp do_resource_each(x, [:outer|acc], f) do + defp do_resource_each(x, [:outer | acc], f) do case f.(x, acc) do - {:halt, res} -> {:halt, [:inner|res]} - {op, res} -> {op, [:outer|res]} + {:halt, res} -> {:halt, [:inner | res]} + {op, res} -> {op, [:outer | res]} end end @@ -1203,17 +1203,17 @@ defmodule Stream do @compile {:inline, lazy: 2, lazy: 3, lazy: 4} defp lazy(%Stream{done: nil, funs: funs} = lazy, fun), - do: %{lazy | funs: [fun|funs] } + do: %{lazy | funs: [fun | funs] } defp lazy(enum, fun), do: %Stream{enum: enum, funs: [fun]} defp lazy(%Stream{done: nil, funs: funs, accs: accs} = lazy, acc, fun), - do: %{lazy | funs: [fun|funs], accs: [acc|accs] } + do: %{lazy | funs: [fun | funs], accs: [acc | accs] } defp lazy(enum, acc, fun), do: %Stream{enum: enum, funs: [fun], accs: [acc]} defp lazy(%Stream{done: nil, funs: funs, accs: accs} = lazy, acc, fun, done), - do: %{lazy | funs: [fun|funs], accs: [acc|accs], done: done} + do: %{lazy | funs: [fun | funs], accs: [acc | accs], done: done} defp lazy(enum, acc, fun, done), do: %Stream{enum: enum, funs: [fun], accs: [acc], done: done} end @@ -1243,8 +1243,8 @@ defimpl Enumerable, for: Stream do end defp do_each(reduce, done, accs, {command, acc}) do - case reduce.({command, [acc|accs]}) do - {:suspended, [acc|accs], continuation} -> + case reduce.({command, [acc | accs]}) do + {:suspended, [acc | accs], continuation} -> {:suspended, acc, &do_each(continuation, done, accs, &1)} {:halted, accs} -> do_done {:halted, accs}, done @@ -1253,13 +1253,13 @@ defimpl Enumerable, for: Stream do end end - defp do_done({reason, [acc|_]}, nil), do: {reason, acc} - defp do_done({reason, [acc|t]}, {done, fun}) do - [h|_] = Enum.reverse(t) + defp do_done({reason, [acc | _]}, nil), do: {reason, acc} + defp do_done({reason, [acc | t]}, {done, fun}) do + [h | _] = Enum.reverse(t) case done.([acc, h], fun) do - {:cont, [acc|_]} -> {reason, acc} - {:halt, [acc|_]} -> {:halted, acc} - {:suspend, [acc|_]} -> {:suspended, acc, &({:done, elem(&1, 1)})} + {:cont, [acc | _]} -> {reason, acc} + {:halt, [acc | _]} -> {:halted, acc} + {:suspend, [acc | _]} -> {:suspended, acc, &({:done, elem(&1, 1)})} end end end diff --git a/lib/elixir/lib/stream/reducers.ex b/lib/elixir/lib/stream/reducers.ex index fcfad6bfdfd..f14399f8cc3 100644 --- a/lib/elixir/lib/stream/reducers.ex +++ b/lib/elixir/lib/stream/reducers.ex @@ -5,7 +5,7 @@ defmodule Stream.Reducers do defmacro chunk(n, step, limit, f \\ nil) do quote do fn entry, acc(h, {buffer, count}, t) -> - buffer = [entry|buffer] + buffer = [entry | buffer] count = count + 1 new = @@ -31,7 +31,7 @@ defmodule Stream.Reducers do entry, acc(h, {buffer, value}, t) -> new_value = unquote(callback).(entry) if new_value == value do - skip(acc(h, {[entry|buffer], value}, t)) + skip(acc(h, {[entry | buffer], value}, t)) else next_with_acc(unquote(f), :lists.reverse(buffer), h, {[entry], new_value}, t) end diff --git a/lib/elixir/lib/string.ex b/lib/elixir/lib/string.ex index 241c51e295d..32c0bd5fc68 100644 --- a/lib/elixir/lib/string.ex +++ b/lib/elixir/lib/string.ex @@ -353,7 +353,7 @@ defmodule String do defp split_each(string, _pattern, _trim, 1) when is_binary(string), do: [string] defp split_each(string, pattern, trim, count) do case do_splitter(string, pattern, trim) do - {h, t} -> [h|split_each(t, pattern, trim, count - 1)] + {h, t} -> [h | split_each(t, pattern, trim, count - 1)] nil -> [] end end @@ -977,7 +977,7 @@ defmodule String do end defp do_reverse({grapheme, rest}, acc) do - do_reverse(next_grapheme(rest), [grapheme|acc]) + do_reverse(next_grapheme(rest), [grapheme | acc]) end defp do_reverse(nil, acc), do: IO.iodata_to_binary(acc) @@ -1144,7 +1144,7 @@ defmodule String do defp do_chunk(string, acc, chunk, flag, pred_fn) do {cp, rest} = next_codepoint(string) if pred_fn.(cp) != flag do - do_chunk(rest, [chunk|acc], cp, not flag, pred_fn) + do_chunk(rest, [chunk | acc], cp, not flag, pred_fn) else do_chunk(rest, acc, chunk <> cp, flag, pred_fn) end @@ -1471,7 +1471,7 @@ defmodule String do defp add_if_negative(value, _to_add), do: value defp do_acc_bytes({size, rest}, bytes, length) do - do_acc_bytes(next_grapheme_size(rest), [size|bytes], length + 1) + do_acc_bytes(next_grapheme_size(rest), [size | bytes], length + 1) end defp do_acc_bytes(nil, bytes, length) do diff --git a/lib/elixir/lib/string_io.ex b/lib/elixir/lib/string_io.ex index 5ce7dcb731b..dc8d390db74 100644 --- a/lib/elixir/lib/string_io.ex +++ b/lib/elixir/lib/string_io.ex @@ -339,7 +339,7 @@ defmodule StringIO do ## io_requests - defp io_requests([r|rs], {:ok, s}) do + defp io_requests([r | rs], {:ok, s}) do io_requests(rs, io_request(r, s)) end @@ -358,15 +358,15 @@ defmodule StringIO do end defp collect_line([?\r, ?\n | rest], stack) do - {:lists.reverse([?\n|stack]), rest} + {:lists.reverse([?\n | stack]), rest} end defp collect_line([?\n | rest], stack) do - {:lists.reverse([?\n|stack]), rest} + {:lists.reverse([?\n | stack]), rest} end - defp collect_line([h|t], stack) do - collect_line(t, [h|stack]) + defp collect_line([h | t], stack) do + collect_line(t, [h | stack]) end defp io_reply(from, reply_as, reply) do diff --git a/lib/elixir/lib/supervisor.ex b/lib/elixir/lib/supervisor.ex index 5d5695e609e..f15fa592d0d 100644 --- a/lib/elixir/lib/supervisor.ex +++ b/lib/elixir/lib/supervisor.ex @@ -24,12 +24,12 @@ defmodule Supervisor do GenServer.start_link(__MODULE__, state, opts) end - def handle_call(:pop, _from, [h|t]) do + def handle_call(:pop, _from, [h | t]) do {:reply, h, t} end def handle_cast({:push, h}, t) do - {:noreply, [h|t]} + {:noreply, [h | t]} end end diff --git a/lib/elixir/lib/supervisor/spec.ex b/lib/elixir/lib/supervisor/spec.ex index 66ffa1495a1..d748948dd56 100644 --- a/lib/elixir/lib/supervisor/spec.ex +++ b/lib/elixir/lib/supervisor/spec.ex @@ -171,7 +171,7 @@ defmodule Supervisor.Spec do {:ok, {{strategy, maxR, maxS}, children}} end - defp assert_unique_ids([id|rest]) do + defp assert_unique_ids([id | rest]) do if id in rest do raise ArgumentError, "duplicated id #{inspect id} found in the supervisor specification, " <> diff --git a/lib/elixir/lib/system.ex b/lib/elixir/lib/system.ex index ec8351769d4..848a42da15f 100644 --- a/lib/elixir/lib/system.ex +++ b/lib/elixir/lib/system.ex @@ -314,7 +314,7 @@ defmodule System do The function must receive the exit status code as an argument. """ def at_exit(fun) when is_function(fun, 1) do - :elixir_config.update :at_exit, &[fun|&1] + :elixir_config.update :at_exit, &[fun | &1] end @doc """ @@ -569,28 +569,28 @@ defmodule System do end end - defp cmd_opts([{:into, any}|t], opts, _into), + defp cmd_opts([{:into, any} | t], opts, _into), do: cmd_opts(t, opts, any) - defp cmd_opts([{:cd, bin}|t], opts, into) when is_binary(bin), - do: cmd_opts(t, [{:cd, bin}|opts], into) + defp cmd_opts([{:cd, bin} | t], opts, into) when is_binary(bin), + do: cmd_opts(t, [{:cd, bin} | opts], into) - defp cmd_opts([{:arg0, bin}|t], opts, into) when is_binary(bin), - do: cmd_opts(t, [{:arg0, bin}|opts], into) + defp cmd_opts([{:arg0, bin} | t], opts, into) when is_binary(bin), + do: cmd_opts(t, [{:arg0, bin} | opts], into) - defp cmd_opts([{:stderr_to_stdout, true}|t], opts, into), - do: cmd_opts(t, [:stderr_to_stdout|opts], into) + defp cmd_opts([{:stderr_to_stdout, true} | t], opts, into), + do: cmd_opts(t, [:stderr_to_stdout | opts], into) - defp cmd_opts([{:stderr_to_stdout, false}|t], opts, into), + defp cmd_opts([{:stderr_to_stdout, false} | t], opts, into), do: cmd_opts(t, opts, into) - defp cmd_opts([{:parallelism, bool}|t], opts, into) when is_boolean(bool), - do: cmd_opts(t, [{:parallelism, bool}|opts], into) + defp cmd_opts([{:parallelism, bool} | t], opts, into) when is_boolean(bool), + do: cmd_opts(t, [{:parallelism, bool} | opts], into) - defp cmd_opts([{:env, enum}|t], opts, into), - do: cmd_opts(t, [{:env, validate_env(enum)}|opts], into) + defp cmd_opts([{:env, enum} | t], opts, into), + do: cmd_opts(t, [{:env, validate_env(enum)} | opts], into) - defp cmd_opts([{key, val}|_], _opts, _into), + defp cmd_opts([{key, val} | _], _opts, _into), do: raise(ArgumentError, "invalid option #{inspect key} with value #{inspect val}") defp cmd_opts([], opts, into), diff --git a/lib/elixir/lib/task.ex b/lib/elixir/lib/task.ex index dd553a5113c..fff26de8f20 100644 --- a/lib/elixir/lib/task.ex +++ b/lib/elixir/lib/task.ex @@ -480,7 +480,7 @@ defmodule Task do end end - defp yield_many([%Task{ref: ref, owner: owner}=task|rest], timeout_ref, timeout) do + defp yield_many([%Task{ref: ref, owner: owner}=task | rest], timeout_ref, timeout) do if owner != self() do raise ArgumentError, invalid_owner_error(task) end @@ -488,20 +488,20 @@ defmodule Task do receive do {^ref, reply} -> Process.demonitor(ref, [:flush]) - [{task, {:ok, reply}}|yield_many(rest, timeout_ref, timeout)] + [{task, {:ok, reply}} | yield_many(rest, timeout_ref, timeout)] {:DOWN, ^ref, _, proc, :noconnection} -> throw({:noconnection, reason(:noconnection, proc)}) {:DOWN, ^ref, _, _, reason} -> - [{task, {:exit, reason}}|yield_many(rest, timeout_ref, timeout)] + [{task, {:exit, reason}} | yield_many(rest, timeout_ref, timeout)] ^timeout_ref -> - [{task, nil}|yield_many(rest, timeout_ref, 0)] + [{task, nil} | yield_many(rest, timeout_ref, 0)] after timeout -> - [{task, nil}|yield_many(rest, timeout_ref, 0)] + [{task, nil} | yield_many(rest, timeout_ref, 0)] end end diff --git a/lib/elixir/lib/version.ex b/lib/elixir/lib/version.ex index debda4c8ccf..dc279e05cfa 100644 --- a/lib/elixir/lib/version.ex +++ b/lib/elixir/lib/version.ex @@ -428,14 +428,14 @@ defmodule Version do defp parse_pre(nil), do: {:ok, []} defp parse_pre(pre), do: parse_pre(String.split(pre, "."), []) - defp parse_pre([piece|t], acc) do + defp parse_pre([piece | t], acc) do cond do piece =~ ~r/^(0|[1-9][0-9]*)$/ -> - parse_pre(t, [String.to_integer(piece)|acc]) + parse_pre(t, [String.to_integer(piece) | acc]) piece =~ ~r/^[0-9]*$/ -> :error true -> - parse_pre(t, [piece|acc]) + parse_pre(t, [piece | acc]) end end diff --git a/lib/elixir/src/elixir.erl b/lib/elixir/src/elixir.erl index 25940889d5c..f7225212e4e 100644 --- a/lib/elixir/src/elixir.erl +++ b/lib/elixir/src/elixir.erl @@ -251,7 +251,7 @@ quoted_to_erl(Quoted, Env, Scope) -> %% Converts a given string (char list) into quote expression string_to_quoted(String, StartLine, File, Opts) when is_integer(StartLine), is_binary(File) -> - case elixir_tokenizer:tokenize(String, StartLine, [{file, File}|Opts]) of + case elixir_tokenizer:tokenize(String, StartLine, [{file, File} | Opts]) of {ok, _Line, _Column, Tokens} -> put(elixir_parser_file, File), try elixir_parser:parse(Tokens) of diff --git a/lib/elixir/src/elixir_aliases.erl b/lib/elixir/src/elixir_aliases.erl index 6b8050c3eed..22e16c52f9a 100644 --- a/lib/elixir/src/elixir_aliases.erl +++ b/lib/elixir/src/elixir_aliases.erl @@ -40,7 +40,7 @@ record_warn(Meta, Ref, Opts, Lexical) -> %% Expand an alias. It returns an atom (meaning that there %% was an expansion) or a list of atoms. -expand({'__aliases__', _Meta, ['Elixir'|_] = List}, _Aliases, _MacroAliases, _LexicalTracker) -> +expand({'__aliases__', _Meta, ['Elixir' | _] = List}, _Aliases, _MacroAliases, _LexicalTracker) -> concat(List); expand({'__aliases__', Meta, _} = Alias, Aliases, MacroAliases, LexicalTracker) -> @@ -53,19 +53,19 @@ expand({'__aliases__', Meta, _} = Alias, Aliases, MacroAliases, LexicalTracker) expand(Alias, Aliases, LexicalTracker) end. -expand({'__aliases__', Meta, [H|T]}, Aliases, LexicalTracker) when is_atom(H) -> +expand({'__aliases__', Meta, [H | T]}, Aliases, LexicalTracker) when is_atom(H) -> Lookup = list_to_atom("Elixir." ++ atom_to_list(H)), Counter = case lists:keyfind(counter, 1, Meta) of {counter, C} -> C; _ -> nil end, case lookup(Lookup, Aliases, Counter) of - Lookup -> [H|T]; + Lookup -> [H | T]; Atom -> elixir_lexical:record_alias(Lookup, LexicalTracker), case T of [] -> Atom; - _ -> concat([Atom|T]) + _ -> concat([Atom | T]) end end; @@ -97,9 +97,9 @@ last(Atom) -> Last = last(lists:reverse(atom_to_list(Atom)), []), list_to_atom("Elixir." ++ Last). -last([$.|_], Acc) -> Acc; -last([H|T], Acc) -> last(T, [H|Acc]); -last([], Acc) -> Acc. +last([$. | _], Acc) -> Acc; +last([H | T], Acc) -> last(T, [H | Acc]); +last([], Acc) -> Acc. %% Receives a list of atoms, binaries or lists %% representing modules and concatenates them. @@ -107,20 +107,20 @@ last([], Acc) -> Acc. concat(Args) -> binary_to_atom(do_concat(Args), utf8). safe_concat(Args) -> binary_to_existing_atom(do_concat(Args), utf8). -do_concat([H|T]) when is_atom(H), H /= nil -> - do_concat([atom_to_binary(H, utf8)|T]); -do_concat([<<"Elixir.", _/binary>>=H|T]) -> +do_concat([H | T]) when is_atom(H), H /= nil -> + do_concat([atom_to_binary(H, utf8) | T]); +do_concat([<<"Elixir.", _/binary>>=H | T]) -> do_concat(T, H); -do_concat([<<"Elixir">>=H|T]) -> +do_concat([<<"Elixir">>=H | T]) -> do_concat(T, H); do_concat(T) -> do_concat(T, <<"Elixir">>). -do_concat([nil|T], Acc) -> +do_concat([nil | T], Acc) -> do_concat(T, Acc); -do_concat([H|T], Acc) when is_atom(H) -> +do_concat([H | T], Acc) when is_atom(H) -> do_concat(T, <>); -do_concat([H|T], Acc) when is_binary(H) -> +do_concat([H | T], Acc) when is_binary(H) -> do_concat(T, <>); do_concat([], Acc) -> Acc. diff --git a/lib/elixir/src/elixir_bitstring.erl b/lib/elixir/src/elixir_bitstring.erl index 56aaa8e743e..bc0d3fe8b5c 100644 --- a/lib/elixir/src/elixir_bitstring.erl +++ b/lib/elixir/src/elixir_bitstring.erl @@ -16,7 +16,7 @@ expand(Meta, Args, E) -> expand_bitstr(_Fun, [], Acc, E) -> {lists:reverse(Acc), E}; -expand_bitstr(Fun, [{'::', Meta, [Left, Right]}|T], Acc, E) -> +expand_bitstr(Fun, [{'::', Meta, [Left, Right]} | T], Acc, E) -> {ELeft, EL} = Fun(Left, E), %% Variables defined outside the binary can be accounted @@ -27,18 +27,18 @@ expand_bitstr(Fun, [{'::', Meta, [Left, Right]}|T], Acc, E) -> end, ERight = expand_bit_info(Meta, Right, ER), - expand_bitstr(Fun, T, [{'::', Meta, [ELeft, ERight]}|Acc], EL); + expand_bitstr(Fun, T, [{'::', Meta, [ELeft, ERight]} | Acc], EL); -expand_bitstr(Fun, [H|T], Acc, E) -> +expand_bitstr(Fun, [H | T], Acc, E) -> {Expr, ES} = Fun(H, E), - expand_bitstr(Fun, T, [Expr|Acc], ES). + expand_bitstr(Fun, T, [Expr | Acc], ES). %% Expand bit info expand_bit_info(Meta, Info, E) -> expand_bit_info(Meta, unpack_bit_info(Info, []), default, [], E). -expand_bit_info(Meta, [{size, _, [_]=Args}|T], Size, Types, E) -> +expand_bit_info(Meta, [{size, _, [_]=Args} | T], Size, Types, E) -> case Size of default -> {[EArg], EE} = elixir_exp:expand_args(Args, E), @@ -60,22 +60,22 @@ expand_bit_info(Meta, [{size, _, [_]=Args}|T], Size, Types, E) -> "duplicated size definition in bitstring") end; -expand_bit_info(Meta, [{Expr, ExprMeta, Args}|T], Size, Types, E) when is_atom(Expr) -> +expand_bit_info(Meta, [{Expr, ExprMeta, Args} | T], Size, Types, E) when is_atom(Expr) -> case expand_bit_type(Expr, Args) of type -> {EArgs, EE} = elixir_exp:expand_args(Args, E), validate_bit_type_args(Meta, Expr, EArgs, EE), - expand_bit_info(Meta, T, Size, [{Expr, [], EArgs}|Types], EE); + expand_bit_info(Meta, T, Size, [{Expr, [], EArgs} | Types], EE); none -> handle_unknown_bit_info(Meta, {Expr, ExprMeta, Args}, T, Size, Types, E) end; -expand_bit_info(Meta, [Expr|_], _Size, _Types, E) -> +expand_bit_info(Meta, [Expr | _], _Size, _Types, E) -> elixir_errors:compile_error(Meta, ?m(E, file), "unknown bitstring specifier ~ts", ['Elixir.Kernel':inspect(Expr)]); expand_bit_info(Meta, [], Size, Types, _) -> - [H|T] = case Size of + [H | T] = case Size of default -> lists:reverse(Types); _ -> lists:reverse(Types, [Size]) end, @@ -117,16 +117,16 @@ handle_unknown_bit_info(Meta, Expr, T, Size, Types, E) -> unpack_bit_info({'-', _, [H, T]}, Acc) -> unpack_bit_info(H, unpack_bit_info(T, Acc)); unpack_bit_info({'*', _, [{'_', _, Atom}, Unit]}, Acc) when is_atom(Atom) and is_integer(Unit) -> - [{unit, [], [Unit]}|Acc]; + [{unit, [], [Unit]} | Acc]; unpack_bit_info({'*', _, [Size, Unit]}, Acc) when is_integer(Size) and is_integer(Unit) -> - [{size, [], [Size]}, {unit, [], [Unit]}|Acc]; + [{size, [], [Size]}, {unit, [], [Unit]} | Acc]; unpack_bit_info(Size, Acc) when is_integer(Size) -> - [{size, [], [Size]}|Acc]; + [{size, [], [Size]} | Acc]; unpack_bit_info({Expr, Meta, Args}, Acc) when is_atom(Expr) -> ListArgs = if is_atom(Args) -> []; is_list(Args) -> Args end, - [{Expr, Meta, ListArgs}|Acc]; + [{Expr, Meta, ListArgs} | Acc]; unpack_bit_info(Other, Acc) -> - [Other|Acc]. + [Other | Acc]. %% Translation @@ -152,11 +152,11 @@ build_bitstr(Fun, Exprs, Meta, S) -> build_bitstr_each(_Fun, [], _Meta, S, Acc) -> {Acc, S}; -build_bitstr_each(Fun, [{'::', _, [H, V]}|T], Meta, S, Acc) -> +build_bitstr_each(Fun, [{'::', _, [H, V]} | T], Meta, S, Acc) -> {Size, Types} = extract_bit_info(V, S#elixir_scope{context=nil}), build_bitstr_each(Fun, T, Meta, S, Acc, H, Size, Types); -build_bitstr_each(Fun, [H|T], Meta, S, Acc) -> +build_bitstr_each(Fun, [H | T], Meta, S, Acc) -> build_bitstr_each(Fun, T, Meta, S, Acc, H, default, default). build_bitstr_each(Fun, T, Meta, S, Acc, H, default, Types) when is_binary(H) -> @@ -176,7 +176,7 @@ build_bitstr_each(Fun, T, Meta, S, Acc, H, default, Types) when is_binary(H) -> end end, - build_bitstr_each(Fun, T, Meta, S, [Element|Acc]); + build_bitstr_each(Fun, T, Meta, S, [Element | Acc]); build_bitstr_each(_Fun, _T, Meta, S, _Acc, H, _Size, _Types) when is_binary(H) -> elixir_errors:compile_error(Meta, S#elixir_scope.file, "size is not supported for literal string in <<>>"); @@ -192,14 +192,14 @@ build_bitstr_each(Fun, T, Meta, S, Acc, H, Size, Types) -> {bin, _, Elements} -> case (Size == default) andalso types_allow_splice(Types, Elements) of true -> build_bitstr_each(Fun, T, Meta, NS, lists:reverse(Elements, Acc)); - false -> build_bitstr_each(Fun, T, Meta, NS, [{bin_element, ?ann(Meta), Expr, Size, Types}|Acc]) + false -> build_bitstr_each(Fun, T, Meta, NS, [{bin_element, ?ann(Meta), Expr, Size, Types} | Acc]) end; _ -> - build_bitstr_each(Fun, T, Meta, NS, [{bin_element, ?ann(Meta), Expr, Size, Types}|Acc]) + build_bitstr_each(Fun, T, Meta, NS, [{bin_element, ?ann(Meta), Expr, Size, Types} | Acc]) end. -types_require_conversion([End|T]) when End == little; End == big -> types_require_conversion(T); -types_require_conversion([UTF|T]) when UTF == utf8; UTF == utf16; UTF == utf32 -> types_require_conversion(T); +types_require_conversion([End | T]) when End == little; End == big -> types_require_conversion(T); +types_require_conversion([UTF | T]) when UTF == utf8; UTF == utf16; UTF == utf32 -> types_require_conversion(T); types_require_conversion([]) -> true; types_require_conversion(_) -> false. @@ -210,7 +210,7 @@ types_allow_splice([bitstring], _) -> true; types_allow_splice(default, _) -> true; types_allow_splice(_, _) -> false. -is_byte_size([Element|T], Acc) -> +is_byte_size([Element | T], Acc) -> case elem_size(Element) of {unknown, Unit} when Unit rem 8 == 0 -> is_byte_size(T, Acc); {unknown, _Unit} -> false; @@ -219,15 +219,15 @@ is_byte_size([Element|T], Acc) -> is_byte_size([], Size) -> Size rem 8 == 0. -elem_size({bin_element, _, _, default, _}) -> {0, 0}; +elem_size({bin_element, _, _, default, _}) -> {0, 0}; elem_size({bin_element, _, _, {integer, _, Size}, Types}) -> {Size, unit_size(Types, 1)}; -elem_size({bin_element, _, _, _Size, Types}) -> {unknown, unit_size(Types, 1)}. +elem_size({bin_element, _, _, _Size, Types}) -> {unknown, unit_size(Types, 1)}. -unit_size([binary|T], _) -> unit_size(T, 8); -unit_size([bytes|T], _) -> unit_size(T, 8); -unit_size([{unit, Size}|_], _) -> Size; -unit_size([_|T], Guess) -> unit_size(T, Guess); -unit_size([], Guess) -> Guess. +unit_size([binary | T], _) -> unit_size(T, 8); +unit_size([bytes | T], _) -> unit_size(T, 8); +unit_size([{unit, Size} | _], _) -> Size; +unit_size([_ | T], Guess) -> unit_size(T, Guess); +unit_size([], Guess) -> Guess. %% Extra bitstring specifiers @@ -245,6 +245,6 @@ extract_bit_size(Size, S) -> extract_bit_type({'-', _, [L, R]}, Acc) -> extract_bit_type(L, extract_bit_type(R, Acc)); extract_bit_type({unit, _, [Arg]}, Acc) -> - [{unit, Arg}|Acc]; + [{unit, Arg} | Acc]; extract_bit_type({Other, _, []}, Acc) -> - [Other|Acc]. + [Other | Acc]. diff --git a/lib/elixir/src/elixir_clauses.erl b/lib/elixir/src/elixir_clauses.erl index 1de32cd782c..e8fbe3ba607 100644 --- a/lib/elixir/src/elixir_clauses.erl +++ b/lib/elixir/src/elixir_clauses.erl @@ -51,17 +51,17 @@ guards(Guards, Extra, S) -> end. translate_guard(Guard, Extra, S) -> - [element(1, elixir_translator:translate(Guard, S))|Extra]. + [element(1, elixir_translator:translate(Guard, S)) | Extra]. extract_guards({'when', _, [Left, Right]}) -> {Left, extract_or_guards(Right)}; extract_guards(Else) -> {Else, []}. -extract_or_guards({'when', _, [Left, Right]}) -> [Left|extract_or_guards(Right)]; +extract_or_guards({'when', _, [Left, Right]}) -> [Left | extract_or_guards(Right)]; extract_or_guards(Term) -> [Term]. % Extract guards when multiple left side args are allowed. -extract_splat_guards([{'when', _, [_, _|_] = Args}]) -> +extract_splat_guards([{'when', _, [_, _ | _] = Args}]) -> {Left, Right} = elixir_utils:split_last(Args), {Left, extract_or_guards(Right)}; extract_splat_guards(Else) -> @@ -81,7 +81,7 @@ do_clauses(Meta, DecoupledClauses, S) -> % and storing variables defined inside each clause. Transformer = fun(X, {SAcc, VAcc}) -> {TX, TS} = each_clause(X, SAcc), - {TX, {elixir_scope:mergec(S, TS), [TS#elixir_scope.export_vars|VAcc]}} + {TX, {elixir_scope:mergec(S, TS), [TS#elixir_scope.export_vars | VAcc]}} end, {TClauses, {TS, ReverseCV}} = @@ -104,14 +104,14 @@ do_clauses(Meta, DecoupledClauses, S) -> % that defines variables missing in one clause to the others. expand_clauses(?ann(Meta), TClauses, CV, FinalVars, [], FS). -expand_clauses(Ann, [Clause|T], [ClauseVars|V], FinalVars, Acc, S) -> +expand_clauses(Ann, [Clause | T], [ClauseVars | V], FinalVars, Acc, S) -> case generate_match_vars(FinalVars, ClauseVars, [], []) of {[], []} -> - expand_clauses(Ann, T, V, FinalVars, [Clause|Acc], S); + expand_clauses(Ann, T, V, FinalVars, [Clause | Acc], S); {Left, Right} -> MatchExpr = generate_match(Ann, Left, Right), ClauseExprs = element(5, Clause), - [Final|RawClauseExprs] = lists:reverse(ClauseExprs), + [Final | RawClauseExprs] = lists:reverse(ClauseExprs), % If the last sentence has a match clause, we need to assign its value % in the variable list. If not, we insert the variable list before the @@ -120,19 +120,19 @@ expand_clauses(Ann, [Clause|T], [ClauseVars|V], FinalVars, Acc, S) -> true -> case Final of {match, _, {var, _, UserVarName} = UserVar, _} when UserVarName /= '_' -> - {[UserVar, MatchExpr, Final|RawClauseExprs], S}; + {[UserVar, MatchExpr, Final | RawClauseExprs], S}; _ -> {VarName, _, SS} = elixir_scope:build_var('_', S), StorageVar = {var, Ann, VarName}, StorageExpr = {match, Ann, StorageVar, Final}, - {[StorageVar, MatchExpr, StorageExpr|RawClauseExprs], SS} + {[StorageVar, MatchExpr, StorageExpr | RawClauseExprs], SS} end; false -> - {[Final, MatchExpr|RawClauseExprs], S} + {[Final, MatchExpr | RawClauseExprs], S} end, FinalClause = setelement(5, Clause, lists:reverse(FinalClauseExprs)), - expand_clauses(Ann, T, V, FinalVars, [FinalClause|Acc], FS) + expand_clauses(Ann, T, V, FinalVars, [FinalClause | Acc], FS) end; expand_clauses(_Ann, [], [], _FinalVars, Acc, S) -> @@ -198,17 +198,17 @@ normalize_vars(Key, {Ref, Counter, _Safe}, % Generate match vars by checking if they were updated % or not and assigning the previous value. -generate_match_vars([{Key, Value, Expr}|T], ClauseVars, Left, Right) -> +generate_match_vars([{Key, Value, Expr} | T], ClauseVars, Left, Right) -> case maps:find(Key, ClauseVars) of {ok, Value} -> generate_match_vars(T, ClauseVars, Left, Right); {ok, Clause} -> generate_match_vars(T, ClauseVars, - [{var, 0, element(1, Value)}|Left], - [{var, 0, element(1, Clause)}|Right]); + [{var, 0, element(1, Value)} | Left], + [{var, 0, element(1, Clause)} | Right]); error -> generate_match_vars(T, ClauseVars, - [{var, 0, element(1, Value)}|Left], [Expr|Right]) + [{var, 0, element(1, Value)} | Left], [Expr | Right]) end; generate_match_vars([], _ClauseVars, Left, Right) -> diff --git a/lib/elixir/src/elixir_code_server.erl b/lib/elixir/src/elixir_code_server.erl index 0f8d743edd2..4141be1134f 100644 --- a/lib/elixir/src/elixir_code_server.erl +++ b/lib/elixir/src/elixir_code_server.erl @@ -46,7 +46,7 @@ handle_call({acquire, Path}, From, Config) -> {ok, true} -> {reply, loaded, Config}; {ok, {Ref, List}} when is_list(List), is_reference(Ref) -> - Queued = maps:put(Path, {Ref, [From|List]}, Current), + Queued = maps:put(Path, {Ref, [From | List]}, Current), {reply, {queued, Ref}, Config#elixir_code_server{loaded=Queued}}; error -> Queued = maps:put(Path, {make_ref(), []}, Current), @@ -65,7 +65,7 @@ handle_call({compilation_status, CompilerPid}, _From, Config) -> handle_call(retrieve_module_name, _From, Config) -> case Config#elixir_code_server.mod_pool of - {[H|T], Counter} -> + {[H | T], Counter} -> {reply, module_tuple(H), Config#elixir_code_server{mod_pool={T, Counter}}}; {[], Counter} -> {reply, module_tuple(Counter), Config#elixir_code_server{mod_pool={[], Counter+1}}} @@ -108,7 +108,7 @@ handle_cast({unload_files, Files}, Config) -> {noreply, Config#elixir_code_server{loaded=Unloaded}}; handle_cast({return_module_name, H}, #elixir_code_server{mod_pool={T, Counter}} = Config) -> - {noreply, Config#elixir_code_server{mod_pool={[H|T], Counter}}}; + {noreply, Config#elixir_code_server{mod_pool={[H | T], Counter}}}; handle_cast(Request, Config) -> {stop, {badcast, Request}, Config}. diff --git a/lib/elixir/src/elixir_compiler.erl b/lib/elixir/src/elixir_compiler.erl index 3602bacccae..3b9bc3d5792 100644 --- a/lib/elixir/src/elixir_compiler.erl +++ b/lib/elixir/src/elixir_compiler.erl @@ -186,7 +186,7 @@ inner_module(Forms, ErlOpts, ExOpts, #{file := File} = E, Callback) when Autoload = proplists:get_value(autoload, ExOpts, true), Bootstrap = proplists:get_value(bootstrap, ExOpts, false), - case compile:noenv_forms([no_auto_import()|Forms], [return, {source, Source}|ErlOpts]) of + case compile:noenv_forms([no_auto_import() | Forms], [return, {source, Source} | ErlOpts]) of {ok, Module, Binary, Warnings} -> format_warnings(Bootstrap, Warnings), {module, Module} = diff --git a/lib/elixir/src/elixir_def.erl b/lib/elixir/src/elixir_def.erl index db75ee9e9f3..45a25e5ec99 100644 --- a/lib/elixir/src/elixir_def.erl +++ b/lib/elixir/src/elixir_def.erl @@ -181,7 +181,7 @@ translate_clause(_, Line, Kind, Args, Guards, Body, S) -> FClause = case is_macro(Kind) of true -> FArgs = {var, Line, '_@CALLER'}, - MClause = setelement(3, TClause, [FArgs|element(3, TClause)]), + MClause = setelement(3, TClause, [FArgs | element(3, TClause)]), case TS#elixir_scope.caller of true -> @@ -189,7 +189,7 @@ translate_clause(_, Line, Kind, Args, Guards, Body, S) -> {'var', Line, '__CALLER__'}, elixir_utils:erl_call(Line, elixir_env, linify, [{var, Line, '_@CALLER'}]) }, - setelement(5, MClause, [FBody|element(5, TClause)]); + setelement(5, MClause, [FBody | element(5, TClause)]); false -> MClause end; @@ -218,7 +218,7 @@ unwrap_definitions(File, Module) -> Unreachable = elixir_locals:warn_unused_local(File, Module, Private), split_definition(All, Unreachable, [], [], [], [], [], {[], []}). -unwrap_definition([Fun|T], File, Module, CTable, All, Private) -> +unwrap_definition([Fun | T], File, Module, CTable, All, Private) -> {Tuple, Kind, Line, _, Check, Location, {Defaults, _, _}} = Fun, Export = export(Kind, Tuple), @@ -233,43 +233,43 @@ unwrap_definition([Fun|T], File, Module, CTable, All, Private) -> NewPrivate = if Kind == defp; Kind == defmacrop -> - [{Tuple, Kind, Line, Check, Defaults}|Private]; + [{Tuple, Kind, Line, Check, Defaults} | Private]; true -> Private end, - unwrap_definition(T, File, Module, CTable, [Unwrapped|All], NewPrivate) + unwrap_definition(T, File, Module, CTable, [Unwrapped | All], NewPrivate) end; unwrap_definition([], _File, _Module, _CTable, All, Private) -> {All, Private}. -split_definition([{Tuple, def, Line, Location, Body}|T], Unreachable, +split_definition([{Tuple, def, Line, Location, Body} | T], Unreachable, Def, Defp, Defmacro, Defmacrop, Exports, Functions) -> - split_definition(T, Unreachable, [Tuple|Def], Defp, Defmacro, Defmacrop, - [export(def, Tuple)|Exports], + split_definition(T, Unreachable, [Tuple | Def], Defp, Defmacro, Defmacrop, + [export(def, Tuple) | Exports], add_definition(Line, Location, Body, Functions)); -split_definition([{Tuple, defp, Line, Location, Body}|T], Unreachable, +split_definition([{Tuple, defp, Line, Location, Body} | T], Unreachable, Def, Defp, Defmacro, Defmacrop, Exports, Functions) -> case lists:member(Tuple, Unreachable) of false -> - split_definition(T, Unreachable, Def, [Tuple|Defp], Defmacro, Defmacrop, + split_definition(T, Unreachable, Def, [Tuple | Defp], Defmacro, Defmacrop, Exports, add_definition(Line, Location, Body, Functions)); true -> - split_definition(T, Unreachable, Def, [Tuple|Defp], Defmacro, Defmacrop, + split_definition(T, Unreachable, Def, [Tuple | Defp], Defmacro, Defmacrop, Exports, Functions) end; -split_definition([{Tuple, defmacro, Line, Location, Body}|T], Unreachable, +split_definition([{Tuple, defmacro, Line, Location, Body} | T], Unreachable, Def, Defp, Defmacro, Defmacrop, Exports, Functions) -> - split_definition(T, Unreachable, Def, Defp, [Tuple|Defmacro], Defmacrop, - [export(defmacro, Tuple)|Exports], + split_definition(T, Unreachable, Def, Defp, [Tuple | Defmacro], Defmacrop, + [export(defmacro, Tuple) | Exports], add_definition(Line, Location, Body, Functions)); -split_definition([{Tuple, defmacrop, _Line, _Location, _Body}|T], Unreachable, +split_definition([{Tuple, defmacrop, _Line, _Location, _Body} | T], Unreachable, Def, Defp, Defmacro, Defmacrop, Exports, Functions) -> - split_definition(T, Unreachable, Def, Defp, Defmacro, [Tuple|Defmacrop], + split_definition(T, Unreachable, Def, Defp, Defmacro, [Tuple | Defmacrop], Exports, Functions); split_definition([], Unreachable, Def, Defp, Defmacro, Defmacrop, Exports, {Head, Tail}) -> @@ -286,10 +286,10 @@ function_for_stored_definition(Line, {Name, Arity}, Clauses) -> {function, Line, Name, Arity, Clauses}. add_definition(_Line, nil, Body, {Head, Tail}) -> - {[Body|Head], Tail}; + {[Body | Head], Tail}; add_definition(Line, Location, Body, {Head, Tail}) -> {Head, - [{attribute, Line, file, Location}, Body|Tail]}. + [{attribute, Line, file, Location}, Body | Tail]}. default_function_for(Kind, Name, {clause, Line, Args, _Guards, _Exprs} = Clause) when Kind == defmacro; Kind == defmacrop -> diff --git a/lib/elixir/src/elixir_def_defaults.erl b/lib/elixir/src/elixir_def_defaults.erl index e3825d2cce3..50ee1f3fac8 100644 --- a/lib/elixir/src/elixir_def_defaults.erl +++ b/lib/elixir/src/elixir_def_defaults.erl @@ -22,7 +22,7 @@ unpack(Kind, Name, Args, S) -> %% Unpack default from given args. %% Returns the given arguments without their default %% clauses and a list of clauses for the default calls. -unpack_each(Kind, Name, [{'\\\\', DefMeta, [Expr, _]}|T] = List, Acc, Clauses, S) -> +unpack_each(Kind, Name, [{'\\\\', DefMeta, [Expr, _]} | T] = List, Acc, Clauses, S) -> Base = wrap_kind(Kind, build_match(Acc, [])), {Args, Invoke} = extract_defaults(List, length(Base), [], []), @@ -37,22 +37,22 @@ unpack_each(Kind, Name, [{'\\\\', DefMeta, [Expr, _]}|T] = List, Acc, Clauses, S }, Clause = {clause, Ann, DefArgs, [], [Call]}, - unpack_each(Kind, Name, T, [Expr|Acc], [Clause|Clauses], S); + unpack_each(Kind, Name, T, [Expr | Acc], [Clause | Clauses], S); -unpack_each(Kind, Name, [H|T], Acc, Clauses, S) -> - unpack_each(Kind, Name, T, [H|Acc], Clauses, S); +unpack_each(Kind, Name, [H | T], Acc, Clauses, S) -> + unpack_each(Kind, Name, T, [H | Acc], Clauses, S); unpack_each(_Kind, _Name, [], Acc, Clauses, _S) -> {lists:reverse(Acc), lists:reverse(Clauses)}. % Extract default values from args following the current default clause. -extract_defaults([{'\\\\', _, [_Expr, Default]}|T], Counter, NewArgs, NewInvoke) -> - extract_defaults(T, Counter, NewArgs, [Default|NewInvoke]); +extract_defaults([{'\\\\', _, [_Expr, Default]} | T], Counter, NewArgs, NewInvoke) -> + extract_defaults(T, Counter, NewArgs, [Default | NewInvoke]); -extract_defaults([_|T], Counter, NewArgs, NewInvoke) -> +extract_defaults([_ | T], Counter, NewArgs, NewInvoke) -> H = {elixir_utils:atom_concat(["x", Counter]), [], nil}, - extract_defaults(T, Counter + 1, [H|NewArgs], [H|NewInvoke]); + extract_defaults(T, Counter + 1, [H | NewArgs], [H | NewInvoke]); extract_defaults([], _Counter, NewArgs, NewInvoke) -> {lists:reverse(NewArgs), lists:reverse(NewInvoke)}. @@ -61,13 +61,13 @@ extract_defaults([], _Counter, NewArgs, NewInvoke) -> build_match([], Acc) -> Acc; -build_match([_|T], Acc) -> +build_match([_ | T], Acc) -> Var = {elixir_utils:atom_concat(["x", length(T)]), [], nil}, - build_match(T, [Var|Acc]). + build_match(T, [Var | Acc]). % Given the invoked function name based on the kind -wrap_kind(Kind, Args) when Kind == defmacro; Kind == defmacrop -> [{c, [], nil}|Args]; +wrap_kind(Kind, Args) when Kind == defmacro; Kind == defmacrop -> [{c, [], nil} | Args]; wrap_kind(_Kind, Args) -> Args. name_for_kind(Kind, Name) when Kind == defmacro; Kind == defmacrop -> elixir_utils:macro_name(Name); diff --git a/lib/elixir/src/elixir_dispatch.erl b/lib/elixir/src/elixir_dispatch.erl index b4098794466..2ba2a90499f 100644 --- a/lib/elixir/src/elixir_dispatch.erl +++ b/lib/elixir/src/elixir_dispatch.erl @@ -146,7 +146,7 @@ do_expand_import(Meta, {Name, Arity} = Tuple, Args, Module, E, Result) -> elixir_locals:record_import(Tuple, Receiver, Module, ?m(E, function)), {ok, Receiver, expand_macro_named(Meta, Receiver, Name, Arity, Args, E)}; {import, Receiver} -> - case expand_require([{require, false}|Meta], Receiver, Tuple, Args, E) of + case expand_require([{require, false} | Meta], Receiver, Tuple, Args, E) of {ok, _, _} = Response -> Response; error -> {ok, Receiver, Name, Args} end; @@ -185,7 +185,7 @@ expand_macro_fun(Meta, Fun, Receiver, Name, Args, E) -> EArg = {Line, E}, try - apply(Fun, [EArg|Args]) + apply(Fun, [EArg | Args]) catch Kind:Reason -> Arity = length(Args), @@ -247,7 +247,7 @@ find_dispatch(Meta, Tuple, Extra, E) -> {[], []} -> false; _ -> {Name, Arity} = Tuple, - [First, Second|_] = FunMatch ++ MacMatch, + [First, Second | _] = FunMatch ++ MacMatch, Error = {ambiguous_call, {First, Second, Name, Arity}}, elixir_errors:form_error(Meta, ?m(E, file), ?MODULE, Error) end @@ -267,16 +267,16 @@ is_import(Meta) -> end. % %% We've reached the macro wrapper fun, skip it with the rest -prune_stacktrace([{_, _, [E|_], _}|_], _MFA, Info, E) -> +prune_stacktrace([{_, _, [E | _], _} | _], _MFA, Info, E) -> Info; %% We've reached the invoked macro, skip it -prune_stacktrace([{M, F, A, _}|_], {M, F, A}, Info, _E) -> +prune_stacktrace([{M, F, A, _} | _], {M, F, A}, Info, _E) -> Info; %% We've reached the elixir_dispatch internals, skip it with the rest -prune_stacktrace([{Mod, _, _, _}|_], _MFA, Info, _E) when Mod == elixir_dispatch; Mod == elixir_exp -> +prune_stacktrace([{Mod, _, _, _} | _], _MFA, Info, _E) when Mod == elixir_dispatch; Mod == elixir_exp -> Info; -prune_stacktrace([H|T], MFA, Info, E) -> - [H|prune_stacktrace(T, MFA, Info, E)]; +prune_stacktrace([H | T], MFA, Info, E) -> + [H | prune_stacktrace(T, MFA, Info, E)]; prune_stacktrace([], _MFA, Info, _E) -> Info. diff --git a/lib/elixir/src/elixir_errors.erl b/lib/elixir/src/elixir_errors.erl index c3ece3d2657..00363cc04da 100644 --- a/lib/elixir/src/elixir_errors.erl +++ b/lib/elixir/src/elixir_errors.erl @@ -61,7 +61,7 @@ parse_error(Line, File, <<"syntax error before: ">>, <<"'end'">>) -> %% Produce a human-readable message for errors before a sigil parse_error(Line, File, <<"syntax error before: ">>, <<"{sigil,", _Rest/binary>> = Full) -> - {sigil, _, Sigil, [Content|_], _} = parse_erl_term(Full), + {sigil, _, Sigil, [Content | _], _} = parse_erl_term(Full), Content2 = case is_binary(Content) of true -> Content; false -> <<>> @@ -78,7 +78,7 @@ parse_error(Line, File, Error, <<"['", _/binary>> = Full) when is_binary(Error) %% Binaries (and interpolation) are wrapped in [<<...>>] parse_error(Line, File, Error, <<"[", _/binary>> = Full) when is_binary(Error) -> Term = case parse_erl_term(Full) of - [H|_] when is_binary(H) -> <<$", H/binary, $">>; + [H | _] when is_binary(H) -> <<$", H/binary, $">>; _ -> <<$">> end, do_raise(Line, File, 'Elixir.SyntaxError', <>); diff --git a/lib/elixir/src/elixir_exp.erl b/lib/elixir/src/elixir_exp.erl index bfb6194c4a8..5ec2caa53c5 100644 --- a/lib/elixir/src/elixir_exp.erl +++ b/lib/elixir/src/elixir_exp.erl @@ -260,12 +260,12 @@ expand({'try', Meta, [KV]}, E) -> %% Comprehensions -expand({for, Meta, [_|_] = Args}, E) -> +expand({for, Meta, [_ | _] = Args}, E) -> elixir_for:expand(Meta, Args, E); %% With -expand({with, Meta, [_|_] = Args}, E) -> +expand({with, Meta, [_ | _] = Args}, E) -> elixir_with:expand(Meta, Args, E); %% Super @@ -403,10 +403,10 @@ expand_multi_alias_call(Kind, Meta, Base, Refs, Opts, E) -> expand_list([{'|', Meta, [_, _] = Args}], Fun, Acc, List) -> {EArgs, EAcc} = lists:mapfoldl(Fun, Acc, Args), - expand_list([], Fun, EAcc, [{'|', Meta, EArgs}|List]); -expand_list([H|T], Fun, Acc, List) -> + expand_list([], Fun, EAcc, [{'|', Meta, EArgs} | List]); +expand_list([H | T], Fun, Acc, List) -> {EArg, EAcc} = Fun(H, Acc), - expand_list(T, Fun, EAcc, [EArg|List]); + expand_list(T, Fun, EAcc, [EArg | List]); expand_list([], _Fun, Acc, List) -> {lists:reverse(List), Acc}. @@ -414,8 +414,8 @@ expand_block([], Acc, _Meta, E) -> {lists:reverse(Acc), E}; expand_block([H], Acc, Meta, E) -> {EH, EE} = expand(H, E), - expand_block([], [EH|Acc], Meta, EE); -expand_block([H|T], Acc, Meta, E) -> + expand_block([], [EH | Acc], Meta, EE); +expand_block([H | T], Acc, Meta, E) -> {EH, EE} = expand(H, E), %% Notice checks rely on the code BEFORE expansion @@ -435,7 +435,7 @@ expand_block([H|T], Acc, Meta, E) -> ok end, - expand_block(T, [EH|Acc], Meta, EE). + expand_block(T, [EH | Acc], Meta, EE). %% Notice we don't handle atoms on purpose. They are common %% when unquoting AST and it is unlikely that we would catch @@ -548,8 +548,8 @@ no_alias_opts(KV) when is_list(KV) -> end; no_alias_opts(KV) -> KV. -no_alias_expansion({'__aliases__', _, [H|T]}) when is_atom(H) -> - elixir_aliases:concat([H|T]); +no_alias_expansion({'__aliases__', _, [H | T]}) when is_atom(H) -> + elixir_aliases:concat([H | T]); no_alias_expansion(Other) -> Other. @@ -568,7 +568,7 @@ expand_alias(Meta, IncludeByDefault, Ref, KV, #{context_modules := Context} = E) %% module in context modules. NewContext = case lists:keyfind(defined, 1, Meta) of - {defined, Mod} when is_atom(Mod) -> [Mod|Context]; + {defined, Mod} when is_atom(Mod) -> [Mod | Context]; false -> Context end, diff --git a/lib/elixir/src/elixir_exp_clauses.erl b/lib/elixir/src/elixir_exp_clauses.erl index 64ab95dde12..abf11b57185 100644 --- a/lib/elixir/src/elixir_exp_clauses.erl +++ b/lib/elixir/src/elixir_exp_clauses.erl @@ -25,7 +25,7 @@ clause(_Meta, _Kind, Fun, {'->', Meta, [Left, Right]}, #{export_vars := ExportVa clause(Meta, Kind, _Fun, _, E) -> compile_error(Meta, ?m(E, file), "expected -> clauses in ~ts", [Kind]). -head([{'when', Meta, [_, _|_] = All}], E) -> +head([{'when', Meta, [_, _ | _] = All}], E) -> {Args, Guard} = elixir_utils:split_last(All), {EArgs, EA} = match(fun elixir_exp:expand_args/2, Args, E), {EGuard, EG} = guard(Guard, EA#{context := guard}), diff --git a/lib/elixir/src/elixir_fn.erl b/lib/elixir/src/elixir_fn.erl index 9f3a597689c..03bc14e73c2 100644 --- a/lib/elixir/src/elixir_fn.erl +++ b/lib/elixir/src/elixir_fn.erl @@ -119,17 +119,17 @@ invalid_capture(Meta, Arg, E) -> "&local/arity or a capture containing at least one argument as &1, got: ~ts", compile_error(Meta, ?m(E, file), Message, ['Elixir.Macro':to_string(Arg)]). -validate(Meta, [{Pos, Var}|T], Pos, E) -> - [Var|validate(Meta, T, Pos + 1, E)]; +validate(Meta, [{Pos, Var} | T], Pos, E) -> + [Var | validate(Meta, T, Pos + 1, E)]; -validate(Meta, [{Pos, _}|_], Expected, E) -> +validate(Meta, [{Pos, _} | _], Expected, E) -> compile_error(Meta, ?m(E, file), "capture &~B cannot be defined without &~B", [Pos, Expected]); validate(_Meta, [], _Pos, _E) -> []. do_escape({'&', _, [Pos]}, Counter, _E, Dict) when is_integer(Pos), Pos > 0 -> - Var = {list_to_atom([$x|integer_to_list(Pos)]), [{counter, Counter}], elixir_fn}, + Var = {list_to_atom([$x | integer_to_list(Pos)]), [{counter, Counter}], elixir_fn}, {Var, orddict:store(Pos, Var, Dict)}; do_escape({'&', Meta, [Pos]}, _Counter, E, _Dict) when is_integer(Pos) -> @@ -164,7 +164,7 @@ args_from_arity(Meta, A, E) -> is_sequential_and_not_empty([]) -> false; is_sequential_and_not_empty(List) -> is_sequential(List, 1). -is_sequential([{'&', _, [Int]}|T], Int) -> +is_sequential([{'&', _, [Int]} | T], Int) -> is_sequential(T, Int + 1); is_sequential([], _Int) -> true; is_sequential(_, _Int) -> false. diff --git a/lib/elixir/src/elixir_for.erl b/lib/elixir/src/elixir_for.erl index af5eab003cd..2c9b8c98c82 100644 --- a/lib/elixir/src/elixir_for.erl +++ b/lib/elixir/src/elixir_for.erl @@ -30,7 +30,7 @@ expand(Meta, Args, E) -> {EOpts, EO} = elixir_exp:expand(Opts, E), {ECases, EC} = lists:mapfoldl(fun expand/2, EO, Cases), {EExpr, _} = elixir_exp:expand(Expr, EC), - {{for, Meta, ECases ++ [[{do, EExpr}|EOpts]]}, E}. + {{for, Meta, ECases ++ [[{do, EExpr} | EOpts]]}, E}. expand({'<-', Meta, [Left, Right]}, E) -> {ERight, ER} = elixir_exp:expand(Right, E), @@ -59,7 +59,7 @@ translate(Meta, Args, Return, S) -> Acc = {var, Ann, AccName}, Var = {var, Ann, VarName}, - {Cases, [{do, Expr}|Opts]} = elixir_utils:split_last(Args), + {Cases, [{do, Expr} | Opts]} = elixir_utils:split_last(Args), {TInto, SI} = case lists:keyfind(into, 1, Opts) of @@ -84,13 +84,13 @@ translate(Meta, Args, Return, S) -> wrap_expr(Expr, false) -> {'__block__', [], [Expr, nil]}; wrap_expr(Expr, _) -> Expr. -translate_gen(ForMeta, [{'<-', Meta, [Left, Right]}|T], Acc, S) -> +translate_gen(ForMeta, [{'<-', Meta, [Left, Right]} | T], Acc, S) -> {TLeft, TRight, TFilters, TT, TS} = translate_gen(Meta, Left, Right, T, S), - TAcc = [{enum, Meta, TLeft, TRight, TFilters}|Acc], + TAcc = [{enum, Meta, TLeft, TRight, TFilters} | Acc], translate_gen(ForMeta, TT, TAcc, TS); -translate_gen(ForMeta, [{'<<>>', _, [ {'<-', Meta, [Left, Right]} ]}|T], Acc, S) -> +translate_gen(ForMeta, [{'<<>>', _, [ {'<-', Meta, [Left, Right]} ]} | T], Acc, S) -> {TLeft, TRight, TFilters, TT, TS} = translate_gen(Meta, Left, Right, T, S), - TAcc = [{bin, Meta, TLeft, TRight, TFilters}|Acc], + TAcc = [{bin, Meta, TLeft, TRight, TFilters} | Acc], case elixir_bitstring:has_size(TLeft) of true -> translate_gen(ForMeta, TT, TAcc, TS); false -> @@ -138,12 +138,12 @@ translate_filter(Filter, S) -> {{{var, 0, Name}, TFilter}, VS} end. -collect_filters([{'<-', _, [_, _]}|_] = T, Acc) -> +collect_filters([{'<-', _, [_, _]} | _] = T, Acc) -> {Acc, T}; -collect_filters([{'<<>>', _, [{'<-', _, [_, _]}]}|_] = T, Acc) -> +collect_filters([{'<<>>', _, [{'<-', _, [_, _]}]} | _] = T, Acc) -> {Acc, T}; -collect_filters([H|T], Acc) -> - collect_filters(T, [H|Acc]); +collect_filters([H | T], Acc) -> + collect_filters(T, [H | Acc]); collect_filters([], Acc) -> {Acc, []}. @@ -202,10 +202,10 @@ build_reduce(Clauses, Expr, {nil, Ann} = Into, Acc, S) -> [build_reduce_clause(Clauses, ListExpr, Into, Acc, S)]); build_reduce(Clauses, Expr, {bin, _, _} = Into, Acc, S) -> {bin, Ann, Elements} = Expr, - BinExpr = {bin, Ann, [{bin_element, Ann, Acc, default, [bitstring]}|Elements]}, + BinExpr = {bin, Ann, [{bin_element, Ann, Acc, default, [bitstring]} | Elements]}, build_reduce_clause(Clauses, BinExpr, Into, Acc, S). -build_reduce_clause([{enum, Meta, Left, Right, Filters}|T], Expr, Arg, Acc, S) -> +build_reduce_clause([{enum, Meta, Left, Right, Filters} | T], Expr, Arg, Acc, S) -> Ann = ?ann(Meta), True = build_reduce_clause(T, Expr, Acc, Acc, S), False = Acc, @@ -222,12 +222,12 @@ build_reduce_clause([{enum, Meta, Left, Right, Filters}|T], Expr, Arg, Acc, S) - Clauses1 = [{clause, Ann, [Left, Acc], [], - [join_filters(Ann, Filters, True, False)]}|Clauses0], + [join_filters(Ann, Filters, True, False)]} | Clauses0], Args = [Right, Arg, {'fun', Ann, {clauses, Clauses1}}], elixir_utils:erl_call(Ann, 'Elixir.Enum', reduce, Args); -build_reduce_clause([{bin, Meta, Left, Right, Filters}|T], Expr, Arg, Acc, S) -> +build_reduce_clause([{bin, Meta, Left, Right, Filters} | T], Expr, Arg, Acc, S) -> Ann = ?ann(Meta), {Tail, ST} = build_var(Ann, S), {Fun, SF} = build_var(Ann, ST), @@ -284,7 +284,7 @@ build_comprehension(Ann, Clauses, Expr, false) -> build_comprehension(Ann, Clauses, Expr, Into) -> {comprehension_kind(Into), Ann, Expr, comprehension_clause(Clauses)}. -comprehension_clause([{Kind, Meta, Left, Right, Filters}|T]) -> +comprehension_clause([{Kind, Meta, Left, Right, Filters} | T]) -> Ann = ?ann(Meta), [{comprehension_generator(Kind), Ann, Left, Right}] ++ comprehension_filter(Ann, Filters) ++ @@ -316,7 +316,7 @@ comprehension_filter(Ann, Filters) -> join_filters(_Ann, [], True, _False) -> True; -join_filters(Ann, [H|T], True, False) -> +join_filters(Ann, [H | T], True, False) -> lists:foldl(fun(Filter, Acc) -> join_filter(Ann, Filter, Acc, False) end, join_filter(Ann, H, True, False), T). diff --git a/lib/elixir/src/elixir_import.erl b/lib/elixir/src/elixir_import.erl index 9b8f4c1001f..9486eededa4 100644 --- a/lib/elixir/src/elixir_import.erl +++ b/lib/elixir/src/elixir_import.erl @@ -70,7 +70,7 @@ calculate(Meta, Key, Opts, Old, File, Existing) -> " when :only is either :functions or :macros") end, case Only -- get_exports(Key) of - [{Name, Arity}|_] -> + [{Name, Arity} | _] -> Tuple = {invalid_import, {Key, Name, Arity}}, elixir_errors:form_error(Meta, File, ?MODULE, Tuple); _ -> @@ -97,7 +97,7 @@ calculate(Meta, Key, Opts, Old, File, Existing) -> {false, keydelete(Key, Old)}; _ -> ensure_no_special_form_conflict(Meta, File, Key, Final), - {true, [{Key, Final}|keydelete(Key, Old)]} + {true, [{Key, Final} | keydelete(Key, Old)]} end. %% Retrieve functions and macros from modules @@ -138,7 +138,7 @@ get_optional_macros(Module) -> %% VALIDATION HELPERS -ensure_no_special_form_conflict(Meta, File, Key, [{Name, Arity}|T]) -> +ensure_no_special_form_conflict(Meta, File, Key, [{Name, Arity} | T]) -> case special_form(Name, Arity) of true -> Tuple = {special_form_conflict, {Key, Name, Arity}}, @@ -178,9 +178,9 @@ keyfind(Key, List) -> keydelete(Key, List) -> lists:keydelete(Key, 1, List). -intersection([H|T], All) -> +intersection([H | T], All) -> case lists:member(H, All) of - true -> [H|intersection(T, All)]; + true -> [H | intersection(T, All)]; false -> intersection(T, All) end; diff --git a/lib/elixir/src/elixir_interpolation.erl b/lib/elixir/src/elixir_interpolation.erl index af4e102a557..43571bcf3e6 100644 --- a/lib/elixir/src/elixir_interpolation.erl +++ b/lib/elixir/src/elixir_interpolation.erl @@ -19,30 +19,30 @@ extract(Line, Column, _Scope, _Interpol, [], Buffer, Output, []) -> extract(Line, _Column, _Scope, _Interpol, [], _Buffer, _Output, Last) -> {error, {string, Line, io_lib:format("missing terminator: ~ts", [[Last]]), []}}; -extract(Line, Column, _Scope, _Interpol, [Last|Remaining], Buffer, Output, Last) -> +extract(Line, Column, _Scope, _Interpol, [Last | Remaining], Buffer, Output, Last) -> finish_extraction(Line, Column + 1, Buffer, Output, Remaining); %% Going through the string -extract(Line, _Column, Scope, true, [$\\, $\n|Rest], Buffer, Output, Last) -> +extract(Line, _Column, Scope, true, [$\\, $\n | Rest], Buffer, Output, Last) -> extract(Line+1, 1, Scope, true, Rest, Buffer, Output, Last); -extract(Line, _Column, Scope, true, [$\\, $\r, $\n|Rest], Buffer, Output, Last) -> +extract(Line, _Column, Scope, true, [$\\, $\r, $\n | Rest], Buffer, Output, Last) -> extract(Line+1, 1, Scope, true, Rest, Buffer, Output, Last); -extract(Line, _Column, Scope, Interpol, [$\n|Rest], Buffer, Output, Last) -> - extract(Line+1, 1, Scope, Interpol, Rest, [$\n|Buffer], Output, Last); +extract(Line, _Column, Scope, Interpol, [$\n | Rest], Buffer, Output, Last) -> + extract(Line+1, 1, Scope, Interpol, Rest, [$\n | Buffer], Output, Last); -extract(Line, Column, Scope, Interpol, [$\\, Last|Rest], Buffer, Output, Last) -> - extract(Line, Column+2, Scope, Interpol, Rest, [Last|Buffer], Output, Last); +extract(Line, Column, Scope, Interpol, [$\\, Last | Rest], Buffer, Output, Last) -> + extract(Line, Column+2, Scope, Interpol, Rest, [Last | Buffer], Output, Last); -extract(Line, Column, Scope, true, [$\\, $#, ${|Rest], Buffer, Output, Last) -> - extract(Line, Column+1, Scope, true, Rest, [${, $#|Buffer], Output, Last); +extract(Line, Column, Scope, true, [$\\, $#, ${ | Rest], Buffer, Output, Last) -> + extract(Line, Column+1, Scope, true, Rest, [${, $# | Buffer], Output, Last); -extract(Line, Column, Scope, true, [$#, ${|Rest], Buffer, Output, Last) -> +extract(Line, Column, Scope, true, [$#, ${ | Rest], Buffer, Output, Last) -> Output1 = build_string(Line, Buffer, Output), case elixir_tokenizer:tokenize(Rest, Line, Column + 2, Scope) of - {error, {{EndLine, _, EndColumn}, _, "}"}, [$}|NewRest], Tokens} -> + {error, {{EndLine, _, EndColumn}, _, "}"}, [$} | NewRest], Tokens} -> Output2 = build_interpol(Line, Column, EndColumn, Tokens, Output1), extract(EndLine, EndColumn, Scope, true, NewRest, [], Output2, Last); {error, Reason, _, _} -> @@ -51,13 +51,13 @@ extract(Line, Column, Scope, true, [$#, ${|Rest], Buffer, Output, Last) -> {error, {string, Line, "missing interpolation terminator:}", []}} end; -extract(Line, Column, Scope, Interpol, [$\\, Char|Rest], Buffer, Output, Last) -> - extract(Line, Column+2, Scope, Interpol, Rest, [Char, $\\|Buffer], Output, Last); +extract(Line, Column, Scope, Interpol, [$\\, Char | Rest], Buffer, Output, Last) -> + extract(Line, Column+2, Scope, Interpol, Rest, [Char, $\\ | Buffer], Output, Last); %% Catch all clause -extract(Line, Column, Scope, Interpol, [Char|Rest], Buffer, Output, Last) -> - extract(Line, Column + 1, Scope, Interpol, Rest, [Char|Buffer], Output, Last). +extract(Line, Column, Scope, Interpol, [Char | Rest], Buffer, Output, Last) -> + extract(Line, Column + 1, Scope, Interpol, Rest, [Char | Buffer], Output, Last). %% Unescape a series of tokens as returned by extract. @@ -203,7 +203,7 @@ finish_extraction(Line, Column, Buffer, Output, Remaining) -> build_string(_Line, [], Output) -> Output; build_string(_Line, Buffer, Output) -> - [elixir_utils:characters_to_binary(lists:reverse(Buffer))|Output]. + [elixir_utils:characters_to_binary(lists:reverse(Buffer)) | Output]. build_interpol(Line, Column, EndColumn, Buffer, Output) -> - [{{Line, Column, EndColumn}, lists:reverse(Buffer)}|Output]. + [{{Line, Column, EndColumn}, lists:reverse(Buffer)} | Output]. diff --git a/lib/elixir/src/elixir_locals.erl b/lib/elixir/src/elixir_locals.erl index 762ab54c588..0a17ef11f81 100644 --- a/lib/elixir/src/elixir_locals.erl +++ b/lib/elixir/src/elixir_locals.erl @@ -15,7 +15,7 @@ macro_for(Module, Name, Arity) -> Tuple = {Name, Arity}, try elixir_def:lookup_definition(Module, Tuple) of - {{Tuple, Kind, Line, _, _, _, _}, [_|_] = Clauses} + {{Tuple, Kind, Line, _, _, _, _}, [_ | _] = Clauses} when Kind == defmacro; Kind == defmacrop -> fun() -> get_function(Line, Module, Clauses) end; _ -> @@ -29,12 +29,12 @@ local_for(Module, Name, Arity) -> local_for(Module, Name, Arity, Given) -> Tuple = {Name, Arity}, case elixir_def:lookup_definition(Module, Tuple) of - {{Tuple, Kind, Line, _, _, _, _}, [_|_] = Clauses} + {{Tuple, Kind, Line, _, _, _, _}, [_ | _] = Clauses} when Given == nil; Kind == Given -> get_function(Line, Module, Clauses); _ -> - [_|T] = erlang:get_stacktrace(), - erlang:raise(error, undef, [{Module, Name, Arity, []}|T]) + [_ | T] = erlang:get_stacktrace(), + erlang:raise(error, undef, [{Module, Name, Arity, []} | T]) end. get_function(Line, Module, Clauses) -> diff --git a/lib/elixir/src/elixir_map.erl b/lib/elixir/src/elixir_map.erl index a5e72a97977..f28a20e4126 100644 --- a/lib/elixir/src/elixir_map.erl +++ b/lib/elixir/src/elixir_map.erl @@ -4,7 +4,7 @@ -include("elixir.hrl"). expand_map(Meta, [{'|', UpdateMeta, [Left, Right]}], E) -> - {[ELeft|ERight], EA} = elixir_exp:expand_args([Left|Right], E), + {[ELeft | ERight], EA} = elixir_exp:expand_args([Left | Right], E), validate_kv(Meta, ERight, Right, E), {{'%{}', Meta, [{'|', UpdateMeta, [ELeft, ERight]}]}, EA}; expand_map(Meta, Args, E) -> @@ -30,7 +30,7 @@ expand_struct(Meta, Left, Right, #{context := Context} = E) -> EMeta = case lists:member(ELeft, ?m(E, context_modules)) of - true -> [{struct, context}|Meta]; + true -> [{struct, context} | Meta]; false -> Meta end, diff --git a/lib/elixir/src/elixir_module.erl b/lib/elixir/src/elixir_module.erl index 5191bcbedeb..7847a7fab9b 100644 --- a/lib/elixir/src/elixir_module.erl +++ b/lib/elixir/src/elixir_module.erl @@ -166,8 +166,8 @@ build(Line, File, Module, Docs, Lexical) -> Attributes = [behaviour, on_load, compile, external_resource, dialyzer], ets:insert(Data, {?acc_attr, [before_compile, after_compile, on_definition, derive, - spec, type, typep, opaque, callback, macrocallback|Attributes]}), - ets:insert(Data, {?persisted_attr, [vsn|Attributes]}), + spec, type, typep, opaque, callback, macrocallback | Attributes]}), + ets:insert(Data, {?persisted_attr, [vsn | Attributes]}), ets:insert(Data, {?lexical_attr, Lexical}), %% Setup definition related modules @@ -201,8 +201,8 @@ functions_form(Line, File, Module, Def, Defp, Defmacro, Defmacrop, Exports, Body All = Def ++ Defmacro ++ Defp ++ Defmacrop, {Spec, Info} = add_info_function(Line, File, Module, All, Def, Defmacro), - {[{'__info__', 1}|All], - [{attribute, Line, export, lists:sort([{'__info__', 1}|Exports])}, + {[{'__info__', 1} | All], + [{attribute, Line, export, lists:sort([{'__info__', 1} | Exports])}, Spec, Info | Body]}. %% Add attributes handling to the form @@ -222,7 +222,7 @@ attributes_form(Line, File, Data, Current) -> end, lists:foldl(fun(X, Final) -> - [{attribute, Line, Key, X}|Final] + [{attribute, Line, Key, X} | Final] end, Acc, process_attribute(Line, File, Key, Values)) end end, @@ -263,14 +263,14 @@ types_form(Line, File, Data, Forms0) -> types_attributes(Types, Forms) -> Fun = fun({{Kind, _NameArity, Expr}, Line, _Export}, Acc) -> - [{attribute, Line, Kind, Expr}|Acc] + [{attribute, Line, Kind, Expr} | Acc] end, lists:foldl(Fun, Forms, Types). export_types_attributes(Types, Forms) -> Fun = fun ({{_Kind, NameArity, _Expr}, Line, true}, Acc) -> - [{attribute, Line, export_type, [NameArity]}|Acc]; + [{attribute, Line, export_type, [NameArity]} | Acc]; ({_Type, _Line, false}, Acc) -> Acc end, @@ -304,7 +304,7 @@ specs_attributes(Forms, Specs) -> dict:fold(fun({Kind, NameArity}, ExprsLines, Acc) -> {Exprs, Lines} = lists:unzip(ExprsLines), Line = lists:min(Lines), - [{attribute, Line, Kind, {NameArity, Exprs}}|Acc] + [{attribute, Line, Kind, {NameArity, Exprs}} | Acc] end, Forms, Dict). translate_macro_spec({{spec, NameArity, Spec}, Line}, Defmacro, Defmacrop) -> @@ -323,9 +323,9 @@ translate_macro_spec({{spec, NameArity, Spec}, Line}, Defmacro, Defmacrop) -> translate_macro_spec({{callback, NameArity, Spec}, Line}, _Defmacro, _Defmacrop) -> [{{callback, NameArity, Spec}, Line}]. -spec_for_macro({type, Line, 'fun', [{type, _, product, Args}|T]}) -> - NewArgs = [{type, Line, term, []}|Args], - {type, Line, 'fun', [{type, Line, product, NewArgs}|T]}; +spec_for_macro({type, Line, 'fun', [{type, _, product, Args} | T]}) -> + NewArgs = [{type, Line, term, []} | Args], + {type, Line, 'fun', [{type, Line, product, NewArgs} | T]}; spec_for_macro(Else) -> Else. @@ -345,7 +345,7 @@ load_form(Line, Data, Forms, Opts, E) -> case get(elixir_compiled) of Current when is_list(Current) -> - put(elixir_compiled, [{Module, Binary}|Current]), + put(elixir_compiled, [{Module, Binary} | Current]), case get(elixir_compiler_pid) of undefined -> ok; @@ -490,7 +490,7 @@ add_beam_chunk(Bin, Id, ChunkData) when is_binary(Bin), is_list(Id), is_binary(ChunkData) -> {ok, _, Chunks0} = beam_lib:all_chunks(Bin), NewChunk = {Id, ChunkData}, - Chunks = [NewChunk|Chunks0], + Chunks = [NewChunk | Chunks0], {ok, NewBin} = beam_lib:build_module(Chunks), NewBin. @@ -523,12 +523,12 @@ location(Line, E) -> [{file, elixir_utils:characters_to_list(?m(E, file))}, {line, Line}]. %% We've reached the elixir_module or eval internals, skip it with the rest -prune_stacktrace(Info, [{elixir, eval_forms, _, _}|_]) -> +prune_stacktrace(Info, [{elixir, eval_forms, _, _} | _]) -> [Info]; -prune_stacktrace(Info, [{elixir_module, _, _, _}|_]) -> +prune_stacktrace(Info, [{elixir_module, _, _, _} | _]) -> [Info]; -prune_stacktrace(Info, [H|T]) -> - [H|prune_stacktrace(Info, T)]; +prune_stacktrace(Info, [H | T]) -> + [H | prune_stacktrace(Info, T)]; prune_stacktrace(Info, []) -> [Info]. diff --git a/lib/elixir/src/elixir_parser.yrl b/lib/elixir/src/elixir_parser.yrl index 9a82b22e766..c81428448c5 100644 --- a/lib/elixir/src/elixir_parser.yrl +++ b/lib/elixir/src/elixir_parser.yrl @@ -86,7 +86,7 @@ grammar -> '$empty' : nil. % Note expressions are on reverse order expr_list -> expr : ['$1']. -expr_list -> expr_list eoe expr : ['$3'|'$1']. +expr_list -> expr_list eoe expr : ['$3' | '$1']. expr -> matched_expr : '$1'. expr -> no_parens_expr : '$1'. @@ -281,8 +281,8 @@ bracket_at_expr -> at_op_eol access_expr bracket_arg : do_block -> do_eoe 'end' : [[{do, nil}]]. do_block -> do_eoe stab end_eoe : [[{do, build_stab(reverse('$2'))}]]. -do_block -> do_eoe block_list 'end' : [[{do, nil}|'$2']]. -do_block -> do_eoe stab_eoe block_list 'end' : [[{do, build_stab(reverse('$2'))}|'$3']]. +do_block -> do_eoe block_list 'end' : [[{do, nil} | '$2']]. +do_block -> do_eoe stab_eoe block_list 'end' : [[{do, build_stab(reverse('$2'))} | '$3']]. eoe -> eol : '$1'. eoe -> ';' : '$1'. @@ -301,7 +301,7 @@ block_eoe -> block_identifier : '$1'. block_eoe -> block_identifier eoe : '$1'. stab -> stab_expr : ['$1']. -stab -> stab eoe stab_expr : ['$3'|'$1']. +stab -> stab eoe stab_expr : ['$3' | '$1']. stab_eoe -> stab : '$1'. stab_eoe -> stab eoe : '$1'. @@ -328,7 +328,7 @@ block_item -> block_eoe stab_eoe : {?exprs('$1'), build_stab(reverse('$2'))}. block_item -> block_eoe : {?exprs('$1'), nil}. block_list -> block_item : ['$1']. -block_list -> block_item block_list : ['$1'|'$2']. +block_list -> block_item block_list : ['$1' | '$2']. %% Helpers @@ -453,7 +453,7 @@ call_args_no_parens_expr -> matched_expr : '$1'. call_args_no_parens_expr -> no_parens_expr : throw_no_parens_many_strict('$1'). call_args_no_parens_comma_expr -> matched_expr ',' call_args_no_parens_expr : ['$3', '$1']. -call_args_no_parens_comma_expr -> call_args_no_parens_comma_expr ',' call_args_no_parens_expr : ['$3'|'$1']. +call_args_no_parens_comma_expr -> call_args_no_parens_comma_expr ',' call_args_no_parens_expr : ['$3' | '$1']. call_args_no_parens_all -> call_args_no_parens_one : '$1'. call_args_no_parens_all -> call_args_no_parens_ambig : '$1'. @@ -466,7 +466,7 @@ call_args_no_parens_ambig -> no_parens_expr : ['$1']. call_args_no_parens_many -> matched_expr ',' call_args_no_parens_kw : ['$1', '$3']. call_args_no_parens_many -> call_args_no_parens_comma_expr : reverse('$1'). -call_args_no_parens_many -> call_args_no_parens_comma_expr ',' call_args_no_parens_kw : reverse(['$3'|'$1']). +call_args_no_parens_many -> call_args_no_parens_comma_expr ',' call_args_no_parens_kw : reverse(['$3' | '$1']). call_args_no_parens_many_strict -> call_args_no_parens_many : '$1'. call_args_no_parens_many_strict -> open_paren call_args_no_parens_kw close_paren : throw_no_parens_strict('$1'). @@ -482,11 +482,11 @@ container_expr -> unmatched_expr : '$1'. container_expr -> no_parens_expr : throw_no_parens_container_strict('$1'). container_args_base -> container_expr : ['$1']. -container_args_base -> container_args_base ',' container_expr : ['$3'|'$1']. +container_args_base -> container_args_base ',' container_expr : ['$3' | '$1']. container_args -> container_args_base : lists:reverse('$1'). container_args -> container_args_base ',' : lists:reverse('$1'). -container_args -> container_args_base ',' kw : lists:reverse(['$3'|'$1']). +container_args -> container_args_base ',' kw : lists:reverse(['$3' | '$1']). % Function calls with parentheses @@ -495,13 +495,13 @@ call_args_parens_expr -> unmatched_expr : '$1'. call_args_parens_expr -> no_parens_expr : throw_no_parens_many_strict('$1'). call_args_parens_base -> call_args_parens_expr : ['$1']. -call_args_parens_base -> call_args_parens_base ',' call_args_parens_expr : ['$3'|'$1']. +call_args_parens_base -> call_args_parens_base ',' call_args_parens_expr : ['$3' | '$1']. call_args_parens -> empty_paren : []. call_args_parens -> open_paren no_parens_expr close_paren : ['$2']. call_args_parens -> open_paren kw close_paren : ['$2']. call_args_parens -> open_paren call_args_parens_base close_paren : reverse('$2'). -call_args_parens -> open_paren call_args_parens_base ',' kw close_paren : reverse(['$4'|'$2']). +call_args_parens -> open_paren call_args_parens_base ',' kw close_paren : reverse(['$4' | '$2']). % KV @@ -513,7 +513,7 @@ kw_eol -> kw_identifier_unsafe : build_quoted_atom('$1', false). kw_eol -> kw_identifier_unsafe eol : build_quoted_atom('$1', false). kw_base -> kw_eol container_expr : [{'$1', '$2'}]. -kw_base -> kw_base ',' kw_eol container_expr : [{'$3', '$4'}|'$1']. +kw_base -> kw_base ',' kw_eol container_expr : [{'$3', '$4'} | '$1']. kw -> kw_base : reverse('$1'). kw -> kw_base ',' : reverse('$1'). @@ -522,7 +522,7 @@ call_args_no_parens_kw_expr -> kw_eol matched_expr : {'$1', '$2'}. call_args_no_parens_kw_expr -> kw_eol no_parens_expr : {'$1', '$2'}. call_args_no_parens_kw -> call_args_no_parens_kw_expr : ['$1']. -call_args_no_parens_kw -> call_args_no_parens_kw_expr ',' call_args_no_parens_kw : ['$1'|'$3']. +call_args_no_parens_kw -> call_args_no_parens_kw_expr ',' call_args_no_parens_kw : ['$1' | '$3']. % Lists @@ -568,7 +568,7 @@ assoc_update_kw -> matched_expr pipe_op_eol kw : {'$2', '$1', '$3'}. assoc_update_kw -> unmatched_expr pipe_op_eol kw : {'$2', '$1', '$3'}. assoc_base -> assoc_expr : ['$1']. -assoc_base -> assoc_base ',' assoc_expr : ['$3'|'$1']. +assoc_base -> assoc_base ',' assoc_expr : ['$3' | '$1']. assoc -> assoc_base : reverse('$1'). assoc -> assoc_base ',' : reverse('$1'). @@ -610,7 +610,7 @@ Erlang code. -compile([{hipe, [{regalloc, linear_scan}]}]). -import(lists, [reverse/1, reverse/2]). -meta_from_token(Token, Counter) -> [{counter, Counter}|meta_from_token(Token)]. +meta_from_token(Token, Counter) -> [{counter, Counter} | meta_from_token(Token)]. meta_from_token(Token) -> meta_from_location(?location(Token)). meta_from_location({Line, Column, EndColumn}) @@ -661,7 +661,7 @@ build_dot_alias(_Dot, Atom, {'aliases', _, _} = Token) when is_atom(Atom) -> throw_bad_atom(Token); build_dot_alias(Dot, Other, {'aliases', _, Right}) -> - {'__aliases__', meta_from_token(Dot), [Other|Right]}. + {'__aliases__', meta_from_token(Dot), [Other | Right]}. build_dot_container(Dot, Left, Right) -> Meta = meta_from_token(Dot), @@ -690,14 +690,14 @@ build_identifier({'.', Meta, _} = Dot, Args) -> {Dot, Meta, FArgs}; build_identifier({op_identifier, Location, Identifier}, [Arg]) -> - {Identifier, [{ambiguous_op, nil}|meta_from_location(Location)], [Arg]}; + {Identifier, [{ambiguous_op, nil} | meta_from_location(Location)], [Arg]}; build_identifier({_, Location, Identifier}, Args) -> {Identifier, meta_from_location(Location), Args}. %% Fn -build_fn(Op, [{'->', _, [_, _]}|_] = Stab) -> +build_fn(Op, [{'->', _, [_, _]} | _] = Stab) -> {fn, meta_from_token(Op), build_stab(Stab)}; build_fn(Op, _Stab) -> throw(meta_from_token(Op), "expected clauses to be defined with -> inside: ", "'fn'"). @@ -751,22 +751,22 @@ string_tokens_parse(Tokens) -> %% Keywords -build_stab([{'->', Meta, [Left, Right]}|T]) -> +build_stab([{'->', Meta, [Left, Right]} | T]) -> build_stab(Meta, T, Left, [Right], []); build_stab(Else) -> build_block(Else). -build_stab(Old, [{'->', New, [Left, Right]}|T], Marker, Temp, Acc) -> +build_stab(Old, [{'->', New, [Left, Right]} | T], Marker, Temp, Acc) -> H = {'->', Old, [Marker, build_block(reverse(Temp))]}, - build_stab(New, T, Left, [Right], [H|Acc]); + build_stab(New, T, Left, [Right], [H | Acc]); -build_stab(Meta, [H|T], Marker, Temp, Acc) -> - build_stab(Meta, T, Marker, [H|Temp], Acc); +build_stab(Meta, [H | T], Marker, Temp, Acc) -> + build_stab(Meta, T, Marker, [H | Temp], Acc); build_stab(Meta, [], Marker, Temp, Acc) -> H = {'->', Meta, [Marker, build_block(reverse(Temp))]}, - reverse([H|Acc]). + reverse([H | Acc]). %% Every time the parser sees a (unquote_splicing()) %% it assumes that a block is being spliced, wrapping @@ -845,7 +845,7 @@ warn_empty_stab_clause({stab_op, {Line, _Begin, _End}, '->'}) -> "an expression is always required on the right side of ->. " "Please provide a value after ->"). -warn_pipe({arrow_op, {Line, _Begin, _End}, Op}, {_, [_|_], [_|_]}) -> +warn_pipe({arrow_op, {Line, _Begin, _End}, Op}, {_, [_ | _], [_ | _]}) -> elixir_errors:warn(Line, ?file(), io_lib:format( "you are piping into a function call without parentheses, which may be ambiguous. " diff --git a/lib/elixir/src/elixir_quote.erl b/lib/elixir/src/elixir_quote.erl index 098222853c4..88c443b7ca3 100644 --- a/lib/elixir/src/elixir_quote.erl +++ b/lib/elixir/src/elixir_quote.erl @@ -23,7 +23,7 @@ do_linify(Line, Key, {Receiver, Counter} = Var, {Left, Meta, Receiver}) when is_atom(Left), is_list(Meta), Left /= '_' -> do_tuple_linify(Line, Key, Var, keynew(counter, Meta, Counter), Left, Receiver); -do_linify(Line, Key, {_, Counter} = Var, {Lexical, [_|_] = Meta, [_|_] = Args}) +do_linify(Line, Key, {_, Counter} = Var, {Lexical, [_ | _] = Meta, [_ | _] = Args}) when ?lexical(Lexical); Lexical == '__aliases__' -> do_tuple_linify(Line, Key, Var, keynew(counter, Meta, Counter), Lexical, Args); @@ -66,7 +66,7 @@ dot(Meta, Left, Right, Args, Context) -> annotate(dot(Meta, Left, Right, Args), Context). dot(Meta, Left, {'__aliases__', _, Args}, nil) -> - {'__aliases__', Meta, [Left|Args]}; + {'__aliases__', Meta, [Left | Args]}; dot(Meta, Left, Right, nil) when is_atom(Right) -> case atom_to_list(Right) of @@ -106,8 +106,8 @@ tail_list(Left, Right, Tail) when is_list(Right), is_list(Tail) -> tail_list(Left, Right, Tail) when is_list(Left) -> validate_list(Left), - [H|T] = lists:reverse(Tail ++ Left), - lists:reverse([{'|', [], [H, Right]}|T]). + [H | T] = lists:reverse(Tail ++ Left), + lists:reverse([{'|', [], [H, Right]} | T]). validate_list(List) when is_list(List) -> ok; @@ -125,12 +125,12 @@ argument_error(Message) -> %% expressions, so we need to clean up the forms to %% allow them to get a new counter on the next expansion. -annotate({Def, Meta, [{H, M, A}|T]}, Context) when ?defs(Def) -> - {Def, Meta, [{H, keystore(context, M, Context), A}|T]}; -annotate({{'.', _, [_, Def]} = Target, Meta, [{H, M, A}|T]}, Context) when ?defs(Def) -> - {Target, Meta, [{H, keystore(context, M, Context), A}|T]}; +annotate({Def, Meta, [{H, M, A} | T]}, Context) when ?defs(Def) -> + {Def, Meta, [{H, keystore(context, M, Context), A} | T]}; +annotate({{'.', _, [_, Def]} = Target, Meta, [{H, M, A} | T]}, Context) when ?defs(Def) -> + {Target, Meta, [{H, keystore(context, M, Context), A} | T]}; -annotate({Lexical, Meta, [_|_] = Args}, Context) when ?lexical(Lexical) -> +annotate({Lexical, Meta, [_ | _] = Args}, Context) when ?lexical(Lexical) -> NewMeta = keystore(context, keydelete(counter, Meta), Context), {Lexical, NewMeta, Args}; annotate(Tree, _Context) -> Tree. @@ -182,14 +182,14 @@ do_quote({unquote, _Meta, [Expr]}, #elixir_quote{unquote=true} = Q, _) -> %% Aliases -do_quote({'__aliases__', Meta, [H|T]} = Alias, #elixir_quote{aliases_hygiene=true} = Q, E) when is_atom(H) and (H /= 'Elixir') -> +do_quote({'__aliases__', Meta, [H | T]} = Alias, #elixir_quote{aliases_hygiene=true} = Q, E) when is_atom(H) and (H /= 'Elixir') -> Annotation = case elixir_aliases:expand(Alias, ?m(E, aliases), ?m(E, macro_aliases), ?m(E, lexical_tracker)) of Atom when is_atom(Atom) -> Atom; Aliases when is_list(Aliases) -> false end, AliasMeta = keystore(alias, keydelete(counter, Meta), Annotation), - do_quote_tuple({'__aliases__', AliasMeta, [H|T]}, Q, E); + do_quote_tuple({'__aliases__', AliasMeta, [H | T]}, Q, E); %% Vars @@ -335,11 +335,11 @@ do_quote_tuple({Left, Meta, Right}, Q, E) -> meta(Meta, Q) -> generated(file(line(Meta, Q), Q), Q). -generated(Meta, #elixir_quote{generated=true}) -> [{generated, true}|Meta]; +generated(Meta, #elixir_quote{generated=true}) -> [{generated, true} | Meta]; generated(Meta, #elixir_quote{generated=false}) -> Meta. file(Meta, #elixir_quote{file=nil}) -> Meta; -file(Meta, #elixir_quote{file=File}) -> [{file, File}|Meta]. +file(Meta, #elixir_quote{file=File}) -> [{file, File} | Meta]. line(Meta, #elixir_quote{file=File}) when File /= nil -> [case KV of {line, V} -> {keep, V}; _ -> KV end || KV <- Meta]; @@ -352,12 +352,12 @@ line(Meta, #elixir_quote{line=Line}) -> reverse_improper(L) -> reverse_improper(L, []). reverse_improper([], Acc) -> {Acc}; -reverse_improper([H|T], Acc) when is_list(T) -> reverse_improper(T, [H|Acc]); -reverse_improper([H|T], Acc) -> {[H|Acc], T}. +reverse_improper([H | T], Acc) when is_list(T) -> reverse_improper(T, [H | Acc]); +reverse_improper([H | T], Acc) -> {[H | Acc], T}. update_last([], _) -> []; update_last([H], F) -> [F(H)]; -update_last([H|T], F) -> [H|update_last(T, F)]. +update_last([H | T], F) -> [H | update_last(T, F)]. keyfind(Key, Meta) -> lists:keyfind(Key, 1, Meta). @@ -379,9 +379,9 @@ keynew(Key, Meta, Value) -> %% Quote splicing -do_splice([{'|', Meta, [{unquote_splicing, _, [Left]}, Right]}|T], #elixir_quote{unquote=true} = Q, E) -> +do_splice([{'|', Meta, [{unquote_splicing, _, [Left]}, Right]} | T], #elixir_quote{unquote=true} = Q, E) -> %% Process the remaining entries on the list. - %% For [1, 2, 3, unquote_splicing(arg)|tail], this will quote + %% For [1, 2, 3, unquote_splicing(arg) | tail], this will quote %% 1, 2 and 3, which could even be unquotes. {TT, QT} = do_splice(T, Q, E, [], []), {TR, QR} = do_quote(Right, QT, E), @@ -390,12 +390,12 @@ do_splice([{'|', Meta, [{unquote_splicing, _, [Left]}, Right]}|T], #elixir_quote do_splice(List, Q, E) -> do_splice(List, Q, E, [], []). -do_splice([{unquote_splicing, Meta, [Expr]}|T], #elixir_quote{unquote=true} = Q, E, Buffer, Acc) -> +do_splice([{unquote_splicing, Meta, [Expr]} | T], #elixir_quote{unquote=true} = Q, E, Buffer, Acc) -> do_splice(T, Q#elixir_quote{unquoted=true}, E, [], do_runtime_list(Meta, list, [Expr, do_join(Buffer, Acc)])); -do_splice([H|T], Q, E, Buffer, Acc) -> +do_splice([H | T], Q, E, Buffer, Acc) -> {TH, TQ} = do_quote(H, Q, E), - do_splice(T, TQ, E, [TH|Buffer], Acc); + do_splice(T, TQ, E, [TH | Buffer], Acc); do_splice([], Q, _E, Buffer, Acc) -> {do_join(Buffer, Acc), Q}. diff --git a/lib/elixir/src/elixir_scope.erl b/lib/elixir/src/elixir_scope.erl index 960d4cd466a..36395f6dbc2 100644 --- a/lib/elixir/src/elixir_scope.erl +++ b/lib/elixir/src/elixir_scope.erl @@ -170,7 +170,7 @@ load_binding(Binding, Scope) -> counter=#{'_' => NewCounter} }}. -load_binding([{Key, Value}|T], Binding, Keys, Vars, Counter) -> +load_binding([{Key, Value} | T], Binding, Keys, Vars, Counter) -> Actual = case Key of {_Name, _Kind} -> Key; Name when is_atom(Name) -> {Name, nil} diff --git a/lib/elixir/src/elixir_tokenizer.erl b/lib/elixir/src/elixir_tokenizer.erl index dd1752fbfd3..93d52f0bd97 100644 --- a/lib/elixir/src/elixir_tokenizer.erl +++ b/lib/elixir/src/elixir_tokenizer.erl @@ -127,47 +127,47 @@ tokenize(String, Line, Opts) -> tokenize([], Line, Column, #elixir_tokenizer{terminators=[]}, Tokens) -> {ok, Line, Column, lists:reverse(Tokens)}; -tokenize([], EndLine, _Column, #elixir_tokenizer{terminators=[{Start, {StartLine, _, _}}|_]}, Tokens) -> +tokenize([], EndLine, _Column, #elixir_tokenizer{terminators=[{Start, {StartLine, _, _}} | _]}, Tokens) -> End = terminator(Start), Message = io_lib:format("missing terminator: ~ts (for \"~ts\" starting at line ~B)", [End, Start, StartLine]), {error, {EndLine, Message, []}, [], Tokens}; % Base integers -tokenize([$0, $x, H|T], Line, Column, Scope, Tokens) when ?is_hex(H) -> - {Rest, Number, Length} = tokenize_hex([H|T], []), - tokenize(Rest, Line, Column + 2 + Length, Scope, [{number, {Line, Column, Column + 2 + Length}, Number}|Tokens]); +tokenize([$0, $x, H | T], Line, Column, Scope, Tokens) when ?is_hex(H) -> + {Rest, Number, Length} = tokenize_hex([H | T], []), + tokenize(Rest, Line, Column + 2 + Length, Scope, [{number, {Line, Column, Column + 2 + Length}, Number} | Tokens]); -tokenize([$0, $b, H|T], Line, Column, Scope, Tokens) when ?is_bin(H) -> - {Rest, Number, Length} = tokenize_bin([H|T], []), - tokenize(Rest, Line, Column + 2 + Length, Scope, [{number, {Line, Column, Column + 2 + Length}, Number}|Tokens]); +tokenize([$0, $b, H | T], Line, Column, Scope, Tokens) when ?is_bin(H) -> + {Rest, Number, Length} = tokenize_bin([H | T], []), + tokenize(Rest, Line, Column + 2 + Length, Scope, [{number, {Line, Column, Column + 2 + Length}, Number} | Tokens]); -tokenize([$0, $o, H|T], Line, Column, Scope, Tokens) when ?is_octal(H) -> - {Rest, Number, Length} = tokenize_octal([H|T], []), - tokenize(Rest, Line, Column + 2 + Length, Scope, [{number, {Line, Column, Column + 2 + Length}, Number}|Tokens]); +tokenize([$0, $o, H | T], Line, Column, Scope, Tokens) when ?is_octal(H) -> + {Rest, Number, Length} = tokenize_octal([H | T], []), + tokenize(Rest, Line, Column + 2 + Length, Scope, [{number, {Line, Column, Column + 2 + Length}, Number} | Tokens]); % Comments -tokenize([$#|String], Line, Column, Scope, Tokens) -> +tokenize([$# | String], Line, Column, Scope, Tokens) -> Rest = tokenize_comment(String), tokenize(Rest, Line, Column, Scope, Tokens); % Sigils -tokenize([$~, S, H, H, H|T] = Original, Line, Column, Scope, Tokens) when ?is_quote(H), ?is_upcase(S) orelse ?is_downcase(S) -> +tokenize([$~, S, H, H, H | T] = Original, Line, Column, Scope, Tokens) when ?is_quote(H), ?is_upcase(S) orelse ?is_downcase(S) -> case extract_heredoc_with_interpolation(Line, Column, Scope, ?is_downcase(S), T, H) of {ok, NewLine, NewColumn, Parts, Rest} -> {Final, Modifiers} = collect_modifiers(Rest, []), - tokenize(Final, NewLine, NewColumn, Scope, [{sigil, {Line, Column, NewColumn}, S, Parts, Modifiers}|Tokens]); + tokenize(Final, NewLine, NewColumn, Scope, [{sigil, {Line, Column, NewColumn}, S, Parts, Modifiers} | Tokens]); {error, Reason} -> {error, Reason, Original, Tokens} end; -tokenize([$~, S, H|T] = Original, Line, Column, Scope, Tokens) when ?is_sigil(H), ?is_upcase(S) orelse ?is_downcase(S) -> +tokenize([$~, S, H | T] = Original, Line, Column, Scope, Tokens) when ?is_sigil(H), ?is_upcase(S) orelse ?is_downcase(S) -> case elixir_interpolation:extract(Line, Column + 3, Scope, ?is_downcase(S), T, sigil_terminator(H)) of {NewLine, NewColumn, Parts, Rest} -> {Final, Modifiers} = collect_modifiers(Rest, []), - tokenize(Final, NewLine, NewColumn, Scope, [{sigil, {Line, Column, NewColumn}, S, Parts, Modifiers}|Tokens]); + tokenize(Final, NewLine, NewColumn, Scope, [{sigil, {Line, Column, NewColumn}, S, Parts, Modifiers} | Tokens]); {error, Reason} -> Sigil = [$~, S, H], interpolation_error(Reason, Original, Tokens, " (for sigil ~ts starting at line ~B)", [Sigil, Line]) @@ -181,11 +181,11 @@ tokenize([$~, S, H|T] = Original, Line, Column, Scope, Tokens) when ?is_sigil(H) % elixir_errors.erl as by default {char, _, _} tokens are "hijacked" by Erlang % and printed with Erlang syntax ($a) in the parser's error messages. -tokenize([$?, $\\, H|T], Line, Column, Scope, Tokens) -> +tokenize([$?, $\\, H | T], Line, Column, Scope, Tokens) -> Char = elixir_interpolation:unescape_map(H), - tokenize(T, Line, Column + 3, Scope, [{char, {Line, Column, Column + 3}, Char}|Tokens]); + tokenize(T, Line, Column + 3, Scope, [{char, {Line, Column, Column + 3}, Char} | Tokens]); -tokenize([$?, Char|T], Line, Column, Scope, Tokens) -> +tokenize([$?, Char | T], Line, Column, Scope, Tokens) -> case handle_char(Char) of {Escape, Name} -> Msg = io_lib:format("found ? followed by codepoint 0x~.16B (~ts), please use ~ts instead", @@ -194,7 +194,7 @@ tokenize([$?, Char|T], Line, Column, Scope, Tokens) -> false -> ok end, - tokenize(T, Line, Column + 2, Scope, [{char, {Line, Column, Column + 2}, Char}|Tokens]); + tokenize(T, Line, Column + 2, Scope, [{char, {Line, Column, Column + 2}, Char} | Tokens]); % Heredocs @@ -206,14 +206,14 @@ tokenize("'''" ++ T, Line, Column, Scope, Tokens) -> % Strings -tokenize([$"|T], Line, Column, Scope, Tokens) -> +tokenize([$" | T], Line, Column, Scope, Tokens) -> handle_strings(T, Line, Column + 1, $", Scope, Tokens); -tokenize([$'|T], Line, Column, Scope, Tokens) -> +tokenize([$' | T], Line, Column, Scope, Tokens) -> handle_strings(T, Line, Column + 1, $', Scope, Tokens); % Atoms -tokenize([$:, H|T] = Original, Line, Column, Scope, Tokens) when ?is_quote(H) -> +tokenize([$:, H | T] = Original, Line, Column, Scope, Tokens) when ?is_quote(H) -> case elixir_interpolation:extract(Line, Column + 2, Scope, true, T, H) of {NewLine, NewColumn, Parts, Rest} -> Unescaped = unescape_tokens(Parts), @@ -221,16 +221,16 @@ tokenize([$:, H|T] = Original, Line, Column, Scope, Tokens) when ?is_quote(H) -> true -> atom_safe; false -> atom_unsafe end, - tokenize(Rest, NewLine, NewColumn, Scope, [{Key, {Line, Column, NewColumn}, Unescaped}|Tokens]); + tokenize(Rest, NewLine, NewColumn, Scope, [{Key, {Line, Column, NewColumn}, Unescaped} | Tokens]); {error, Reason} -> interpolation_error(Reason, Original, Tokens, " (for atom starting at line ~B)", [Line]) end; -tokenize([$:, T|String] = Original, Line, Column, Scope, Tokens) when ?is_atom_start(T) -> - {Rest, Part, Length} = tokenize_atom([T|String], []), +tokenize([$:, T | String] = Original, Line, Column, Scope, Tokens) when ?is_atom_start(T) -> + {Rest, Part, Length} = tokenize_atom([T | String], []), case unsafe_to_atom(Part, Line, Scope) of {ok, Atom} -> - tokenize(Rest, Line, Column + 1 + Length, Scope, [{atom, {Line, Column, Column + 1 + Length}, Atom}|Tokens]); + tokenize(Rest, Line, Column + 1 + Length, Scope, [{atom, {Line, Column, Column + 1 + Length}, Atom} | Tokens]); {error, Reason} -> {error, Reason, Original, Tokens} end; @@ -238,53 +238,53 @@ tokenize([$:, T|String] = Original, Line, Column, Scope, Tokens) when ?is_atom_s % %% Special atom identifiers / operators tokenize(":..." ++ Rest, Line, Column, Scope, Tokens) -> - tokenize(Rest, Line, Column + 4, Scope, [{atom, {Line, Column, Column + 4}, '...'}|Tokens]); + tokenize(Rest, Line, Column + 4, Scope, [{atom, {Line, Column, Column + 4}, '...'} | Tokens]); tokenize(":<<>>" ++ Rest, Line, Column, Scope, Tokens) -> - tokenize(Rest, Line, Column + 5, Scope, [{atom, {Line, Column, Column + 5}, '<<>>'}|Tokens]); + tokenize(Rest, Line, Column + 5, Scope, [{atom, {Line, Column, Column + 5}, '<<>>'} | Tokens]); tokenize(":%{}" ++ Rest, Line, Column, Scope, Tokens) -> - tokenize(Rest, Line, Column + 4, Scope, [{atom, {Line, Column, Column + 4}, '%{}'}|Tokens]); + tokenize(Rest, Line, Column + 4, Scope, [{atom, {Line, Column, Column + 4}, '%{}'} | Tokens]); tokenize(":%" ++ Rest, Line, Column, Scope, Tokens) -> - tokenize(Rest, Line, Column + 2, Scope, [{atom, {Line, Column, Column + 2}, '%'}|Tokens]); + tokenize(Rest, Line, Column + 2, Scope, [{atom, {Line, Column, Column + 2}, '%'} | Tokens]); tokenize(":{}" ++ Rest, Line, Column, Scope, Tokens) -> - tokenize(Rest, Line, Column + 3, Scope, [{atom, {Line, Column, Column + 3}, '{}'}|Tokens]); + tokenize(Rest, Line, Column + 3, Scope, [{atom, {Line, Column, Column + 3}, '{}'} | Tokens]); tokenize("...:" ++ Rest, Line, Column, Scope, Tokens) when ?is_space(hd(Rest)) -> - tokenize(Rest, Line, Column + 4, Scope, [{kw_identifier, {Line, Column, Column + 4}, '...'}|Tokens]); + tokenize(Rest, Line, Column + 4, Scope, [{kw_identifier, {Line, Column, Column + 4}, '...'} | Tokens]); tokenize("<<>>:" ++ Rest, Line, Column, Scope, Tokens) when ?is_space(hd(Rest)) -> - tokenize(Rest, Line, Column + 5, Scope, [{kw_identifier, {Line, Column, Column + 5}, '<<>>'}|Tokens]); + tokenize(Rest, Line, Column + 5, Scope, [{kw_identifier, {Line, Column, Column + 5}, '<<>>'} | Tokens]); tokenize("%{}:" ++ Rest, Line, Column, Scope, Tokens) when ?is_space(hd(Rest)) -> - tokenize(Rest, Line, Column + 4, Scope, [{kw_identifier, {Line, Column, Column + 4}, '%{}'}|Tokens]); + tokenize(Rest, Line, Column + 4, Scope, [{kw_identifier, {Line, Column, Column + 4}, '%{}'} | Tokens]); tokenize("%:" ++ Rest, Line, Column, Scope, Tokens) when ?is_space(hd(Rest)) -> - tokenize(Rest, Line, Column + 2, Scope, [{kw_identifier, {Line, Column, Column + 2}, '%'}|Tokens]); + tokenize(Rest, Line, Column + 2, Scope, [{kw_identifier, {Line, Column, Column + 2}, '%'} | Tokens]); tokenize("{}:" ++ Rest, Line, Column, Scope, Tokens) when ?is_space(hd(Rest)) -> - tokenize(Rest, Line, Column + 3, Scope, [{kw_identifier, {Line, Column, Column + 3}, '{}'}|Tokens]); + tokenize(Rest, Line, Column + 3, Scope, [{kw_identifier, {Line, Column, Column + 3}, '{}'} | Tokens]); % ## Three Token Operators -tokenize([$:, T1, T2, T3|Rest], Line, Column, Scope, Tokens) when +tokenize([$:, T1, T2, T3 | Rest], Line, Column, Scope, Tokens) when ?unary_op3(T1, T2, T3); ?comp_op3(T1, T2, T3); ?and_op3(T1, T2, T3); ?or_op3(T1, T2, T3); ?arrow_op3(T1, T2, T3); ?three_op(T1, T2, T3) -> - tokenize(Rest, Line, Column + 4, Scope, [{atom, {Line, Column, Column + 4}, list_to_atom([T1, T2, T3])}|Tokens]); + tokenize(Rest, Line, Column + 4, Scope, [{atom, {Line, Column, Column + 4}, list_to_atom([T1, T2, T3])} | Tokens]); % ## Two Token Operators -tokenize([$:, T1, T2|Rest], Line, Column, Scope, Tokens) when +tokenize([$:, T1, T2 | Rest], Line, Column, Scope, Tokens) when ?comp_op2(T1, T2); ?rel_op2(T1, T2); ?and_op(T1, T2); ?or_op(T1, T2); ?arrow_op(T1, T2); ?in_match_op(T1, T2); ?two_op(T1, T2); ?stab_op(T1, T2); ?type_op(T1, T2) -> - tokenize(Rest, Line, Column + 3, Scope, [{atom, {Line, Column, Column + 3}, list_to_atom([T1, T2])}|Tokens]); + tokenize(Rest, Line, Column + 3, Scope, [{atom, {Line, Column, Column + 3}, list_to_atom([T1, T2])} | Tokens]); % ## Single Token Operators -tokenize([$:, T|Rest], Line, Column, Scope, Tokens) when +tokenize([$:, T | Rest], Line, Column, Scope, Tokens) when ?at_op(T); ?unary_op(T); ?capture_op(T); ?dual_op(T); ?mult_op(T); ?rel_op(T); ?match_op(T); ?pipe_op(T); T == $. -> - tokenize(Rest, Line, Column + 2, Scope, [{atom, {Line, Column, Column + 2}, list_to_atom([T])}|Tokens]); + tokenize(Rest, Line, Column + 2, Scope, [{atom, {Line, Column, Column + 2}, list_to_atom([T])} | Tokens]); % End of line tokenize(";" ++ Rest, Line, Column, Scope, []) -> tokenize(Rest, Line, Column + 1, Scope, [{';', {Line, Column, Column + 1}}]); -tokenize(";" ++ Rest, Line, Column, Scope, [Top|_] = Tokens) when element(1, Top) /= ';' -> - tokenize(Rest, Line, Column + 1, Scope, [{';', {Line, Column, Column + 1}}|Tokens]); +tokenize(";" ++ Rest, Line, Column, Scope, [Top | _] = Tokens) when element(1, Top) /= ';' -> + tokenize(Rest, Line, Column + 1, Scope, [{';', {Line, Column, Column + 1}} | Tokens]); tokenize("\\" = Original, Line, _Column, _Scope, Tokens) -> {error, {Line, "invalid escape \\ at end of file", []}, Original, Tokens}; @@ -311,121 +311,121 @@ tokenize("\r\n" ++ Rest, Line, Column, Scope, Tokens) -> tokenize("..." ++ Rest, Line, Column, Scope, Tokens) -> Token = check_call_identifier(identifier, Line, Column, 3, '...', Rest), - tokenize(Rest, Line, Column + 3, Scope, [Token|Tokens]); + tokenize(Rest, Line, Column + 3, Scope, [Token | Tokens]); tokenize("=>" ++ Rest, Line, Column, Scope, Tokens) -> tokenize(Rest, Line, Column + 2, Scope, add_token_with_nl({assoc_op, {Line, Column, Column + 2}, '=>'}, Tokens)); % ## Three token operators -tokenize([T1, T2, T3|Rest], Line, Column, Scope, Tokens) when ?unary_op3(T1, T2, T3) -> +tokenize([T1, T2, T3 | Rest], Line, Column, Scope, Tokens) when ?unary_op3(T1, T2, T3) -> handle_unary_op(Rest, Line, Column, unary_op, 3, list_to_atom([T1, T2, T3]), Scope, Tokens); -tokenize([T1, T2, T3|Rest], Line, Column, Scope, Tokens) when ?comp_op3(T1, T2, T3) -> +tokenize([T1, T2, T3 | Rest], Line, Column, Scope, Tokens) when ?comp_op3(T1, T2, T3) -> handle_op(Rest, Line, Column, comp_op, 3, list_to_atom([T1, T2, T3]), Scope, Tokens); -tokenize([T1, T2, T3|Rest], Line, Column, Scope, Tokens) when ?and_op3(T1, T2, T3) -> +tokenize([T1, T2, T3 | Rest], Line, Column, Scope, Tokens) when ?and_op3(T1, T2, T3) -> handle_op(Rest, Line, Column, and_op, 3, list_to_atom([T1, T2, T3]), Scope, Tokens); -tokenize([T1, T2, T3|Rest], Line, Column, Scope, Tokens) when ?or_op3(T1, T2, T3) -> +tokenize([T1, T2, T3 | Rest], Line, Column, Scope, Tokens) when ?or_op3(T1, T2, T3) -> handle_op(Rest, Line, Column, or_op, 3, list_to_atom([T1, T2, T3]), Scope, Tokens); -tokenize([T1, T2, T3|Rest], Line, Column, Scope, Tokens) when ?three_op(T1, T2, T3) -> +tokenize([T1, T2, T3 | Rest], Line, Column, Scope, Tokens) when ?three_op(T1, T2, T3) -> handle_op(Rest, Line, Column, three_op, 3, list_to_atom([T1, T2, T3]), Scope, Tokens); -tokenize([T1, T2, T3|Rest], Line, Column, Scope, Tokens) when ?arrow_op3(T1, T2, T3) -> +tokenize([T1, T2, T3 | Rest], Line, Column, Scope, Tokens) when ?arrow_op3(T1, T2, T3) -> handle_op(Rest, Line, Column, arrow_op, 3, list_to_atom([T1, T2, T3]), Scope, Tokens); % ## Containers + punctuation tokens -tokenize([T, T|Rest], Line, Column, Scope, Tokens) when T == $<; T == $> -> +tokenize([T, T | Rest], Line, Column, Scope, Tokens) when T == $<; T == $> -> Token = {list_to_atom([T, T]), {Line, Column, Column + 2}}, handle_terminator(Rest, Line, Column + 2, Scope, Token, Tokens); -tokenize([T|Rest], Line, Column, Scope, Tokens) when T == $(; +tokenize([T | Rest], Line, Column, Scope, Tokens) when T == $(; T == ${; T == $}; T == $[; T == $]; T == $); T == $, -> Token = {list_to_atom([T]), {Line, Column, Column + 1}}, handle_terminator(Rest, Line, Column + 1, Scope, Token, Tokens); % ## Two Token Operators -tokenize([T1, T2|Rest], Line, Column, Scope, Tokens) when ?two_op(T1, T2) -> +tokenize([T1, T2 | Rest], Line, Column, Scope, Tokens) when ?two_op(T1, T2) -> handle_op(Rest, Line, Column, two_op, 2, list_to_atom([T1, T2]), Scope, Tokens); -tokenize([T1, T2|Rest], Line, Column, Scope, Tokens) when ?arrow_op(T1, T2) -> +tokenize([T1, T2 | Rest], Line, Column, Scope, Tokens) when ?arrow_op(T1, T2) -> handle_op(Rest, Line, Column, arrow_op, 2, list_to_atom([T1, T2]), Scope, Tokens); -tokenize([T1, T2|Rest], Line, Column, Scope, Tokens) when ?comp_op2(T1, T2) -> +tokenize([T1, T2 | Rest], Line, Column, Scope, Tokens) when ?comp_op2(T1, T2) -> handle_op(Rest, Line, Column, comp_op, 2, list_to_atom([T1, T2]), Scope, Tokens); -tokenize([T1, T2|Rest], Line, Column, Scope, Tokens) when ?rel_op2(T1, T2) -> +tokenize([T1, T2 | Rest], Line, Column, Scope, Tokens) when ?rel_op2(T1, T2) -> handle_op(Rest, Line, Column, rel_op, 2, list_to_atom([T1, T2]), Scope, Tokens); -tokenize([T1, T2|Rest], Line, Column, Scope, Tokens) when ?and_op(T1, T2) -> +tokenize([T1, T2 | Rest], Line, Column, Scope, Tokens) when ?and_op(T1, T2) -> handle_op(Rest, Line, Column, and_op, 2, list_to_atom([T1, T2]), Scope, Tokens); -tokenize([T1, T2|Rest], Line, Column, Scope, Tokens) when ?or_op(T1, T2) -> +tokenize([T1, T2 | Rest], Line, Column, Scope, Tokens) when ?or_op(T1, T2) -> handle_op(Rest, Line, Column, or_op, 2, list_to_atom([T1, T2]), Scope, Tokens); -tokenize([T1, T2|Rest], Line, Column, Scope, Tokens) when ?in_match_op(T1, T2) -> +tokenize([T1, T2 | Rest], Line, Column, Scope, Tokens) when ?in_match_op(T1, T2) -> handle_op(Rest, Line, Column, in_match_op, 2, list_to_atom([T1, T2]), Scope, Tokens); -tokenize([T1, T2|Rest], Line, Column, Scope, Tokens) when ?type_op(T1, T2) -> +tokenize([T1, T2 | Rest], Line, Column, Scope, Tokens) when ?type_op(T1, T2) -> handle_op(Rest, Line, Column, type_op, 2, list_to_atom([T1, T2]), Scope, Tokens); -tokenize([T1, T2|Rest], Line, Column, Scope, Tokens) when ?stab_op(T1, T2) -> +tokenize([T1, T2 | Rest], Line, Column, Scope, Tokens) when ?stab_op(T1, T2) -> handle_op(Rest, Line, Column, stab_op, 2, list_to_atom([T1, T2]), Scope, Tokens); % ## Single Token Operators -tokenize([T|Rest], Line, Column, Scope, Tokens) when ?at_op(T) -> +tokenize([T | Rest], Line, Column, Scope, Tokens) when ?at_op(T) -> handle_unary_op(Rest, Line, Column, at_op, 1, list_to_atom([T]), Scope, Tokens); -tokenize([T|Rest], Line, Column, Scope, Tokens) when ?capture_op(T) -> +tokenize([T | Rest], Line, Column, Scope, Tokens) when ?capture_op(T) -> handle_unary_op(Rest, Line, Column, capture_op, 1, list_to_atom([T]), Scope, Tokens); -tokenize([T|Rest], Line, Column, Scope, Tokens) when ?unary_op(T) -> +tokenize([T | Rest], Line, Column, Scope, Tokens) when ?unary_op(T) -> handle_unary_op(Rest, Line, Column, unary_op, 1, list_to_atom([T]), Scope, Tokens); -tokenize([T|Rest], Line, Column, Scope, Tokens) when ?rel_op(T) -> +tokenize([T | Rest], Line, Column, Scope, Tokens) when ?rel_op(T) -> handle_op(Rest, Line, Column, rel_op, 1, list_to_atom([T]), Scope, Tokens); -tokenize([T|Rest], Line, Column, Scope, Tokens) when ?dual_op(T) -> +tokenize([T | Rest], Line, Column, Scope, Tokens) when ?dual_op(T) -> handle_unary_op(Rest, Line, Column, dual_op, 1, list_to_atom([T]), Scope, Tokens); -tokenize([T|Rest], Line, Column, Scope, Tokens) when ?mult_op(T) -> +tokenize([T | Rest], Line, Column, Scope, Tokens) when ?mult_op(T) -> handle_op(Rest, Line, Column, mult_op, 1, list_to_atom([T]), Scope, Tokens); -tokenize([T|Rest], Line, Column, Scope, Tokens) when ?match_op(T) -> +tokenize([T | Rest], Line, Column, Scope, Tokens) when ?match_op(T) -> handle_op(Rest, Line, Column, match_op, 1, list_to_atom([T]), Scope, Tokens); -tokenize([T|Rest], Line, Column, Scope, Tokens) when ?pipe_op(T) -> +tokenize([T | Rest], Line, Column, Scope, Tokens) when ?pipe_op(T) -> handle_op(Rest, Line, Column, pipe_op, 1, list_to_atom([T]), Scope, Tokens); % Others -tokenize([$%, ${|T], Line, Column, Scope, Tokens) -> - tokenize([${|T], Line, Column + 1, Scope, [{'%{}', {Line, Column, Column + 1}}|Tokens]); +tokenize([$%, ${ | T], Line, Column, Scope, Tokens) -> + tokenize([${ | T], Line, Column + 1, Scope, [{'%{}', {Line, Column, Column + 1}} | Tokens]); -tokenize([$%|T], Line, Column, Scope, Tokens) -> - tokenize(T, Line, Column + 1, Scope, [{'%', {Line, Column, Column + 1}}|Tokens]); +tokenize([$% | T], Line, Column, Scope, Tokens) -> + tokenize(T, Line, Column + 1, Scope, [{'%', {Line, Column, Column + 1}} | Tokens]); -tokenize([$.|T], Line, Column, Scope, Tokens) -> +tokenize([$. | T], Line, Column, Scope, Tokens) -> {Rest, Counter, Offset} = strip_dot_space(T, 0, Column + 1), - handle_dot([$.|Rest], Line + Counter, Offset - 1, Column, Scope, Tokens); + handle_dot([$. | Rest], Line + Counter, Offset - 1, Column, Scope, Tokens); % Integers and floats -tokenize([H|_] = String, Line, Column, Scope, Tokens) when ?is_digit(H) -> +tokenize([H | _] = String, Line, Column, Scope, Tokens) when ?is_digit(H) -> {Rest, Number, Length} = tokenize_number(String, [], false), - tokenize(Rest, Line, Column + Length, Scope, [{number, {Line, Column, Column + Length}, Number}|Tokens]); + tokenize(Rest, Line, Column + Length, Scope, [{number, {Line, Column, Column + Length}, Number} | Tokens]); % Identifiers (including aliases) -tokenize([H|_] = Original, Line, Column, Scope, Tokens) when ?is_identifier_start(H) -> +tokenize([H | _] = Original, Line, Column, Scope, Tokens) when ?is_identifier_start(H) -> case tokenize_any_identifier(Original, Line, Scope) of {ok, Rest, Atom, Length, HasAt, HasEnding} -> case Rest of - [$:|T] when ?is_space(hd(T)) -> - tokenize(T, Line, Column + Length + 1, Scope, [{kw_identifier, {Line, Column, Column + Length + 1}, Atom}|Tokens]); - [$:|T] when hd(T) /= $: -> + [$: | T] when ?is_space(hd(T)) -> + tokenize(T, Line, Column + Length + 1, Scope, [{kw_identifier, {Line, Column, Column + Length + 1}, Atom} | Tokens]); + [$: | T] when hd(T) /= $: -> String = atom_to_list(Atom) ++ [$:], Reason = {Line, "keyword argument must be followed by space after: ", String}, {error, Reason, Original, Tokens}; @@ -443,20 +443,20 @@ tokenize([H|_] = Original, Line, Column, Scope, Tokens) when ?is_identifier_star % Spaces -tokenize([T|Rest], Line, Column, Scope, Tokens) when ?is_horizontal_space(T) -> +tokenize([T | Rest], Line, Column, Scope, Tokens) when ?is_horizontal_space(T) -> case strip_horizontal_space(Rest) of {Remaining, Stripped} -> handle_space_sensitive_tokens(Remaining, Line, Column + 1 + Stripped, Scope, Tokens) end; -tokenize([T|Rest], Line, Column, _Scope, Tokens) -> +tokenize([T | Rest], Line, Column, _Scope, Tokens) -> Message = io_lib:format("\"~ts\" (column ~p, codepoint U+~4.16.0B)", [[T], Column, T]), {error, {Line, "unexpected token: ", Message}, Rest, Tokens}. strip_horizontal_space(T) -> strip_horizontal_space(T, 0). -strip_horizontal_space([H|T], Counter) when ?is_horizontal_space(H) -> +strip_horizontal_space([H | T], Counter) when ?is_horizontal_space(H) -> strip_horizontal_space(T, Counter + 1); strip_horizontal_space(T, Counter) -> {T, Counter}. @@ -487,7 +487,7 @@ handle_heredocs(T, Line, Column, H, Scope, Tokens) -> case extract_heredoc_with_interpolation(Line, Column, Scope, true, T, H) of {ok, NewLine, NewColumn, Parts, Rest} -> Token = {string_type(H), {Line, Column, NewColumn}, unescape_tokens(Parts)}, - tokenize(Rest, NewLine, NewColumn, Scope, [Token|Tokens]); + tokenize(Rest, NewLine, NewColumn, Scope, [Token | Tokens]); {error, Reason} -> {error, Reason, [H, H, H] ++ T, Tokens} end. @@ -495,70 +495,70 @@ handle_heredocs(T, Line, Column, H, Scope, Tokens) -> handle_strings(T, Line, Column, H, Scope, Tokens) -> case elixir_interpolation:extract(Line, Column, Scope, true, T, H) of {error, Reason} -> - interpolation_error(Reason, [H|T], Tokens, " (for string starting at line ~B)", [Line]); - {NewLine, NewColumn, Parts, [$:|Rest]} when ?is_space(hd(Rest)) -> + interpolation_error(Reason, [H | T], Tokens, " (for string starting at line ~B)", [Line]); + {NewLine, NewColumn, Parts, [$: | Rest]} when ?is_space(hd(Rest)) -> Unescaped = unescape_tokens(Parts), Key = case Scope#elixir_tokenizer.existing_atoms_only of true -> kw_identifier_safe; false -> kw_identifier_unsafe end, - tokenize(Rest, NewLine, NewColumn, Scope, [{Key, {Line, Column - 1, NewColumn}, Unescaped}|Tokens]); + tokenize(Rest, NewLine, NewColumn, Scope, [{Key, {Line, Column - 1, NewColumn}, Unescaped} | Tokens]); {NewLine, NewColumn, Parts, Rest} -> Token = {string_type(H), {Line, Column - 1, NewColumn}, unescape_tokens(Parts)}, - tokenize(Rest, NewLine, NewColumn, Scope, [Token|Tokens]) + tokenize(Rest, NewLine, NewColumn, Scope, [Token | Tokens]) end. -handle_unary_op([$:|Rest], Line, Column, _Kind, Length, Op, Scope, Tokens) when ?is_space(hd(Rest)) -> - tokenize(Rest, Line, Column + Length + 1, Scope, [{kw_identifier, {Line, Column, Column + Length}, Op}|Tokens]); +handle_unary_op([$: | Rest], Line, Column, _Kind, Length, Op, Scope, Tokens) when ?is_space(hd(Rest)) -> + tokenize(Rest, Line, Column + Length + 1, Scope, [{kw_identifier, {Line, Column, Column + Length}, Op} | Tokens]); handle_unary_op(Rest, Line, Column, Kind, Length, Op, Scope, Tokens) -> case strip_horizontal_space(Rest) of - {[$/|_] = Remaining, Extra} -> + {[$/ | _] = Remaining, Extra} -> tokenize(Remaining, Line, Column + Length + Extra, Scope, - [{identifier, {Line, Column, Column + Length}, Op}|Tokens]); + [{identifier, {Line, Column, Column + Length}, Op} | Tokens]); {Remaining, Extra} -> tokenize(Remaining, Line, Column + Length + Extra, Scope, - [{Kind, {Line, Column, Column + Length}, Op}|Tokens]) + [{Kind, {Line, Column, Column + Length}, Op} | Tokens]) end. -handle_op([$:|Rest], Line, Column, _Kind, Length, Op, Scope, Tokens) when ?is_space(hd(Rest)) -> +handle_op([$: | Rest], Line, Column, _Kind, Length, Op, Scope, Tokens) when ?is_space(hd(Rest)) -> tokenize(Rest, Line, Column + Length + 1, Scope, - [{kw_identifier, {Line, Column, Column + Length}, Op}|Tokens]); + [{kw_identifier, {Line, Column, Column + Length}, Op} | Tokens]); handle_op(Rest, Line, Column, Kind, Length, Op, Scope, Tokens) -> case strip_horizontal_space(Rest) of - {[$/|_] = Remaining, Extra} -> + {[$/ | _] = Remaining, Extra} -> tokenize(Remaining, Line, Column + Length + Extra, Scope, - [{identifier, {Line, Column, Column + Length}, Op}|Tokens]); + [{identifier, {Line, Column, Column + Length}, Op} | Tokens]); {Remaining, Extra} -> tokenize(Remaining, Line, Column + Length + Extra, Scope, add_token_with_nl({Kind, {Line, Column, Column + Length}, Op}, Tokens)) end. % ## Three Token Operators -handle_dot([$., T1, T2, T3|Rest], Line, Column, DotColumn, Scope, Tokens) when +handle_dot([$., T1, T2, T3 | Rest], Line, Column, DotColumn, Scope, Tokens) when ?unary_op3(T1, T2, T3); ?comp_op3(T1, T2, T3); ?and_op3(T1, T2, T3); ?or_op3(T1, T2, T3); ?arrow_op3(T1, T2, T3); ?three_op(T1, T2, T3) -> handle_call_identifier(Rest, Line, Column + 1, DotColumn, 3, list_to_atom([T1, T2, T3]), Scope, Tokens); % ## Two Token Operators -handle_dot([$., T1, T2|Rest], Line, Column, DotColumn, Scope, Tokens) when +handle_dot([$., T1, T2 | Rest], Line, Column, DotColumn, Scope, Tokens) when ?comp_op2(T1, T2); ?rel_op2(T1, T2); ?and_op(T1, T2); ?or_op(T1, T2); ?arrow_op(T1, T2); ?in_match_op(T1, T2); ?two_op(T1, T2); ?stab_op(T1, T2); ?type_op(T1, T2) -> handle_call_identifier(Rest, Line, Column + 1, DotColumn, 2, list_to_atom([T1, T2]), Scope, Tokens); % ## Single Token Operators -handle_dot([$., T|Rest], Line, Column, DotColumn, Scope, Tokens) when +handle_dot([$., T | Rest], Line, Column, DotColumn, Scope, Tokens) when ?at_op(T); ?unary_op(T); ?capture_op(T); ?dual_op(T); ?mult_op(T); ?rel_op(T); ?match_op(T); ?pipe_op(T); T == $% -> handle_call_identifier(Rest, Line, Column + 1, DotColumn, 1, list_to_atom([T]), Scope, Tokens); % ## Exception for .( as it needs to be treated specially in the parser -handle_dot([$., $(|Rest], Line, Column, DotColumn, Scope, Tokens) -> - tokenize([$(|Rest], Line, Column + 2, Scope, add_token_with_nl({dot_call_op, {Line, DotColumn, DotColumn + 1}, '.'}, Tokens)); +handle_dot([$., $( | Rest], Line, Column, DotColumn, Scope, Tokens) -> + tokenize([$( | Rest], Line, Column + 2, Scope, add_token_with_nl({dot_call_op, {Line, DotColumn, DotColumn + 1}, '.'}, Tokens)); -handle_dot([$., H|T] = Original, Line, Column, DotColumn, Scope, Tokens) when ?is_quote(H) -> +handle_dot([$., H | T] = Original, Line, Column, DotColumn, Scope, Tokens) when ?is_quote(H) -> case elixir_interpolation:extract(Line, Column + 2, Scope, true, T, H) of {NewLine, NewColumn, [Part], Rest} when is_binary(Part) -> case unsafe_to_atom(Part, Line, Scope) of @@ -566,7 +566,7 @@ handle_dot([$., H|T] = Original, Line, Column, DotColumn, Scope, Tokens) when ?i Token = check_call_identifier(identifier, Line, Column, max(NewColumn - Column, 0), Atom, Rest), tokenize(Rest, NewLine, NewColumn, Scope, - [Token|add_token_with_nl({'.', {Line, DotColumn, DotColumn + 1}}, Tokens)]); + [Token | add_token_with_nl({'.', {Line, DotColumn, DotColumn + 1}}, Tokens)]); {error, Reason} -> {error, Reason, Original, Tokens} end; @@ -574,33 +574,33 @@ handle_dot([$., H|T] = Original, Line, Column, DotColumn, Scope, Tokens) when ?i interpolation_error(Reason, Original, Tokens, " (for function name starting at line ~B)", [Line]) end; -handle_dot([$.|Rest], Line, Column, DotColumn, Scope, Tokens) -> +handle_dot([$. | Rest], Line, Column, DotColumn, Scope, Tokens) -> tokenize(Rest, Line, Column + 1, Scope, add_token_with_nl({'.', {Line, DotColumn, DotColumn + 1}}, Tokens)). handle_call_identifier(Rest, Line, Column, DotColumn, Length, Op, Scope, Tokens) -> {_, {_, _, NewColumn}, _} = Token = check_call_identifier(identifier, Line, Column, Length, Op, Rest), tokenize(Rest, Line, NewColumn, Scope, - [Token|add_token_with_nl({'.', {Line, DotColumn, DotColumn + 1}}, Tokens)]). + [Token | add_token_with_nl({'.', {Line, DotColumn, DotColumn + 1}}, Tokens)]). % ## Ambiguous unary/binary operators tokens -handle_space_sensitive_tokens([Sign, NotMarker|T], Line, Column, Scope, [{Identifier, _, _} = H|Tokens]) when +handle_space_sensitive_tokens([Sign, NotMarker | T], Line, Column, Scope, [{Identifier, _, _} = H | Tokens]) when ?dual_op(Sign), not(?is_space(NotMarker)), NotMarker /= $(, NotMarker /= $[, NotMarker /= $<, NotMarker /= ${, %% containers NotMarker /= $%, NotMarker /= $+, NotMarker /= $-, NotMarker /= $/, NotMarker /= $>, %% operators Identifier == identifier -> - Rest = [NotMarker|T], - tokenize(Rest, Line, Column + 1, Scope, [{dual_op, {Line, Column, Column + 1}, list_to_atom([Sign])}, setelement(1, H, op_identifier)|Tokens]); + Rest = [NotMarker | T], + tokenize(Rest, Line, Column + 1, Scope, [{dual_op, {Line, Column, Column + 1}, list_to_atom([Sign])}, setelement(1, H, op_identifier) | Tokens]); handle_space_sensitive_tokens(String, Line, Column, Scope, Tokens) -> tokenize(String, Line, Column, Scope, Tokens). %% Helpers -eol(_Line, _Column, [{';', _}|_] = Tokens) -> Tokens; -eol(_Line, _Column, [{',', _}|_] = Tokens) -> Tokens; -eol(_Line, _Column, [{eol, _}|_] = Tokens) -> Tokens; -eol(Line, Column, Tokens) -> [{eol, {Line, Column, Column + 1}}|Tokens]. +eol(_Line, _Column, [{';', _} | _] = Tokens) -> Tokens; +eol(_Line, _Column, [{',', _} | _] = Tokens) -> Tokens; +eol(_Line, _Column, [{eol, _} | _] = Tokens) -> Tokens; +eol(Line, Column, Tokens) -> [{eol, {Line, Column, Column + 1}} | Tokens]. unsafe_to_atom(Part, Line, #elixir_tokenizer{}) when is_binary(Part) andalso size(Part) > 255; @@ -615,8 +615,8 @@ unsafe_to_atom(List, _Line, #elixir_tokenizer{existing_atoms_only=true}) when is unsafe_to_atom(List, _Line, #elixir_tokenizer{}) when is_list(List) -> {ok, list_to_atom(List)}. -collect_modifiers([H|T], Buffer) when ?is_downcase(H) or ?is_upcase(H) -> - collect_modifiers(T, [H|Buffer]); +collect_modifiers([H | T], Buffer) when ?is_downcase(H) or ?is_upcase(H) -> + collect_modifiers(T, [H | Buffer]); collect_modifiers(Rest, Buffer) -> {Rest, lists:reverse(Buffer)}. @@ -642,7 +642,7 @@ extract_heredoc(Line0, Column0, Rest0, Marker) -> %% We prepend a new line so we can transparently remove %% spaces later. This new line is removed by calling "tl" %% in the final heredoc body three lines below. - case extract_heredoc_body(Line0, Column0, Marker, [$\n|Rest1], []) of + case extract_heredoc_body(Line0, Column0, Marker, [$\n | Rest1], []) of {ok, Line1, Body, Rest2, Spaces} -> {ok, Line1, 1, tl(remove_heredoc_spaces(Body, Spaces)), Rest2}; {error, Reason, ErrorLine} -> @@ -665,15 +665,15 @@ heredoc_error_message(misplacedterminator, _Line, Terminator) -> %% Remove spaces from heredoc based on the position of the final quotes. remove_heredoc_spaces(Body, 0) -> - lists:reverse([0|Body]); + lists:reverse([0 | Body]); remove_heredoc_spaces(Body, Spaces) -> - remove_heredoc_spaces([0|Body], [], Spaces, Spaces). -remove_heredoc_spaces([H, $\n|T], [Backtrack|Buffer], Spaces, Original) when Spaces > 0, ?is_horizontal_space(H) -> - remove_heredoc_spaces([Backtrack, $\n|T], Buffer, Spaces - 1, Original); -remove_heredoc_spaces([$\n=H|T], Buffer, _Spaces, Original) -> - remove_heredoc_spaces(T, [H|Buffer], Original, Original); -remove_heredoc_spaces([H|T], Buffer, Spaces, Original) -> - remove_heredoc_spaces(T, [H|Buffer], Spaces, Original); + remove_heredoc_spaces([0 | Body], [], Spaces, Spaces). +remove_heredoc_spaces([H, $\n | T], [Backtrack | Buffer], Spaces, Original) when Spaces > 0, ?is_horizontal_space(H) -> + remove_heredoc_spaces([Backtrack, $\n | T], Buffer, Spaces - 1, Original); +remove_heredoc_spaces([$\n=H | T], Buffer, _Spaces, Original) -> + remove_heredoc_spaces(T, [H | Buffer], Original, Original); +remove_heredoc_spaces([H | T], Buffer, Spaces, Original) -> + remove_heredoc_spaces(T, [H | Buffer], Spaces, Original); remove_heredoc_spaces([], Buffer, _Spaces, _Original) -> Buffer. @@ -683,7 +683,7 @@ extract_heredoc_header("\r\n" ++ Rest) -> {ok, Rest}; extract_heredoc_header("\n" ++ Rest) -> {ok, Rest}; -extract_heredoc_header([H|T]) when ?is_horizontal_space(H) -> +extract_heredoc_header([H | T]) when ?is_horizontal_space(H) -> extract_heredoc_header(T); extract_heredoc_header(_) -> error. @@ -705,26 +705,26 @@ extract_heredoc_body(Line, _Column, Marker, Rest, Buffer) -> %% Extract a line from the heredoc prepending its contents to a buffer. %% Allow lazy escaping (e.g. \""") -extract_heredoc_line(Marker, [$\\, $\\|T], Buffer) -> - extract_heredoc_line(Marker, T, [$\\, $\\|Buffer]); -extract_heredoc_line(Marker, [$\\, Marker|T], Buffer) -> - extract_heredoc_line(Marker, T, [Marker, $\\|Buffer]); -extract_heredoc_line(Marker, [Marker, Marker, Marker|_], _) -> +extract_heredoc_line(Marker, [$\\, $\\ | T], Buffer) -> + extract_heredoc_line(Marker, T, [$\\, $\\ | Buffer]); +extract_heredoc_line(Marker, [$\\, Marker | T], Buffer) -> + extract_heredoc_line(Marker, T, [Marker, $\\ | Buffer]); +extract_heredoc_line(Marker, [Marker, Marker, Marker | _], _) -> {error, misplacedterminator}; extract_heredoc_line(_, "\r\n" ++ Rest, Buffer) -> - {ok, [$\n|Buffer], Rest}; + {ok, [$\n | Buffer], Rest}; extract_heredoc_line(_, "\n" ++ Rest, Buffer) -> - {ok, [$\n|Buffer], Rest}; -extract_heredoc_line(Marker, [H|T], Buffer) -> - extract_heredoc_line(Marker, T, [H|Buffer]); + {ok, [$\n | Buffer], Rest}; +extract_heredoc_line(Marker, [H | T], Buffer) -> + extract_heredoc_line(Marker, T, [H | Buffer]); extract_heredoc_line(_, _, _) -> {error, eof}. %% Extract each heredoc line trying to find a match according to the marker. -extract_heredoc_line(Marker, [H|T], Buffer, Counter) when ?is_horizontal_space(H) -> - extract_heredoc_line(Marker, T, [H|Buffer], Counter + 1); -extract_heredoc_line(Marker, [Marker, Marker, Marker|T], Buffer, Counter) -> +extract_heredoc_line(Marker, [H | T], Buffer, Counter) when ?is_horizontal_space(H) -> + extract_heredoc_line(Marker, T, [H | Buffer], Counter + 1); +extract_heredoc_line(Marker, [Marker, Marker, Marker | T], Buffer, Counter) -> {ok, Buffer, T, Counter}; extract_heredoc_line(Marker, Rest, Buffer, _Counter) -> extract_heredoc_line(Marker, Rest, Buffer). @@ -733,26 +733,26 @@ extract_heredoc_line(Marker, Rest, Buffer, _Counter) -> %% At this point, we are at least sure the first digit is a number. %% Check if we have a point followed by a number; -tokenize_number([$., H|T], Acc, false) when ?is_digit(H) -> - tokenize_number(T, [H, $.|Acc], true); +tokenize_number([$., H | T], Acc, false) when ?is_digit(H) -> + tokenize_number(T, [H, $. | Acc], true); %% Check if we have an underscore followed by a number; -tokenize_number([$_, H|T], Acc, Bool) when ?is_digit(H) -> - tokenize_number(T, [H|Acc], Bool); +tokenize_number([$_, H | T], Acc, Bool) when ?is_digit(H) -> + tokenize_number(T, [H | Acc], Bool); %% Check if we have e- followed by numbers (valid only for floats); -tokenize_number([E, S, H|T], Acc, true) +tokenize_number([E, S, H | T], Acc, true) when (E == $E) or (E == $e), ?is_digit(H), S == $+ orelse S == $- -> - tokenize_number(T, [H, S, $e|Acc], true); + tokenize_number(T, [H, S, $e | Acc], true); %% Check if we have e followed by numbers (valid only for floats); -tokenize_number([E, H|T], Acc, true) +tokenize_number([E, H | T], Acc, true) when (E == $E) or (E == $e), ?is_digit(H) -> - tokenize_number(T, [H, $e|Acc], true); + tokenize_number(T, [H, $e | Acc], true); %% Finally just numbers. -tokenize_number([H|T], Acc, Bool) when ?is_digit(H) -> - tokenize_number(T, [H|Acc], Bool); +tokenize_number([H | T], Acc, Bool) when ?is_digit(H) -> + tokenize_number(T, [H | Acc], Bool); %% Cast to float... tokenize_number(Rest, Acc, true) -> @@ -762,23 +762,23 @@ tokenize_number(Rest, Acc, true) -> tokenize_number(Rest, Acc, false) -> {Rest, list_to_integer(lists:reverse(Acc)), length(Acc)}. -tokenize_hex([H|T], Acc) when ?is_hex(H) -> tokenize_hex(T, [H|Acc]); -tokenize_hex([$_, H|T], Acc) when ?is_hex(H) -> tokenize_hex(T, [H|Acc]); +tokenize_hex([H | T], Acc) when ?is_hex(H) -> tokenize_hex(T, [H | Acc]); +tokenize_hex([$_, H | T], Acc) when ?is_hex(H) -> tokenize_hex(T, [H | Acc]); tokenize_hex(Rest, Acc) -> {Rest, list_to_integer(lists:reverse(Acc), 16), length(Acc)}. -tokenize_octal([H|T], Acc) when ?is_octal(H) -> tokenize_octal(T, [H|Acc]); -tokenize_octal([$_, H|T], Acc) when ?is_octal(H) -> tokenize_octal(T, [H|Acc]); +tokenize_octal([H | T], Acc) when ?is_octal(H) -> tokenize_octal(T, [H | Acc]); +tokenize_octal([$_, H | T], Acc) when ?is_octal(H) -> tokenize_octal(T, [H | Acc]); tokenize_octal(Rest, Acc) -> {Rest, list_to_integer(lists:reverse(Acc), 8), length(Acc)}. -tokenize_bin([H|T], Acc) when ?is_bin(H) -> tokenize_bin(T, [H|Acc]); -tokenize_bin([$_, H|T], Acc) when ?is_bin(H) -> tokenize_bin(T, [H|Acc]); +tokenize_bin([H | T], Acc) when ?is_bin(H) -> tokenize_bin(T, [H | Acc]); +tokenize_bin([$_, H | T], Acc) when ?is_bin(H) -> tokenize_bin(T, [H | Acc]); tokenize_bin(Rest, Acc) -> {Rest, list_to_integer(lists:reverse(Acc), 2), length(Acc)}. %% Comments tokenize_comment("\r\n" ++ _ = Rest) -> Rest; tokenize_comment("\n" ++ _ = Rest) -> Rest; -tokenize_comment([_|Rest]) -> tokenize_comment(Rest); +tokenize_comment([_ | Rest]) -> tokenize_comment(Rest); tokenize_comment([]) -> []. %% Atoms @@ -787,11 +787,11 @@ tokenize_comment([]) -> []. tokenize_atom(T, Acc) -> tokenize_atom(T, Acc, 0). -tokenize_atom([H|T], Acc, Length) when ?is_atom(H) -> - tokenize_atom(T, [H|Acc], Length + 1); +tokenize_atom([H | T], Acc, Length) when ?is_atom(H) -> + tokenize_atom(T, [H | Acc], Length + 1); -tokenize_atom([H|T], Acc, Length) when H == $?; H == $! -> - {T, lists:reverse([H|Acc]), Length + 1}; +tokenize_atom([H | T], Acc, Length) when H == $?; H == $! -> + {T, lists:reverse([H | Acc]), Length + 1}; tokenize_atom(Rest, Acc, Length) -> {Rest, lists:reverse(Acc), Length}. @@ -802,8 +802,8 @@ tokenize_atom(Rest, Acc, Length) -> tokenize_any_base_identifier(Original) -> tokenize_any_base_identifier(Original, [], false). -tokenize_any_base_identifier([H|T], Acc, HasAt) when ?is_atom(H) -> - tokenize_any_base_identifier(T, [H|Acc], HasAt orelse H == $@); +tokenize_any_base_identifier([H | T], Acc, HasAt) when ?is_atom(H) -> + tokenize_any_base_identifier(T, [H | Acc], HasAt orelse H == $@); tokenize_any_base_identifier(Rest, Acc, HasAt) -> {Rest, lists:reverse(Acc), length(Acc), HasAt}. @@ -815,7 +815,7 @@ tokenize_any_identifier(Original, Line, Scope) -> {AllIdentifier, AllRest, AllLength, HasEnding} = case Rest of - [H|T] when H == $?; H == $! -> {Identifier ++ [H], T, Length + 1, true}; + [H | T] when H == $?; H == $! -> {Identifier ++ [H], T, Length + 1, true}; _ -> {Identifier, Rest, Length, false} end, @@ -834,7 +834,7 @@ tokenize_alias(Rest, Line, Column, Atom, Length, HasEnding, Scope, Tokens) -> Reason = {Line, invalid_character_error(Ending), AtomName}, {error, Reason, AtomName, Tokens}; _ -> - tokenize(Rest, Line, Column + Length, Scope, [{aliases, {Line, Column, Column + Length}, [Atom]}|Tokens]) + tokenize(Rest, Line, Column + Length, Scope, [{aliases, {Line, Column, Column + Length}, [Atom]} | Tokens]) end. tokenize_other_identifier(Rest, Line, Column, Length, Atom, Scope, Tokens) -> @@ -844,7 +844,7 @@ tokenize_other_identifier(Rest, Line, Column, Length, Atom, Scope, Tokens) -> {keyword, Rest, {_, {_, _, EndColumn}, _} = Check, T} -> handle_terminator(Rest, Line, EndColumn, Scope, Check, T); {identifier, Rest, {_, {_, _, EndColumn}, _} = Token} -> - tokenize(Rest, Line, EndColumn, Scope, [Token|Tokens]); + tokenize(Rest, Line, EndColumn, Scope, [Token | Tokens]); {error, _, _, _} = Error -> Error end. @@ -853,7 +853,7 @@ tokenize_kw_or_other(Rest, Kind, Line, Column, Length, Atom, Tokens) -> case check_keyword(Line, Column, Length, Atom, Tokens) of nomatch -> {identifier, Rest, check_call_identifier(Kind, Line, Column, Length, Atom, Rest)}; - {ok, [Check|T]} -> + {ok, [Check | T]} -> {keyword, Rest, Check, T}; {error, Message, Token} -> {error, {Line, Message, Token}, atom_to_list(Atom) ++ Rest, Tokens} @@ -861,15 +861,15 @@ tokenize_kw_or_other(Rest, Kind, Line, Column, Length, Atom, Tokens) -> %% Check if it is a call identifier (paren | bracket | do) -check_call_identifier(_Kind, Line, Column, Length, Atom, [$(|_]) -> +check_call_identifier(_Kind, Line, Column, Length, Atom, [$( | _]) -> {paren_identifier, {Line, Column, Column + Length}, Atom}; -check_call_identifier(_Kind, Line, Column, Length, Atom, [$[|_]) -> +check_call_identifier(_Kind, Line, Column, Length, Atom, [$[ | _]) -> {bracket_identifier, {Line, Column, Column + Length}, Atom}; check_call_identifier(Kind, Line, Column, Length, Atom, _Rest) -> {Kind, {Line, Column, Column + Length}, Atom}. -add_token_with_nl(Left, [{eol, _}|T]) -> [Left|T]; -add_token_with_nl(Left, T) -> [Left|T]. +add_token_with_nl(Left, [{eol, _} | T]) -> [Left | T]; +add_token_with_nl(Left, T) -> [Left | T]. %% Error handling @@ -877,7 +877,7 @@ interpolation_error(Reason, Rest, Tokens, Extension, Args) -> {error, interpolation_format(Reason, Extension, Args), Rest, Tokens}. interpolation_format({string, Line, Message, Token}, Extension, Args) -> - {Line, io_lib:format("~ts" ++ Extension, [Message|Args]), Token}; + {Line, io_lib:format("~ts" ++ Extension, [Message | Args]), Token}; interpolation_format({_, _, _} = Reason, _Extension, _Args) -> Reason. @@ -888,7 +888,7 @@ handle_terminator(Rest, Line, Column, Scope, Token, Tokens) -> {error, Reason} -> {error, Reason, atom_to_list(element(1, Token)) ++ Rest, Tokens}; New -> - tokenize(Rest, Line, Column, New, [Token|Tokens]) + tokenize(Rest, Line, Column, New, [Token | Tokens]) end. handle_terminator(_, #elixir_tokenizer{check_terminators=false} = Scope) -> @@ -906,9 +906,9 @@ check_terminator({S, _} = New, Terminators) when S == '['; S == '{'; S == '<<' -> - [New|Terminators]; + [New | Terminators]; -check_terminator({E, _}, [{S, _}|Terminators]) when +check_terminator({E, _}, [{S, _} | Terminators]) when S == 'do', E == 'end'; S == 'fn', E == 'end'; S == '(', E == ')'; @@ -917,7 +917,7 @@ check_terminator({E, _}, [{S, _}|Terminators]) when S == '<<', E == '>>' -> Terminators; -check_terminator({E, {Line, _, _}}, [{Start, {StartLine, _, _}}|_]) when +check_terminator({E, {Line, _, _}}, [{Start, {StartLine, _, _}} | _]) when E == 'end'; E == ')'; E == ']'; E == '}'; E == '>>' -> End = terminator(Start), MessagePrefix = "unexpected token: \"", @@ -950,13 +950,13 @@ terminator('<<') -> '>>'. %% Keywords checking -check_keyword(_Line, _Column, _Length, _Atom, [{'.', _}|_]) -> +check_keyword(_Line, _Column, _Length, _Atom, [{'.', _} | _]) -> nomatch; -check_keyword(_Line, _Column, _Length, Atom, [{capture_op, _, _}|_]) when ?operator_kw(Atom) -> +check_keyword(_Line, _Column, _Length, Atom, [{capture_op, _, _} | _]) when ?operator_kw(Atom) -> nomatch; -check_keyword(DoLine, DoColumn, _Length, do, [{Identifier, {Line, Column, EndColumn}, Atom}|T]) when Identifier == identifier -> +check_keyword(DoLine, DoColumn, _Length, do, [{Identifier, {Line, Column, EndColumn}, Atom} | T]) when Identifier == identifier -> {ok, add_token_with_nl({do, {DoLine, DoColumn, DoColumn + 2}}, - [{do_identifier, {Line, Column, EndColumn}, Atom}|T])}; + [{do_identifier, {Line, Column, EndColumn}, Atom} | T])}; check_keyword(Line, Column, _Length, do, Tokens) -> case do_keyword_valid(Tokens) of true -> {ok, add_token_with_nl({do, {Line, Column, Column + 2}}, Tokens)}; @@ -965,15 +965,15 @@ check_keyword(Line, Column, _Length, do, Tokens) -> check_keyword(Line, Column, Length, Atom, Tokens) -> case keyword(Atom) of false -> nomatch; - token -> {ok, [{Atom, {Line, Column, Column + Length}}|Tokens]}; - block -> {ok, [{block_identifier, {Line, Column, Column + Length}, Atom}|Tokens]}; - unary_op -> {ok, [{unary_op, {Line, Column, Column + Length}, Atom}|Tokens]}; + token -> {ok, [{Atom, {Line, Column, Column + Length}} | Tokens]}; + block -> {ok, [{block_identifier, {Line, Column, Column + Length}, Atom} | Tokens]}; + unary_op -> {ok, [{unary_op, {Line, Column, Column + Length}, Atom} | Tokens]}; Kind -> {ok, add_token_with_nl({Kind, {Line, Column, Column + Length}, Atom}, Tokens)} end. %% Fail early on invalid do syntax. For example, after %% most keywords, after comma and so on. -do_keyword_valid([{Atom, _}|_]) -> +do_keyword_valid([{Atom, _} | _]) -> case Atom of ',' -> false; ';' -> false; diff --git a/lib/elixir/src/elixir_translator.erl b/lib/elixir/src/elixir_translator.erl index 943795a7ffd..130beaae0a3 100644 --- a/lib/elixir/src/elixir_translator.erl +++ b/lib/elixir/src/elixir_translator.erl @@ -72,7 +72,7 @@ translate({fn, Meta, Clauses}, S) -> %% Cond translate({'cond', CondMeta, [[{do, Pairs}]]}, S) -> - [{'->', Meta, [[Condition], Body]} = H|T] = lists:reverse(Pairs), + [{'->', Meta, [[Condition], Body]} = H | T] = lists:reverse(Pairs), Case = case Condition of @@ -83,7 +83,7 @@ translate({'cond', CondMeta, [[{do, Pairs}]]}, S) -> build_cond_clauses(T, Body, Meta); _ -> Error = {{'.', Meta, [erlang, error]}, [], [cond_clause]}, - build_cond_clauses([H|T], Error, Meta) + build_cond_clauses([H | T], Error, Meta) end, translate(replace_case_meta(CondMeta, Case), S); @@ -136,12 +136,12 @@ translate({'receive', Meta, [KV]}, S) -> %% Comprehensions -translate({for, Meta, [_|_] = Args}, S) -> +translate({for, Meta, [_ | _] = Args}, S) -> elixir_for:translate(Meta, Args, true, S); %% With -translate({with, Meta, [_|_] = Args}, S) -> +translate({with, Meta, [_ | _] = Args}, S) -> elixir_with:translate(Meta, Args, S); %% Super @@ -180,7 +180,7 @@ translate({'^', Meta, [{Name, VarMeta, Kind}]}, #elixir_scope{context=match, fil pin_guard -> {TVar, TS} = elixir_scope:translate_var(VarMeta, Name, var_kind(VarMeta, Kind), S), Guard = {op, PAnn, '=:=', PVar, TVar}, - {TVar, TS#elixir_scope{extra_guards=[Guard|TS#elixir_scope.extra_guards]}}; + {TVar, TS#elixir_scope{extra_guards=[Guard | TS#elixir_scope.extra_guards]}}; _ -> {PVar, S} end; @@ -318,14 +318,14 @@ guard_op(Op, Arity) -> translate_list([{'|', _, [_, _]=Args}], Fun, Acc, List) -> {[TLeft, TRight], TAcc} = lists:mapfoldl(Fun, Acc, Args), - {build_list([TLeft|List], TRight), TAcc}; -translate_list([H|T], Fun, Acc, List) -> + {build_list([TLeft | List], TRight), TAcc}; +translate_list([H | T], Fun, Acc, List) -> {TH, TAcc} = Fun(H, Acc), - translate_list(T, Fun, TAcc, [TH|List]); + translate_list(T, Fun, TAcc, [TH | List]); translate_list([], _Fun, Acc, List) -> {build_list(List, {nil, 0}), Acc}. -build_list([H|T], Acc) -> +build_list([H | T], Acc) -> build_list(T, {cons, 0, H, Acc}); build_list([], Acc) -> Acc. @@ -361,22 +361,22 @@ translate_block([], Acc, S) -> {lists:reverse(Acc), S}; translate_block([H], Acc, S) -> {TH, TS} = translate(H, S), - translate_block([], [TH|Acc], TS); -translate_block([{'__block__', _Meta, Args}|T], Acc, S) when is_list(Args) -> + translate_block([], [TH | Acc], TS); +translate_block([{'__block__', _Meta, Args} | T], Acc, S) when is_list(Args) -> translate_block(Args ++ T, Acc, S); -translate_block([{for, Meta, [_|_] = Args}|T], Acc, S) -> +translate_block([{for, Meta, [_ | _] = Args} | T], Acc, S) -> {TH, TS} = elixir_for:translate(Meta, Args, false, S), - translate_block(T, [TH|Acc], TS); -translate_block([{'=', _, [{'_', _, Ctx}, {for, Meta, [_|_] = Args}]}|T], Acc, S) when is_atom(Ctx) -> + translate_block(T, [TH | Acc], TS); +translate_block([{'=', _, [{'_', _, Ctx}, {for, Meta, [_ | _] = Args}]} | T], Acc, S) when is_atom(Ctx) -> {TH, TS} = elixir_for:translate(Meta, Args, false, S), - translate_block(T, [TH|Acc], TS); -translate_block([H|T], Acc, S) -> + translate_block(T, [TH | Acc], TS); +translate_block([H | T], Acc, S) -> {TH, TS} = translate(H, S), - translate_block(T, [TH|Acc], TS). + translate_block(T, [TH | Acc], TS). %% Cond -build_cond_clauses([{'->', NewMeta, [[Condition], Body]}|T], Acc, OldMeta) -> +build_cond_clauses([{'->', NewMeta, [[Condition], Body]} | T], Acc, OldMeta) -> {NewCondition, Truthy, Other} = build_truthy_clause(NewMeta, Condition, Body), Falsy = {'->', OldMeta, [[Other], Acc]}, Case = {'case', NewMeta, [NewCondition, [{do, [Truthy, Falsy]}]]}, diff --git a/lib/elixir/src/elixir_try.erl b/lib/elixir/src/elixir_try.erl index e53b425e3ef..d8fc75fa297 100644 --- a/lib/elixir/src/elixir_try.erl +++ b/lib/elixir/src/elixir_try.erl @@ -7,7 +7,7 @@ clauses(_Meta, Clauses, S) -> Rescue = elixir_clauses:get_pairs(rescue, Clauses, rescue), reduce_clauses(Rescue ++ Catch, [], S, S). -reduce_clauses([H|T], Acc, SAcc, S) -> +reduce_clauses([H | T], Acc, SAcc, S) -> {TH, TS} = each_clause(H, SAcc), reduce_clauses(T, TH ++ Acc, elixir_scope:mergec(S, TS), S); reduce_clauses([], Acc, SAcc, _S) -> @@ -100,10 +100,10 @@ rescue_guards(Meta, Var, Aliases, S) -> %% Matching of variables is done with Erlang exceptions is done in %% function for optimization. -rescue_each_ref(Meta, Var, [H|T], Elixir, Erlang, S) when is_atom(H) -> +rescue_each_ref(Meta, Var, [H | T], Elixir, Erlang, S) when is_atom(H) -> case erl_rescue_guard_for(Meta, Var, H) of - false -> rescue_each_ref(Meta, Var, T, [H|Elixir], Erlang, S); - Expr -> rescue_each_ref(Meta, Var, T, [H|Elixir], [Expr|Erlang], S) + false -> rescue_each_ref(Meta, Var, T, [H | Elixir], Erlang, S); + Expr -> rescue_each_ref(Meta, Var, T, [H | Elixir], [Expr | Erlang], S) end; rescue_each_ref(_, _, [], Elixir, Erlang, _) -> @@ -202,7 +202,7 @@ erl_record_compare(Meta, Var, Expr) -> ]}. prepend_to_block(_Meta, Expr, {'__block__', Meta, Args}) -> - {'__block__', Meta, [Expr|Args]}; + {'__block__', Meta, [Expr | Args]}; prepend_to_block(Meta, Expr, Args) -> {'__block__', Meta, [Expr, Args]}. diff --git a/lib/elixir/src/elixir_utils.erl b/lib/elixir/src/elixir_utils.erl index e3d6dfc846d..d06ca386b5f 100644 --- a/lib/elixir/src/elixir_utils.erl +++ b/lib/elixir/src/elixir_utils.erl @@ -30,16 +30,16 @@ get_line(Opts) when is_list(Opts) -> get_ann(Opts) when is_list(Opts) -> get_ann(Opts, [], 0). -get_ann([{generated, Gen}|T], Acc, Line) -> get_ann(T, [{generated, Gen}|Acc], Line); -get_ann([{line, Line}|T], Acc, _) -> get_ann(T, Acc, Line); -get_ann([_|T], Acc, Line) -> get_ann(T, Acc, Line); +get_ann([{generated, Gen} | T], Acc, Line) -> get_ann(T, [{generated, Gen} | Acc], Line); +get_ann([{line, Line} | T], Acc, _) -> get_ann(T, Acc, Line); +get_ann([_ | T], Acc, Line) -> get_ann(T, Acc, Line); get_ann([], [], Line) -> Line; -get_ann([], Acc, Line) -> [{location, Line}|Acc]. +get_ann([], Acc, Line) -> [{location, Line} | Acc]. -split_last([]) -> {[], []}; -split_last(List) -> split_last(List, []). -split_last([H], Acc) -> {lists:reverse(Acc), H}; -split_last([H|T], Acc) -> split_last(T, [H|Acc]). +split_last([]) -> {[], []}; +split_last(List) -> split_last(List, []). +split_last([H], Acc) -> {lists:reverse(Acc), H}; +split_last([H | T], Acc) -> split_last(T, [H | Acc]). read_file_type(File) -> case file:read_file_info(File) of @@ -162,10 +162,10 @@ elixir_to_erl(Pid) when is_pid(Pid) -> elixir_to_erl(_Other) -> error(badarg). -elixir_to_erl_cons_1([H|T], Acc) -> elixir_to_erl_cons_1(T, [H|Acc]); +elixir_to_erl_cons_1([H | T], Acc) -> elixir_to_erl_cons_1(T, [H | Acc]); elixir_to_erl_cons_1(Other, Acc) -> elixir_to_erl_cons_2(Acc, elixir_to_erl(Other)). -elixir_to_erl_cons_2([H|T], Acc) -> +elixir_to_erl_cons_2([H | T], Acc) -> elixir_to_erl_cons_2(T, {cons, 0, elixir_to_erl(H), Acc}); elixir_to_erl_cons_2([], Acc) -> Acc. diff --git a/lib/elixir/src/elixir_with.erl b/lib/elixir/src/elixir_with.erl index b70a5ec338d..9f6af197f83 100644 --- a/lib/elixir/src/elixir_with.erl +++ b/lib/elixir/src/elixir_with.erl @@ -36,7 +36,7 @@ expand(Meta, Args, E) -> end, case ElseOpts of - [{Key, _}|_] -> + [{Key, _} | _] -> elixir_errors:compile_error(Meta, ?m(E, file), "unexpected keyword ~ts in with", [Key]); [] -> diff --git a/lib/elixir/test/elixir/exception_test.exs b/lib/elixir/test/elixir/exception_test.exs index 36bf14d1932..b4f22f4710d 100644 --- a/lib/elixir/test/elixir/exception_test.exs +++ b/lib/elixir/test/elixir/exception_test.exs @@ -10,7 +10,7 @@ defmodule ExceptionTest do try do raise "a" rescue _ -> - [top|_] = System.stacktrace + [top | _] = System.stacktrace top end file = __ENV__.file |> Path.relative_to_cwd |> String.to_char_list diff --git a/lib/elixir/test/elixir/gen_server_test.exs b/lib/elixir/test/elixir/gen_server_test.exs index 7fc52e0487f..fd5c4260d56 100644 --- a/lib/elixir/test/elixir/gen_server_test.exs +++ b/lib/elixir/test/elixir/gen_server_test.exs @@ -6,7 +6,7 @@ defmodule GenServerTest do defmodule Stack do use GenServer - def handle_call(:pop, _from, [h|t]) do + def handle_call(:pop, _from, [h | t]) do {:reply, h, t} end @@ -19,7 +19,7 @@ defmodule GenServerTest do end def handle_cast({:push, item}, state) do - {:noreply, [item|state]} + {:noreply, [item | state]} end def handle_cast(request, state) do diff --git a/lib/elixir/test/elixir/inspect_test.exs b/lib/elixir/test/elixir/inspect_test.exs index aae06691a35..6f618c6a426 100644 --- a/lib/elixir/test/elixir/inspect_test.exs +++ b/lib/elixir/test/elixir/inspect_test.exs @@ -224,7 +224,7 @@ defmodule Inspect.ListTest do test "improper" do assert inspect([:foo | :bar]) == "[:foo | :bar]" - assert inspect([1, 2, 3, 4, 5|42], [pretty: true, width: 1]) == "[1,\n 2,\n 3,\n 4,\n 5 |\n 42]" + assert inspect([1, 2, 3, 4, 5 | 42], [pretty: true, width: 1]) == "[1,\n 2,\n 3,\n 4,\n 5 |\n 42]" end test "nested" do @@ -309,7 +309,7 @@ defmodule Inspect.MapTest do inspect(%Failing{}, safe: false) end - assert [{Inspect.Inspect.MapTest.Failing, :inspect, 2, _}|_] = System.stacktrace + assert [{Inspect.Inspect.MapTest.Failing, :inspect, 2, _} | _] = System.stacktrace end test "bad implementation safe" do diff --git a/lib/elixir/test/elixir/kernel/comprehension_test.exs b/lib/elixir/test/elixir/kernel/comprehension_test.exs index 6ae6c163ac0..374fd350ba3 100644 --- a/lib/elixir/test/elixir/kernel/comprehension_test.exs +++ b/lib/elixir/test/elixir/kernel/comprehension_test.exs @@ -14,7 +14,7 @@ defmodule Kernel.ComprehensionTest do def into(struct) do {struct, fn - _, {:cont, x} -> Process.put(:into_cont, [x|Process.get(:into_cont)]) + _, {:cont, x} -> Process.put(:into_cont, [x | Process.get(:into_cont)]) _, :done -> Process.put(:into_done, true) _, :halt -> Process.put(:into_halt, true) end} diff --git a/lib/elixir/test/elixir/kernel/errors_test.exs b/lib/elixir/test/elixir/kernel/errors_test.exs index 38739e538d7..1e3eb83989d 100644 --- a/lib/elixir/test/elixir/kernel/errors_test.exs +++ b/lib/elixir/test/elixir/kernel/errors_test.exs @@ -949,7 +949,7 @@ defmodule Kernel.ErrorsTest do test "macros error stacktrace" do assert [{:erlang, :+, [1, :foo], _}, - {Kernel.ErrorsTest.MacrosErrorStacktrace, :sample, 1, _}|_] = + {Kernel.ErrorsTest.MacrosErrorStacktrace, :sample, 1, _} | _] = rescue_stacktrace(""" defmodule Kernel.ErrorsTest.MacrosErrorStacktrace do defmacro sample(num), do: num + :foo @@ -959,7 +959,7 @@ defmodule Kernel.ErrorsTest do end test "macros function clause stacktrace" do - assert [{__MODULE__, :sample, 1, _}|_] = + assert [{__MODULE__, :sample, 1, _} | _] = rescue_stacktrace(""" defmodule Kernel.ErrorsTest.MacrosFunctionClauseStacktrace do import Kernel.ErrorsTest @@ -969,7 +969,7 @@ defmodule Kernel.ErrorsTest do end test "macros interpreted function clause stacktrace" do - assert [{Kernel.ErrorsTest.MacrosInterpretedFunctionClauseStacktrace, :sample, 1, _}|_] = + assert [{Kernel.ErrorsTest.MacrosInterpretedFunctionClauseStacktrace, :sample, 1, _} | _] = rescue_stacktrace(""" defmodule Kernel.ErrorsTest.MacrosInterpretedFunctionClauseStacktrace do defmacro sample(0), do: 0 @@ -979,7 +979,7 @@ defmodule Kernel.ErrorsTest do end test "macros compiled callback" do - assert [{Kernel.ErrorsTest, :__before_compile__, [%Macro.Env{module: Kernel.ErrorsTest.MacrosCompiledCallback}], _}|_] = + assert [{Kernel.ErrorsTest, :__before_compile__, [%Macro.Env{module: Kernel.ErrorsTest.MacrosCompiledCallback}], _} | _] = rescue_stacktrace(""" defmodule Kernel.ErrorsTest.MacrosCompiledCallback do Module.put_attribute(__MODULE__, :before_compile, Kernel.ErrorsTest) diff --git a/lib/elixir/test/elixir/kernel/fn_test.exs b/lib/elixir/test/elixir/kernel/fn_test.exs index c4db076c141..550a16db191 100644 --- a/lib/elixir/test/elixir/kernel/fn_test.exs +++ b/lib/elixir/test/elixir/kernel/fn_test.exs @@ -102,7 +102,7 @@ defmodule Kernel.FnTest do assert (&[ 1, &1 ]).(2) == [ 1, 2 ] assert (&[ 1, &1, &2 ]).(2, 3) == [ 1, 2, 3 ] - assert (&[&1|&2]).(1, 2) == [1|2] + assert (&[&1 | &2]).(1, 2) == [1 | 2] end test "capture and partially apply on call" do diff --git a/lib/elixir/test/elixir/kernel/quote_test.exs b/lib/elixir/test/elixir/kernel/quote_test.exs index e4c61110e18..ad90f42891a 100644 --- a/lib/elixir/test/elixir/kernel/quote_test.exs +++ b/lib/elixir/test/elixir/kernel/quote_test.exs @@ -86,13 +86,13 @@ defmodule Kernel.QuoteTest do test "splice with tail" do contents = [1, 2, 3] - assert quote(do: [unquote_splicing(contents)|[1, 2, 3]]) == + assert quote(do: [unquote_splicing(contents) | [1, 2, 3]]) == [1, 2, 3, 1, 2, 3] - assert quote(do: [unquote_splicing(contents)|val]) == + assert quote(do: [unquote_splicing(contents) | val]) == quote(do: [1, 2, 3 | val]) - assert quote(do: [unquote_splicing(contents)|unquote([4])]) == + assert quote(do: [unquote_splicing(contents) | unquote([4])]) == quote(do: [1, 2, 3, 4]) end @@ -108,7 +108,7 @@ defmodule Kernel.QuoteTest do test "splice on definition" do defmodule Hello do - def world([unquote_splicing(["foo", "bar"])|rest]) do + def world([unquote_splicing(["foo", "bar"]) | rest]) do rest end end @@ -220,7 +220,7 @@ defmodule Kernel.QuoteTest.ErrorsTest do mod = Kernel.QuoteTest.ErrorsTest file = __ENV__.file |> Path.relative_to_cwd |> String.to_char_list - assert [{^mod, :add, 2, [file: ^file, line: 200]}|_] = System.stacktrace + assert [{^mod, :add, 2, [file: ^file, line: 200]} | _] = System.stacktrace end test "outside function error" do @@ -230,7 +230,7 @@ defmodule Kernel.QuoteTest.ErrorsTest do mod = Kernel.QuoteTest.ErrorsTest file = __ENV__.file |> Path.relative_to_cwd |> String.to_char_list - assert [{^mod, _, _, [file: ^file, line: 228]}|_] = System.stacktrace + assert [{^mod, _, _, [file: ^file, line: 228]} | _] = System.stacktrace end end diff --git a/lib/elixir/test/elixir/kernel_test.exs b/lib/elixir/test/elixir/kernel_test.exs index 6af4b6eb6fd..be71b0a4f29 100644 --- a/lib/elixir/test/elixir/kernel_test.exs +++ b/lib/elixir/test/elixir/kernel_test.exs @@ -225,7 +225,7 @@ defmodule KernelTest do end test "apply/3 and apply/2" do - assert apply(Enum, :reverse, [[1|[2, 3]]]) == [3, 2, 1] + assert apply(Enum, :reverse, [[1 | [2, 3]]]) == [3, 2, 1] assert apply(fn x -> x * 2 end, [2]) == 4 end diff --git a/lib/elixir/test/elixir/list_test.exs b/lib/elixir/test/elixir/list_test.exs index 66781bd93f6..1720c1fa7d1 100644 --- a/lib/elixir/test/elixir/list_test.exs +++ b/lib/elixir/test/elixir/list_test.exs @@ -6,7 +6,7 @@ defmodule ListTest do doctest List test "cons cell precedence" do - assert [1|:lists.flatten([2, 3])] == [1, 2, 3] + assert [1 | :lists.flatten([2, 3])] == [1, 2, 3] end test "optional comma" do @@ -18,8 +18,8 @@ defmodule ListTest do assert (&[&1, 2]).(1) == [1, 2] assert (&[&1, &2]).(1, 2) == [1, 2] assert (&[&2, &1]).(2, 1) == [1, 2] - assert (&[&1|&2]).(1, 2) == [1|2] - assert (&[&1, &2|&3]).(1, 2, 3) == [1, 2|3] + assert (&[&1 | &2]).(1, 2) == [1 | 2] + assert (&[&1, &2 | &3]).(1, 2, 3) == [1, 2 | 3] end test "wrap" do diff --git a/lib/elixir/test/elixir/macro_test.exs b/lib/elixir/test/elixir/macro_test.exs index 7acbf68f7c7..1da8b64a502 100644 --- a/lib/elixir/test/elixir/macro_test.exs +++ b/lib/elixir/test/elixir/macro_test.exs @@ -51,8 +51,8 @@ defmodule MacroTest do end test "escape improper" do - assert [{:|, [], [1, 2]}] == Macro.escape([1|2]) - assert [1, {:|, [], [2, 3]}] == Macro.escape([1, 2|3]) + assert [{:|, [], [1, 2]}] == Macro.escape([1 | 2]) + assert [1, {:|, [], [2, 3]}] == Macro.escape([1, 2 | 3]) end test "escape with unquote" do @@ -104,7 +104,7 @@ defmodule MacroTest do contents = quote unquote: false, do: [1, unquote_splicing([2]), 3, unquote_splicing([4]), 5] assert eval_escaped(contents) == [1, 2, 3, 4, 5] - contents = quote unquote: false, do: [1, unquote_splicing([2]), 3, unquote_splicing([4])|[5]] + contents = quote unquote: false, do: [1, unquote_splicing([2]), 3, unquote_splicing([4]) | [5]] assert eval_escaped(contents) == [1, 2, 3, 4, 5] end @@ -411,7 +411,7 @@ defmodule MacroTest do test "binary ops to string" do assert Macro.to_string(quote do: 1 + 2) == "1 + 2" assert Macro.to_string(quote do: [ 1, 2 | 3 ]) == "[1, 2 | 3]" - assert Macro.to_string(quote do: [h|t] = [1, 2, 3]) == "[h | t] = [1, 2, 3]" + assert Macro.to_string(quote do: [h | t] = [1, 2, 3]) == "[h | t] = [1, 2, 3]" assert Macro.to_string(quote do: (x ++ y) ++ z) == "(x ++ y) ++ z" end @@ -599,7 +599,7 @@ defmodule MacroTest do end defp traverse(ast) do - Macro.traverse(ast, [], &{&1, [&1|&2]}, &{&1, [&1|&2]}) |> elem(1) |> Enum.reverse + Macro.traverse(ast, [], &{&1, [&1 | &2]}, &{&1, [&1 | &2]}) |> elem(1) |> Enum.reverse end test "prewalk" do @@ -617,7 +617,7 @@ defmodule MacroTest do end defp prewalk(ast) do - Macro.prewalk(ast, [], &{&1, [&1|&2]}) |> elem(1) |> Enum.reverse + Macro.prewalk(ast, [], &{&1, [&1 | &2]}) |> elem(1) |> Enum.reverse end test "postwalk" do @@ -635,7 +635,7 @@ defmodule MacroTest do end defp postwalk(ast) do - Macro.postwalk(ast, [], &{&1, [&1|&2]}) |> elem(1) |> Enum.reverse + Macro.postwalk(ast, [], &{&1, [&1 | &2]}) |> elem(1) |> Enum.reverse end test "underscore" do diff --git a/lib/elixir/test/elixir/path_test.exs b/lib/elixir/test/elixir/path_test.exs index 6c6a038a3cc..cb46f22418a 100644 --- a/lib/elixir/test/elixir/path_test.exs +++ b/lib/elixir/test/elixir/path_test.exs @@ -236,7 +236,7 @@ defmodule PathTest do end if windows? do - defp strip_drive_letter_if_windows([_d, ?:|rest]), do: rest + defp strip_drive_letter_if_windows([_d, ?: | rest]), do: rest defp strip_drive_letter_if_windows(<<_d, ?:, rest::binary>>), do: rest else defp strip_drive_letter_if_windows(path), do: path diff --git a/lib/elixir/test/elixir/stream_test.exs b/lib/elixir/test/elixir/stream_test.exs index ba706a10a3d..28660f3c9b0 100644 --- a/lib/elixir/test/elixir/stream_test.exs +++ b/lib/elixir/test/elixir/stream_test.exs @@ -12,7 +12,7 @@ defmodule StreamTest do def into(struct) do {struct, fn - _, {:cont, x} -> Process.put(:stream_cont, [x|Process.get(:stream_cont)]) + _, {:cont, x} -> Process.put(:stream_cont, [x | Process.get(:stream_cont)]) _, :done -> Process.put(:stream_done, true) _, :halt -> Process.put(:stream_halt, true) end} @@ -235,7 +235,7 @@ defmodule StreamTest do Process.put(:stream_each, []) stream = Stream.each([1, 2, 3], fn x -> - Process.put(:stream_each, [x|Process.get(:stream_each)]) + Process.put(:stream_each, [x | Process.get(:stream_each)]) end) assert is_lazy(stream) @@ -743,7 +743,7 @@ defmodule StreamTest do stream = Stream.take(1..100, -5) assert is_lazy(stream) - stream = Stream.each(stream, &Process.put(:stream_each, [&1|Process.get(:stream_each)])) + stream = Stream.each(stream, &Process.put(:stream_each, [&1 | Process.get(:stream_each)])) assert Enum.to_list(stream) == [96, 97, 98, 99, 100] assert Process.get(:stream_each) == [100, 99, 98, 97, 96] end diff --git a/lib/elixir/test/elixir/string/chars_test.exs b/lib/elixir/test/elixir/string/chars_test.exs index f594d8e7adb..777c04b83f3 100644 --- a/lib/elixir/test/elixir/string/chars_test.exs +++ b/lib/elixir/test/elixir/string/chars_test.exs @@ -133,7 +133,7 @@ defmodule String.Chars.ErrorsTest do end test "port" do - [port|_] = Port.list + [port | _] = Port.list assert_raise Protocol.UndefinedError, ~r"^protocol String\.Chars not implemented for #Port<.+?>$", fn -> to_string(port) end diff --git a/lib/elixir/test/elixir/supervisor_test.exs b/lib/elixir/test/elixir/supervisor_test.exs index 0bccbc0314e..36ca3b3ffb7 100644 --- a/lib/elixir/test/elixir/supervisor_test.exs +++ b/lib/elixir/test/elixir/supervisor_test.exs @@ -10,7 +10,7 @@ defmodule SupervisorTest do GenServer.start_link(__MODULE__, state, opts) end - def handle_call(:pop, _from, [h|t]) do + def handle_call(:pop, _from, [h | t]) do {:reply, h, t} end @@ -26,7 +26,7 @@ defmodule SupervisorTest do end def handle_cast({:push, h}, t) do - {:noreply, [h|t]} + {:noreply, [h | t]} end end diff --git a/lib/elixir/test/erlang/function_test.erl b/lib/elixir/test/erlang/function_test.erl index 49d78d2bade..e30bb87b2e7 100644 --- a/lib/elixir/test/erlang/function_test.erl +++ b/lib/elixir/test/erlang/function_test.erl @@ -32,7 +32,7 @@ function_with_kv_args_test() -> 6 = Fun(1, [{other, 2}, {another, 3}]). function_as_closure_test() -> - {_, [{a, Res1}|_]} = eval("b = 1; a = fn -> b + 2 end"), + {_, [{a, Res1} | _]} = eval("b = 1; a = fn -> b + 2 end"), 3 = Res1(). function_apply_test() -> diff --git a/lib/elixir/test/erlang/match_test.erl b/lib/elixir/test/erlang/match_test.erl index 48f16bbf1df..2a28cf469d1 100644 --- a/lib/elixir/test/erlang/match_test.erl +++ b/lib/elixir/test/erlang/match_test.erl @@ -96,12 +96,12 @@ list_vars_test() -> {[3, 1], [{x, 3}]} = eval("x = 1\n[x = x + 2, x]"). head_and_tail_test() -> - {_, [{h, 1}, {t, [2, 3]}]} = eval("[h|t] = [1, 2, 3]"), - {_, [{h, 2}, {t, [3]}]} = eval("[1, h|t] = [1, 2, 3]"), - {_, [{t, [3]}]} = eval("[1, 2|t] = [1, 2, 3]"), - {_, [{h, 1}]} = eval("[h|[2, 3]] = [1, 2, 3]"), - {_, [{t, [2, 3]}]} = eval("[+1|t] = [1, 2, 3]"), - ?assertError({badmatch, _}, eval("[2, h|t] = [1, 2, 3]")). + {_, [{h, 1}, {t, [2, 3]}]} = eval("[h | t] = [1, 2, 3]"), + {_, [{h, 2}, {t, [3]}]} = eval("[1, h | t] = [1, 2, 3]"), + {_, [{t, [3]}]} = eval("[1, 2 | t] = [1, 2, 3]"), + {_, [{h, 1}]} = eval("[h | [2, 3]] = [1, 2, 3]"), + {_, [{t, [2, 3]}]} = eval("[+1 | t] = [1, 2, 3]"), + ?assertError({badmatch, _}, eval("[2, h | t] = [1, 2, 3]")). % Keyword match @@ -112,7 +112,7 @@ orrdict_match_test() -> function_clause_test() -> F = fun() -> - eval("defmodule Foo do\ndef a([{_k, _}=e|_]), do: e\nend"), + eval("defmodule Foo do\ndef a([{_k, _}=e | _]), do: e\nend"), {{foo, bar}, _} = eval("Foo.a([{:foo, :bar}])") end, test_helper:run_and_remove(F, ['Elixir.Foo']). diff --git a/lib/elixir/test/erlang/tokenizer_test.erl b/lib/elixir/test/erlang/tokenizer_test.erl index a28848690e7..a11a9155b37 100644 --- a/lib/elixir/test/erlang/tokenizer_test.erl +++ b/lib/elixir/test/erlang/tokenizer_test.erl @@ -47,7 +47,7 @@ quoted_atom_test() -> [{atom_unsafe, {1, 1, 11}, [<<"foo bar">>]}] = tokenize(":\"foo bar\""). oversized_atom_test() -> - OversizedAtom = [$:|string:copies("a", 256)], + OversizedAtom = [$: | string:copies("a", 256)], {1, "atom length must be less than system limit", ":"} = tokenize_error(OversizedAtom). op_atom_test() -> diff --git a/lib/elixir/unicode/unicode.ex b/lib/elixir/unicode/unicode.ex index 6ce70508022..e677357bc4e 100644 --- a/lib/elixir/unicode/unicode.ex +++ b/lib/elixir/unicode/unicode.ex @@ -172,7 +172,7 @@ defmodule String.Unicode do end defp do_graphemes({size, rest}, binary) do - [:binary.part(binary, 0, size)|do_graphemes(next_grapheme_size(rest), rest)] + [:binary.part(binary, 0, size) | do_graphemes(next_grapheme_size(rest), rest)] end defp do_graphemes(nil, _) do @@ -227,7 +227,7 @@ defmodule String.Unicode do end defp do_codepoints({c, rest}) do - [c|do_codepoints(next_codepoint(rest))] + [c | do_codepoints(next_codepoint(rest))] end defp do_codepoints(nil) do @@ -266,7 +266,7 @@ data_path = Path.join(__DIR__, "UnicodeData.txt") wacc = case decomposition do - "" <> _ -> [to_binary.(codepoint)|wacc] + "" <> _ -> [to_binary.(codepoint) | wacc] _ -> wacc end @@ -448,7 +448,7 @@ defmodule String.Break do @compile {:inline, add_buffer_to_acc: 2} defp add_buffer_to_acc("", acc), do: acc - defp add_buffer_to_acc(buffer, acc), do: [buffer|acc] + defp add_buffer_to_acc(buffer, acc), do: [buffer | acc] # Decompose @@ -538,7 +538,7 @@ defmodule String.Normalizer do defp canonical_order(<>, acc) do case combining_class(h) do 0 -> canonical_order(acc) <> canonical_order(t, [{h, 0}]) - n -> canonical_order(t, [{h, n}|acc]) + n -> canonical_order(t, [{h, n} | acc]) end end defp canonical_order(<<>>, acc) do diff --git a/lib/ex_unit/lib/ex_unit/assertions.ex b/lib/ex_unit/lib/ex_unit/assertions.ex index 7b1d777df6b..b9ea76447d6 100644 --- a/lib/ex_unit/lib/ex_unit/assertions.ex +++ b/lib/ex_unit/lib/ex_unit/assertions.ex @@ -412,7 +412,7 @@ defmodule ExUnit.Assertions do {_, pins} = Macro.prewalk(expr, [], fn {:^, _, [{name, _, _} = var]}, acc -> - {:ok, [{name, var}|acc]} + {:ok, [{name, var} | acc]} form, acc -> {form, acc} end) diff --git a/lib/ex_unit/lib/ex_unit/callbacks.ex b/lib/ex_unit/lib/ex_unit/callbacks.ex index 745a3d80c34..9da33a9f691 100644 --- a/lib/ex_unit/lib/ex_unit/callbacks.ex +++ b/lib/ex_unit/lib/ex_unit/callbacks.ex @@ -109,7 +109,7 @@ defmodule ExUnit.Callbacks do quote bind_quoted: [var: escape(var), block: escape(block)] do name = :"__ex_unit_setup_#{length(@ex_unit_setup)}" defp unquote(name)(unquote(var)), unquote(block) - @ex_unit_setup [name|@ex_unit_setup] + @ex_unit_setup [name | @ex_unit_setup] end end @@ -120,7 +120,7 @@ defmodule ExUnit.Callbacks do quote bind_quoted: [var: escape(var), block: escape(block)] do name = :"__ex_unit_setup_all_#{length(@ex_unit_setup_all)}" defp unquote(name)(unquote(var)), unquote(block) - @ex_unit_setup_all [name|@ex_unit_setup_all] + @ex_unit_setup_all [name | @ex_unit_setup_all] end end @@ -199,7 +199,7 @@ defmodule ExUnit.Callbacks do case callbacks do [] -> quote do: {:ok, context} - [h|t] -> + [h | t] -> Enum.reduce t, compile_merge(h), fn(callback, acc) -> quote do {:ok, context} = unquote(acc) diff --git a/lib/ex_unit/lib/ex_unit/doc_test.ex b/lib/ex_unit/lib/ex_unit/doc_test.ex index 8c68c65e7de..24edd9ea534 100644 --- a/lib/ex_unit/lib/ex_unit/doc_test.ex +++ b/lib/ex_unit/lib/ex_unit/doc_test.ex @@ -429,16 +429,16 @@ defmodule ExUnit.DocTest do @iex_prompt ["iex>", "iex("] @dot_prompt ["...>", "...("] - defp adjust_indent(:text, [line|rest], line_no, adjusted_lines, indent, module) do + defp adjust_indent(:text, [line | rest], line_no, adjusted_lines, indent, module) do case String.starts_with?(String.lstrip(line), @iex_prompt) do true -> - adjust_indent(:prompt, [line|rest], line_no, adjusted_lines, get_indent(line, indent), module) + adjust_indent(:prompt, [line | rest], line_no, adjusted_lines, get_indent(line, indent), module) false -> adjust_indent(:text, rest, line_no + 1, adjusted_lines, indent, module) end end - defp adjust_indent(kind, [line|rest], line_no, adjusted_lines, indent, module) when kind in [:prompt, :after_prompt] do + defp adjust_indent(kind, [line | rest], line_no, adjusted_lines, indent, module) when kind in [:prompt, :after_prompt] do stripped_line = strip_indent(line, indent) case String.lstrip(line) do @@ -456,7 +456,7 @@ defmodule ExUnit.DocTest do message: "indentation level mismatch: #{inspect line}, should have been #{n_spaces}" end - adjusted_lines = [{stripped_line, line_no}|adjusted_lines] + adjusted_lines = [{stripped_line, line_no} | adjusted_lines] if String.starts_with?(stripped_line, @iex_prompt ++ @dot_prompt) do adjust_indent(:after_prompt, rest, line_no + 1, adjusted_lines, indent, module) @@ -466,15 +466,15 @@ defmodule ExUnit.DocTest do end end - defp adjust_indent(:code, [line|rest], line_no, adjusted_lines, indent, module) do + defp adjust_indent(:code, [line | rest], line_no, adjusted_lines, indent, module) do stripped_line = strip_indent(line, indent) cond do stripped_line == "" -> - adjust_indent(:text, rest, line_no + 1, [{stripped_line, line_no}|adjusted_lines], 0, module) + adjust_indent(:text, rest, line_no + 1, [{stripped_line, line_no} | adjusted_lines], 0, module) String.starts_with?(String.lstrip(line), @iex_prompt) -> - adjust_indent(:prompt, [line|rest], line_no, adjusted_lines, indent, module) + adjust_indent(:prompt, [line | rest], line_no, adjusted_lines, indent, module) true -> - adjust_indent(:code, rest, line_no + 1, [{stripped_line, line_no}|adjusted_lines], indent, module) + adjust_indent(:code, rest, line_no + 1, [{stripped_line, line_no} | adjusted_lines], indent, module) end end @@ -503,23 +503,23 @@ defmodule ExUnit.DocTest do end # End of input and we've still got a test pending. - defp extract_tests([], expr_acc, expected_acc, [test=%{exprs: exprs}|t], _) do + defp extract_tests([], expr_acc, expected_acc, [test=%{exprs: exprs} | t], _) do test = %{test | exprs: [{expr_acc, {:test, expected_acc}} | exprs]} - Enum.reverse(reverse_last_test([test|t])) + Enum.reverse(reverse_last_test([test | t])) end # We've encountered the next test on an adjacent line. Put them into one group. - defp extract_tests([{"iex>" <> _, _} | _] = list, expr_acc, expected_acc, [test=%{exprs: exprs}|t], newtest) + defp extract_tests([{"iex>" <> _, _} | _] = list, expr_acc, expected_acc, [test=%{exprs: exprs} | t], newtest) when expr_acc != "" and expected_acc != "" do test = %{test | exprs: [{expr_acc, {:test, expected_acc}} | exprs]} - extract_tests(list, "", "", [test|t], newtest) + extract_tests(list, "", "", [test | t], newtest) end # Store expr_acc and start a new test case. defp extract_tests([{"iex>" <> string, line} | lines], "", expected_acc, acc, true) do acc = reverse_last_test(acc) test = %{line: line, fun_arity: nil, exprs: []} - extract_tests(lines, string, expected_acc, [test|acc], false) + extract_tests(lines, string, expected_acc, [test | acc], false) end # Store expr_acc. @@ -548,28 +548,28 @@ defmodule ExUnit.DocTest do end # Skip empty or documentation line. - defp extract_tests([_|lines], "", "", acc, _) do + defp extract_tests([_ | lines], "", "", acc, _) do extract_tests(lines, "", "", acc, true) end # Encountered an empty line, store pending test - defp extract_tests([{"", _}|lines], expr_acc, expected_acc, [test=%{exprs: exprs}|t], _) do + defp extract_tests([{"", _} | lines], expr_acc, expected_acc, [test=%{exprs: exprs} | t], _) do test = %{test | exprs: [{expr_acc, {:test, expected_acc}} | exprs]} - extract_tests(lines, "", "", [test|t], true) + extract_tests(lines, "", "", [test | t], true) end # Exception test. - defp extract_tests([{"** (" <> string, _} | lines], expr_acc, "", [test=%{exprs: exprs}|t], newtest) do + defp extract_tests([{"** (" <> string, _} | lines], expr_acc, "", [test=%{exprs: exprs} | t], newtest) do test = %{test | exprs: [{expr_acc, extract_error(string, "")} | exprs]} - extract_tests(lines, "", "", [test|t], newtest) + extract_tests(lines, "", "", [test | t], newtest) end # Finally, parse expected_acc. - defp extract_tests([{expected, _}|lines], expr_acc, expected_acc, [test=%{exprs: exprs}|t]=acc, newtest) do + defp extract_tests([{expected, _} | lines], expr_acc, expected_acc, [test=%{exprs: exprs} | t]=acc, newtest) do if expected =~ ~r/^#[A-Z][\w\.]*<.*>$/ do expected = expected_acc <> "\n" <> inspect(expected) test = %{test | exprs: [{expr_acc, {:inspect, expected}} | exprs]} - extract_tests(lines, "", "", [test|t], newtest) + extract_tests(lines, "", "", [test | t], newtest) else extract_tests(lines, expr_acc, expected_acc <> "\n" <> expected, acc, newtest) end diff --git a/lib/ex_unit/lib/ex_unit/runner.ex b/lib/ex_unit/lib/ex_unit/runner.ex index 9894c42452e..9c46de0b3d9 100644 --- a/lib/ex_unit/lib/ex_unit/runner.ex +++ b/lib/ex_unit/lib/ex_unit/runner.ex @@ -24,7 +24,7 @@ defmodule ExUnit.Runner do opts = normalize_opts(opts) {:ok, pid} = EM.start_link - formatters = [ExUnit.RunnerStats|opts[:formatters]] + formatters = [ExUnit.RunnerStats | opts[:formatters]] Enum.each formatters, &(:ok = EM.add_handler(pid, &1, opts)) config = %{ @@ -340,8 +340,8 @@ defmodule ExUnit.Runner do defp take_sync_cases(config) do case config.sync_cases do - [h|t] -> {%{config | sync_cases: t}, [h]} - [] -> nil + [h | t] -> {%{config | sync_cases: t}, [h]} + [] -> nil end end @@ -359,12 +359,12 @@ defmodule ExUnit.Runner do defp pruned_stacktrace, do: prune_stacktrace(System.stacktrace) # Assertions can pop-up in the middle of the stack - defp prune_stacktrace([{ExUnit.Assertions, _, _, _}|t]), do: prune_stacktrace(t) + defp prune_stacktrace([{ExUnit.Assertions, _, _, _} | t]), do: prune_stacktrace(t) # As soon as we see a Runner, it is time to ignore the stacktrace - defp prune_stacktrace([{ExUnit.Runner, _, _, _}|_]), do: [] + defp prune_stacktrace([{ExUnit.Runner, _, _, _} | _]), do: [] # All other cases - defp prune_stacktrace([h|t]), do: [h|prune_stacktrace(t)] + defp prune_stacktrace([h | t]), do: [h | prune_stacktrace(t)] defp prune_stacktrace([]), do: [] end diff --git a/lib/ex_unit/test/ex_unit/assertions_test.exs b/lib/ex_unit/test/ex_unit/assertions_test.exs index 51b4663899f..04312e44a8d 100644 --- a/lib/ex_unit/test/ex_unit/assertions_test.exs +++ b/lib/ex_unit/test/ex_unit/assertions_test.exs @@ -427,7 +427,7 @@ defmodule ExUnit.AssertionsTest do rescue ExUnit.AssertionError -> stacktrace = System.stacktrace - [{Not.Defined, :function, [1, 2, 3], _}|_] = stacktrace + [{Not.Defined, :function, [1, 2, 3], _} | _] = stacktrace end test "assert raise with erlang error" do diff --git a/lib/ex_unit/test/ex_unit/capture_io_test.exs b/lib/ex_unit/test/ex_unit/capture_io_test.exs index 925177f1378..2140acb10eb 100644 --- a/lib/ex_unit/test/ex_unit/capture_io_test.exs +++ b/lib/ex_unit/test/ex_unit/capture_io_test.exs @@ -12,7 +12,7 @@ defmodule ExUnit.CaptureIOTest do case Enum.split_while(chars, fn(c) -> c != stop_char end) do {l, []} -> {:more, this_far ++ l} - {l, [stop_char|rest]} -> + {l, [stop_char | rest]} -> {:done, this_far ++ l ++ [stop_char], rest} end end diff --git a/lib/iex/lib/iex.ex b/lib/iex/lib/iex.ex index 954132ab020..f7eaeffcb8f 100644 --- a/lib/iex/lib/iex.ex +++ b/lib/iex/lib/iex.ex @@ -459,7 +459,7 @@ defmodule IEx do env.file |> File.stream! |> Enum.slice(max(env.line - 3, 0), 5) - Enum.intersperse(["\n\n"|lines], " ") + Enum.intersperse(["\n\n" | lines], " ") end ## Callbacks diff --git a/lib/iex/lib/iex/autocomplete.ex b/lib/iex/lib/iex/autocomplete.ex index 6cb68b2a147..f61a43960ac 100644 --- a/lib/iex/lib/iex/autocomplete.ex +++ b/lib/iex/lib/iex/autocomplete.ex @@ -5,7 +5,7 @@ defmodule IEx.Autocomplete do expand_import("") end - def expand([h|t]=expr) do + def expand([h | t]=expr) do cond do h === ?. and t != [] -> expand_dot(reduce(t)) @@ -45,7 +45,7 @@ defmodule IEx.Autocomplete do expand_import(Atom.to_string(atom)) {:ok, {:__aliases__, _, [root]}} -> expand_elixir_modules([], Atom.to_string(root)) - {:ok, {:__aliases__, _, [h|_] = list}} when is_atom(h) -> + {:ok, {:__aliases__, _, [h | _] = list}} when is_atom(h) -> hint = Atom.to_string(List.last(list)) list = Enum.take(list, length(list) - 1) expand_elixir_modules(list, hint) @@ -62,7 +62,7 @@ defmodule IEx.Autocomplete do end) |> Enum.reverse |> strip_ampersand end - defp strip_ampersand([?&|t]), do: t + defp strip_ampersand([?& | t]), do: t defp strip_ampersand(expr), do: expr defp yes(hint, entries) do @@ -86,7 +86,7 @@ defmodule IEx.Autocomplete do end end - defp format_expansion([first|_]=entries, hint) do + defp format_expansion([first | _]=entries, hint) do binary = Enum.map(entries, &(&1.name)) length = byte_size(hint) prefix = :binary.longest_common_prefix(binary) @@ -163,7 +163,7 @@ defmodule IEx.Autocomplete do if alias === module do case Atom.to_string(mod) do "Elixir." <> mod -> - Module.concat [mod|rest] + Module.concat [mod | rest] _ -> mod end @@ -249,8 +249,8 @@ defmodule IEx.Autocomplete do list = Enum.reduce falist, [], fn {f, a}, acc -> case :lists.keyfind(f, 1, acc) do - {f, aa} -> :lists.keyreplace(f, 1, acc, {f, [a|aa]}) - false -> [{f, [a]}|acc] + {f, aa} -> :lists.keyreplace(f, 1, acc, {f, [a | aa]}) + false -> [{f, [a]} | acc] end end diff --git a/lib/iex/lib/iex/cli.ex b/lib/iex/lib/iex/cli.ex index 4cc6d588f32..aa3a99bc49c 100644 --- a/lib/iex/lib/iex/cli.ex +++ b/lib/iex/lib/iex/cli.ex @@ -136,11 +136,11 @@ defmodule IEx.CLI do {:erlang, :apply, [function, []]} end - defp find_dot_iex(['--dot-iex', h|_]), do: List.to_string(h) - defp find_dot_iex([_|t]), do: find_dot_iex(t) + defp find_dot_iex(['--dot-iex', h | _]), do: List.to_string(h) + defp find_dot_iex([_ | t]), do: find_dot_iex(t) defp find_dot_iex([]), do: nil - defp get_remsh(['--remsh', h|_]), do: List.to_atom(h) - defp get_remsh([_|t]), do: get_remsh(t) + defp get_remsh(['--remsh', h | _]), do: List.to_atom(h) + defp get_remsh([_ | t]), do: get_remsh(t) defp get_remsh([]), do: nil end diff --git a/lib/iex/lib/iex/info.ex b/lib/iex/lib/iex/info.ex index 7a212537308..91810c1e025 100644 --- a/lib/iex/lib/iex/info.ex +++ b/lib/iex/lib/iex/info.ex @@ -231,7 +231,7 @@ defimpl IEx.Info, for: PID do def info(pid) do extra = case :rpc.pinfo(pid, @keys) do - [_|_] = info -> + [_ | _] = info -> ["Alive": true, "Name": process_name(info[:registered_name]), "Links": links(info[:links]), diff --git a/lib/iex/lib/iex/server.ex b/lib/iex/lib/iex/server.ex index 75c323c22d8..72ab5789fac 100644 --- a/lib/iex/lib/iex/server.ex +++ b/lib/iex/lib/iex/server.ex @@ -12,7 +12,7 @@ defmodule IEx.Server do """ @spec whereis :: pid | nil def whereis() do - Enum.find_value([node()|Node.list], fn node -> + Enum.find_value([node() | Node.list], fn node -> server = :rpc.call(node, IEx.Server, :local, []) if is_pid(server), do: server end) diff --git a/lib/logger/lib/logger/config.ex b/lib/logger/lib/logger/config.ex index f5ea29380c3..3628f5f7355 100644 --- a/lib/logger/lib/logger/config.ex +++ b/lib/logger/lib/logger/config.ex @@ -118,7 +118,7 @@ defmodule Logger.Config do end def handle_call({:add_translator, translator}, state) do - state = update_translators(state, fn t -> [translator|List.delete(t, translator)] end) + state = update_translators(state, fn t -> [translator | List.delete(t, translator)] end) {:ok, :ok, state} end @@ -128,7 +128,7 @@ defmodule Logger.Config do end def handle_call({:add_backend, backend}, state) do - update_backends(&[backend|List.delete(&1, backend)]) + update_backends(&[backend | List.delete(&1, backend)]) {:ok, :ok, state} end diff --git a/lib/logger/lib/logger/error_handler.ex b/lib/logger/lib/logger/error_handler.ex index fa3e3bb1577..ba3a8b589e8 100644 --- a/lib/logger/lib/logger/error_handler.ex +++ b/lib/logger/lib/logger/error_handler.ex @@ -116,7 +116,7 @@ defmodule Logger.ErrorHandler do end end - defp translate([{mod, fun}|t], min_level, level, kind, data, truncate) do + defp translate([{mod, fun} | t], min_level, level, kind, data, truncate) do case apply(mod, fun, [min_level, level, kind, data]) do {:ok, chardata} -> {:ok, chardata} :skip -> :skip diff --git a/lib/logger/lib/logger/utils.ex b/lib/logger/lib/logger/utils.ex index 29b826b3751..e1f941d80d9 100644 --- a/lib/logger/lib/logger/utils.ex +++ b/lib/logger/lib/logger/utils.ex @@ -45,9 +45,9 @@ defmodule Logger.Utils do {:lists.reverse(acc), n} end - defp truncate_n_list([h|t], n, acc) do + defp truncate_n_list([h | t], n, acc) do {h, n} = truncate_n(h, n) - truncate_n_list(t, n, [h|acc]) + truncate_n_list(t, n, [h | acc]) end defp truncate_n_list([], n, acc) do @@ -112,86 +112,86 @@ defmodule Logger.Utils do do_inspect(format, args, [], [], opts) end - defp do_inspect([?~|t], args, used_format, used_args, opts) do + defp do_inspect([?~ | t], args, used_format, used_args, opts) do {t, args, cc_format, cc_args} = collect_cc(:width, t, args, [?~], [], opts) do_inspect(t, args, cc_format ++ used_format, cc_args ++ used_args, opts) end - defp do_inspect([h|t], args, used_format, used_args, opts), - do: do_inspect(t, args, [h|used_format], used_args, opts) + defp do_inspect([h | t], args, used_format, used_args, opts), + do: do_inspect(t, args, [h | used_format], used_args, opts) defp do_inspect([], [], used_format, used_args, _opts), do: {:lists.reverse(used_format), :lists.reverse(used_args)} ## width - defp collect_cc(:width, [?-|t], args, used_format, used_args, opts), - do: collect_value(:width, t, args, [?-|used_format], used_args, opts, :precision) + defp collect_cc(:width, [?- | t], args, used_format, used_args, opts), + do: collect_value(:width, t, args, [?- | used_format], used_args, opts, :precision) defp collect_cc(:width, t, args, used_format, used_args, opts), do: collect_value(:width, t, args, used_format, used_args, opts, :precision) ## precision - defp collect_cc(:precision, [?.|t], args, used_format, used_args, opts), - do: collect_value(:precision, t, args, [?.|used_format], used_args, opts, :pad_char) + defp collect_cc(:precision, [?. | t], args, used_format, used_args, opts), + do: collect_value(:precision, t, args, [?. | used_format], used_args, opts, :pad_char) defp collect_cc(:precision, t, args, used_format, used_args, opts), do: collect_cc(:pad_char, t, args, used_format, used_args, opts) ## pad char - defp collect_cc(:pad_char, [?., ?*|t], [arg|args], used_format, used_args, opts), - do: collect_cc(:encoding, t, args, [?*, ?.|used_format], [arg|used_args], opts) + defp collect_cc(:pad_char, [?., ?* | t], [arg | args], used_format, used_args, opts), + do: collect_cc(:encoding, t, args, [?*, ?. | used_format], [arg | used_args], opts) - defp collect_cc(:pad_char, [?., p|t], args, used_format, used_args, opts), - do: collect_cc(:encoding, t, args, [p, ?.|used_format], used_args, opts) + defp collect_cc(:pad_char, [?., p | t], args, used_format, used_args, opts), + do: collect_cc(:encoding, t, args, [p, ?. | used_format], used_args, opts) defp collect_cc(:pad_char, t, args, used_format, used_args, opts), do: collect_cc(:encoding, t, args, used_format, used_args, opts) ## encoding - defp collect_cc(:encoding, [?l|t], args, used_format, used_args, opts), - do: collect_cc(:done, t, args, [?l|used_format], used_args, %{opts | char_lists: false}) + defp collect_cc(:encoding, [?l | t], args, used_format, used_args, opts), + do: collect_cc(:done, t, args, [?l | used_format], used_args, %{opts | char_lists: false}) - defp collect_cc(:encoding, [?t|t], args, used_format, used_args, opts), - do: collect_cc(:done, t, args, [?t|used_format], used_args, opts) + defp collect_cc(:encoding, [?t | t], args, used_format, used_args, opts), + do: collect_cc(:done, t, args, [?t | used_format], used_args, opts) defp collect_cc(:encoding, t, args, used_format, used_args, opts), do: collect_cc(:done, t, args, used_format, used_args, opts) ## done - defp collect_cc(:done, [?W|t], [data, limit|args], _used_format, _used_args, opts), + defp collect_cc(:done, [?W | t], [data, limit | args], _used_format, _used_args, opts), do: collect_inspect(t, args, data, %{opts | limit: limit, width: :infinity}) - defp collect_cc(:done, [?w|t], [data|args], _used_format, _used_args, opts), + defp collect_cc(:done, [?w | t], [data | args], _used_format, _used_args, opts), do: collect_inspect(t, args, data, %{opts | width: :infinity}) - defp collect_cc(:done, [?P|t], [data, limit|args], _used_format, _used_args, opts), + defp collect_cc(:done, [?P | t], [data, limit | args], _used_format, _used_args, opts), do: collect_inspect(t, args, data, %{opts | limit: limit}) - defp collect_cc(:done, [?p|t], [data|args], _used_format, _used_args, opts), + defp collect_cc(:done, [?p | t], [data | args], _used_format, _used_args, opts), do: collect_inspect(t, args, data, opts) - defp collect_cc(:done, [h|t], args, used_format, used_args, _opts) do + defp collect_cc(:done, [h | t], args, used_format, used_args, _opts) do {args, used_args} = collect_cc(h, args, used_args) - {t, args, [h|used_format], used_args} + {t, args, [h | used_format], used_args} end - defp collect_cc(?x, [a, prefix|args], used), do: {args, [prefix, a|used]} - defp collect_cc(?X, [a, prefix|args], used), do: {args, [prefix, a|used]} - defp collect_cc(?s, [a|args], used), do: {args, [a|used]} - defp collect_cc(?e, [a|args], used), do: {args, [a|used]} - defp collect_cc(?f, [a|args], used), do: {args, [a|used]} - defp collect_cc(?g, [a|args], used), do: {args, [a|used]} - defp collect_cc(?b, [a|args], used), do: {args, [a|used]} - defp collect_cc(?B, [a|args], used), do: {args, [a|used]} - defp collect_cc(?+, [a|args], used), do: {args, [a|used]} - defp collect_cc(?#, [a|args], used), do: {args, [a|used]} - defp collect_cc(?c, [a|args], used), do: {args, [a|used]} - defp collect_cc(?i, [a|args], used), do: {args, [a|used]} + defp collect_cc(?x, [a, prefix | args], used), do: {args, [prefix, a | used]} + defp collect_cc(?X, [a, prefix | args], used), do: {args, [prefix, a | used]} + defp collect_cc(?s, [a | args], used), do: {args, [a | used]} + defp collect_cc(?e, [a | args], used), do: {args, [a | used]} + defp collect_cc(?f, [a | args], used), do: {args, [a | used]} + defp collect_cc(?g, [a | args], used), do: {args, [a | used]} + defp collect_cc(?b, [a | args], used), do: {args, [a | used]} + defp collect_cc(?B, [a | args], used), do: {args, [a | used]} + defp collect_cc(?+, [a | args], used), do: {args, [a | used]} + defp collect_cc(?#, [a | args], used), do: {args, [a | used]} + defp collect_cc(?c, [a | args], used), do: {args, [a | used]} + defp collect_cc(?i, [a | args], used), do: {args, [a | used]} defp collect_cc(?~, args, used), do: {args, used} defp collect_cc(?n, args, used), do: {args, used} @@ -203,15 +203,15 @@ defmodule Logger.Utils do {t, args, 'st~', [data]} end - defp collect_value(current, [?*|t], [arg|args], used_format, used_args, opts, next) + defp collect_value(current, [?* | t], [arg | args], used_format, used_args, opts, next) when is_integer(arg) do - collect_cc(next, t, args, [?*|used_format], [arg|used_args], + collect_cc(next, t, args, [?* | used_format], [arg | used_args], put_value(opts, current, arg)) end - defp collect_value(current, [c|t], args, used_format, used_args, opts, next) + defp collect_value(current, [c | t], args, used_format, used_args, opts, next) when is_integer(c) and c >= ?0 and c <= ?9 do - {t, c} = collect_value([c|t], []) + {t, c} = collect_value([c | t], []) collect_cc(next, t, args, c ++ used_format, used_args, put_value(opts, current, c |> :lists.reverse |> List.to_integer)) end @@ -219,9 +219,9 @@ defmodule Logger.Utils do defp collect_value(_current, t, args, used_format, used_args, opts, next), do: collect_cc(next, t, args, used_format, used_args, opts) - defp collect_value([c|t], buffer) + defp collect_value([c | t], buffer) when is_integer(c) and c >= ?0 and c <= ?9, - do: collect_value(t, [c|buffer]) + do: collect_value(t, [c | buffer]) defp collect_value(other, buffer), do: {other, buffer} diff --git a/lib/mix/lib/mix/cli.ex b/lib/mix/lib/mix/cli.ex index 60a514c8bfa..379bf79a7e8 100644 --- a/lib/mix/lib/mix/cli.ex +++ b/lib/mix/lib/mix/cli.ex @@ -37,13 +37,13 @@ defmodule Mix.CLI do end end - defp get_task(["-" <> _|_]) do + defp get_task(["-" <> _ | _]) do Mix.shell.error "** (Mix) Cannot implicitly pass flags to default Mix task, " <> "please invoke instead \"mix #{Mix.Project.config[:default_task]}\"" exit({:shutdown, 1}) end - defp get_task([h|t]) do + defp get_task([h | t]) do {h, t} end @@ -119,10 +119,10 @@ defmodule Mix.CLI do end # Check for --help or --version in the args - defp check_for_shortcuts([first_arg|_]) when first_arg in + defp check_for_shortcuts([first_arg | _]) when first_arg in ["--help", "-h"], do: :help - defp check_for_shortcuts([first_arg|_]) when first_arg in + defp check_for_shortcuts([first_arg | _]) when first_arg in ["--version", "-v"], do: :version defp check_for_shortcuts(_), do: nil diff --git a/lib/mix/lib/mix/compilers/elixir.ex b/lib/mix/lib/mix/compilers/elixir.ex index e8d6d6aba6d..9a501ee3211 100644 --- a/lib/mix/lib/mix/compilers/elixir.ex +++ b/lib/mix/lib/mix/compilers/elixir.ex @@ -42,7 +42,7 @@ defmodule Mix.Compilers.Elixir do ++ # Plus the sources that have changed in disk for({source, files} <- all_sources, - times = Enum.map([source|files], &Map.fetch!(sources_mtimes, &1)), + times = Enum.map([source | files], &Map.fetch!(sources_mtimes, &1)), Mix.Utils.stale?(times, [modified]), do: source) end @@ -69,7 +69,7 @@ defmodule Mix.Compilers.Elixir do defp mtimes(sources) do Enum.reduce(sources, %{}, fn {source, files}, map -> - Enum.reduce([source|files], map, fn file, map -> + Enum.reduce([source | files], map, fn file, map -> Map.put_new_lazy(map, file, fn -> Mix.Utils.last_modified(file) end) end) end) @@ -220,11 +220,11 @@ defmodule Mix.Compilers.Elixir do # If I have a runtime time dependency on something stale, # I am stale too. Enum.any?(runtime, &Map.has_key?(stale, &1)) -> - {[entry|rest], Map.put(stale, module, true), removed} + {[entry | rest], Map.put(stale, module, true), removed} # Otherwise, we don't store it anywhere true -> - {[entry|rest], stale, removed} + {[entry | rest], stale, removed} end end @@ -250,7 +250,7 @@ defmodule Mix.Compilers.Elixir do defp read_manifest(manifest) do case :file.consult(manifest) do - {:ok, [@manifest_vsn|t]} -> t + {:ok, [@manifest_vsn | t]} -> t _ -> [] end end diff --git a/lib/mix/lib/mix/dep/converger.ex b/lib/mix/lib/mix/dep/converger.ex index f4a0edd26b7..a4bd81324cb 100644 --- a/lib/mix/lib/mix/dep/converger.ex +++ b/lib/mix/lib/mix/dep/converger.ex @@ -154,14 +154,14 @@ defmodule Mix.Dep.Converger do # Now, since "d" was specified in a parent project, no # exception is going to be raised since d is considered # to be the authoritative source. - defp all([dep|t], acc, upper_breadths, current_breadths, callback, rest, lock, env, cache) do + defp all([dep | t], acc, upper_breadths, current_breadths, callback, rest, lock, env, cache) do cond do new_acc = diverged_deps(acc, upper_breadths, dep) -> all(t, new_acc, upper_breadths, current_breadths, callback, rest, lock, env, cache) Mix.Dep.Loader.skip?(dep, env) -> # We still keep skipped dependencies around to detect conflicts. # They must be rejected after every all iteration. - all(t, [dep|acc], upper_breadths, current_breadths, callback, rest, lock, env, cache) + all(t, [dep | acc], upper_breadths, current_breadths, callback, rest, lock, env, cache) true -> {dep, rest, lock} = case cache.(dep) do @@ -177,7 +177,7 @@ defmodule Mix.Dep.Converger do end {acc, rest, lock} = - all(t, [dep|acc], upper_breadths, current_breadths, callback, rest, lock, env, cache) + all(t, [dep | acc], upper_breadths, current_breadths, callback, rest, lock, env, cache) deps = reject_non_fullfilled_optional(dep.deps, current_breadths) new_breadths = Enum.map(deps, &(&1.app)) ++ current_breadths diff --git a/lib/mix/lib/mix/dep/fetcher.ex b/lib/mix/lib/mix/dep/fetcher.ex index c13593c9764..ec19e4bab47 100644 --- a/lib/mix/lib/mix/dep/fetcher.ex +++ b/lib/mix/lib/mix/dep/fetcher.ex @@ -51,7 +51,7 @@ defmodule Mix.Dep.Fetcher do cond do # Dependencies that cannot be fetched are always compiled afterwards not scm.fetchable? -> - {dep, [app|acc], lock} + {dep, [app | acc], lock} # If the dependency is not available or we have a lock mismatch out_of_date?(dep) -> @@ -65,7 +65,7 @@ defmodule Mix.Dep.Fetcher do end if new do - {dep, [app|acc], Map.put(lock, app, new)} + {dep, [app | acc], Map.put(lock, app, new)} else {dep, acc, lock} end diff --git a/lib/mix/lib/mix/local.ex b/lib/mix/lib/mix/local.ex index 0e3bb72059c..8f16b96f069 100644 --- a/lib/mix/lib/mix/local.ex +++ b/lib/mix/lib/mix/local.ex @@ -156,7 +156,7 @@ defmodule Mix.Local do |> Enum.find_value(entries, &find_version(&1, current_version)) end - defp find_version([artifact_version, digest|versions], current_version) do + defp find_version([artifact_version, digest | versions], current_version) do if version = Enum.find(versions, &Version.compare(&1, current_version) != :gt) do {version, artifact_version, digest} end diff --git a/lib/mix/lib/mix/project.ex b/lib/mix/lib/mix/project.ex index 2cb25100cf9..1d8c73032e0 100644 --- a/lib/mix/lib/mix/project.ex +++ b/lib/mix/lib/mix/project.ex @@ -159,7 +159,7 @@ defmodule Mix.Project do |> Path.join("**/*.*") |> Path.wildcard |> Enum.reject(&String.starts_with?(Path.basename(&1), ".")) - [file|configs] + [file | configs] _ -> [] end diff --git a/lib/mix/lib/mix/project_stack.ex b/lib/mix/lib/mix/project_stack.ex index fb204163aeb..5ae52fb42fd 100644 --- a/lib/mix/lib/mix/project_stack.ex +++ b/lib/mix/lib/mix/project_stack.ex @@ -29,7 +29,7 @@ defmodule Mix.ProjectStack do file = find_project_named(module, stack) -> {{:error, file}, state} true -> - {:ok, %{state | post_config: [], stack: [project|state.stack]}} + {:ok, %{state | post_config: [], stack: [project | state.stack]}} end end end @@ -38,8 +38,8 @@ defmodule Mix.ProjectStack do def configured_applications(apps) do cast fn state -> update_in state.stack, fn - [h|t] -> [%{h | configured_applications: apps}|t] - [] -> [] + [h | t] -> [%{h | configured_applications: apps} | t] + [] -> [] end end end @@ -47,7 +47,7 @@ defmodule Mix.ProjectStack do @spec configured_applications() :: [atom] def configured_applications() do get fn - %{stack: [h|_]} -> h.configured_applications + %{stack: [h | _]} -> h.configured_applications %{stack: []} -> [] end end @@ -56,7 +56,7 @@ defmodule Mix.ProjectStack do def pop do get_and_update fn %{stack: stack} = state -> case stack do - [h|t] -> {take(h), %{state | stack: t}} + [h | t] -> {take(h), %{state | stack: t}} [] -> {nil, state} end end @@ -66,7 +66,7 @@ defmodule Mix.ProjectStack do def peek do get fn %{stack: stack} -> case stack do - [h|_] -> take(h) + [h | _] -> take(h) [] -> nil end end @@ -78,15 +78,15 @@ defmodule Mix.ProjectStack do def root(fun) do {top, file} = get_and_update fn %{stack: stack} = state -> - {top, [mid|bottom]} = Enum.split_while(stack, &(not &1.recursing?)) - {{top, mid.file}, %{state | stack: [%{mid | recursing?: false}|bottom]}} + {top, [mid | bottom]} = Enum.split_while(stack, &(not &1.recursing?)) + {{top, mid.file}, %{state | stack: [%{mid | recursing?: false} | bottom]}} end try do File.cd! Path.dirname(file), fun after - cast fn %{stack: [mid|bottom]} = state -> - %{state | stack: top ++ [%{mid | recursing?: true}|bottom]} + cast fn %{stack: [mid | bottom]} = state -> + %{state | stack: top ++ [%{mid | recursing?: true} | bottom]} end end end @@ -104,12 +104,12 @@ defmodule Mix.ProjectStack do case stack do [] -> {nil, state} - [%{io_done: true}|_] -> + [%{io_done: true} | _] -> {nil, state} - [h|t] -> + [h | t] -> h = %{h | io_done: true} t = Enum.map(t, &%{&1 | io_done: false}) - {h.config[:app], %{state | stack: [h|t]}} + {h.config[:app], %{state | stack: [h | t]}} end end end @@ -127,15 +127,15 @@ defmodule Mix.ProjectStack do """ @spec recur((... -> result)) :: result when result: var def recur(fun) do - cast fn %{stack: [h|t]} = state -> - %{state | stack: [%{h | recursing?: true}|t]} + cast fn %{stack: [h | t]} = state -> + %{state | stack: [%{h | recursing?: true} | t]} end try do fun.() after - cast fn %{stack: [h|t]} = state -> - %{state | stack: [%{h | recursing?: false}|t]} + cast fn %{stack: [h | t]} = state -> + %{state | stack: [%{h | recursing?: false} | t]} end end end diff --git a/lib/mix/lib/mix/rebar.ex b/lib/mix/lib/mix/rebar.ex index 80830bd03ec..8ed09cac75a 100644 --- a/lib/mix/lib/mix/rebar.ex +++ b/lib/mix/lib/mix/rebar.ex @@ -92,22 +92,22 @@ defmodule Mix.Rebar do defp do_tuple_merge(old, []), do: old - defp do_tuple_merge(olds, [new|news]), + defp do_tuple_merge(olds, [new | news]), do: do_tuple_umerge_dedup(umerge(:new, olds, [], news, new), []) defp umerge(_, [], [], acc, current), - do: [current|acc] + do: [current | acc] defp umerge(:new, [], news, acc, current), - do: Enum.reverse(news, [current|acc]) + do: Enum.reverse(news, [current | acc]) defp umerge(:old, olds, [], acc, current), - do: Enum.reverse(olds, [current|acc]) - defp umerge(:new, [old|olds], news, acc, current) do + do: Enum.reverse(olds, [current | acc]) + defp umerge(:new, [old | olds], news, acc, current) do {dir, merged, new_current} = compare({:new, current}, {:old, old}) - umerge(dir, olds, news, [merged|acc], new_current) + umerge(dir, olds, news, [merged | acc], new_current) end - defp umerge(:old, olds, [new|news], acc, current) do + defp umerge(:old, olds, [new | news], acc, current) do {dir, merged, new_current} = compare({:new, new}, {:old, current}) - umerge(dir, olds, news, [merged|acc], new_current) + umerge(dir, olds, news, [merged | acc], new_current) end defp compare({priority, a}, {secondary, b}) when is_tuple(a) and is_tuple(b) do @@ -144,11 +144,11 @@ defmodule Mix.Rebar do end defp do_tuple_umerge_dedup([], acc), do: acc - defp do_tuple_umerge_dedup([h|t], acc) do + defp do_tuple_umerge_dedup([h | t], acc) do if h in t do do_tuple_umerge_dedup(t, acc) else - do_tuple_umerge_dedup(t, [h|acc]) + do_tuple_umerge_dedup(t, [h | acc]) end end @@ -199,7 +199,7 @@ defmodule Mix.Rebar do |> Enum.map(&recur(&1, fun)) |> Enum.concat - [fun.(config)|subs] + [fun.(config) | subs] end defp parse_dep(app) when is_atom(app) do @@ -223,12 +223,12 @@ defmodule Mix.Rebar do ref = case source do - [""|_] -> [branch: "HEAD"] - [{:branch, branch}|_] -> [branch: to_string(branch)] - [{:tag, tag}|_] -> [tag: to_string(tag)] - [{:ref, ref}|_] -> [ref: to_string(ref)] - [ref|_] -> [ref: to_string(ref)] - _ -> [] + ["" | _] -> [branch: "HEAD"] + [{:branch, branch} | _] -> [branch: to_string(branch)] + [{:tag, tag} | _] -> [tag: to_string(tag)] + [{:ref, ref} | _] -> [ref: to_string(ref)] + [ref | _] -> [ref: to_string(ref)] + _ -> [] end compile = diff --git a/lib/mix/lib/mix/shell.ex b/lib/mix/lib/mix/shell.ex index 08f246a55e2..fc0023d3f0c 100644 --- a/lib/mix/lib/mix/shell.ex +++ b/lib/mix/lib/mix/shell.ex @@ -89,7 +89,7 @@ defmodule Mix.Shell do end port = Port.open({:spawn, shell_command(command)}, - [:stream, :binary, :exit_status, :hide, :use_stdio, {:env, env}|args]) + [:stream, :binary, :exit_status, :hide, :use_stdio, {:env, env} | args]) do_cmd(port, callback) end diff --git a/lib/mix/lib/mix/state.ex b/lib/mix/lib/mix/state.ex index ae13cc6cdbd..906ef5758f1 100644 --- a/lib/mix/lib/mix/state.ex +++ b/lib/mix/lib/mix/state.ex @@ -25,7 +25,7 @@ defmodule Mix.State do end def prepend(key, value) do - Agent.update(@name, Map, :update, [key, [value], &[value|List.delete(&1, value)]]) + Agent.update(@name, Map, :update, [key, [value], &[value | List.delete(&1, value)]]) end def append(key, value) do diff --git a/lib/mix/lib/mix/task.ex b/lib/mix/lib/mix/task.ex index 6a954d9a107..d6c91177453 100644 --- a/lib/mix/lib/mix/task.ex +++ b/lib/mix/lib/mix/task.ex @@ -318,13 +318,13 @@ defmodule Mix.Task do end end - defp run_alias([h|t], alias_args, _res) when is_binary(h) do - [task|args] = OptionParser.split(h) + defp run_alias([h | t], alias_args, _res) when is_binary(h) do + [task | args] = OptionParser.split(h) res = Mix.Task.run task, join_args(args, alias_args, t) run_alias(t, alias_args, res) end - defp run_alias([h|t], alias_args, _res) when is_function(h, 1) do + defp run_alias([h | t], alias_args, _res) when is_function(h, 1) do res = h.(join_args([], alias_args, t)) run_alias(t, alias_args, res) end diff --git a/lib/mix/lib/mix/tasks/archive.build.ex b/lib/mix/lib/mix/tasks/archive.build.ex index 1f77555aca9..35a415447b8 100644 --- a/lib/mix/lib/mix/tasks/archive.build.ex +++ b/lib/mix/lib/mix/tasks/archive.build.ex @@ -97,7 +97,7 @@ defmodule Mix.Tasks.Archive.Build do Enum.reduce evsn ++ ebin ++ priv, [], fn(f, acc) -> case File.read(f) do {:ok, bin} -> - [{Path.join(dir, f) |> String.to_char_list, bin}|acc] + [{Path.join(dir, f) |> String.to_char_list, bin} | acc] {:error, _} -> acc end diff --git a/lib/mix/lib/mix/tasks/compile.erlang.ex b/lib/mix/lib/mix/tasks/compile.erlang.ex index e69c1fece4a..a793c77829d 100644 --- a/lib/mix/lib/mix/tasks/compile.erlang.ex +++ b/lib/mix/lib/mix/tasks/compile.erlang.ex @@ -130,14 +130,14 @@ defmodule Mix.Tasks.Compile.Erlang do case form do {:attribute, _, :file, {include_file, _}} when file != include_file -> if File.regular?(include_file) do - %{erl | includes: [include_file|erl.includes]} + %{erl | includes: [include_file | erl.includes]} else erl end {:attribute, _, :behaviour, behaviour} -> - %{erl | behaviours: [behaviour|erl.behaviours]} + %{erl | behaviours: [behaviour | erl.behaviours]} {:attribute, _, :compile, value} -> - %{erl | compile: [value|erl.compile]} + %{erl | compile: [value | erl.compile]} _ -> erl end @@ -175,7 +175,7 @@ defmodule Mix.Tasks.Compile.Erlang do defp annotate_target(erl, compile_path, force) do beam = Path.join(compile_path, "#{erl.module}#{:code.objfile_extension}") - if force || Mix.Utils.stale?([erl.file|erl.includes], [beam]) do + if force || Mix.Utils.stale?([erl.file | erl.includes], [beam]) do {:stale, erl.file, beam} else {:ok, erl.file, beam} diff --git a/lib/mix/lib/mix/tasks/compile.protocols.ex b/lib/mix/lib/mix/tasks/compile.protocols.ex index 85ab2d812a4..61b6f06e3fc 100644 --- a/lib/mix/lib/mix/tasks/compile.protocols.ex +++ b/lib/mix/lib/mix/tasks/compile.protocols.ex @@ -136,7 +136,7 @@ defmodule Mix.Tasks.Compile.Protocols do defp read_manifest(manifest) do case :file.consult(manifest) do - {:ok, [@manifest_vsn|t]} -> t + {:ok, [@manifest_vsn | t]} -> t _ -> [] end end diff --git a/lib/mix/lib/mix/tasks/deps.check.ex b/lib/mix/lib/mix/tasks/deps.check.ex index 2efa45ece58..9a5501b89be 100644 --- a/lib/mix/lib/mix/tasks/deps.check.ex +++ b/lib/mix/lib/mix/tasks/deps.check.ex @@ -93,13 +93,13 @@ defmodule Mix.Tasks.Deps.Check do end end - defp partition([dep|deps], not_ok, compile) do + defp partition([dep | deps], not_ok, compile) do cond do from_umbrella?(dep) -> partition(deps, not_ok, compile) - compilable?(dep) -> partition(deps, not_ok, [dep|compile]) - ok?(dep) and local?(dep) -> partition(deps, not_ok, [dep|compile]) + compilable?(dep) -> partition(deps, not_ok, [dep | compile]) + ok?(dep) and local?(dep) -> partition(deps, not_ok, [dep | compile]) ok?(dep) -> partition(deps, not_ok, compile) - true -> partition(deps, [dep|not_ok], compile) + true -> partition(deps, [dep | not_ok], compile) end end diff --git a/lib/mix/lib/mix/tasks/do.ex b/lib/mix/lib/mix/tasks/do.ex index 3601fbdc2ae..779ac627ccd 100644 --- a/lib/mix/lib/mix/tasks/do.ex +++ b/lib/mix/lib/mix/tasks/do.ex @@ -18,7 +18,7 @@ defmodule Mix.Tasks.Do do @spec run(OptionParser.argv) :: :ok def run(args) do Enum.each gather_commands(args), fn - [task|args] -> Mix.Task.run task, args + [task | args] -> Mix.Task.run task, args [] -> Mix.raise "No expression between commas" end end @@ -27,17 +27,17 @@ defmodule Mix.Tasks.Do do gather_commands args, [], [] end - defp gather_commands([h|t], current, acc) when binary_part(h, byte_size(h), -1) == "," do + defp gather_commands([h | t], current, acc) when binary_part(h, byte_size(h), -1) == "," do part = binary_part(h, 0, byte_size(h) - 1) - current = Enum.reverse([part|current]) - gather_commands t, [], [current|acc] + current = Enum.reverse([part | current]) + gather_commands t, [], [current | acc] end - defp gather_commands([h|t], current, acc) do - gather_commands t, [h|current], acc + defp gather_commands([h | t], current, acc) do + gather_commands t, [h | current], acc end defp gather_commands([], current, acc) do - Enum.reverse [Enum.reverse(current)|acc] + Enum.reverse [Enum.reverse(current) | acc] end end diff --git a/lib/mix/lib/mix/tasks/escript.build.ex b/lib/mix/lib/mix/tasks/escript.build.ex index 32f874d6369..78fa5ef94a1 100644 --- a/lib/mix/lib/mix/tasks/escript.build.ex +++ b/lib/mix/lib/mix/tasks/escript.build.ex @@ -173,7 +173,7 @@ defmodule Mix.Tasks.Escript.Build do defp core_files(escript_opts, language) do if Keyword.get(escript_opts, :embed_elixir, language == :elixir) do - Enum.flat_map [:elixir|extra_apps()], &app_files/1 + Enum.flat_map [:elixir | extra_apps()], &app_files/1 else [] end diff --git a/lib/mix/lib/mix/tasks/local.public_keys.ex b/lib/mix/lib/mix/tasks/local.public_keys.ex index 00dd8f2777b..ab00f620c10 100644 --- a/lib/mix/lib/mix/tasks/local.public_keys.ex +++ b/lib/mix/lib/mix/tasks/local.public_keys.ex @@ -37,8 +37,8 @@ defmodule Mix.Tasks.Local.PublicKeys do {opts, argv, _} = OptionParser.parse(argv, switches: [force: :boolean, detailed: :boolean]) case argv do - [] -> show(opts) - [path|_] -> install(path, opts) + [] -> show(opts) + [path | _] -> install(path, opts) end end diff --git a/lib/mix/lib/mix/tasks/new.ex b/lib/mix/lib/mix/tasks/new.ex index 224e83cf7ce..92e0a9007ca 100644 --- a/lib/mix/lib/mix/tasks/new.ex +++ b/lib/mix/lib/mix/tasks/new.ex @@ -50,7 +50,7 @@ defmodule Mix.Tasks.New do case argv do [] -> Mix.raise "Expected PATH to be given, please use \"mix new PATH\"" - [path|_] -> + [path | _] -> app = opts[:app] || Path.basename(Path.expand(path)) check_application_name!(app, !!opts[:app]) mod = opts[:module] || camelize(app) @@ -174,8 +174,8 @@ defmodule Mix.Tasks.New do {:ok, version} = Version.parse(version) "#{version.major}.#{version.minor}" <> case version.pre do - [h|_] -> "-#{h}" - [] -> "" + [h | _] -> "-#{h}" + [] -> "" end end diff --git a/lib/mix/lib/mix/tasks/profile.fprof.ex b/lib/mix/lib/mix/tasks/profile.fprof.ex index cc7e3796df8..6c2990c59c9 100644 --- a/lib/mix/lib/mix/tasks/profile.fprof.ex +++ b/lib/mix/lib/mix/tasks/profile.fprof.ex @@ -112,9 +112,9 @@ defmodule Mix.Tasks.Profile.Fprof do {file, argv} = case {Keyword.has_key?(opts, :eval), head} do - {true, _} -> {nil, head} - {_, [h|t]} -> {h, t} - {_, []} -> {nil, []} + {true, _} -> {nil, head} + {_, [h | t]} -> {h, t} + {_, []} -> {nil, []} end System.argv(argv) diff --git a/lib/mix/lib/mix/tasks/run.ex b/lib/mix/lib/mix/tasks/run.ex index c46ba80eff9..180ff7b7e14 100644 --- a/lib/mix/lib/mix/tasks/run.ex +++ b/lib/mix/lib/mix/tasks/run.ex @@ -50,9 +50,9 @@ defmodule Mix.Tasks.Run do {file, argv} = case {Keyword.has_key?(opts, :eval), head} do - {true, _} -> {nil, head} - {_, [h|t]} -> {h, t} - {_, []} -> {nil, []} + {true, _} -> {nil, head} + {_, [h | t]} -> {h, t} + {_, []} -> {nil, []} end System.argv(argv) diff --git a/lib/mix/lib/mix/tasks/test.ex b/lib/mix/lib/mix/tasks/test.ex index af25d5a095e..ba8ea7d9101 100644 --- a/lib/mix/lib/mix/tasks/test.ex +++ b/lib/mix/lib/mix/tasks/test.ex @@ -298,7 +298,7 @@ defmodule Mix.Tasks.Test do |> Keyword.put_new(:include, []) |> Keyword.put_new(:exclude, []) |> Keyword.update!(:include, &(filters ++ &1)) - |> Keyword.update!(:exclude, &[:test|&1]) + |> Keyword.update!(:exclude, &[:test | &1]) else opts end diff --git a/lib/mix/lib/mix/utils.ex b/lib/mix/lib/mix/utils.ex index 714db326a94..0c96a9854d6 100644 --- a/lib/mix/lib/mix/utils.ex +++ b/lib/mix/lib/mix/utils.ex @@ -272,7 +272,7 @@ defmodule Mix.Utils do do_make_relative_path(Path.split(source), Path.split(target)) end - defp do_make_relative_path([h|t1], [h|t2]) do + defp do_make_relative_path([h | t1], [h | t2]) do do_make_relative_path(t1, t2) end diff --git a/lib/mix/test/mix/cli_test.exs b/lib/mix/test/mix/cli_test.exs index bdf123a08cf..473145412cc 100644 --- a/lib/mix/test/mix/cli_test.exs +++ b/lib/mix/test/mix/cli_test.exs @@ -170,7 +170,7 @@ defmodule Mix.CLITest do defp mix(args, envs \\ []) when is_list(args) do System.cmd(elixir_executable, - ["-r", mix_executable, "--"|args], + ["-r", mix_executable, "--" | args], stderr_to_stdout: true, env: envs) |> elem(0) end diff --git a/lib/mix/test/mix/tasks/deps.git_test.exs b/lib/mix/test/mix/tasks/deps.git_test.exs index eaa6a4666d7..5045dcb7eb4 100644 --- a/lib/mix/test/mix/tasks/deps.git_test.exs +++ b/lib/mix/test/mix/tasks/deps.git_test.exs @@ -208,7 +208,7 @@ defmodule Mix.Tasks.DepsGitTest do Mix.Project.push GitApp # Get git repo first revision - [last, first|_] = get_git_repo_revs + [last, first | _] = get_git_repo_revs in_fixture "no_mixfile", fn -> Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), first, []}} @@ -234,7 +234,7 @@ defmodule Mix.Tasks.DepsGitTest do test "updates the repo when the lock updates" do Mix.Project.push GitApp - [last, first|_] = get_git_repo_revs + [last, first | _] = get_git_repo_revs in_fixture "no_mixfile", fn -> Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), first, []}} @@ -270,7 +270,7 @@ defmodule Mix.Tasks.DepsGitTest do test "updates the repo and the lock when the mixfile updates" do Mix.Project.push GitApp - [last, first|_] = get_git_repo_revs + [last, first | _] = get_git_repo_revs in_fixture "no_mixfile", fn -> # Move to the first version @@ -313,7 +313,7 @@ defmodule Mix.Tasks.DepsGitTest do test "does not load bad mixfiles on get" do Mix.Project.push GitApp - [last, _, bad|_] = get_git_repo_revs + [last, _, bad | _] = get_git_repo_revs in_fixture "no_mixfile", fn -> Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), bad, []}} @@ -347,7 +347,7 @@ defmodule Mix.Tasks.DepsGitTest do test "does not load bad mixfiles on update" do Mix.Project.push GitApp - [last, _, bad|_] = get_git_repo_revs + [last, _, bad | _] = get_git_repo_revs in_fixture "no_mixfile", fn -> Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), bad, []}}