1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//! A gcode parsing library designed for `no_std` environments.
//!
//! # Examples
//!
//! The `gcode` API is extremely minimal, containing a single `parse()`
//! function which takes a string and returns an iterator over the `Gcode`s it
//! contains.
//!
//! Parsing is done on a best-effort basis, with any syntax errors being
//! silently ignored. Because of this, you'll probably want to ensure a file is
//! well formed.
//!
//! > **Note:** The [examples/] folder in this project's repository contains a
//! > simple program that will read an input file and print out any `Gcode`s it
//! > sees.
//!
//! ```rust
//! use gcode::Mnemonic;
//!
//! let src = "O1000
//! T1 M6
//! G90
//! G01 X-75 Y-75 S500 M3
//! G43 Z100 H1
//! G01 Z5
//! N20 G01 Z-20 F100";
//!
//! let mut lines = gcode::parse(src);
//!
//! let program_number = lines.next().unwrap();
//! assert_eq!(program_number.major_number(), 1000);
//!
//! let tool_change = lines.next().unwrap();
//! assert_eq!(tool_change.mnemonic(), Mnemonic::ToolChange);
//! assert_eq!(tool_change.major_number(), 1);
//!
//! // skip the M6 and G90
//! let _ = lines.next();
//! let _ = lines.next();
//!
//! let g01 = lines.next().unwrap();
//! assert_eq!(g01.major_number(), 1);
//! assert_eq!(g01.args().len(), 3);
//! assert_eq!(g01.value_for('X'), Some(-75.0));
//!
//! let rest: Vec<_> = lines.collect();
//! assert_eq!(rest.len(), 4);
//! assert_eq!(rest[3].line_number(), Some(20));
//! ```
//!
//! # FFI Bindings
//!
//! The `ffi` feature (disabled by default) will also generate FFI bindings for
//! calling the library from a non-Rust language. The FFI bindings are unstable
//! and no stability guarantees are made about them.
//!
//! A C-style header file can be generated by running the `cbindgen` program
//! from this repository's root directory.
//!
//! ```console
//! $ cargo install cbindgen
//! $ git clone https://github.com/Michael-F-Bryan/gcode-rs
//! $ cd gcode-rs
//! $ cbindgen --output gcode.h
//! ```
//!
//! When you compile the library, it will automatically generate dynamic and
//! static libraries which can be called from C.
//!
//! ```console
//! $ cargo build --release
//! $ ls target/release/libgcode.*
//! libgcode.a libgcode.rlib libgcode.so
//!
//! # Print out some of the available function symbols
//! $ nm target/release/libgcode.so | grep ' T gcode\|parser' | grep -v '_Z'
//! 0000000000005e10 T gcode_args
//! 0000000000005e20 T gcode_arg_value
//! 0000000000005ef0 T gcode_line_number
//! 0000000000005de0 T gcode_major_number
//! 0000000000005dc0 T gcode_mnemonic
//! 0000000000005e00 T gcode_num_args
//! 0000000000005dd0 T gcode_number
//! 0000000000005ed0 T gcode_span
//! 0000000000005f10 T parser_destroy
//! 0000000000005d20 T parser_new
//! 0000000000005d70 T parser_next
//! ```
//!
//! The repository also contains [a basic example] showing how this library can
//! be used from a normal C program.
//!
//! [examples/]: https://github.com/Michael-F-Bryan/gcode-rs/tree/master/examples
//! [a basic example]: https://github.com/Michael-F-Bryan/gcode-rs/blob/master/ffi-example/main.c
extern crate arrayvec;
extern crate cfg_if;
extern crate std;
extern crate pretty_assertions;
pub use ;
pub use *;
use ;
/// Print a bunch of gcodes as ASCII text.