Gcode.Model.Block (gcode v1.0.0)

A sequence of G-code words on a single line.

Link to this section Summary

Types

Any error results in this module will return this type

t()

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.

Link to this section Types

Link to this type

block_contents()

@type block_contents() ::
  Gcode.Model.Word.t() | Gcode.Model.Skip.t() | Gcode.Model.Expr.t()
Link to this type

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()]
}

Link to this section Functions

Link to this function

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

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
@spec init() :: Gcode.Result.t(t())

Initialise a new empty G-code program.

example

Example

iex> Block.init()
{:ok, %Block{words: [], comment: none()}}
Link to this function

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

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}}]}}
@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}}]}