gcode/test/support/parser_engine_helper.ex
James Harton ad8f6c44ef feat: Implement (a common subset) G-code parsing.
It turns out that G-code is a turing complete programming language. That was a surprise! I've implemented enough of the parser to be able to parse the output of Fusion 360 and Cura, both of which I use on a daily basis.  It is not a complete implementation.
2021-01-10 17:43:25 +13:00

43 lines
974 B
Elixir

defmodule ParserEngineHelper do
alias Gcode.Parser.Engine
@moduledoc false
defmacro __using__(_) do
quote do
require ParserEngineHelper
import ParserEngineHelper
end
end
defmacro it_parses_into(input, {:fn, _, _} = callback) do
quote do
input_length = byte_size(unquote(input))
description =
if input_length < 60,
do: unquote(input),
else: "#{input_length} byte input"
test description do
assert ok(tokens) = Engine.parse(unquote(input))
unquote(callback).(tokens)
end
end
end
defmacro it_parses_into(input, pattern) do
quote do
input_length = byte_size(unquote(input))
description =
if input_length < 60,
do: unquote(input),
else: "#{input_length} byte input"
test description do
assert ok(tokens) = Engine.parse(unquote(input))
assert unquote(pattern) = tokens
end
end
end
end