Skip to content

Commit

Permalink
0.3.4: update deps, fix lints, Rust 2021 Edition
Browse files Browse the repository at this point in the history
  • Loading branch information
sameer committed Feb 16, 2023
1 parent ac2fc73 commit 6b9f41d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 36 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "g-code"
version = "0.3.3"
version = "0.3.4"
authors = ["Sameer Puri <[email protected]>"]
edition = "2018"
edition = "2021"
keywords = ["gcode", "g-code", "plotter", "cnc"]
categories = ["parsing"]
repository = "https://github.com/sameer/g-code"
Expand All @@ -17,8 +17,8 @@ is-it-maintained-open-issues = { repository = "sameer/g-code" }
maintenance = { status = "passively-maintained" }

[dependencies]
peg = "0.7"
rust_decimal = { version = "1.14", default-features = false, features = ["std"] }
peg = "0.8"
rust_decimal = { version = "1.28", default-features = false, features = ["std"] }
codespan = { version = "0.11", optional = true }
codespan-reporting = { version = "0.11", optional = true }
paste = "1"
Expand Down
26 changes: 13 additions & 13 deletions src/emit/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ macro_rules! formatter_core {
}

if $opts.line_numbers && preceded_by_newline {
write!(w, "N{} ", line_number)?;
write!(w, "N{line_number} ")?;
}

match token {
Expand All @@ -96,20 +96,20 @@ macro_rules! formatter_core {
writeln!(w)?;
w.reset();
if $opts.line_numbers {
write!(w, "N{} ", line_number)?;
write!(w, "N{line_number} ")?;
}
} else {
write!(w, " ")?;
}
}
write!(w, "{}", f)?;
write!(w, "{f}")?;
preceded_by_newline = false;
}
Comment {
is_inline: true,
inner,
} => {
write!(w, "({})", inner)?;
write!(w, "({inner})")?;
preceded_by_newline = false;
}
Comment {
Expand All @@ -120,7 +120,7 @@ macro_rules! formatter_core {
write!(w, "*{}", w.checksum())?;
}
line_number += 1;
writeln!(w, ";{}", inner)?;
writeln!(w, ";{inner}")?;
w.reset();
preceded_by_newline = true;
}
Expand Down Expand Up @@ -162,10 +162,10 @@ impl fmt::Display for Token<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use Token::*;
match self {
Field(field) => write!(f, "{}", field),
Field(field) => write!(f, "{field}"),
Comment { is_inline, inner } => match is_inline {
true => write!(f, "({})", inner),
false => write!(f, ";{}", inner),
true => write!(f, "({inner})"),
false => write!(f, ";{inner}"),
},
}
}
Expand All @@ -186,14 +186,14 @@ impl fmt::Display for Value<'_> {
// so add it back in.
if r.fract().is_zero() {
if let Some(i64_rep) = r.to_i64() {
return write!(f, "{}.", i64_rep);
return write!(f, "{i64_rep}.");
}
}
write!(f, "{}", r)
write!(f, "{r}")
}
Self::Float(float) => write!(f, "{}", float),
Self::Integer(i) => write!(f, "{}", i),
Self::String(s) => write!(f, "\"{}\"", s),
Self::Float(float) => write!(f, "{float}"),
Self::Integer(i) => write!(f, "{i}"),
Self::String(s) => write!(f, "\"{s}\""),
}
}
}
6 changes: 3 additions & 3 deletions src/emit/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ impl<'a, 'input: 'a> From<&'a ParsedInlineComment<'input>> for Token<'input> {
inner: Cow::Borrowed(
comment
.inner
.strip_prefix("(")
.strip_prefix('(')
.unwrap()
.strip_suffix(")")
.strip_suffix(')')
.unwrap(),
),
}
Expand All @@ -46,7 +46,7 @@ impl<'input> From<&ParsedComment<'input>> for Token<'input> {
fn from(comment: &ParsedComment<'input>) -> Self {
Self::Comment {
is_inline: false,
inner: Cow::Borrowed(comment.inner.strip_prefix(";").unwrap()),
inner: Cow::Borrowed(comment.inner.strip_prefix(';').unwrap()),
}
}
}
Expand Down
12 changes: 3 additions & 9 deletions src/parse/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ impl std::ops::Add for Span {
}
impl std::ops::AddAssign for Span {
fn add_assign(&mut self, rhs: Self) {
*self = Self {
0: self.0.min(rhs.0),
1: self.1.max(rhs.1),
}
*self = Self(self.0.min(rhs.0), self.1.max(rhs.1))
}
}

Expand Down Expand Up @@ -150,7 +147,7 @@ impl<'input> Snippet<'input> {

/// Iterate by [u8] in the snippet.
pub fn iter_bytes(&self) -> impl Iterator<Item = &u8> {
self.iter().map(|line| line.iter_bytes()).flatten()
self.iter().flat_map(|line| line.iter_bytes())
}

/// Iterate by [Comment] in the snippet.
Expand Down Expand Up @@ -245,10 +242,7 @@ impl<'input> Line<'input> {

/// Iterate over [u8] in a [Line].
pub fn iter_bytes(&self) -> impl Iterator<Item = &u8> {
self.line_components
.iter()
.map(|c| c.iter_bytes())
.flatten()
self.line_components.iter().flat_map(|c| c.iter_bytes())
}

/// XORs bytes in a [Line] leading up to the asterisk of a [`Checksum`].
Expand Down
5 changes: 3 additions & 2 deletions src/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ fn decimal_err_into_str(err: Error) -> &'static str {
"precision necessary to represent exceeds the maximum possible"
}
Error::ErrorString(_) => "cannot parse as decimal (unable to display root cause)",
Error::Underflow => "cannot parse as decimal (unable to display root cause)",
Error::ConversionTo(_) => "cannot parse as decimal (unable to display root cause)",
Error::Underflow => "number contains more fractional digits than can be represented",
Error::ConversionTo(_) => "cannot convert to/from decimal type",
_ => "cannot parse as decimal (unknown root cause)",
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/parse/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<'input> Field<'input> {
self.letters
.as_bytes()
.iter()
.chain(self.raw_value.iter().map(|s| s.as_bytes().iter()).flatten())
.chain(self.raw_value.iter().flat_map(|s| s.as_bytes().iter()))
}
}

Expand Down Expand Up @@ -164,9 +164,8 @@ impl<'input> LineComponent<'input> {
pub fn iter_bytes(&'input self) -> impl Iterator<Item = &'input u8> + 'input {
self.field
.iter()
.map(|f| f.iter_bytes())
.flatten()
.chain(self.whitespace.iter().map(|w| w.iter_bytes()).flatten())
.chain(self.inline_comment.iter().map(|i| i.iter_bytes()).flatten())
.flat_map(|f| f.iter_bytes())
.chain(self.whitespace.iter().flat_map(|w| w.iter_bytes()))
.chain(self.inline_comment.iter().flat_map(|i| i.iter_bytes()))
}
}

0 comments on commit 6b9f41d

Please sign in to comment.