From 2f5695e59d0602c97ebef2a66a001b40349a460f Mon Sep 17 00:00:00 2001 From: Bryce Miller Date: Mon, 22 May 2023 22:29:32 -0400 Subject: [PATCH] use `word` instead of `word10` --- crates/compiler/parse/src/parser.rs | 59 ++++++-------------- crates/compiler/parse/src/type_annotation.rs | 30 +--------- 2 files changed, 20 insertions(+), 69 deletions(-) diff --git a/crates/compiler/parse/src/parser.rs b/crates/compiler/parse/src/parser.rs index ec6b618606..2604888417 100644 --- a/crates/compiler/parse/src/parser.rs +++ b/crates/compiler/parse/src/parser.rs @@ -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) => { diff --git a/crates/compiler/parse/src/type_annotation.rs b/crates/compiler/parse/src/type_annotation.rs index 92ec2404c1..a45bd3699a 100644 --- a/crates/compiler/parse/src/type_annotation.rs +++ b/crates/compiler/parse/src/type_annotation.rs @@ -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>, 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>, 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!(