use word instead of word10

This commit is contained in:
Bryce Miller 2023-05-22 22:29:32 -04:00
parent 9bd2077010
commit 2f5695e59d
No known key found for this signature in database
GPG key ID: F1E97BF8DF152350
2 changed files with 20 additions and 69 deletions

View file

@ -1524,6 +1524,23 @@ where
}
}
pub fn word<'a, ToError, E>(word: &'static str, to_error: ToError) -> impl Parser<'a, (), E>
where
ToError: Fn(Position) -> E,
E: 'a,
{
debug_assert!(!word.contains('\n'));
move |_arena: &'a Bump, state: State<'a>, _min_indent: u32| {
if state.bytes().starts_with(word.as_bytes()) {
let state = state.advance(word.len());
Ok((MadeProgress, (), state))
} else {
Err((NoProgress, to_error(state.pos())))
}
}
}
pub fn word1<'a, ToError, E>(word: u8, to_error: ToError) -> impl Parser<'a, (), E>
where
ToError: Fn(Position) -> E,
@ -1608,48 +1625,6 @@ where
}
}
pub fn word10<'a, ToError, E>(
word_1: u8,
word_2: u8,
word_3: u8,
word_4: u8,
word_5: u8,
word_6: u8,
word_7: u8,
word_8: u8,
word_9: u8,
word_10: u8,
to_error: ToError,
) -> impl Parser<'a, (), E>
where
ToError: Fn(Position) -> E,
E: 'a,
{
debug_assert_ne!(word_1, b'\n');
debug_assert_ne!(word_2, b'\n');
debug_assert_ne!(word_3, b'\n');
debug_assert_ne!(word_4, b'\n');
debug_assert_ne!(word_5, b'\n');
debug_assert_ne!(word_6, b'\n');
debug_assert_ne!(word_7, b'\n');
debug_assert_ne!(word_8, b'\n');
debug_assert_ne!(word_9, b'\n');
debug_assert_ne!(word_10, b'\n');
let needle = [
word_1, word_2, word_3, word_4, word_5, word_6, word_7, word_8, word_9, word_10,
];
move |_arena: &'a Bump, state: State<'a>, _min_indent: u32| {
if state.bytes().starts_with(&needle) {
let state = state.advance(10);
Ok((MadeProgress, (), state))
} else {
Err((NoProgress, to_error(state.pos())))
}
}
}
#[macro_export]
macro_rules! word1_check_indent {
($word:expr, $word_problem:expr, $min_indent:expr, $indent_problem:expr) => {

View file

@ -12,7 +12,7 @@ use crate::parser::{
absolute_column_min_indent, increment_min_indent, then, ERecord, ETypeAbilityImpl,
};
use crate::parser::{
allocated, backtrackable, fail, optional, specialize, specialize_ref, word1, word10, word2,
allocated, backtrackable, fail, optional, specialize, specialize_ref, word, word1, word2,
EType, ETypeApply, ETypeInParens, ETypeInlineAlias, ETypeRecord, ETypeTagUnion, Parser,
Progress::{self, *},
};
@ -459,19 +459,7 @@ fn implements_clause<'a>() -> impl Parser<'a, Loc<ImplementsClause<'a>>, EType<'
),
skip_first!(
// Parse "implements"; we don't care about this keyword
word10(
b'i',
b'm',
b'p',
b'l',
b'e',
b'm',
b'e',
b'n',
b't',
b's',
EType::THasClause
),
word("implements", EType::THasClause),
// Parse "Hash & ..."; this may be qualified from another module like "Hash.Hash"
absolute_column_min_indent(ability_chain())
)
@ -524,19 +512,7 @@ fn implements_clause_chain<'a>(
pub fn implements_abilities<'a>() -> impl Parser<'a, Loc<ImplementsAbilities<'a>>, EType<'a>> {
increment_min_indent(skip_first!(
// Parse "implements"; we don't care about this keyword
word10(
b'i',
b'm',
b'p',
b'l',
b'e',
b'm',
b'e',
b'n',
b't',
b's',
EType::THasClause
),
word("implements", EType::THasClause),
// Parse "Hash"; this may be qualified from another module like "Hash.Hash"
space0_before_e(
loc!(map!(