-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for gcode_macro #30
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ use std::collections::BTreeMap; | |
use std::fmt::Display; | ||
use std::io::{self, BufRead}; | ||
|
||
use serde::Serialize; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, PartialEq, PartialOrd, Clone)] | ||
|
@@ -81,7 +82,7 @@ impl Display for GCodeOperation { | |
} | ||
} | ||
|
||
#[derive(Debug, PartialEq, PartialOrd, Clone)] | ||
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone)] | ||
pub struct GCodeTraditionalParams(Vec<(char, String)>); | ||
|
||
impl GCodeTraditionalParams { | ||
|
@@ -121,7 +122,7 @@ impl Display for GCodeTraditionalParams { | |
} | ||
} | ||
|
||
#[derive(Debug, PartialEq, PartialOrd, Clone)] | ||
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone, Serialize)] | ||
pub struct GCodeExtendedParams(BTreeMap<String, String>); | ||
|
||
impl GCodeExtendedParams { | ||
|
@@ -279,7 +280,7 @@ mod parser { | |
fn parse(s: &str) -> IResult<&str, GCodeCommand> { | ||
let (s, _) = space0(s)?; | ||
|
||
let (s, _line_no) = opt(line_number)(s)?; | ||
// let (s, _line_no) = opt(line_number)(s)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was there an issue with this? |
||
|
||
let (s, (op, comment)) = alt(( | ||
complete(traditional_gcode), | ||
|
@@ -314,7 +315,7 @@ mod parser { | |
} | ||
|
||
fn traditional_gcode(s: &str) -> IResult<&str, (GCodeOperation, Option<&str>)> { | ||
let (s, letter) = satisfy(|c| c.is_alphabetic())(s)?; | ||
let (s, letter) = satisfy(|c| matches!(c.to_ascii_lowercase(), 'g' | 'm'))(s)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably not good, as e.g. tool selections fall under "traditional gcode" as well. Why was this change needed? |
||
let (s, code) = match lexical_core::parse_partial::<u16>(s.as_bytes()) { | ||
Ok((_, 0)) => return Err(Err::Error(Error::from_error_kind(s, ErrorKind::Digit))), | ||
Ok((value, processed)) => (s.slice(processed..), value), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to add a
to_map
or similar function that the caller can then serialize after. Doesn't feel right to need this to beSerialize
withingcode.rs
. A better option still is likely to add a wrapper inmacros.rs
. This wrapper can implementminijinja::value::Object
and call directly to getters without going through a serialization step.