Skip to content
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

Remove warnings: Use ~c"" instead, compiler for .yrl and .xrl #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use Mix.Config
import Config
64 changes: 41 additions & 23 deletions lib/erlex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ defmodule Erlex do
end

@spec pretty_print_infix(infix :: String.t()) :: String.t()
def pretty_print_infix('=:='), do: "==="
def pretty_print_infix('=/='), do: "!=="
def pretty_print_infix('/='), do: "!="
def pretty_print_infix('=<'), do: "<="
def pretty_print_infix(~c"=:="), do: "==="
def pretty_print_infix(~c"=/="), do: "!=="
def pretty_print_infix(~c"/="), do: "!="
def pretty_print_infix(~c"=<"), do: "<="
def pretty_print_infix(infix), do: to_string(infix)

@spec pretty_print(str :: String.t()) :: String.t()
Expand All @@ -93,7 +93,7 @@ defmodule Erlex do
end

@spec pretty_print_pattern(pattern :: String.t()) :: String.t()
def pretty_print_pattern('pattern ' ++ rest) do
def pretty_print_pattern(~c"pattern " ++ rest) do
pretty_print_type(rest)
end

Expand Down Expand Up @@ -217,7 +217,7 @@ defmodule Erlex do
"_"
end

defp do_pretty_print({:atom, ['_']}) do
defp do_pretty_print({:atom, [~c"_"]}) do
"_"
end

Expand Down Expand Up @@ -291,7 +291,7 @@ defmodule Erlex do
{:list, :square,
[
tuple: [
{:type_list, ['a', 't', 'o', 'm'], {:list, :paren, []}},
{:type_list, [~c"a", ~c"t", ~c"o", ~c"m"], {:list, :paren, []}},
{:atom, [:_]}
]
]}
Expand All @@ -303,7 +303,7 @@ defmodule Erlex do
{:list, :square,
[
tuple: [
{:type_list, ['a', 't', 'o', 'm'], {:list, :paren, []}},
{:type_list, [~c"a", ~c"t", ~c"o", ~c"m"], {:list, :paren, []}},
t
]
]}
Expand All @@ -322,7 +322,7 @@ defmodule Erlex do
defp do_pretty_print(
{:map,
[
{:map_entry, {:atom, '\'__struct__\''}, {:atom, [:_]}},
{:map_entry, {:atom, ~c{'__struct__'}}, {:atom, [:_]}},
{:map_entry, {:atom, [:_]}, {:atom, [:_]}}
]}
) do
Expand All @@ -332,9 +332,10 @@ defmodule Erlex do
defp do_pretty_print(
{:map,
[
{:map_entry, {:atom, '\'__struct__\''},
{:type_list, ['a', 't', 'o', 'm'], {:list, :paren, []}}},
{:map_entry, {:type_list, ['a', 't', 'o', 'm'], {:list, :paren, []}}, {:atom, [:_]}}
{:map_entry, {:atom, ~c{'__struct__'}},
{:type_list, [~c"a", ~c"t", ~c"o", ~c"m"], {:list, :paren, []}}},
{:map_entry, {:type_list, [~c"a", ~c"t", ~c"o", ~c"m"], {:list, :paren, []}},
{:atom, [:_]}}
]}
) do
"struct()"
Expand All @@ -343,8 +344,8 @@ defmodule Erlex do
defp do_pretty_print(
{:map,
[
{:map_entry, {:atom, '\'__struct__\''},
{:type_list, ['a', 't', 'o', 'm'], {:list, :paren, []}}},
{:map_entry, {:atom, ~c{'__struct__'}},
{:type_list, [~c"a", ~c"t", ~c"o", ~c"m"], {:list, :paren, []}}},
{:map_entry, {:atom, [:_]}, {:atom, [:_]}}
]}
) do
Expand All @@ -354,8 +355,8 @@ defmodule Erlex do
defp do_pretty_print(
{:map,
[
{:map_entry, {:atom, '\'__exception__\''}, {:atom, '\'true\''}},
{:map_entry, {:atom, '\'__struct__\''}, {:atom, [:_]}},
{:map_entry, {:atom, ~c{'__exception__'}}, {:atom, ~c{'true'}}},
{:map_entry, {:atom, ~c{'__struct__'}}, {:atom, [:_]}},
{:map_entry, {:atom, [:_]}, {:atom, [:_]}}
]}
) do
Expand Down Expand Up @@ -396,7 +397,7 @@ defmodule Erlex do

defp do_pretty_print({:named_type, named_type, type}) when is_tuple(named_type) do
case named_type do
{:atom, name = '\'Elixir' ++ _} ->
{:atom, name = ~c{'Elixir} ++ _} ->
"#{atomize(name)}.#{deatomize(type)}()"

{:atom, name} ->
Expand All @@ -417,15 +418,32 @@ defmodule Erlex do
end

defp do_pretty_print(
{:pipe_list, {:atom, ['f', 'a', 'l', 's', 'e']}, {:atom, ['t', 'r', 'u', 'e']}}
{:pipe_list, {:atom, [~c"f", ~c"a", ~c"l", ~c"s", ~c"e"]},
{:atom, [~c"t", ~c"r", ~c"u", ~c"e"]}}
) do
"boolean()"
end

defp do_pretty_print(
{:pipe_list, {:atom, '\'infinity\''},
{:type_list, ['n', 'o', 'n', :_, 'n', 'e', 'g', :_, 'i', 'n', 't', 'e', 'g', 'e', 'r'],
{:list, :paren, []}}}
{:pipe_list, {:atom, ~c{'infinity'}},
{:type_list,
[
~c"n",
~c"o",
~c"n",
:_,
~c"n",
~c"e",
~c"g",
:_,
~c"i",
~c"n",
~c"t",
~c"e",
~c"g",
~c"e",
~c"r"
], {:list, :paren, []}}}
) do
"timeout()"
end
Expand Down Expand Up @@ -580,7 +598,7 @@ defmodule Erlex do
%{name: name, entries: Enum.reverse(entries)}
end

defp struct_part({:map_entry, {:atom, '\'__struct__\''}, {:atom, name}}, struct_parts) do
defp struct_part({:map_entry, {:atom, ~c{'__struct__'}}, {:atom, name}}, struct_parts) do
name =
name
|> atomize()
Expand All @@ -593,7 +611,7 @@ defmodule Erlex do
Map.put(struct_parts, :entries, [entry | entries])
end

defp deatomize([:_, :_, '@', {:int, _}]) do
defp deatomize([:_, :_, ~c"@", {:int, _}]) do
"_"
end

Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ defmodule Erlex.MixProject do
description: description(),
package: package(),
docs: docs(),
dialyzer: dialyzer()
dialyzer: dialyzer(),
compilers: [:leex, :yecc] ++ Mix.compilers()
]
end

Expand Down
6 changes: 3 additions & 3 deletions test/pretty_print_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ defmodule Erlex.Test.PretyPrintTest do
end

test "patterns get pretty printed appropriately" do
input = 'pattern {\'ok\', Vuser@1}'
input = ~c"pattern {\'ok\', Vuser@1}"
pretty_printed = Erlex.pretty_print_pattern(input)

expected_output = "{:ok, user}"
Expand Down Expand Up @@ -221,7 +221,7 @@ defmodule Erlex.Test.PretyPrintTest do
end

test "modules with numbers are pretty printed appropriately" do
input = 'Elixir.Project.Resources.Components.V1.Actions'
input = ~c"Elixir.Project.Resources.Components.V1.Actions"

pretty_printed = Erlex.pretty_print(input)

Expand Down Expand Up @@ -250,7 +250,7 @@ defmodule Erlex.Test.PretyPrintTest do
end

test "elixir SSA numbered variables get pretty printed appropriately" do
input = '_money@1'
input = ~c"_money@1"

pretty_printed = Erlex.pretty_print(input)

Expand Down