James Harton
ad8f6c44ef
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.
43 lines
974 B
Elixir
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
|