Skip to content

Commit 726cebd

Browse files
committed
Initial support for macros
1 parent 29afa82 commit 726cebd

File tree

9 files changed

+670
-186
lines changed

9 files changed

+670
-186
lines changed

Cargo.lock

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ glam = { version = "0.20", features = ["serde"] }
1414
thiserror = "1"
1515
regex = "1"
1616
lazy_static = "1"
17+
minijinja = { version = "^0.18", features = ["source"] }
18+
serde_json = "^1"

lib/src/firmware_retraction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct FirmwareRetractionOptions {
1818
pub lift_z: f64,
1919
}
2020

21-
#[derive(Debug)]
21+
#[derive(Debug, Clone, Copy)]
2222
pub enum FirmwareRetractionState {
2323
Unretracted,
2424
Retracted {

lib/src/gcode.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::BTreeMap;
22
use std::fmt::Display;
33
use std::io::{self, BufRead};
44

5+
use serde::Serialize;
56
use thiserror::Error;
67

78
#[derive(Debug, PartialEq, PartialOrd, Clone)]
@@ -118,7 +119,7 @@ impl Display for GCodeTraditionalParams {
118119
}
119120
}
120121

121-
#[derive(Debug, PartialEq, PartialOrd, Clone)]
122+
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone, Serialize)]
122123
pub struct GCodeExtendedParams(BTreeMap<String, String>);
123124

124125
impl GCodeExtendedParams {
@@ -273,7 +274,7 @@ mod parser {
273274
fn parse(s: &str) -> IResult<&str, GCodeCommand> {
274275
let (s, _) = space0(s)?;
275276

276-
let (s, _line_no) = opt(line_number)(s)?;
277+
// let (s, _line_no) = opt(line_number)(s)?;
277278

278279
let (s, (op, comment)) = alt((
279280
complete(traditional_gcode),
@@ -308,7 +309,7 @@ mod parser {
308309
}
309310

310311
fn traditional_gcode(s: &str) -> IResult<&str, (GCodeOperation, Option<&str>)> {
311-
let (s, letter) = satisfy(|c| c.is_alphabetic())(s)?;
312+
let (s, letter) = satisfy(|c| matches!(c.to_ascii_lowercase(), 'g' | 'm') )(s)?;
312313
let (s, code) = match lexical_core::parse_partial::<u16>(s.as_bytes()) {
313314
Ok((_, 0)) => return Err(Err::Error(Error::from_error_kind(s, ErrorKind::Digit))),
314315
Ok((value, processed)) => (s.slice(processed..), value),

lib/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extern crate lazy_static;
44
pub mod firmware_retraction;
55
pub mod gcode;
66
mod kind_tracker;
7+
mod macros;
78
pub mod planner;
89
pub mod slicer;
910

0 commit comments

Comments
 (0)