mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 03:42:17 +00:00
use word
instead of word10
This commit is contained in:
parent
9bd2077010
commit
2f5695e59d
2 changed files with 20 additions and 69 deletions
|
@ -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>
|
pub fn word1<'a, ToError, E>(word: u8, to_error: ToError) -> impl Parser<'a, (), E>
|
||||||
where
|
where
|
||||||
ToError: Fn(Position) -> E,
|
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_export]
|
||||||
macro_rules! word1_check_indent {
|
macro_rules! word1_check_indent {
|
||||||
($word:expr, $word_problem:expr, $min_indent:expr, $indent_problem:expr) => {
|
($word:expr, $word_problem:expr, $min_indent:expr, $indent_problem:expr) => {
|
||||||
|
|
|
@ -12,7 +12,7 @@ use crate::parser::{
|
||||||
absolute_column_min_indent, increment_min_indent, then, ERecord, ETypeAbilityImpl,
|
absolute_column_min_indent, increment_min_indent, then, ERecord, ETypeAbilityImpl,
|
||||||
};
|
};
|
||||||
use crate::parser::{
|
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,
|
EType, ETypeApply, ETypeInParens, ETypeInlineAlias, ETypeRecord, ETypeTagUnion, Parser,
|
||||||
Progress::{self, *},
|
Progress::{self, *},
|
||||||
};
|
};
|
||||||
|
@ -459,19 +459,7 @@ fn implements_clause<'a>() -> impl Parser<'a, Loc<ImplementsClause<'a>>, EType<'
|
||||||
),
|
),
|
||||||
skip_first!(
|
skip_first!(
|
||||||
// Parse "implements"; we don't care about this keyword
|
// Parse "implements"; we don't care about this keyword
|
||||||
word10(
|
word("implements", EType::THasClause),
|
||||||
b'i',
|
|
||||||
b'm',
|
|
||||||
b'p',
|
|
||||||
b'l',
|
|
||||||
b'e',
|
|
||||||
b'm',
|
|
||||||
b'e',
|
|
||||||
b'n',
|
|
||||||
b't',
|
|
||||||
b's',
|
|
||||||
EType::THasClause
|
|
||||||
),
|
|
||||||
// Parse "Hash & ..."; this may be qualified from another module like "Hash.Hash"
|
// Parse "Hash & ..."; this may be qualified from another module like "Hash.Hash"
|
||||||
absolute_column_min_indent(ability_chain())
|
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>> {
|
pub fn implements_abilities<'a>() -> impl Parser<'a, Loc<ImplementsAbilities<'a>>, EType<'a>> {
|
||||||
increment_min_indent(skip_first!(
|
increment_min_indent(skip_first!(
|
||||||
// Parse "implements"; we don't care about this keyword
|
// Parse "implements"; we don't care about this keyword
|
||||||
word10(
|
word("implements", EType::THasClause),
|
||||||
b'i',
|
|
||||||
b'm',
|
|
||||||
b'p',
|
|
||||||
b'l',
|
|
||||||
b'e',
|
|
||||||
b'm',
|
|
||||||
b'e',
|
|
||||||
b'n',
|
|
||||||
b't',
|
|
||||||
b's',
|
|
||||||
EType::THasClause
|
|
||||||
),
|
|
||||||
// Parse "Hash"; this may be qualified from another module like "Hash.Hash"
|
// Parse "Hash"; this may be qualified from another module like "Hash.Hash"
|
||||||
space0_before_e(
|
space0_before_e(
|
||||||
loc!(map!(
|
loc!(map!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue