fix: bug in parsing not returning errors

This commit is contained in:
James Harton 2021-01-13 13:26:50 +13:00
parent 6edee4b073
commit 0ae33a44ff

View file

@ -19,12 +19,14 @@ defmodule Gcode.Parser do
ok(program) <- hydrate(tokens) do
ok(program)
else
{:error, reason} ->
{:parse_error, reason}
error(reason) ->
error({:parse_error, reason})
{:error, {message, unexpected, _, {line, _}, col}} ->
{:parse_error,
"Unexpected #{inspect(unexpected)} at line: #{line}:#{col + 1}. #{message}."}
error({message, unexpected, _, {line, _}, col}) ->
error(
{:parse_error,
"Unexpected #{inspect(unexpected)} at line: #{line}:#{col + 1}. #{message}."}
)
end
end
@ -38,12 +40,14 @@ defmodule Gcode.Parser do
ok(program) <- hydrate(tokens) do
ok(program)
else
{:error, reason} ->
{:parse_error, reason}
error(reason) ->
error({:parse_error, reason})
{:error, {message, unexpected, _, {line, _}, col}} ->
{:parse_error,
"Unexpected #{inspect(unexpected)} at line: #{line}:#{col + 1}. #{message}."}
error({message, unexpected, _, {line, _}, col}) ->
error(
{:parse_error,
"Unexpected #{inspect(unexpected)} at line: #{line}:#{col + 1}. #{message}."}
)
end
end