Skip to content

Commit

Permalink
Upgrade itertools dependency to ^0.11.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
olson-sean-k committed Sep 12, 2023
1 parent 800917d commit e484398
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ walk = ["dep:walkdir"]

[dependencies]
const_format = "^0.2.0"
itertools = "^0.10.0"
itertools = "^0.11.0"
nom = "^7.0.0"
pori = "=0.0.0"
thiserror = "^1.0.0"
Expand Down
19 changes: 9 additions & 10 deletions src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::fmt::Display;
use thiserror::Error;

use crate::token::Token;
use crate::PositionExt as _;

#[cfg(windows)]
const SEPARATOR_CLASS_EXPRESSION: &str = "/\\\\";
Expand Down Expand Up @@ -155,7 +154,7 @@ where
#[allow(clippy::double_parens)]
fn encode<'t, A, T>(
grouping: Grouping,
superposition: Option<Position<()>>,
superposition: Option<Position>,
pattern: &mut String,
tokens: impl IntoIterator<Item = T>,
) where
Expand All @@ -179,8 +178,8 @@ fn encode<'t, A, T>(

// TODO: Use `Grouping` everywhere a group is encoded. For invariant groups
// that ignore `grouping`, construct a local `Grouping` instead.
for token in tokens.into_iter().with_position() {
match token.interior_borrow().map(Token::kind).as_tuple() {
for (position, token) in tokens.into_iter().with_position() {
match (position, token.borrow().kind()) {
(_, Literal(literal)) => {
// TODO: Only encode changes to casing flags.
// TODO: Should Unicode support also be toggled by casing flags?
Expand Down Expand Up @@ -269,8 +268,8 @@ fn encode<'t, A, T>(
(_, Wildcard(One)) => grouping.push_str(pattern, nsepexpr!("{0}")),
(_, Wildcard(ZeroOrMore(Eager))) => grouping.push_str(pattern, nsepexpr!("{0}*")),
(_, Wildcard(ZeroOrMore(Lazy))) => grouping.push_str(pattern, nsepexpr!("{0}*?")),
(First(_), Wildcard(Tree { has_root })) => {
if let Some(Middle(_) | Last(_)) = superposition {
(First, Wildcard(Tree { has_root })) => {
if let Some(Middle | Last) = superposition {
encode_intermediate_tree(grouping, pattern);
}
else if *has_root {
Expand All @@ -282,11 +281,11 @@ fn encode<'t, A, T>(
pattern.push(')');
}
},
(Middle(_), Wildcard(Tree { .. })) => {
(Middle, Wildcard(Tree { .. })) => {
encode_intermediate_tree(grouping, pattern);
},
(Last(_), Wildcard(Tree { .. })) => {
if let Some(First(_) | Middle(_)) = superposition {
(Last, Wildcard(Tree { .. })) => {
if let Some(First | Middle) = superposition {
encode_intermediate_tree(grouping, pattern);
}
else {
Expand All @@ -295,7 +294,7 @@ fn encode<'t, A, T>(
pattern.push(')');
}
},
(Only(_), Wildcard(Tree { .. })) => grouping.push_str(pattern, ".*"),
(Only, Wildcard(Tree { .. })) => grouping.push_str(pattern, ".*"),
}
}
}
Expand Down
48 changes: 0 additions & 48 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ mod rule;
mod token;
mod walk;

use itertools::Position;
#[cfg(feature = "miette")]
use miette::Diagnostic;
use regex::Regex;
Expand Down Expand Up @@ -91,53 +90,6 @@ impl StrExt for str {
}
}

trait PositionExt<T> {
fn as_tuple(&self) -> (Position<()>, &T);

fn map<U, F>(self, f: F) -> Position<U>
where
F: FnMut(T) -> U;

fn interior_borrow<B>(&self) -> Position<&B>
where
T: Borrow<B>;
}

impl<T> PositionExt<T> for Position<T> {
fn as_tuple(&self) -> (Position<()>, &T) {
match *self {
Position::First(ref item) => (Position::First(()), item),
Position::Middle(ref item) => (Position::Middle(()), item),
Position::Last(ref item) => (Position::Last(()), item),
Position::Only(ref item) => (Position::Only(()), item),
}
}

fn map<U, F>(self, mut f: F) -> Position<U>
where
F: FnMut(T) -> U,
{
match self {
Position::First(item) => Position::First(f(item)),
Position::Middle(item) => Position::Middle(f(item)),
Position::Last(item) => Position::Last(f(item)),
Position::Only(item) => Position::Only(f(item)),
}
}

fn interior_borrow<B>(&self) -> Position<&B>
where
T: Borrow<B>,
{
match *self {
Position::First(ref item) => Position::First(item.borrow()),
Position::Middle(ref item) => Position::Middle(item.borrow()),
Position::Last(ref item) => Position::Last(item.borrow()),
Position::Only(ref item) => Position::Only(item.borrow()),
}
}
}

/// Token that captures matched text in a glob expression.
///
/// # Examples
Expand Down
10 changes: 5 additions & 5 deletions src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use walkdir::{self, DirEntry, WalkDir};
use crate::capture::MatchedText;
use crate::encode::CompileError;
use crate::token::{self, Token, TokenTree};
use crate::{BuildError, CandidatePath, Compose, Glob, PositionExt as _};
use crate::{BuildError, CandidatePath, Compose, Glob};

pub type WalkItem<'e> = Result<WalkEntry<'e>, WalkError>;

Expand Down Expand Up @@ -139,7 +139,7 @@ macro_rules! walk {
.strip_prefix(&$state.prefix)
.expect("path is not in tree");
let depth = entry.depth().saturating_sub(1);
for candidate in path
for (position, candidate) in path
.components()
.skip(depth)
.filter_map(|component| match component {
Expand All @@ -149,8 +149,8 @@ macro_rules! walk {
.zip_longest($state.components.iter().skip(depth))
.with_position()
{
match candidate.as_tuple() {
(First(_) | Middle(_), Both(component, pattern)) => {
match (position, candidate) {
(First | Middle, Both(component, pattern)) => {
if !pattern.is_match(component.as_ref()) {
// Do not descend into directories that do not match
// the corresponding component pattern.
Expand All @@ -160,7 +160,7 @@ macro_rules! walk {
continue 'walk;
}
}
(Last(_) | Only(_), Both(component, pattern)) => {
(Last | Only, Both(component, pattern)) => {
if pattern.is_match(component.as_ref()) {
let path = CandidatePath::from(path);
if let Some(matched) =
Expand Down

0 comments on commit e484398

Please sign in to comment.