chore(typos): Add parse tracing

This commit is contained in:
Ed Page 2023-07-14 12:32:07 -05:00
parent a1ad167632
commit e98fc52b0d

View file

@ -133,6 +133,7 @@ mod parser {
use winnow::stream::Stream; use winnow::stream::Stream;
use winnow::stream::StreamIsPartial; use winnow::stream::StreamIsPartial;
use winnow::token::*; use winnow::token::*;
use winnow::trace::trace;
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
@ -153,7 +154,7 @@ mod parser {
// `{XID_Continue}+` because XID_Continue is a superset of XID_Start and rather catch odd // `{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 // or unexpected cases than strip off start characters to a word since we aren't doing a
// proper word boundary parse // proper word boundary parse
take_while(1.., is_xid_continue).parse_next(input) trace("identifier", take_while(1.., is_xid_continue)).parse_next(input)
} }
fn ignore<T>(input: T) -> IResult<T, <T as Stream>::Slice> fn ignore<T>(input: T) -> IResult<T, <T as Stream>::Slice>
@ -162,6 +163,8 @@ mod parser {
<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,
{ {
trace(
"ignore",
take_many0(alt(( take_many0(alt((
// CAUTION: If adding an ignorable literal, if it doesn't start with `is_xid_continue`, // CAUTION: If adding an ignorable literal, if it doesn't start with `is_xid_continue`,
// - Update `is_ignore_char` to make sure `sep1` doesn't eat it all up // - Update `is_ignore_char` to make sure `sep1` doesn't eat it all up
@ -178,7 +181,8 @@ mod parser {
c_escape, c_escape,
printf, printf,
other, other,
))) ))),
)
.parse_next(input) .parse_next(input)
} }
@ -201,11 +205,14 @@ mod parser {
<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,
{ {
trace(
"other",
( (
one_of(|c| !is_xid_continue(c)), one_of(|c| !is_xid_continue(c)),
take_while(0.., is_ignore_char), take_while(0.., is_ignore_char),
) )
.recognize() .recognize(),
)
.parse_next(input) .parse_next(input)
} }
@ -221,13 +228,16 @@ mod parser {
['_'].contains(&c) ['_'].contains(&c)
} }
trace(
"ordinal_literal",
( (
take_while(0.., is_sep), take_while(0.., is_sep),
take_while(1.., is_dec_digit), take_while(1.., is_dec_digit),
alt((('s', 't'), ('n', 'd'), ('r', 'd'), ('t', 'h'))), alt((('s', 't'), ('n', 'd'), ('r', 'd'), ('t', 'h'))),
take_while(0.., is_sep), take_while(0.., is_sep),
) )
.recognize() .recognize(),
)
.parse_next(input) .parse_next(input)
} }
@ -237,7 +247,7 @@ mod parser {
<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,
{ {
take_while(1.., is_dec_digit_with_sep).parse_next(input) trace("dec_literal", take_while(1.., is_dec_digit_with_sep)).parse_next(input)
} }
fn hex_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice> fn hex_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
@ -259,12 +269,15 @@ mod parser {
<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,
{ {
trace(
"color",
preceded( preceded(
'#', '#',
alt(( alt((
terminated(take_while(3..=8, is_lower_hex_digit), peek(sep1)), terminated(take_while(3..=8, is_lower_hex_digit), peek(sep1)),
terminated(take_while(3..=8, is_upper_hex_digit), peek(sep1)), terminated(take_while(3..=8, is_upper_hex_digit), peek(sep1)),
)), )),
),
) )
.parse_next(input) .parse_next(input)
} }
@ -275,6 +288,8 @@ mod parser {
<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,
{ {
trace(
"uuid",
alt(( alt((
( (
take_while(8, is_lower_hex_digit), take_while(8, is_lower_hex_digit),
@ -299,7 +314,8 @@ mod parser {
take_while(12, is_upper_hex_digit), take_while(12, is_upper_hex_digit),
), ),
)) ))
.recognize() .recognize(),
)
.parse_next(input) .parse_next(input)
} }
@ -319,10 +335,13 @@ mod parser {
// or more. // or more.
const IGNORE_HEX_MIN: usize = 32; const IGNORE_HEX_MIN: usize = 32;
trace(
"hash",
alt(( alt((
take_while(IGNORE_HEX_MIN.., is_lower_hex_digit), take_while(IGNORE_HEX_MIN.., is_lower_hex_digit),
take_while(IGNORE_HEX_MIN.., is_upper_hex_digit), take_while(IGNORE_HEX_MIN.., is_upper_hex_digit),
)) )),
)
.parse_next(input) .parse_next(input)
} }
@ -332,6 +351,7 @@ mod parser {
<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,
{ {
trace("base64", move |input: T| {
let (padding, captured) = take_while(1.., is_base64_digit).parse_next(input.clone())?; let (padding, captured) = take_while(1.., is_base64_digit).parse_next(input.clone())?;
const CHUNK: usize = 4; const CHUNK: usize = 4;
@ -358,6 +378,8 @@ mod parser {
let after_offset = input.offset_to(&after); let after_offset = input.offset_to(&after);
Ok(input.next_slice(after_offset)) Ok(input.next_slice(after_offset))
})
.parse_next(input)
} }
fn email_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice> fn email_literal<T>(input: T) -> IResult<T, <T as Stream>::Slice>
@ -366,12 +388,15 @@ mod parser {
<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,
{ {
trace(
"email",
( (
take_while(1.., is_localport_char), take_while(1.., is_localport_char),
'@', '@',
take_while(1.., is_domain_char), take_while(1.., is_domain_char),
) )
.recognize() .recognize(),
)
.parse_next(input) .parse_next(input)
} }
@ -381,6 +406,8 @@ mod parser {
<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,
{ {
trace(
"url",
( (
opt(terminated( opt(terminated(
take_while(1.., is_scheme_char), take_while(1.., is_scheme_char),
@ -397,7 +424,8 @@ mod parser {
// HACK: Too lazy to enumerate // HACK: Too lazy to enumerate
take_while(0.., is_path_query_fragment), take_while(0.., is_path_query_fragment),
) )
.recognize() .recognize(),
)
.parse_next(input) .parse_next(input)
} }
@ -407,11 +435,14 @@ mod parser {
<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,
{ {
trace(
"userinfo",
( (
take_while(1.., is_localport_char), take_while(1.., is_localport_char),
opt(preceded(':', take_while(0.., is_localport_char))), opt(preceded(':', take_while(0.., is_localport_char))),
) )
.recognize() .recognize(),
)
.parse_next(input) .parse_next(input)
} }
@ -425,7 +456,11 @@ 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_while(1.., is_escape), take_while(0.., is_xid_continue)).parse_next(input) trace(
"escape",
preceded(take_while(1.., is_escape), take_while(0.., is_xid_continue)),
)
.parse_next(input)
} }
fn printf<T>(input: T) -> IResult<T, <T as Stream>::Slice> fn printf<T>(input: T) -> IResult<T, <T as Stream>::Slice>
@ -434,7 +469,7 @@ mod parser {
<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('%', take_while(1.., is_xid_continue)).parse_next(input) trace("printf", preceded('%', take_while(1.., 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> fn take_many0<I, E, F>(mut f: F) -> impl FnMut(I) -> IResult<I, <I as Stream>::Slice, E>