Skip to content

Commit

Permalink
Merge pull request #697 from epage/update
Browse files Browse the repository at this point in the history
chore: Update winnow
  • Loading branch information
epage authored Mar 23, 2023
2 parents 08f154e + 243b4ef commit c504325
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 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 @@ -14,7 +14,7 @@ include.workspace = true
[dependencies]
anyhow = "1.0"
thiserror = "1.0"
winnow = "0.3.3"
winnow = "0.4.0"
unicode-xid = "0.2.4"
once_cell = "1.17.1"
serde = { version = "1.0", features = ["derive"] }
Expand Down
31 changes: 18 additions & 13 deletions crates/typos/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ mod parser {
<T as Stream>::Slice: AsBStr + SliceLen + Default,
<T as Stream>::Token: AsChar + Copy,
{
preceded(ignore, identifier)(input)
preceded(ignore, identifier).parse_next(input)
}

fn identifier<T>(input: T) -> IResult<T, <T as Stream>::Slice>
Expand All @@ -155,7 +155,7 @@ mod parser {
// `{XID_Continue}+` because XID_Continue is a superset of XID_Start and rather catch odd
// or unexpected cases than strip off start characters to a word since we aren't doing a
// proper word boundary parse
take_while1(is_xid_continue)(input)
take_while1(is_xid_continue).parse_next(input)
}

fn ignore<T>(input: T) -> IResult<T, <T as Stream>::Slice>
Expand All @@ -180,7 +180,8 @@ mod parser {
c_escape,
printf,
other,
)))(input)
)))
.parse_next(input)
}

fn sep1<T>(input: T) -> IResult<T, <T as Stream>::Slice>
Expand All @@ -192,7 +193,8 @@ mod parser {
alt((
one_of(|c| !is_xid_continue(c)).recognize(),
eof.map(|_| <T as Stream>::Slice::default()),
))(input)
))
.parse_next(input)
}

fn other<T>(input: T) -> IResult<T, <T as Stream>::Slice>
Expand Down Expand Up @@ -234,7 +236,7 @@ mod parser {
<T as Stream>::Slice: AsBStr + SliceLen + Default,
<T as Stream>::Token: AsChar + Copy,
{
take_while1(is_dec_digit_with_sep)(input)
take_while1(is_dec_digit_with_sep).parse_next(input)
}

fn hex_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
Expand All @@ -243,7 +245,7 @@ mod parser {
<T as Stream>::Slice: AsBStr + SliceLen + Default,
<T as Stream>::Token: AsChar + Copy,
{
preceded(('0', alt(('x', 'X'))), take_while1(is_hex_digit_with_sep))(input)
preceded(('0', alt(('x', 'X'))), take_while1(is_hex_digit_with_sep)).parse_next(input)
}

fn css_color<T>(input: T) -> IResult<T, <T as Stream>::Slice>
Expand All @@ -258,7 +260,8 @@ mod parser {
terminated(take_while_m_n(3, 8, is_lower_hex_digit), peek(sep1)),
terminated(take_while_m_n(3, 8, is_upper_hex_digit), peek(sep1)),
)),
)(input)
)
.parse_next(input)
}

fn uuid_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
Expand Down Expand Up @@ -315,7 +318,8 @@ mod parser {
alt((
take_while_m_n(IGNORE_HEX_MIN, IGNORE_HEX_MAX, is_lower_hex_digit),
take_while_m_n(IGNORE_HEX_MIN, IGNORE_HEX_MAX, is_upper_hex_digit),
))(input)
))
.parse_next(input)
}

fn base64_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
Expand All @@ -324,7 +328,7 @@ mod parser {
<T as Stream>::Slice: AsBStr + SliceLen + Default,
<T as Stream>::Token: AsChar + Copy,
{
let (padding, captured) = take_while1(is_base64_digit)(input.clone())?;
let (padding, captured) = take_while1(is_base64_digit).parse_next(input.clone())?;

const CHUNK: usize = 4;
let padding_offset = input.offset_to(&padding);
Expand All @@ -341,11 +345,12 @@ mod parser {
.all(|c| !['/', '+'].contains(&c.as_char()))
{
return Err(winnow::error::ErrMode::Backtrack(
winnow::error::Error::new(input, winnow::error::ErrorKind::LengthValue),
winnow::error::Error::new(input, winnow::error::ErrorKind::Slice),
));
}

let (after, _) = take_while_m_n(padding_len, padding_len, is_base64_padding)(padding)?;
let (after, _) =
take_while_m_n(padding_len, padding_len, is_base64_padding).parse_next(padding)?;

let after_offset = input.offset_to(&after);
Ok(input.next_slice(after_offset))
Expand Down Expand Up @@ -416,7 +421,7 @@ mod parser {
// regular string that does escaping. The escaped letter might be part of a word, or it
// might not be. Rather than guess and be wrong part of the time and correct people's words
// incorrectly, we opt for just not evaluating it at all.
preceded(take_while1(is_escape), take_while0(is_xid_continue))(input)
preceded(take_while1(is_escape), take_while0(is_xid_continue)).parse_next(input)
}

fn printf<T>(input: T) -> IResult<T, <T as Stream>::Slice>
Expand All @@ -425,7 +430,7 @@ mod parser {
<T as Stream>::Slice: AsBStr + SliceLen + Default,
<T as Stream>::Token: AsChar + Copy,
{
preceded('%', take_while1(is_xid_continue))(input)
preceded('%', take_while1(is_xid_continue)).parse_next(input)
}

fn take_many0<I, E, F>(mut f: F) -> impl FnMut(I) -> IResult<I, <I as Stream>::Slice, E>
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 @@ -16,7 +16,7 @@ parser = ["winnow"]
flags = ["enumflags2"]

[dependencies]
winnow = { version = "0.3.3", optional = true }
winnow = { version = "0.4.0", optional = true }
enumflags2 = { version = "0.7", optional = true }

[package.metadata.docs.rs]
Expand Down
18 changes: 11 additions & 7 deletions crates/varcon-core/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,20 @@ A B C: coloration's / B. Cv: colouration's
impl Entry {
pub fn parse(input: &str) -> IResult<&str, Self> {
let var_sep = (winnow::character::space0, '/', winnow::character::space0);
let (input, variants) = winnow::multi::separated1(Variant::parse, var_sep)(input)?;
let (input, variants) =
winnow::multi::separated1(Variant::parse, var_sep).parse_next(input)?;

let desc_sep = (winnow::character::space0, '|');
let (input, description) =
winnow::combinator::opt((desc_sep, Self::parse_description))(input)?;
winnow::combinator::opt((desc_sep, Self::parse_description)).parse_next(input)?;

let comment_sep = (winnow::character::space0, '#');
let (input, comment) = winnow::combinator::opt((
comment_sep,
winnow::character::space1,
winnow::character::not_line_ending,
))(input)?;
))
.parse_next(input)?;

let mut e = match description {
Some((_, description)) => description,
Expand Down Expand Up @@ -298,7 +300,8 @@ impl Variant {
pub fn parse(input: &str) -> IResult<&str, Self> {
let types = winnow::multi::separated1(Type::parse, winnow::character::space1);
let sep = (winnow::bytes::tag(":"), winnow::character::space0);
let (input, (types, word)) = winnow::sequence::separated_pair(types, sep, word)(input)?;
let (input, (types, word)) =
winnow::sequence::separated_pair(types, sep, word).parse_next(input)?;
let v = Self { types, word };
Ok((input, v))
}
Expand Down Expand Up @@ -380,8 +383,8 @@ mod test_variant {
impl Type {
pub fn parse(input: &str) -> IResult<&str, Type> {
let (input, category) = Category::parse(input)?;
let (input, tag) = winnow::combinator::opt(Tag::parse)(input)?;
let (input, num) = winnow::combinator::opt(winnow::character::digit1)(input)?;
let (input, tag) = winnow::combinator::opt(Tag::parse).parse_next(input)?;
let (input, num) = winnow::combinator::opt(winnow::character::digit1).parse_next(input)?;
let num = num.map(|s| s.parse().expect("parser ensured its a number"));
let t = Type { category, tag, num };
Ok((input, t))
Expand Down Expand Up @@ -517,7 +520,8 @@ impl Pos {
verb.value(Pos::Verb),
adjective.value(Pos::Adjective),
adverb.value(Pos::Adverb),
))(input)
))
.parse_next(input)
}
}

Expand Down

0 comments on commit c504325

Please sign in to comment.