mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 00:51:11 -05:00
refactor(tokens): Simplify parser logic
This commit is contained in:
parent
8c8f52fe6a
commit
5eab324cdd
1 changed files with 18 additions and 15 deletions
|
@ -271,10 +271,8 @@ mod parser {
|
|||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||
<T as Stream>::Token: AsChar + Copy,
|
||||
{
|
||||
preceded(
|
||||
('0', alt(('x', 'X'))),
|
||||
take_while(1.., is_hex_digit_with_sep),
|
||||
)
|
||||
('0', alt(('x', 'X')), take_while(1.., is_hex_digit_with_sep))
|
||||
.recognize()
|
||||
.parse_next(input)
|
||||
}
|
||||
|
||||
|
@ -287,13 +285,14 @@ mod parser {
|
|||
{
|
||||
trace(
|
||||
"color",
|
||||
preceded(
|
||||
(
|
||||
'#',
|
||||
alt((
|
||||
terminated(take_while(3..=8, is_lower_hex_digit), peek(sep1)),
|
||||
terminated(take_while(3..=8, is_upper_hex_digit), peek(sep1)),
|
||||
(take_while(3..=8, is_lower_hex_digit), peek(sep1)),
|
||||
(take_while(3..=8, is_upper_hex_digit), peek(sep1)),
|
||||
)),
|
||||
),
|
||||
)
|
||||
.recognize(),
|
||||
)
|
||||
.parse_next(input)
|
||||
}
|
||||
|
@ -430,16 +429,16 @@ mod parser {
|
|||
trace(
|
||||
"url",
|
||||
(
|
||||
opt(terminated(
|
||||
opt((
|
||||
take_while(1.., is_scheme_char),
|
||||
// HACK: Technically you can skip `//` if you don't have a domain but that would
|
||||
// get messy to support.
|
||||
(':', '/', '/'),
|
||||
)),
|
||||
(
|
||||
opt(terminated(url_userinfo, '@')),
|
||||
opt((url_userinfo, '@')),
|
||||
take_while(1.., is_domain_char),
|
||||
opt(preceded(':', take_while(1.., AsChar::is_dec_digit))),
|
||||
opt((':', take_while(1.., AsChar::is_dec_digit))),
|
||||
),
|
||||
'/',
|
||||
// HACK: Too lazy to enumerate
|
||||
|
@ -461,7 +460,7 @@ mod parser {
|
|||
"userinfo",
|
||||
(
|
||||
take_while(1.., is_localport_char),
|
||||
opt(preceded(':', take_while(0.., is_localport_char))),
|
||||
opt((':', take_while(0.., is_localport_char))),
|
||||
)
|
||||
.recognize(),
|
||||
)
|
||||
|
@ -480,7 +479,7 @@ mod parser {
|
|||
// incorrectly, we opt for just not evaluating it at all.
|
||||
trace(
|
||||
"escape",
|
||||
preceded(take_while(1.., is_escape), take_while(0.., is_xid_continue)),
|
||||
(take_while(1.., is_escape), take_while(0.., is_xid_continue)).recognize(),
|
||||
)
|
||||
.parse_next(input)
|
||||
}
|
||||
|
@ -492,7 +491,11 @@ mod parser {
|
|||
<T as Stream>::Slice: AsBStr + SliceLen + Default,
|
||||
<T as Stream>::Token: AsChar + Copy,
|
||||
{
|
||||
trace("printf", preceded('%', take_while(1.., is_xid_continue))).parse_next(input)
|
||||
trace(
|
||||
"printf",
|
||||
('%', take_while(1.., is_xid_continue)).recognize(),
|
||||
)
|
||||
.parse_next(input)
|
||||
}
|
||||
|
||||
fn take_many0<I, E, F>(mut f: F) -> impl Parser<I, <I as Stream>::Slice, E>
|
||||
|
|
Loading…
Reference in a new issue