Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ All user visible changes to `cucumber-expressions` crate will be documented in t
- Bumped up [MSRV] to 1.81 because for `#[expect]` attribute usage. ([e1bb9266])
- Upgraded [`nom`] to 8.0 version and [`nom_locate`] to 5.0 version. ([#14], [todo])

### Updated

- [`derive_more`] to 2.0 version. ([#13])

[#13]: /../../pull/13
[#14]: /../../pull/14
[e1bb9266]: /../../commit/e1bb92668617432948ab0faa32232b67d6c530e7
[todo]: /../../commit/todo
Expand Down Expand Up @@ -97,7 +102,6 @@ All user visible changes to `cucumber-expressions` crate will be documented in t
- [`derive_more`] minimal version to `0.99.17`. ([#5])

[#5]: /../../pull/5
[`derive_more`]: https://docs.rs/derive_more



Expand All @@ -120,7 +124,9 @@ All user visible changes to `cucumber-expressions` crate will be documented in t



[`derive_more`]: https://docs.rs/derive_more
[`nom`]: https://docs.rs/nom
[`nom_locate`]: https://docs.rs/nom_locate
[`regex`]: https://docs.rs/regex
[`Regex`]: https://docs.rs/regex
[`regex-syntax`]: https://docs.rs/regex-syntax
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rustdoc-args = ["--cfg", "docsrs"]
into-regex = ["dep:either", "dep:regex", "dep:regex-syntax"]

[dependencies]
derive_more = { version = "0.99.17", features = ["as_ref", "deref", "deref_mut", "display", "error", "from", "into"], default-features = false }
derive_more = { version = "2.0", features = ["as_ref", "debug", "deref", "deref_mut", "display", "error", "from"] }
nom = "8.0"
nom_locate = "5.0"

Expand Down
2 changes: 1 addition & 1 deletion src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! [1]: https://github.com/cucumber/cucumber-expressions#readme
//! [AST]: https://en.wikipedia.org/wiki/Abstract_syntax_tree

use derive_more::{AsRef, Deref, DerefMut};
use derive_more::with_trait::{AsRef, Deref, DerefMut};
use nom::{error::ErrorKind, Err, Input};
use nom_locate::LocatedSpan;

Expand Down
62 changes: 21 additions & 41 deletions src/expand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

pub mod parameters;

use std::{fmt, iter, str, vec};
use std::{iter, str, vec};

use derive_more::{Display, Error, From};
use derive_more::with_trait::{Debug, Display, Error as StdError, From};
use either::Either;
use nom::{AsChar, Input};
use regex::Regex;
Expand Down Expand Up @@ -139,41 +139,32 @@ impl<'s> Expression<Spanned<'s>> {
/// [Cucumber Expression][0] and expanding it into a [`Regex`].
///
/// [0]: https://github.com/cucumber/cucumber-expressions#readme
#[derive(Clone, Debug, Display, Error, From)]
pub enum Error<Input>
where
Input: fmt::Display,
{
#[derive(Clone, Debug, Display, From, StdError)]
pub enum Error<Input> {
/// Parsing error.
#[display(fmt = "Parsing failed: {}", _0)]
#[display("Parsing failed: {_0}")]
Parsing(parse::Error<Input>),

/// Expansion error.
#[display(fmt = "Failed to expand regex: {}", _0)]
#[display("Failed to expand regex: {_0}")]
Expansion(ParameterError<Input>),

/// [`Regex`] creation error.
#[display(fmt = "Regex creation failed: {}", _0)]
#[display("Regex creation failed: {_0}")]
Regex(regex::Error),
}

/// Possible [`Parameter`] errors being used in an [`Expression`].
#[derive(Clone, Debug, Display, Error)]
pub enum ParameterError<Input>
where
Input: fmt::Display,
{
#[derive(Clone, Debug, Display, StdError)]
pub enum ParameterError<Input> {
/// [`Parameter`] not found.
#[display(fmt = "Parameter `{}` not found.", _0)]
#[display("Parameter `{_0}` not found")]
NotFound(Input),

/// Failed to rename [`Regex`] capturing group.
#[display(
fmt = "Failed to rename capturing groups in regex `{}` of \
parameter `{}`: {}",
re,
parameter,
err
"Failed to rename capturing groups in regex `{re}` of \
parameter `{parameter}`: {err}"
)]
RenameRegexGroup {
/// [`Parameter`] name.
Expand All @@ -195,8 +186,8 @@ where
/// [0]: https://github.com/cucumber/cucumber-expressions#readme
/// [1]: https://git.io/J159T
/// [AST]: https://en.wikipedia.org/wiki/Abstract_syntax_tree
pub trait IntoRegexCharIter<I: fmt::Display> {
/// Type of an [`Iterator`] performing the expansion.
pub trait IntoRegexCharIter<I> {
/// Type of [`Iterator`] performing the expansion.
type Iter: Iterator<Item = Result<char, ParameterError<I>>>;

/// Consumes this [AST] element returning an [`Iterator`] over [`char`]s
Expand All @@ -208,7 +199,7 @@ pub trait IntoRegexCharIter<I: fmt::Display> {

impl<I> IntoRegexCharIter<I> for Expression<I>
where
I: Clone + fmt::Display + Input,
I: Clone + Display + Input,
<I as Input>::Item: AsChar,
{
type Iter = ExpressionIter<I>;
Expand Down Expand Up @@ -243,7 +234,7 @@ type ExpressionIter<I> = iter::Chain<

impl<I> IntoRegexCharIter<I> for SingleExpression<I>
where
I: Clone + fmt::Display + Input,
I: Clone + Display + Input,
<I as Input>::Item: AsChar,
{
type Iter = SingleExpressionIter<I>;
Expand Down Expand Up @@ -289,7 +280,7 @@ type SingleExpressionIter<I> = Either<

impl<I> IntoRegexCharIter<I> for Alternation<I>
where
I: fmt::Display + Input,
I: Display + Input,
<I as Input>::Item: AsChar,
{
type Iter = AlternationIter<I>;
Expand Down Expand Up @@ -344,7 +335,7 @@ type AlternationIterInner<I> = iter::Chain<

impl<I> IntoRegexCharIter<I> for Alternative<I>
where
I: fmt::Display + Input,
I: Display + Input,
<I as Input>::Item: AsChar,
{
type Iter = AlternativeIter<I>;
Expand Down Expand Up @@ -378,7 +369,7 @@ type AlternativeIter<I> = Either<

impl<I> IntoRegexCharIter<I> for Optional<I>
where
I: fmt::Display + Input,
I: Display + Input,
<I as Input>::Item: AsChar,
{
type Iter = OptionalIter<I>;
Expand Down Expand Up @@ -415,7 +406,7 @@ type MapOkChar<I> = fn(char) -> Result<char, ParameterError<I>>;

impl<I> IntoRegexCharIter<I> for Parameter<I>
where
I: Clone + fmt::Display + Input,
I: Clone + Display + Input,
<I as Input>::Item: AsChar,
{
type Iter = ParameterIter<I>;
Expand Down Expand Up @@ -483,6 +474,7 @@ type ParameterIter<I> = Either<
/// [`Iterator`] for skipping a last [`Item`].
///
/// [`Item`]: Iterator::Item
#[derive(Debug)]
pub struct SkipLast<Iter: Iterator> {
/// Inner [`Iterator`] to skip the last [`Item`] from.
///
Expand All @@ -502,18 +494,6 @@ where
}
}

impl<Iter> fmt::Debug for SkipLast<Iter>
where
Iter: fmt::Debug + Iterator,
Iter::Item: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SkipLast")
.field("iter", &self.iter)
.finish()
}
}

impl<Iter: Iterator> SkipLast<Iter> {
/// Creates a new [`SkipLast`] [`Iterator`].
pub fn new(iter: Iter) -> Self {
Expand Down
5 changes: 2 additions & 3 deletions src/expand/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,8 @@ mod regex_hir {
HirKind::Look(l) => Hir::look(l),
HirKind::Repetition(rep) => Hir::repetition(rep),
HirKind::Capture(mut capture) => {
capture.name = Some(
format!("__{parameter_id}_{}", *group_id_indexer).into(),
);
capture.name =
Some(format!("__{parameter_id}_{group_id_indexer}").into());
*group_id_indexer += 1;

let inner_hir =
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@
unused_results,
variant_size_differences
)]
// TODO: Remove on next `derive_more` major version.
#![expect(clippy::uninlined_format_args, reason = "`derive_more` expansion")]

pub mod ast;
mod combinator;
Expand Down
Loading