Skip to content

Commit

Permalink
Merge pull request #1220 from epage/w7
Browse files Browse the repository at this point in the history
chore: Update to Winnow 0.7
  • Loading branch information
epage authored Jan 30, 2025
2 parents 3683264 + ba04a1a commit 4f604f6
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 41 deletions.
19 changes: 14 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/typos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]

[dependencies]
winnow = "0.6.7"
winnow = "0.7.0"
unicode-xid = "0.2.4"
serde = { version = "1.0", features = ["derive"] }
simdutf8 = "0.1.4"
Expand Down
43 changes: 21 additions & 22 deletions crates/typos/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,13 @@ mod parser {
use winnow::stream::Stream;
use winnow::stream::StreamIsPartial;
use winnow::token::{one_of, take_while};
use winnow::Result;

/// Avoid worst-case parse times by limiting how much a `take_while` can take if something
/// later may cause it to fail.
const NON_TERMINATING_CAP: usize = 1024;

pub(crate) fn next_identifier<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
pub(crate) fn next_identifier<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Compare<char>,
T: Stream + StreamIsPartial + PartialEq,
Expand All @@ -155,7 +156,7 @@ mod parser {
preceded(ignore, identifier).parse_next(input)
}

fn identifier<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn identifier<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Stream + StreamIsPartial + PartialEq,
<T as Stream>::Slice: AsBStr + SliceLen + Default,
Expand All @@ -173,7 +174,7 @@ mod parser {
.parse_next(input)
}

fn ignore<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn ignore<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Compare<char>,
T: Stream + StreamIsPartial + PartialEq,
Expand Down Expand Up @@ -204,7 +205,7 @@ mod parser {
.parse_next(input)
}

fn sep1<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn sep1<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Stream + StreamIsPartial + PartialEq,
<T as Stream>::Slice: AsBStr + SliceLen + Default,
Expand All @@ -217,7 +218,7 @@ mod parser {
.parse_next(input)
}

fn other<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn other<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Stream + StreamIsPartial + PartialEq,
<T as Stream>::Slice: AsBStr + SliceLen + Default,
Expand All @@ -234,7 +235,7 @@ mod parser {
.parse_next(input)
}

fn ordinal_literal<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn ordinal_literal<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Compare<char>,
T: Stream + StreamIsPartial + PartialEq,
Expand All @@ -260,7 +261,7 @@ mod parser {
.parse_next(input)
}

fn dec_literal<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn dec_literal<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Stream + StreamIsPartial + PartialEq,
<T as Stream>::Slice: AsBStr + SliceLen + Default,
Expand All @@ -269,7 +270,7 @@ mod parser {
trace("dec_literal", take_while(1.., is_dec_digit_with_sep)).parse_next(input)
}

fn hex_literal<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn hex_literal<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Compare<char>,
T: Stream + StreamIsPartial + PartialEq,
Expand All @@ -281,7 +282,7 @@ mod parser {
.parse_next(input)
}

fn css_color<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn css_color<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Compare<char>,
T: Stream + StreamIsPartial + PartialEq,
Expand All @@ -302,7 +303,7 @@ mod parser {
.parse_next(input)
}

fn jwt<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn jwt<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Compare<char>,
T: Stream + StreamIsPartial + PartialEq,
Expand Down Expand Up @@ -337,7 +338,7 @@ mod parser {
|| c == '-'
}

fn uuid_literal<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn uuid_literal<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Compare<char>,
T: Stream + StreamIsPartial + PartialEq,
Expand Down Expand Up @@ -375,7 +376,7 @@ mod parser {
.parse_next(input)
}

fn hash_literal<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn hash_literal<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Stream + StreamIsPartial + PartialEq,
<T as Stream>::Slice: AsBStr + SliceLen + Default,
Expand All @@ -401,7 +402,7 @@ mod parser {
.parse_next(input)
}

fn base64_literal<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn base64_literal<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Stream + StreamIsPartial + PartialEq,
<T as Stream>::Slice: AsBStr + SliceLen + Default,
Expand All @@ -425,10 +426,8 @@ mod parser {
.iter()
.all(|c| !['/', '+'].contains(&c.as_char()))
{
return Err(winnow::error::ErrMode::from_error_kind(
input,
winnow::error::ErrorKind::Slice,
));
#[allow(clippy::unit_arg)]
return Err(ParserError::from_input(input));
}

take_while(padding_len..=padding_len, is_base64_padding).parse_next(input)?;
Expand All @@ -440,7 +439,7 @@ mod parser {
.parse_next(input)
}

fn email_literal<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn email_literal<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Compare<char>,
T: Stream + StreamIsPartial + PartialEq,
Expand All @@ -459,7 +458,7 @@ mod parser {
.parse_next(input)
}

fn url_literal<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn url_literal<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Compare<char>,
T: Stream + StreamIsPartial + PartialEq,
Expand Down Expand Up @@ -492,7 +491,7 @@ mod parser {
.parse_next(input)
}

fn url_userinfo<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn url_userinfo<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Compare<char>,
T: Stream + StreamIsPartial + PartialEq,
Expand All @@ -510,7 +509,7 @@ mod parser {
.parse_next(input)
}

fn c_escape<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn c_escape<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Stream + StreamIsPartial + PartialEq,
<T as Stream>::Slice: AsBStr + SliceLen + Default,
Expand All @@ -531,7 +530,7 @@ mod parser {
.parse_next(input)
}

fn printf<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
fn printf<T>(input: &mut T) -> Result<<T as Stream>::Slice, ()>
where
T: Compare<char>,
T: Stream + StreamIsPartial + PartialEq,
Expand Down
2 changes: 1 addition & 1 deletion crates/varcon-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parser = ["dep:winnow"]
flags = ["dep:enumflags2"]

[dependencies]
winnow = { version = "0.6.7", optional = true }
winnow = { version = "0.7.0", optional = true }
enumflags2 = { version = "0.7", optional = true }

[lints]
Expand Down
24 changes: 12 additions & 12 deletions crates/varcon-core/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ impl Cluster {
Self::parse_.parse(input).map_err(|_err| ParseError)
}

fn parse_(input: &mut &str) -> PResult<Self, ()> {
fn parse_(input: &mut &str) -> ModalResult<Self, ()> {
trace("cluster", move |input: &mut &str| {
let header = (
"#",
Expand Down Expand Up @@ -966,7 +966,7 @@ impl Entry {
Self::parse_.parse(input).map_err(|_err| ParseError)
}

fn parse_(input: &mut &str) -> PResult<Self, ()> {
fn parse_(input: &mut &str) -> ModalResult<Self, ()> {
trace("entry", move |input: &mut &str| {
let var_sep = (winnow::ascii::space0, '/', winnow::ascii::space0);
let variants =
Expand All @@ -987,7 +987,7 @@ impl Entry {
.parse_next(input)
}

fn parse_description(input: &mut &str) -> PResult<Self, ()> {
fn parse_description(input: &mut &str) -> ModalResult<Self, ()> {
trace("description", move |input: &mut &str| {
let mut entry = Self {
variants: Vec::new(),
Expand Down Expand Up @@ -1023,18 +1023,18 @@ impl Entry {
}
}

fn note(input: &mut &str) -> PResult<String, ()> {
fn note(input: &mut &str) -> ModalResult<String, ()> {
let (_, _, note) = (NOTE_PREFIX, space1, description).parse_next(input)?;
Ok(note)
}

const NOTE_PREFIX: &str = "--";

fn archaic(input: &mut &str) -> PResult<(), ()> {
fn archaic(input: &mut &str) -> ModalResult<(), ()> {
"(-)".void().parse_next(input)
}

fn description(input: &mut &str) -> PResult<String, ()> {
fn description(input: &mut &str) -> ModalResult<String, ()> {
let description = winnow::token::take_till(0.., ('\n', '\r', '#', '|')).parse_next(input)?;
Ok(description.to_owned())
}
Expand Down Expand Up @@ -1573,7 +1573,7 @@ impl Variant {
Self::parse_.parse(input).map_err(|_err| ParseError)
}

fn parse_(input: &mut &str) -> PResult<Self, ()> {
fn parse_(input: &mut &str) -> ModalResult<Self, ()> {
trace("variant", move |input: &mut &str| {
let types = winnow::combinator::separated(1.., Type::parse_, space1);
let columns =
Expand All @@ -1592,7 +1592,7 @@ impl Variant {
}
}

fn word(input: &mut &str) -> PResult<String, ()> {
fn word(input: &mut &str) -> ModalResult<String, ()> {
trace("word", move |input: &mut &str| {
winnow::token::take_till(1.., |item: char| item.is_ascii_whitespace())
.map(|s: &str| s.to_owned().replace('_', " "))
Expand Down Expand Up @@ -1734,7 +1734,7 @@ impl Type {
Self::parse_.parse(input).map_err(|_err| ParseError)
}

fn parse_(input: &mut &str) -> PResult<Type, ()> {
fn parse_(input: &mut &str) -> ModalResult<Type, ()> {
trace("type", move |input: &mut &str| {
let category = Category::parse_(input)?;
let tag = opt(Tag::parse_).parse_next(input)?;
Expand Down Expand Up @@ -1850,7 +1850,7 @@ impl Category {
Self::parse_.parse(input).map_err(|_err| ParseError)
}

fn parse_(input: &mut &str) -> PResult<Self, ()> {
fn parse_(input: &mut &str) -> ModalResult<Self, ()> {
trace("category", move |input: &mut &str| {
let symbols = one_of(['A', 'B', 'Z', 'C', 'D', '_']);
symbols
Expand Down Expand Up @@ -1909,7 +1909,7 @@ impl Tag {
Self::parse_.parse(input).map_err(|_err| ParseError)
}

fn parse_(input: &mut &str) -> PResult<Self, ()> {
fn parse_(input: &mut &str) -> ModalResult<Self, ()> {
trace("tag", move |input: &mut &str| {
let symbols = one_of(['.', 'v', 'V', '-', 'x']);
symbols
Expand Down Expand Up @@ -1967,7 +1967,7 @@ impl Pos {
Self::parse_.parse(input).map_err(|_err| ParseError)
}

fn parse_(input: &mut &str) -> PResult<Self, ()> {
fn parse_(input: &mut &str) -> ModalResult<Self, ()> {
trace("pos", move |input: &mut &str| {
alt((
"N".value(Pos::Noun),
Expand Down

0 comments on commit 4f604f6

Please sign in to comment.