Skip to content

Commit

Permalink
idle cleanup (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
CrockAgile committed Jan 25, 2024
1 parent bc2ef5e commit dec7d35
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 67 deletions.
3 changes: 2 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ use nom::{
};

#[derive(PartialEq, Eq, Debug, Clone)]
#[non_exhaustive]
pub enum Error {
ParseError(String),
GenerateError(String),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
match self {
Error::ParseError(ref s) | Error::GenerateError(ref s) => write!(f, "{s}"),
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ impl Expression {

/// Get iterator of `Term`s within `Expression`
pub fn terms_iter(&self) -> impl Iterator<Item = &Term> {
crate::slice_iter::SliceIter { slice: &self.terms }
self.terms.iter()
}

/// Get mutable iterator of `Term`s within `Expression`
pub fn terms_iter_mut(&mut self) -> impl Iterator<Item = &mut Term> {
crate::slice_iter::SliceIterMut {
slice: &mut self.terms,
}
self.terms.iter_mut()
}

/// Determine if this expression terminates or not, i.e contains all terminal elements or every
Expand Down
18 changes: 5 additions & 13 deletions src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,12 @@ impl<'gram> ParseTree<'gram> {

/// Iterate the "right hand side" parse tree nodes
pub fn rhs_iter(&self) -> impl Iterator<Item = &ParseTreeNode> {
crate::slice_iter::SliceIter { slice: &self.rhs }
self.rhs.iter()
}

/// Mutably iterate the "right hand side" parse tree nodes
pub fn rhs_iter_mut<'a>(&'a mut self) -> impl Iterator<Item = &'a mut ParseTreeNode<'gram>> {
crate::slice_iter::SliceIterMut {
slice: &mut self.rhs,
}
self.rhs.iter_mut()
}
}

Expand Down Expand Up @@ -240,16 +238,12 @@ impl Grammar {

/// Get iterator of the `Grammar`'s `Production`s
pub fn productions_iter(&self) -> impl Iterator<Item = &Production> {
crate::slice_iter::SliceIter {
slice: &self.productions,
}
self.productions.iter()
}

/// Get mutable iterator of the `Grammar`'s `Production`s
pub fn productions_iter_mut(&mut self) -> impl Iterator<Item = &mut Production> {
crate::slice_iter::SliceIterMut {
slice: &mut self.productions,
}
self.productions.iter_mut()
}

/// Parse input strings according to `Grammar`
Expand Down Expand Up @@ -470,9 +464,7 @@ impl Grammar {
}
}

terminating_rules
.into_iter()
.any(|term| term == starting_term)
terminating_rules.contains(&starting_term)
}
}

Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod expression;
mod grammar;
mod parsers;
mod production;
mod slice_iter;
mod term;
mod tracing;
pub use crate::error::Error;
Expand Down
6 changes: 2 additions & 4 deletions src/production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ impl Production {

/// Get iterator of the `Production`'s right hand side `Expression`s
pub fn rhs_iter(&self) -> impl Iterator<Item = &Expression> {
crate::slice_iter::SliceIter { slice: &self.rhs }
self.rhs.iter()
}

/// Get mutable iterator of the `Production`'s right hand side `Expression`s
pub fn rhs_iter_mut(&mut self) -> impl Iterator<Item = &mut Expression> {
crate::slice_iter::SliceIterMut {
slice: &mut self.rhs,
}
self.rhs.iter_mut()
}

/// Get number of right hand side `Expression`s
Expand Down
44 changes: 0 additions & 44 deletions src/slice_iter.rs

This file was deleted.

0 comments on commit dec7d35

Please sign in to comment.