Skip to content

Formmating: Add white space around vertical bar #4507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/eex/lib/eex/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
28 changes: 14 additions & 14 deletions lib/eex/lib/eex/tokenizer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -190,22 +190,22 @@ 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
end

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

Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/access.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/code.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions lib/elixir/lib/collectable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand Down
6 changes: 3 additions & 3 deletions lib/elixir/lib/dict.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading