mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-25 02:20:58 -05:00
refactor: Resolve deprecations
This commit is contained in:
parent
15e748d0e5
commit
d99eb1601b
2 changed files with 142 additions and 167 deletions
|
@ -126,8 +126,7 @@ impl<'s> Iterator for Utf8Chunks<'s> {
|
||||||
|
|
||||||
mod parser {
|
mod parser {
|
||||||
use winnow::branch::*;
|
use winnow::branch::*;
|
||||||
use winnow::bytes::complete::*;
|
use winnow::bytes::*;
|
||||||
use winnow::character::complete::*;
|
|
||||||
use winnow::combinator::*;
|
use winnow::combinator::*;
|
||||||
use winnow::prelude::*;
|
use winnow::prelude::*;
|
||||||
use winnow::sequence::*;
|
use winnow::sequence::*;
|
||||||
|
@ -135,10 +134,11 @@ mod parser {
|
||||||
use winnow::stream::AsChar;
|
use winnow::stream::AsChar;
|
||||||
use winnow::stream::SliceLen;
|
use winnow::stream::SliceLen;
|
||||||
use winnow::stream::Stream;
|
use winnow::stream::Stream;
|
||||||
|
use winnow::stream::StreamIsPartial;
|
||||||
|
|
||||||
pub(crate) fn next_identifier<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
pub(crate) fn next_identifier<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
|
@ -147,7 +147,7 @@ mod parser {
|
||||||
|
|
||||||
fn identifier<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn identifier<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
|
@ -160,7 +160,7 @@ mod parser {
|
||||||
|
|
||||||
fn ignore<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn ignore<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
|
@ -185,31 +185,30 @@ mod parser {
|
||||||
|
|
||||||
fn sep1<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn sep1<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
alt((
|
alt((
|
||||||
recognize(satisfy(|c| !is_xid_continue(c))),
|
one_of(|c| !is_xid_continue(c)).recognize(),
|
||||||
map(eof, |_| <T as Stream>::Slice::default()),
|
eof.map(|_| <T as Stream>::Slice::default()),
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn other<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn other<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
recognize(tuple((
|
(one_of(|c| !is_xid_continue(c)), take_while0(is_ignore_char))
|
||||||
satisfy(|c| !is_xid_continue(c)),
|
.recognize()
|
||||||
take_while(is_ignore_char),
|
.parse_next(input)
|
||||||
)))(input)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ordinal_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn ordinal_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
|
@ -219,22 +218,19 @@ mod parser {
|
||||||
['_'].contains(&c)
|
['_'].contains(&c)
|
||||||
}
|
}
|
||||||
|
|
||||||
recognize(tuple((
|
(
|
||||||
take_while(is_sep),
|
take_while0(is_sep),
|
||||||
take_while1(is_dec_digit),
|
take_while1(is_dec_digit),
|
||||||
alt((
|
alt((('s', 't'), ('n', 'd'), ('r', 'd'), ('t', 'h'))),
|
||||||
pair(char('s'), char('t')),
|
take_while0(is_sep),
|
||||||
pair(char('n'), char('d')),
|
)
|
||||||
pair(char('r'), char('d')),
|
.recognize()
|
||||||
pair(char('t'), char('h')),
|
.parse_next(input)
|
||||||
)),
|
|
||||||
take_while(is_sep),
|
|
||||||
)))(input)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn dec_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
|
@ -243,24 +239,21 @@ mod parser {
|
||||||
|
|
||||||
fn hex_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn hex_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
preceded(
|
preceded(('0', alt(('x', 'X'))), take_while1(is_hex_digit_with_sep))(input)
|
||||||
pair(char('0'), alt((char('x'), char('X')))),
|
|
||||||
take_while1(is_hex_digit_with_sep),
|
|
||||||
)(input)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn css_color<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn css_color<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
preceded(
|
preceded(
|
||||||
char('#'),
|
'#',
|
||||||
alt((
|
alt((
|
||||||
terminated(take_while_m_n(3, 8, is_lower_hex_digit), peek(sep1)),
|
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)),
|
terminated(take_while_m_n(3, 8, is_upper_hex_digit), peek(sep1)),
|
||||||
|
@ -270,39 +263,41 @@ mod parser {
|
||||||
|
|
||||||
fn uuid_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn uuid_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
recognize(alt((
|
alt((
|
||||||
tuple((
|
(
|
||||||
take_while_m_n(8, 8, is_lower_hex_digit),
|
take_while_m_n(8, 8, is_lower_hex_digit),
|
||||||
char('-'),
|
'-',
|
||||||
take_while_m_n(4, 4, is_lower_hex_digit),
|
take_while_m_n(4, 4, is_lower_hex_digit),
|
||||||
char('-'),
|
'-',
|
||||||
take_while_m_n(4, 4, is_lower_hex_digit),
|
take_while_m_n(4, 4, is_lower_hex_digit),
|
||||||
char('-'),
|
'-',
|
||||||
take_while_m_n(4, 4, is_lower_hex_digit),
|
take_while_m_n(4, 4, is_lower_hex_digit),
|
||||||
char('-'),
|
'-',
|
||||||
take_while_m_n(12, 12, is_lower_hex_digit),
|
take_while_m_n(12, 12, is_lower_hex_digit),
|
||||||
)),
|
),
|
||||||
tuple((
|
(
|
||||||
take_while_m_n(8, 8, is_upper_hex_digit),
|
take_while_m_n(8, 8, is_upper_hex_digit),
|
||||||
char('-'),
|
'-',
|
||||||
take_while_m_n(4, 4, is_upper_hex_digit),
|
take_while_m_n(4, 4, is_upper_hex_digit),
|
||||||
char('-'),
|
'-',
|
||||||
take_while_m_n(4, 4, is_upper_hex_digit),
|
take_while_m_n(4, 4, is_upper_hex_digit),
|
||||||
char('-'),
|
'-',
|
||||||
take_while_m_n(4, 4, is_upper_hex_digit),
|
take_while_m_n(4, 4, is_upper_hex_digit),
|
||||||
char('-'),
|
'-',
|
||||||
take_while_m_n(12, 12, is_upper_hex_digit),
|
take_while_m_n(12, 12, is_upper_hex_digit),
|
||||||
)),
|
),
|
||||||
)))(input)
|
))
|
||||||
|
.recognize()
|
||||||
|
.parse_next(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn hash_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
|
@ -325,14 +320,14 @@ mod parser {
|
||||||
|
|
||||||
fn base64_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn base64_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
let (padding, captured) = take_while1(is_base64_digit)(input.clone())?;
|
let (padding, captured) = take_while1(is_base64_digit)(input.clone())?;
|
||||||
|
|
||||||
const CHUNK: usize = 4;
|
const CHUNK: usize = 4;
|
||||||
let padding_offset = input.offset(&padding);
|
let padding_offset = input.offset_to(&padding);
|
||||||
let mut padding_len = CHUNK - padding_offset % CHUNK;
|
let mut padding_len = CHUNK - padding_offset % CHUNK;
|
||||||
if padding_len == CHUNK {
|
if padding_len == CHUNK {
|
||||||
padding_len = 0;
|
padding_len = 0;
|
||||||
|
@ -345,70 +340,75 @@ mod parser {
|
||||||
.iter()
|
.iter()
|
||||||
.all(|c| !['/', '+'].contains(&c.as_char()))
|
.all(|c| !['/', '+'].contains(&c.as_char()))
|
||||||
{
|
{
|
||||||
return Err(winnow::Err::Backtrack(winnow::error::Error::new(
|
return Err(winnow::error::ErrMode::Backtrack(
|
||||||
input,
|
winnow::error::Error::new(input, winnow::error::ErrorKind::LengthValue),
|
||||||
winnow::error::ErrorKind::LengthValue,
|
));
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)(padding)?;
|
||||||
|
|
||||||
let after_offset = input.offset(&after);
|
let after_offset = input.offset_to(&after);
|
||||||
Ok(input.next_slice(after_offset))
|
Ok(input.next_slice(after_offset))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn email_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn email_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
recognize(tuple((
|
(
|
||||||
take_while1(is_localport_char),
|
take_while1(is_localport_char),
|
||||||
char('@'),
|
'@',
|
||||||
take_while1(is_domain_char),
|
take_while1(is_domain_char),
|
||||||
)))(input)
|
)
|
||||||
|
.recognize()
|
||||||
|
.parse_next(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn url_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn url_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
recognize(tuple((
|
(
|
||||||
opt(terminated(
|
opt(terminated(
|
||||||
take_while1(is_scheme_char),
|
take_while1(is_scheme_char),
|
||||||
// HACK: Technically you can skip `//` if you don't have a domain but that would
|
// HACK: Technically you can skip `//` if you don't have a domain but that would
|
||||||
// get messy to support.
|
// get messy to support.
|
||||||
tuple((char(':'), char('/'), char('/'))),
|
(':', '/', '/'),
|
||||||
)),
|
)),
|
||||||
tuple((
|
(
|
||||||
opt(terminated(url_userinfo, char('@'))),
|
opt(terminated(url_userinfo, '@')),
|
||||||
take_while1(is_domain_char),
|
take_while1(is_domain_char),
|
||||||
opt(preceded(char(':'), take_while1(AsChar::is_dec_digit))),
|
opt(preceded(':', take_while1(AsChar::is_dec_digit))),
|
||||||
)),
|
),
|
||||||
char('/'),
|
'/',
|
||||||
// HACK: Too lazy to enumerate
|
// HACK: Too lazy to enumerate
|
||||||
take_while(is_path_query_fragment),
|
take_while0(is_path_query_fragment),
|
||||||
)))(input)
|
)
|
||||||
|
.recognize()
|
||||||
|
.parse_next(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn url_userinfo<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn url_userinfo<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
recognize(tuple((
|
(
|
||||||
take_while1(is_localport_char),
|
take_while1(is_localport_char),
|
||||||
opt(preceded(char(':'), take_while(is_localport_char))),
|
opt(preceded(':', take_while0(is_localport_char))),
|
||||||
)))(input)
|
)
|
||||||
|
.recognize()
|
||||||
|
.parse_next(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn c_escape<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn c_escape<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
|
@ -416,16 +416,16 @@ mod parser {
|
||||||
// regular string that does escaping. The escaped letter might be part of a word, or it
|
// 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
|
// 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.
|
// incorrectly, we opt for just not evaluating it at all.
|
||||||
preceded(take_while1(is_escape), take_while(is_xid_continue))(input)
|
preceded(take_while1(is_escape), take_while0(is_xid_continue))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn printf<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
fn printf<T>(input: T) -> IResult<T, <T as Stream>::Slice>
|
||||||
where
|
where
|
||||||
T: Stream + PartialEq,
|
T: Stream + StreamIsPartial + PartialEq,
|
||||||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||||
<T as Stream>::Token: AsChar + Copy,
|
<T as Stream>::Token: AsChar + Copy,
|
||||||
{
|
{
|
||||||
preceded(char('%'), take_while1(is_xid_continue))(input)
|
preceded('%', take_while1(is_xid_continue))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn take_many0<I, E, F>(mut f: F) -> impl FnMut(I) -> IResult<I, <I as Stream>::Slice, E>
|
fn take_many0<I, E, F>(mut f: F) -> impl FnMut(I) -> IResult<I, <I as Stream>::Slice, E>
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
use winnow::stream::Stream;
|
use winnow::prelude::*;
|
||||||
use winnow::IResult;
|
|
||||||
use winnow::Parser;
|
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
|
@ -64,31 +62,28 @@ A Cv: acknowledgment's / Av B C: acknowledgement's
|
||||||
|
|
||||||
impl Cluster {
|
impl Cluster {
|
||||||
pub fn parse(input: &str) -> IResult<&str, Self> {
|
pub fn parse(input: &str) -> IResult<&str, Self> {
|
||||||
let header = winnow::sequence::tuple((
|
let header = (
|
||||||
winnow::bytes::streaming::tag("#"),
|
winnow::bytes::tag("#"),
|
||||||
winnow::character::streaming::space0,
|
winnow::character::space0,
|
||||||
winnow::character::streaming::not_line_ending,
|
winnow::character::not_line_ending,
|
||||||
winnow::character::streaming::line_ending,
|
winnow::character::line_ending,
|
||||||
));
|
);
|
||||||
let note = winnow::sequence::preceded(
|
let note = winnow::sequence::preceded(
|
||||||
winnow::sequence::pair(
|
(winnow::bytes::tag("##"), winnow::character::space0),
|
||||||
winnow::bytes::streaming::tag("##"),
|
|
||||||
winnow::character::streaming::space0,
|
|
||||||
),
|
|
||||||
winnow::sequence::terminated(
|
winnow::sequence::terminated(
|
||||||
winnow::character::streaming::not_line_ending,
|
winnow::character::not_line_ending,
|
||||||
winnow::character::streaming::line_ending,
|
winnow::character::line_ending,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
let mut cluster = winnow::sequence::tuple((
|
let mut cluster = (
|
||||||
winnow::combinator::opt(header),
|
winnow::combinator::opt(header),
|
||||||
winnow::multi::many1(winnow::sequence::terminated(
|
winnow::multi::many1(winnow::sequence::terminated(
|
||||||
Entry::parse,
|
Entry::parse,
|
||||||
winnow::character::streaming::line_ending,
|
winnow::character::line_ending,
|
||||||
)),
|
)),
|
||||||
winnow::multi::many0(note),
|
winnow::multi::many0(note),
|
||||||
));
|
);
|
||||||
let (input, (header, entries, notes)): (_, (_, _, Vec<_>)) = (cluster)(input)?;
|
let (input, (header, entries, notes)): (_, (_, _, Vec<_>)) = cluster.parse_next(input)?;
|
||||||
|
|
||||||
let header = header.map(|s| s.2.to_owned());
|
let header = header.map(|s| s.2.to_owned());
|
||||||
let notes = notes.into_iter().map(|s| s.to_owned()).collect();
|
let notes = notes.into_iter().map(|s| s.to_owned()).collect();
|
||||||
|
@ -150,31 +145,19 @@ A B C: coloration's / B. Cv: colouration's
|
||||||
|
|
||||||
impl Entry {
|
impl Entry {
|
||||||
pub fn parse(input: &str) -> IResult<&str, Self> {
|
pub fn parse(input: &str) -> IResult<&str, Self> {
|
||||||
let var_sep = winnow::sequence::tuple((
|
let var_sep = (winnow::character::space0, '/', winnow::character::space0);
|
||||||
winnow::character::streaming::space0,
|
let (input, variants) = winnow::multi::separated1(Variant::parse, var_sep)(input)?;
|
||||||
winnow::bytes::streaming::tag("/"),
|
|
||||||
winnow::character::streaming::space0,
|
|
||||||
));
|
|
||||||
let (input, variants) = winnow::multi::separated_list1(var_sep, Variant::parse)(input)?;
|
|
||||||
|
|
||||||
let desc_sep = winnow::sequence::tuple((
|
let desc_sep = (winnow::character::space0, '|');
|
||||||
winnow::character::streaming::space0,
|
let (input, description) =
|
||||||
winnow::bytes::streaming::tag("|"),
|
winnow::combinator::opt((desc_sep, Self::parse_description))(input)?;
|
||||||
));
|
|
||||||
let (input, description) = winnow::combinator::opt(winnow::sequence::tuple((
|
|
||||||
desc_sep,
|
|
||||||
Self::parse_description,
|
|
||||||
)))(input)?;
|
|
||||||
|
|
||||||
let comment_sep = winnow::sequence::tuple((
|
let comment_sep = (winnow::character::space0, '#');
|
||||||
winnow::character::streaming::space0,
|
let (input, comment) = winnow::combinator::opt((
|
||||||
winnow::bytes::streaming::tag("#"),
|
|
||||||
));
|
|
||||||
let (input, comment) = winnow::combinator::opt(winnow::sequence::tuple((
|
|
||||||
comment_sep,
|
comment_sep,
|
||||||
winnow::character::streaming::space1,
|
winnow::character::space1,
|
||||||
winnow::character::streaming::not_line_ending,
|
winnow::character::not_line_ending,
|
||||||
)))(input)?;
|
))(input)?;
|
||||||
|
|
||||||
let mut e = match description {
|
let mut e = match description {
|
||||||
Some((_, description)) => description,
|
Some((_, description)) => description,
|
||||||
|
@ -193,24 +176,16 @@ impl Entry {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_description(input: &str) -> IResult<&str, Self> {
|
fn parse_description(input: &str) -> IResult<&str, Self> {
|
||||||
let (input, (pos, archaic, note, description)) = winnow::sequence::tuple((
|
let (input, (pos, archaic, note, description)) = (
|
||||||
winnow::combinator::opt(winnow::sequence::tuple((
|
winnow::combinator::opt((winnow::character::space1, Pos::parse)),
|
||||||
winnow::character::streaming::space1,
|
winnow::combinator::opt((winnow::character::space1, "(-)")),
|
||||||
Pos::parse,
|
winnow::combinator::opt((winnow::character::space1, "--")),
|
||||||
))),
|
winnow::combinator::opt((
|
||||||
winnow::combinator::opt(winnow::sequence::tuple((
|
winnow::character::space1,
|
||||||
winnow::character::streaming::space1,
|
winnow::bytes::take_till0(|c| c == '\n' || c == '\r' || c == '#'),
|
||||||
winnow::bytes::streaming::tag("(-)"),
|
)),
|
||||||
))),
|
)
|
||||||
winnow::combinator::opt(winnow::sequence::tuple((
|
.parse_next(input)?;
|
||||||
winnow::character::streaming::space1,
|
|
||||||
winnow::bytes::streaming::tag("--"),
|
|
||||||
))),
|
|
||||||
winnow::combinator::opt(winnow::sequence::tuple((
|
|
||||||
winnow::character::streaming::space1,
|
|
||||||
winnow::bytes::streaming::take_till(|c| c == '\n' || c == '\r' || c == '#'),
|
|
||||||
))),
|
|
||||||
))(input)?;
|
|
||||||
|
|
||||||
let variants = Vec::new();
|
let variants = Vec::new();
|
||||||
let pos = pos.map(|(_, p)| p);
|
let pos = pos.map(|(_, p)| p);
|
||||||
|
@ -321,12 +296,8 @@ mod test_entry {
|
||||||
|
|
||||||
impl Variant {
|
impl Variant {
|
||||||
pub fn parse(input: &str) -> IResult<&str, Self> {
|
pub fn parse(input: &str) -> IResult<&str, Self> {
|
||||||
let types =
|
let types = winnow::multi::separated1(Type::parse, winnow::character::space1);
|
||||||
winnow::multi::separated_list1(winnow::character::streaming::space1, Type::parse);
|
let sep = (winnow::bytes::tag(":"), winnow::character::space0);
|
||||||
let sep = winnow::sequence::tuple((
|
|
||||||
winnow::bytes::streaming::tag(":"),
|
|
||||||
winnow::character::streaming::space0,
|
|
||||||
));
|
|
||||||
let (input, (types, word)) = winnow::sequence::separated_pair(types, sep, word)(input)?;
|
let (input, (types, word)) = winnow::sequence::separated_pair(types, sep, word)(input)?;
|
||||||
let v = Self { types, word };
|
let v = Self { types, word };
|
||||||
Ok((input, v))
|
Ok((input, v))
|
||||||
|
@ -410,7 +381,7 @@ impl Type {
|
||||||
pub fn parse(input: &str) -> IResult<&str, Type> {
|
pub fn parse(input: &str) -> IResult<&str, Type> {
|
||||||
let (input, category) = Category::parse(input)?;
|
let (input, category) = Category::parse(input)?;
|
||||||
let (input, tag) = winnow::combinator::opt(Tag::parse)(input)?;
|
let (input, tag) = winnow::combinator::opt(Tag::parse)(input)?;
|
||||||
let (input, num) = winnow::combinator::opt(winnow::character::streaming::digit1)(input)?;
|
let (input, num) = winnow::combinator::opt(winnow::character::digit1)(input)?;
|
||||||
let num = num.map(|s| s.parse().expect("parser ensured its a number"));
|
let num = num.map(|s| s.parse().expect("parser ensured its a number"));
|
||||||
let t = Type { category, tag, num };
|
let t = Type { category, tag, num };
|
||||||
Ok((input, t))
|
Ok((input, t))
|
||||||
|
@ -465,16 +436,18 @@ mod test_type {
|
||||||
|
|
||||||
impl Category {
|
impl Category {
|
||||||
pub fn parse(input: &str) -> IResult<&str, Category> {
|
pub fn parse(input: &str) -> IResult<&str, Category> {
|
||||||
let symbols = winnow::character::streaming::one_of("ABZCD_");
|
let symbols = winnow::bytes::one_of("ABZCD_");
|
||||||
winnow::combinator::map(symbols, |c| match c {
|
symbols
|
||||||
'A' => Category::American,
|
.map(|c| match c {
|
||||||
'B' => Category::BritishIse,
|
'A' => Category::American,
|
||||||
'Z' => Category::BritishIze,
|
'B' => Category::BritishIse,
|
||||||
'C' => Category::Canadian,
|
'Z' => Category::BritishIze,
|
||||||
'D' => Category::Australian,
|
'C' => Category::Canadian,
|
||||||
'_' => Category::Other,
|
'D' => Category::Australian,
|
||||||
_ => unreachable!("parser won't select this option"),
|
'_' => Category::Other,
|
||||||
})(input)
|
_ => unreachable!("parser won't select this option"),
|
||||||
|
})
|
||||||
|
.parse_next(input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,15 +472,17 @@ mod test_category {
|
||||||
|
|
||||||
impl Tag {
|
impl Tag {
|
||||||
pub fn parse(input: &str) -> IResult<&str, Tag> {
|
pub fn parse(input: &str) -> IResult<&str, Tag> {
|
||||||
let symbols = winnow::character::streaming::one_of(".vV-x");
|
let symbols = winnow::bytes::one_of(".vV-x");
|
||||||
winnow::combinator::map(symbols, |c| match c {
|
symbols
|
||||||
'.' => Tag::Eq,
|
.map(|c| match c {
|
||||||
'v' => Tag::Variant,
|
'.' => Tag::Eq,
|
||||||
'V' => Tag::Seldom,
|
'v' => Tag::Variant,
|
||||||
'-' => Tag::Possible,
|
'V' => Tag::Seldom,
|
||||||
'x' => Tag::Improper,
|
'-' => Tag::Possible,
|
||||||
_ => unreachable!("parser won't select this option"),
|
'x' => Tag::Improper,
|
||||||
})(input)
|
_ => unreachable!("parser won't select this option"),
|
||||||
|
})
|
||||||
|
.parse_next(input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,16 +507,16 @@ mod test_tag {
|
||||||
|
|
||||||
impl Pos {
|
impl Pos {
|
||||||
pub fn parse(input: &str) -> IResult<&str, Pos> {
|
pub fn parse(input: &str) -> IResult<&str, Pos> {
|
||||||
use winnow::bytes::streaming::tag;
|
use winnow::bytes::tag;
|
||||||
let noun = tag("<N>");
|
let noun = tag("<N>");
|
||||||
let verb = tag("<V>");
|
let verb = tag("<V>");
|
||||||
let adjective = tag("<Adj>");
|
let adjective = tag("<Adj>");
|
||||||
let adverb = tag("<Adv>");
|
let adverb = tag("<Adv>");
|
||||||
winnow::branch::alt((
|
winnow::branch::alt((
|
||||||
noun.map(|_| Pos::Noun),
|
noun.value(Pos::Noun),
|
||||||
verb.map(|_| Pos::Verb),
|
verb.value(Pos::Verb),
|
||||||
adjective.map(|_| Pos::Adjective),
|
adjective.value(Pos::Adjective),
|
||||||
adverb.map(|_| Pos::Adverb),
|
adverb.value(Pos::Adverb),
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue