From 0faac64f3003577cd9d1636f0ead5c90c46add7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 21 Jan 2024 12:40:50 +0100 Subject: [PATCH] Add pending deprecation --- lib/nimble_parsec/compiler.ex | 18 ++++++++++++++---- test/integration_test.exs | 12 ++++++------ test/nimble_parsec_test.exs | 6 +++--- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/nimble_parsec/compiler.ex b/lib/nimble_parsec/compiler.ex index 3a53895..3ed1868 100644 --- a/lib/nimble_parsec/compiler.ex +++ b/lib/nimble_parsec/compiler.ex @@ -430,7 +430,7 @@ defmodule NimbleParsec.Compiler do {acc, context} when acc != :error -> IO.warn( - "Returning a two-element tuple {acc, context} in pre_traverse/post_traverse is deprecated, " <> + "returning a two-element tuple {acc, context} in pre_traverse/post_traverse is deprecated, " <> "please return {rest, acc, context} instead" ) @@ -443,9 +443,19 @@ defmodule NimbleParsec.Compiler do # TODO: Deprecate two element tuple return that is not error quote generated: true do case unquote(quoted) do - {_, _, _} = res -> res - {:error, reason} -> {:error, reason} - {acc, context} -> {unquote(rest), acc, context} + {_, _, _} = res -> + res + + {:error, reason} -> + {:error, reason} + + {acc, context} -> + IO.warn( + "returning a two-element tuple {acc, context} in pre_traverse/post_traverse is deprecated, " <> + "please return {rest, acc, context} instead" + ) + + {unquote(rest), acc, context} end end end diff --git a/test/integration_test.exs b/test/integration_test.exs index 3fdbbc5..1608c6f 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -69,12 +69,12 @@ defmodule NimbleParsec.IntegrationTest do |> post_traverse({:sign_int_value, []}) |> tag(:signed_int) - defp sign_int_value(_rest, [int, _neg], context, _, _) do - {[int * -1], context} + defp sign_int_value(rest, [int, _neg], context, _, _) do + {rest, [int * -1], context} end - defp sign_int_value(_rest, res, context, _, _) do - {res, context} + defp sign_int_value(rest, res, context, _, _) do + {rest, res, context} end test "returns ok/error" do @@ -90,8 +90,8 @@ defmodule NimbleParsec.IntegrationTest do defparsec :language_code, language_code - defp atomize_language_code(_rest, [language_code], context, _line, _offset) do - {[String.to_atom(language_code)], context} + defp atomize_language_code(rest, [language_code], context, _line, _offset) do + {rest, [String.to_atom(language_code)], context} end test "returns ok/error" do diff --git a/test/nimble_parsec_test.exs b/test/nimble_parsec_test.exs index 9adb87e..249a44d 100644 --- a/test/nimble_parsec_test.exs +++ b/test/nimble_parsec_test.exs @@ -1500,8 +1500,8 @@ defmodule NimbleParsecTest do end end - defp location(_rest, args, %{} = context, line, offset, tag) do - {[{tag, args, line, offset}], context} + defp location(rest, args, %{} = context, line, offset, tag) do + {rest, [{tag, args, line, offset}], context} end defp bound?(document) do @@ -1554,6 +1554,6 @@ defmodule NimbleParsecTest do defp private_join_and_wrap(rest, args, %{} = context, {line, line_offset}, byte_offset, joiner) when is_binary(rest) and is_integer(line) and is_integer(line_offset) and is_integer(byte_offset) do - {args |> Enum.join(joiner) |> List.wrap(), context} + {rest, args |> Enum.join(joiner) |> List.wrap(), context} end end