Skip to content

Commit

Permalink
edition 2024: cargo fix --edition (#169)
Browse files Browse the repository at this point in the history
* edition 2024: cargo fix --edition

* edition 2024: cargo fmt

* manual review
  • Loading branch information
CrockAgile authored Feb 21, 2025
1 parent fd16396 commit a8e52a3
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "bnf"
# don't manually edit this version unless you're sure you want to circumvent the process documented in RELEASE.md
version = "0.5.0"
edition = "2021"
edition = "2024"
authors = ["@shnewto", "@CrockAgile"]

description = "A library for parsing Backus–Naur form context-free grammars"
Expand Down
2 changes: 1 addition & 1 deletion benches/criterion.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod util;

use bnf::Grammar;
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{Criterion, criterion_group, criterion_main};
use rand::seq::IndexedRandom;

fn examples(c: &mut Criterion) {
Expand Down
8 changes: 4 additions & 4 deletions src/earley/grammar.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::append_vec::{append_only_vec_id, AppendOnlyVec};
use crate::{tracing, Term};
use crate::append_vec::{AppendOnlyVec, append_only_vec_id};
use crate::{Term, tracing};

append_only_vec_id!(pub(crate) ProductionId);

Expand Down Expand Up @@ -60,15 +60,15 @@ impl<'gram, 'a> ParseGrammar<'gram> {
pub fn get_productions_by_lhs(
&self,
lhs: &'gram crate::Term,
) -> impl Iterator<Item = &Production<'gram>> {
) -> impl Iterator<Item = &Production<'gram>> + use<'_, 'gram> {
self.prods_by_lhs
.get(lhs)
.into_iter()
.flatten()
.map(|prod_id| self.get_production_by_id(*prod_id))
}
#[cfg(test)]
pub fn productions_iter(&self) -> impl Iterator<Item = &Production<'gram>> {
pub fn productions_iter(&self) -> impl Iterator<Item = &Production<'gram>> + use<'_, 'gram> {
self.productions.iter()
}
}
14 changes: 7 additions & 7 deletions src/earley/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod grammar;
mod input_range;
mod traversal;

use crate::{tracing, ParseTree, ParseTreeNode, Term};
use crate::{ParseTree, ParseTreeNode, Term, tracing};
use grammar::{ParseGrammar, Production};
use input_range::InputRange;
use std::collections::{BTreeSet, HashSet, VecDeque};
Expand Down Expand Up @@ -255,20 +255,20 @@ pub(crate) struct CompletionMap<'gram> {
}

impl<'gram> CompletionMap<'gram> {
pub fn get_incomplete(
&'_ self,
pub fn get_incomplete<'map>(
&'map self,
term: &'gram Term,
complete_traversal: &Traversal<'gram>,
) -> impl Iterator<Item = TraversalId> + '_ {
) -> impl Iterator<Item = TraversalId> + use<'map> {
let _span = tracing::span!(tracing::Level::DEBUG, "get_incomplete").entered();
let key = CompletionKey::new_start(term, &complete_traversal.input_range);
self.incomplete.get(&key).into_iter().flatten().cloned()
}
pub fn get_complete(
&'_ self,
pub fn get_complete<'map>(
&'map self,
term: &'gram Term,
input_range: &InputRange<'gram>,
) -> impl Iterator<Item = TraversalId> + '_ {
) -> impl Iterator<Item = TraversalId> + use<'map> {
let _span = tracing::span!(tracing::Level::DEBUG, "get_complete").entered();
let key = CompletionKey::new_total(term, input_range);
self.complete.get(&key).into_iter().flatten().cloned()
Expand Down
9 changes: 5 additions & 4 deletions src/earley/traversal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::{grammar::ProductionId, InputRange, Production};
use super::{InputRange, Production, grammar::ProductionId};
use crate::{
append_vec::{append_only_vec_id, AppendOnlyVec},
tracing, Term,
Term,
append_vec::{AppendOnlyVec, append_only_vec_id},
tracing,
};

append_only_vec_id!(pub(crate) TraversalId);
Expand Down Expand Up @@ -252,8 +253,8 @@ impl<'gram> TraversalTree<'gram> {
#[cfg(test)]
mod tests {
use super::*;
use crate::earley::ParseGrammar;
use crate::Grammar;
use crate::earley::ParseGrammar;

fn dna_grammar() -> Grammar {
let grammar: Grammar = "<dna> ::= <base> | <base> <dna>
Expand Down
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::error;
use std::fmt;
use std::str;

use nom::{error::ErrorKind, Err};
use nom::{Err, error::ErrorKind};

#[derive(PartialEq, Eq, Debug, Clone)]
#[non_exhaustive]
Expand All @@ -14,7 +14,7 @@ pub enum Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::ParseError(ref s) | Error::GenerateError(ref s) => write!(f, "{s}"),
Error::ParseError(s) | Error::GenerateError(s) => write!(f, "{s}"),
}
}
}
Expand Down Expand Up @@ -43,7 +43,7 @@ impl From<(&'_ str, ErrorKind)> for Error {
#[cfg(test)]
mod tests {
use crate::error::Error;
use nom::{bytes::complete::tag, Err, IResult};
use nom::{Err, IResult, bytes::complete::tag};

fn give_error_kind(input: &str) -> IResult<&str, &str> {
let (input, _) = tag("1234")(input)?;
Expand Down
2 changes: 1 addition & 1 deletion src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::fmt;
use std::ops;
use std::str::FromStr;

use nom::combinator::all_consuming;
use nom::Parser;
use nom::combinator::all_consuming;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

Expand Down
10 changes: 5 additions & 5 deletions src/grammar.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![allow(clippy::vec_init_then_push)]

#[cfg(feature = "ABNF")]
use crate::ABNF;
use crate::error::Error;
use crate::expression::Expression;
use crate::parsers::{self, Format, BNF};
use crate::parsers::{self, BNF, Format};
use crate::production::Production;
use crate::term::Term;
#[cfg(feature = "ABNF")]
use crate::ABNF;
use rand::{rng, rngs::StdRng, seq::IndexedRandom, Rng, SeedableRng};
use rand::{Rng, SeedableRng, rng, rngs::StdRng, seq::IndexedRandom};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -631,7 +631,7 @@ mod tests {
fn to_string_and_back() {
QuickCheck::new()
.tests(1000)
.gen(Gen::new(12usize))
.r#gen(Gen::new(12usize))
.quickcheck(prop_to_string_and_back as fn(Grammar) -> TestResult);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ pub use crate::term::Term;

#[cfg(feature = "ABNF")]
pub use parsers::ABNF;
pub use parsers::{Format, BNF};
pub use parsers::{BNF, Format};

pub(crate) use hashbrown::HashMap;
2 changes: 1 addition & 1 deletion src/parsers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use crate::production::Production;
use crate::term::Term;

use nom::{
IResult, Parser,
branch::alt,
bytes::complete::{tag, take_till, take_until},
character::complete::{self, multispace0, satisfy},
combinator::{all_consuming, eof, not, opt, peek, recognize},
multi::many1,
sequence::{delimited, preceded, terminated},
IResult, Parser,
};
use nom_xt::xt_list_with_separator;

Expand Down
2 changes: 1 addition & 1 deletion src/parsers/nom_xt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use nom::{error::ParseError, Input, Parser};
use nom::{Input, Parser, error::ParseError};

///like `nom::many1` but it accepts a secend parser as an element separator
pub fn xt_list_with_separator<I, F, D, E>(
Expand Down
4 changes: 2 additions & 2 deletions src/production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::parsers::{self, BNF};
use crate::term::Term;
use std::fmt;

use nom::combinator::all_consuming;
use nom::Parser;
use nom::combinator::all_consuming;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -191,7 +191,7 @@ mod tests {
fn to_string_and_back() {
QuickCheck::new()
.tests(1000)
.gen(Gen::new(25usize))
.r#gen(Gen::new(25usize))
.quickcheck(prop_to_string_and_back as fn(Production) -> TestResult)
}

Expand Down
4 changes: 2 additions & 2 deletions src/term.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#![allow(clippy::should_implement_trait)]

use crate::Production;
use crate::error::Error;
use crate::expression::Expression;
use crate::parsers::{self, BNF};
use crate::Production;
use std::fmt;
use std::ops;
use std::str::FromStr;

use nom::combinator::all_consuming;
use nom::Parser;
use nom::combinator::all_consuming;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(feature = "tracing")]
mod defs {
pub(crate) use tracing::{event, span, Level};
pub(crate) use tracing::{Level, event, span};

#[allow(dead_code)]
pub fn init_subscriber() {
Expand Down
14 changes: 7 additions & 7 deletions tests/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use bnf::Grammar;
use quickcheck::{Arbitrary, Gen, QuickCheck, TestResult};
use rand::{rngs::StdRng, SeedableRng};
use rand::{SeedableRng, rngs::StdRng};
use std::sync::LazyLock;

#[derive(PartialEq, Debug, Clone)]
Expand Down Expand Up @@ -45,14 +45,14 @@ static GRAMMAR_FOR_ABNF: LazyLock<Grammar> = LazyLock::new(|| {
grammar_abnf
});

fn generate_grammar_with_gen<T>(gen: &mut Gen, grammar: &Grammar) -> T
fn generate_grammar_with_gen<T>(r#gen: &mut Gen, grammar: &Grammar) -> T
where
T: From<String>,
{
let seed: [u8; 32] = {
let mut seed = [0u8; 32];
for byte in seed.iter_mut() {
*byte = Arbitrary::arbitrary(gen);
*byte = Arbitrary::arbitrary(r#gen);
}
seed
};
Expand All @@ -66,15 +66,15 @@ where
}

impl Arbitrary for MetaBNF {
fn arbitrary(gen: &mut Gen) -> Self {
generate_grammar_with_gen(gen, &GRAMMAR_FOR_BNF)
fn arbitrary(r#gen: &mut Gen) -> Self {
generate_grammar_with_gen(r#gen, &GRAMMAR_FOR_BNF)
}
}

#[cfg(feature = "ABNF")]
impl Arbitrary for MetaABNF {
fn arbitrary(gen: &mut Gen) -> Self {
generate_grammar_with_gen(gen, &GRAMMAR_FOR_ABNF)
fn arbitrary(r#gen: &mut Gen) -> Self {
generate_grammar_with_gen(r#gen, &GRAMMAR_FOR_ABNF)
}
}

Expand Down

0 comments on commit a8e52a3

Please sign in to comment.