Gcode.Model.Block (gcode v1.0.1)
A sequence of G-code words on a single line.
Summary
Functions
Set a comment on the block (this is just a sugar to make sure that the comment is rendered on the same line as the block).
Initialise a new empty G-code program.
Pushes a Word
onto the word list.
An accessor which returns the block's words in the correct order.
Types
block_contents()
@type block_contents() :: Gcode.Model.Word.t() | Gcode.Model.Skip.t() | Gcode.Model.Expr.t()
block_error()
@type block_error() :: {:block_error, String.t()}
Any error results in this module will return this type
@type t() :: %Gcode.Model.Block{ comment: Gcode.Option.t(Gcode.Model.Comment), words: [block_contents()] }
Functions
comment(block, comment)
@spec comment(t(), Gcode.Model.Comment.t()) :: Gcode.Result.t(t(), block_error())
Set a comment on the block (this is just a sugar to make sure that the comment is rendered on the same line as the block).
Note: Once a block has a comment set, it cannot be overwritten.
Examples
iex> {:ok, comment} = Comment.init("Jen, in the swing seat, with her night terrors")
...> {:ok, block} = Block.init()
...> {:ok, block} = Block.comment(block, comment)
...> Result.ok?(block.comment)
true
init()
@spec init() :: Gcode.Result.t(t())
Initialise a new empty G-code program.
Example
iex> Block.init()
{:ok, %Block{words: [], comment: none()}}
push(block, pushable)
@spec push(t(), block_contents()) :: Gcode.Result.t(t(), block_error())
Pushes a Word
onto the word list.
Note: Block
stores the words in reverse order because of Erlang list
semantics, you should pretty much always use words/1
to retrieve them in the
correct order.
Example
iex> {:ok, block} = Block.init()
...> {:ok, word} = Word.init("G", 0)
...> {:ok, block} = Block.push(block, word)
...> {:ok, word} = Word.init("N", 100)
...> Block.push(block, word)
{:ok, %Block{words: [%Word{word: "N", address: %Integer{i: 100}}, %Word{word: "G", address: %Integer{i: 0}}]}}
words(block)
@spec words(t()) :: Gcode.Result.t([Gcode.Model.Word.t()], block_error())
An accessor which returns the block's words in the correct order.
iex> {:ok, block} = Block.init()
...> {:ok, word} = Word.init("G", 0)
...> {:ok, block} = Block.push(block, word)
...> {:ok, word} = Word.init("N", 100)
...> {:ok, block} = Block.push(block, word)
...> Block.words(block)
{:ok, [%Word{word: "G", address: %Integer{i: 0}}, %Word{word: "N", address: %Integer{i: 100}}]}