gcode 0.7.0-rc.1

A gcode parser for no-std applications.
Documentation

GCode

Crates.io version Docs CI

A gcode parser designed for use in #[no_std] environments. G-code is the common name for the programming language used by CNC machines and 3D printers.

Design goals:

  • embedded-friendly (no_std / WebAssembly)
  • deterministic memory (optional zero allocation via the core visitor API)
  • error-resistant parsing with diagnostics, and
  • O(n) performance with no backtracking.

Default features: alloc, serde. Omit alloc for zero-allocation parsing via the core visitor API. Requires Rust 1.85+.

Getting Started

First, add gcode to your dependencies:

$ cargo add gcode

Then, you can start using it. Here is a simple example that parses a G-code program using the alloc feature:

fn main() -> Result<(), gcode::Diagnostics> {
    let src = "G90 G00 X10 Y20";
    let program = gcode::parse(src)?;
    assert_eq!(program.blocks.len(), 1);
    Ok(())
}

For a visitor-based example, see the pretty_print_visitor example. Run it with cargo run --example pretty_print_visitor.

Useful Links

License

This project is licensed under either of

at your option.

It is recommended to always use cargo-crev to verify the trustworthiness of each of your dependencies, including this one.

Contribution

The intent of this crate is to be free of soundness bugs. The developers will do their best to avoid them, and welcome help in analyzing and fixing them.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.