summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/elixir/lib/macro.ex6
-rw-r--r--lib/elixir/test/elixir/macro_test.exs5
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/elixir/lib/macro.ex b/lib/elixir/lib/macro.ex
index f180ccd15..1ba92b9fd 100644
--- a/lib/elixir/lib/macro.ex
+++ b/lib/elixir/lib/macro.ex
@@ -537,6 +537,12 @@ defmodule Macro do
fun.(ast, "fn\n " <> block <> "\nend")
end
+ # Ranges
+ def to_string({:.., _, args} = ast, fun) do
+ range = Enum.map_join(args, "..", &to_string(&1, fun))
+ fun.(ast, range)
+ end
+
# left -> right
def to_string([{:->, _, _}|_] = ast, fun) do
fun.(ast, "(" <> arrow_to_string(ast, fun, true) <> ")")
diff --git a/lib/elixir/test/elixir/macro_test.exs b/lib/elixir/test/elixir/macro_test.exs
index 3b5396fb4..4c8f1d7d5 100644
--- a/lib/elixir/test/elixir/macro_test.exs
+++ b/lib/elixir/test/elixir/macro_test.exs
@@ -354,6 +354,11 @@ defmodule MacroTest do
"""
end
+ test "range to string" do
+ assert Macro.to_string(quote do: (1 .. 2)) == "1..2"
+ assert Macro.to_string(quote do: unquote(-1 .. +2)) == "-1..2"
+ end
+
test "when" do
assert Macro.to_string(quote do: (() -> x)) == "(() -> x)"
assert Macro.to_string(quote do: (x when y -> z)) == "(x when y -> z)"