Don't use BoxedParser for char or string

This commit is contained in:
Richard Feldman 2019-11-19 06:34:28 -05:00
parent ecb495a4e2
commit 7050547f9c

View file

@ -529,13 +529,7 @@ fn line_too_long(attempting: Attempting, state: State<'_>) -> (Fail, State<'_>)
} }
/// A single char. /// A single char.
#[cfg(not(debug_assertions))]
pub fn char<'a>(expected: char) -> impl Parser<'a, ()> { pub fn char<'a>(expected: char) -> impl Parser<'a, ()> {
char_impl(expected)
}
#[inline(always)]
pub fn char_impl<'a>(expected: char) -> impl Parser<'a, ()> {
move |_arena, state: State<'a>| match state.input.chars().next() { move |_arena, state: State<'a>| match state.input.chars().next() {
Some(actual) if expected == actual => Ok(((), state.advance_without_indenting(1)?)), Some(actual) if expected == actual => Ok(((), state.advance_without_indenting(1)?)),
Some(other_ch) => Err(unexpected(other_ch, 0, state, Attempting::Keyword)), Some(other_ch) => Err(unexpected(other_ch, 0, state, Attempting::Keyword)),
@ -544,13 +538,7 @@ pub fn char_impl<'a>(expected: char) -> impl Parser<'a, ()> {
} }
/// A hardcoded keyword string with no newlines in it. /// A hardcoded keyword string with no newlines in it.
#[cfg(not(debug_assertions))]
pub fn string<'a>(keyword: &'static str) -> impl Parser<'a, ()> { pub fn string<'a>(keyword: &'static str) -> impl Parser<'a, ()> {
string_impl(keyword)
}
#[inline(always)]
pub fn string_impl<'a>(keyword: &'static str) -> impl Parser<'a, ()> {
// We can't have newlines because we don't attempt to advance the row // We can't have newlines because we don't attempt to advance the row
// in the state, only the column. // in the state, only the column.
debug_assert!(!keyword.contains('\n')); debug_assert!(!keyword.contains('\n'));
@ -1445,16 +1433,6 @@ where
BoxedParser::new(zero_or_more_impl(parser)) BoxedParser::new(zero_or_more_impl(parser))
} }
#[cfg(debug_assertions)]
pub fn char<'a>(expected: char) -> BoxedParser<'a, ()> {
BoxedParser::new(char_impl(expected))
}
#[cfg(debug_assertions)]
pub fn string<'a>(keyword: &'static str) -> BoxedParser<'a, ()> {
BoxedParser::new(string_impl(keyword))
}
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
pub fn either<'a, P1, P2, A, B>(p1: P1, p2: P2) -> BoxedParser<'a, Either<A, B>> pub fn either<'a, P1, P2, A, B>(p1: P1, p2: P2) -> BoxedParser<'a, Either<A, B>>
where where