Skip to content

Commit

Permalink
Merge pull request #276 from epage/p3
Browse files Browse the repository at this point in the history
fix(parser)!: Switch inherent method from parse_next to parse_peek
  • Loading branch information
epage authored Jul 6, 2023
2 parents c4d3cee + d3a288c commit 5e146d7
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 199 deletions.
121 changes: 60 additions & 61 deletions src/ascii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
I: Stream,
I: Compare<&'static str>,
{
trace("crlf", move |input: I| "\r\n".parse_peek(input)).parse_peek(input)
trace("crlf", "\r\n").parse_peek(input)
}

/// Recognizes a string of any char except '\r\n' or '\n'.
Expand Down Expand Up @@ -183,10 +183,7 @@ where
I: Stream,
I: Compare<&'static str>,
{
trace("line_ending", move |input: I| {
alt(("\n", "\r\n")).parse_peek(input)
})
.parse_peek(input)
trace("line_ending", alt(("\n", "\r\n"))).parse_peek(input)
}

/// Matches a newline character '\n'.
Expand Down Expand Up @@ -224,11 +221,7 @@ where
I: Stream,
<I as Stream>::Token: AsChar + Copy,
{
trace("newline", move |input: I| {
'\n'.map(|c: <I as Stream>::Token| c.as_char())
.parse_peek(input)
})
.parse_peek(input)
trace("newline", '\n'.map(|c: <I as Stream>::Token| c.as_char())).parse_peek(input)
}

/// Matches a tab character '\t'.
Expand Down Expand Up @@ -266,11 +259,7 @@ where
I: Stream,
<I as Stream>::Token: AsChar + Copy,
{
trace("tab", move |input: I| {
'\t'.map(|c: <I as Stream>::Token| c.as_char())
.parse_peek(input)
})
.parse_peek(input)
trace("tab", '\t'.map(|c: <I as Stream>::Token| c.as_char())).parse_peek(input)
}

/// Recognizes zero or more lowercase and uppercase ASCII alphabetic characters: a-z, A-Z
Expand Down Expand Up @@ -310,9 +299,10 @@ where
I: Stream,
<I as Stream>::Token: AsChar,
{
trace("alpha0", move |input: I| {
take_while(0.., |c: <I as Stream>::Token| c.is_alpha()).parse_peek(input)
})
trace(
"alpha0",
take_while(0.., |c: <I as Stream>::Token| c.is_alpha()),
)
.parse_peek(input)
}

Expand Down Expand Up @@ -353,9 +343,10 @@ where
I: Stream,
<I as Stream>::Token: AsChar,
{
trace("alpha1", move |input: I| {
take_while(1.., |c: <I as Stream>::Token| c.is_alpha()).parse_peek(input)
})
trace(
"alpha1",
take_while(1.., |c: <I as Stream>::Token| c.is_alpha()),
)
.parse_peek(input)
}

Expand Down Expand Up @@ -397,9 +388,10 @@ where
I: Stream,
<I as Stream>::Token: AsChar,
{
trace("digit0", move |input: I| {
take_while(0.., |c: <I as Stream>::Token| c.is_dec_digit()).parse_peek(input)
})
trace(
"digit0",
take_while(0.., |c: <I as Stream>::Token| c.is_dec_digit()),
)
.parse_peek(input)
}

Expand Down Expand Up @@ -456,9 +448,10 @@ where
I: Stream,
<I as Stream>::Token: AsChar,
{
trace("digit1", move |input: I| {
take_while(1.., |c: <I as Stream>::Token| c.is_dec_digit()).parse_peek(input)
})
trace(
"digit1",
take_while(1.., |c: <I as Stream>::Token| c.is_dec_digit()),
)
.parse_peek(input)
}

Expand Down Expand Up @@ -498,9 +491,10 @@ where
I: Stream,
<I as Stream>::Token: AsChar,
{
trace("hex_digit0", move |input: I| {
take_while(0.., |c: <I as Stream>::Token| c.is_hex_digit()).parse_peek(input)
})
trace(
"hex_digit0",
take_while(0.., |c: <I as Stream>::Token| c.is_hex_digit()),
)
.parse_peek(input)
}

Expand Down Expand Up @@ -541,9 +535,10 @@ where
I: Stream,
<I as Stream>::Token: AsChar,
{
trace("hex_digit1", move |input: I| {
take_while(1.., |c: <I as Stream>::Token| c.is_hex_digit()).parse_peek(input)
})
trace(
"hex_digit1",
take_while(1.., |c: <I as Stream>::Token| c.is_hex_digit()),
)
.parse_peek(input)
}

Expand Down Expand Up @@ -584,9 +579,10 @@ where
I: Stream,
<I as Stream>::Token: AsChar,
{
trace("oct_digit0", move |input: I| {
take_while(0.., |c: <I as Stream>::Token| c.is_oct_digit()).parse_peek(input)
})
trace(
"oct_digit0",
take_while(0.., |c: <I as Stream>::Token| c.is_oct_digit()),
)
.parse_peek(input)
}

Expand Down Expand Up @@ -627,9 +623,10 @@ where
I: Stream,
<I as Stream>::Token: AsChar,
{
trace("oct_digit0", move |input: I| {
take_while(1.., |c: <I as Stream>::Token| c.is_oct_digit()).parse_peek(input)
})
trace(
"oct_digit0",
take_while(1.., |c: <I as Stream>::Token| c.is_oct_digit()),
)
.parse_peek(input)
}

Expand Down Expand Up @@ -670,9 +667,10 @@ where
I: Stream,
<I as Stream>::Token: AsChar,
{
trace("alphanumeric0", move |input: I| {
take_while(0.., |c: <I as Stream>::Token| c.is_alphanum()).parse_peek(input)
})
trace(
"alphanumeric0",
take_while(0.., |c: <I as Stream>::Token| c.is_alphanum()),
)
.parse_peek(input)
}

Expand Down Expand Up @@ -713,9 +711,10 @@ where
I: Stream,
<I as Stream>::Token: AsChar,
{
trace("alphanumeric1", move |input: I| {
take_while(1.., |c: <I as Stream>::Token| c.is_alphanum()).parse_peek(input)
})
trace(
"alphanumeric1",
take_while(1.., |c: <I as Stream>::Token| c.is_alphanum()),
)
.parse_peek(input)
}

Expand Down Expand Up @@ -744,13 +743,13 @@ where
I: Stream,
<I as Stream>::Token: AsChar + Copy,
{
trace("space0", move |input: I| {
trace(
"space0",
take_while(0.., |c: <I as Stream>::Token| {
let ch = c.as_char();
matches!(ch, ' ' | '\t')
})
.parse_peek(input)
})
}),
)
.parse_peek(input)
}

Expand Down Expand Up @@ -791,13 +790,13 @@ where
I: Stream,
<I as Stream>::Token: AsChar + Copy,
{
trace("space1", move |input: I| {
trace(
"space1",
take_while(1.., |c: <I as Stream>::Token| {
let ch = c.as_char();
matches!(ch, ' ' | '\t')
})
.parse_peek(input)
})
}),
)
.parse_peek(input)
}

Expand Down Expand Up @@ -838,13 +837,13 @@ where
I: Stream,
<I as Stream>::Token: AsChar + Copy,
{
trace("multispace0", move |input: I| {
trace(
"multispace0",
take_while(0.., |c: <I as Stream>::Token| {
let ch = c.as_char();
matches!(ch, ' ' | '\t' | '\r' | '\n')
})
.parse_peek(input)
})
}),
)
.parse_peek(input)
}

Expand Down Expand Up @@ -885,13 +884,13 @@ where
I: Stream,
<I as Stream>::Token: AsChar + Copy,
{
trace("multispace1", move |input: I| {
trace(
"multispace1",
take_while(1.., |c: <I as Stream>::Token| {
let ch = c.as_char();
matches!(ch, ' ' | '\t' | '\r' | '\n')
})
.parse_peek(input)
})
}),
)
.parse_peek(input)
}

Expand Down
Loading

0 comments on commit 5e146d7

Please sign in to comment.