ast::Has -> ast::Implements

This commit is contained in:
Bryce Miller 2023-05-20 08:12:20 -04:00
parent d2fed03cb1
commit 64c34a5c6d
No known key found for this signature in database
GPG key ID: F1E97BF8DF152350
4 changed files with 31 additions and 26 deletions

View file

@ -357,12 +357,12 @@ impl<'a> TypeHeader<'a> {
}
}
/// The `has` keyword associated with ability definitions.
/// The `implements` keyword associated with ability definitions.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Has<'a> {
Has,
SpaceBefore(&'a Has<'a>, &'a [CommentOrNewline<'a>]),
SpaceAfter(&'a Has<'a>, &'a [CommentOrNewline<'a>]),
pub enum Implements<'a> {
Implements,
SpaceBefore(&'a Implements<'a>, &'a [CommentOrNewline<'a>]),
SpaceAfter(&'a Implements<'a>, &'a [CommentOrNewline<'a>]),
}
/// An ability demand is a value defining the ability; for example `hash : a -> U64 | a has Hash`
@ -402,7 +402,7 @@ pub enum TypeDef<'a> {
/// hash : a -> U64 | a has Hash
Ability {
header: TypeHeader<'a>,
loc_has: Loc<Has<'a>>,
loc_has: Loc<Implements<'a>>,
members: &'a [AbilityMember<'a>],
},
}
@ -1245,12 +1245,12 @@ impl<'a> Spaceable<'a> for Tag<'a> {
}
}
impl<'a> Spaceable<'a> for Has<'a> {
impl<'a> Spaceable<'a> for Implements<'a> {
fn before(&'a self, spaces: &'a [CommentOrNewline<'a>]) -> Self {
Has::SpaceBefore(self, spaces)
Implements::SpaceBefore(self, spaces)
}
fn after(&'a self, spaces: &'a [CommentOrNewline<'a>]) -> Self {
Has::SpaceAfter(self, spaces)
Implements::SpaceAfter(self, spaces)
}
}
@ -1698,11 +1698,11 @@ impl<'a> Malformed for AbilityMember<'a> {
}
}
impl<'a> Malformed for Has<'a> {
impl<'a> Malformed for Implements<'a> {
fn is_malformed(&self) -> bool {
match self {
Has::Has => false,
Has::SpaceBefore(has, _) | Has::SpaceAfter(has, _) => has.is_malformed(),
Implements::Implements => false,
Implements::SpaceBefore(has, _) | Implements::SpaceAfter(has, _) => has.is_malformed(),
}
}
}

View file

@ -1,6 +1,7 @@
use crate::ast::{
AssignedField, Collection, CommentOrNewline, Defs, Expr, ExtractSpaces, Has, HasAbilities,
Pattern, RecordBuilderField, Spaceable, Spaces, TypeAnnotation, TypeDef, TypeHeader, ValueDef,
AssignedField, Collection, CommentOrNewline, Defs, Expr, ExtractSpaces, HasAbilities,
Implements, Pattern, RecordBuilderField, Spaceable, Spaces, TypeAnnotation, TypeDef,
TypeHeader, ValueDef,
};
use crate::blankspace::{
space0_after_e, space0_around_e_no_after_indent_check, space0_around_ee, space0_before_e,
@ -1075,7 +1076,7 @@ fn opaque_signature_with_space_before<'a>(
),
optional(backtrackable(specialize(
EExpr::Type,
space0_before_e(type_annotation::has_abilities(), EType::TIndentStart,),
space0_before_e(type_annotation::implements_abilities(), EType::TIndentStart,),
)))
)
}
@ -1363,7 +1364,7 @@ fn finish_parsing_ability_def_help<'a>(
start_column: u32,
name: Loc<&'a str>,
args: &'a [Loc<Pattern<'a>>],
loc_has: Loc<Has<'a>>,
loc_has: Loc<Implements<'a>>,
arena: &'a Bump,
state: State<'a>,
) -> ParseResult<'a, (TypeDef<'a>, Region), EExpr<'a>> {
@ -1664,10 +1665,10 @@ fn parse_expr_end<'a>(
// Attach any spaces to the `has` keyword
let has = if !expr_state.spaces_after.is_empty() {
arena
.alloc(Has::Has)
.alloc(Implements::Implements)
.with_spaces_before(expr_state.spaces_after, has.region)
} else {
Loc::at(has.region, Has::Has)
Loc::at(has.region, Implements::Implements)
};
let args = arguments.into_bump_slice();

View file

@ -1,4 +1,4 @@
use crate::ast::{Has, Pattern, PatternAs, Spaceable};
use crate::ast::{Implements, Pattern, PatternAs, Spaceable};
use crate::blankspace::{space0_e, spaces, spaces_before};
use crate::ident::{lowercase_ident, parse_ident, Accessor, Ident};
use crate::keyword;
@ -154,12 +154,16 @@ fn loc_tag_pattern_arg<'a>(
}
}
pub fn loc_has_parser<'a>() -> impl Parser<'a, Loc<Has<'a>>, EPattern<'a>> {
pub fn loc_has_parser<'a>() -> impl Parser<'a, Loc<Implements<'a>>, EPattern<'a>> {
then(
loc_tag_pattern_arg(false),
|_arena, state, progress, pattern| {
if matches!(pattern.value, Pattern::Identifier("has")) {
Ok((progress, Loc::at(pattern.region, Has::Has), state))
Ok((
progress,
Loc::at(pattern.region, Implements::Implements),
state,
))
} else {
Err((progress, EPattern::End(state.pos())))
}