Define and use IMPLEMENTS const in roc_parse::keyword

This commit is contained in:
Bryce Miller 2023-05-29 07:21:27 -04:00
parent 9640fcb6d4
commit e514d0cb83
No known key found for this signature in database
GPG key ID: F1E97BF8DF152350
12 changed files with 37 additions and 26 deletions

View file

@ -1641,7 +1641,7 @@ fn parse_expr_end<'a>(
value:
Expr::Var {
module_name: "",
ident: "implements",
ident: crate::keyword::IMPLEMENTS,
},
..
},

View file

@ -1,3 +1,4 @@
// These keywords are valid in expressions
pub const IF: &str = "if";
pub const THEN: &str = "then";
pub const ELSE: &str = "else";
@ -9,4 +10,8 @@ pub const EXPECT: &str = "expect";
pub const EXPECT_FX: &str = "expect-fx";
pub const CRASH: &str = "crash";
// These keywords are valid in types
pub const IMPLEMENTS: &str = "implements";
pub const WHERE: &str = "where";
pub const KEYWORDS: [&str; 10] = [IF, THEN, ELSE, WHEN, AS, IS, DBG, EXPECT, EXPECT_FX, CRASH];

View file

@ -138,7 +138,7 @@ fn loc_tag_pattern_arg<'a>(
let Loc { region, value } = loc_pat;
if stop_on_has_kw && matches!(value, Pattern::Identifier("implements")) {
if stop_on_has_kw && matches!(value, Pattern::Identifier(crate::keyword::IMPLEMENTS)) {
Err((NoProgress, EPattern::End(original_state.pos())))
} else {
Ok((
@ -158,7 +158,10 @@ pub fn loc_implements_parser<'a>() -> impl Parser<'a, Loc<Implements<'a>>, EPatt
then(
loc_tag_pattern_arg(false),
|_arena, state, progress, pattern| {
if matches!(pattern.value, Pattern::Identifier("implements")) {
if matches!(
pattern.value,
Pattern::Identifier(crate::keyword::IMPLEMENTS)
) {
Ok((
progress,
Loc::at(pattern.region, Implements::Implements),

View file

@ -459,7 +459,7 @@ fn implements_clause<'a>() -> impl Parser<'a, Loc<ImplementsClause<'a>>, EType<'
),
skip_first!(
// Parse "implements"; we don't care about this keyword
word("implements", EType::THasClause),
word(crate::keyword::IMPLEMENTS, EType::THasClause),
// Parse "Hash & ..."; this may be qualified from another module like "Hash.Hash"
absolute_column_min_indent(ability_chain())
)
@ -512,7 +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
word("implements", EType::THasClause),
word(crate::keyword::IMPLEMENTS, EType::THasClause),
// Parse "Hash"; this may be qualified from another module like "Hash.Hash"
space0_before_e(
loc!(map!(
@ -726,7 +726,7 @@ fn parse_type_variable<'a>(
min_indent,
) {
Ok((_, name, state)) => {
if name == "implements" && stop_at_surface_has {
if name == crate::keyword::IMPLEMENTS && stop_at_surface_has {
Err((NoProgress, EType::TEnd(state.pos())))
} else {
let answer = TypeAnnotation::BoundVariable(name);