Skip to content

Commit

Permalink
Mark case as generated
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 15, 2025
1 parent 922b6b1 commit 7d8c3d7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/nimble_parsec/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ defmodule NimbleParsec.Compiler do
args = quote(do: [binary, opts \\ []])
guards = quote(do: is_binary(binary))

case =
quote generated: true do
case unquote(:"#{name}__0")(binary, [], [], context, line, byte_offset) do
{:ok, acc, rest, context, line, offset} ->
{:ok, :lists.reverse(acc), rest, context, line, offset}

{:error, _, _, _, _, _} = error ->
error
end
end

body =
quote do
context = Map.new(Keyword.get(opts, :context, []))
Expand All @@ -48,13 +59,7 @@ defmodule NimbleParsec.Compiler do
line -> {line, byte_offset}
end

case unquote(:"#{name}__0")(binary, [], [], context, line, byte_offset) do
{:ok, acc, rest, context, line, offset} ->
{:ok, :lists.reverse(acc), rest, context, line, offset}

{:error, _, _, _, _, _} = error ->
error
end
unquote(case)
end

{doc, spec, {name, args, guards, body}}
Expand Down

0 comments on commit 7d8c3d7

Please sign in to comment.