mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Rename Derived to HasAbility
This commit is contained in:
parent
0946a7816a
commit
d4d073d8c6
7 changed files with 202 additions and 81 deletions
|
@ -298,7 +298,7 @@ pub enum TypeDef<'a> {
|
|||
Opaque {
|
||||
header: TypeHeader<'a>,
|
||||
typ: Loc<TypeAnnotation<'a>>,
|
||||
derived: Option<Loc<Derived<'a>>>,
|
||||
derived: Option<Loc<HasAbilities<'a>>>,
|
||||
},
|
||||
|
||||
/// An ability definition. E.g.
|
||||
|
@ -434,18 +434,32 @@ pub struct HasClause<'a> {
|
|||
pub ability: AbilityName<'a>,
|
||||
}
|
||||
|
||||
/// `Eq` or `Eq { eq: myEq }`
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub enum Derived<'a> {
|
||||
/// `has [Eq, Hash]`
|
||||
Has(Collection<'a, AbilityName<'a>>),
|
||||
pub enum HasAbility<'a> {
|
||||
HasAbility {
|
||||
/// Should be a zero-argument `Apply` or an error; we'll check this in canonicalization
|
||||
ability: Loc<TypeAnnotation<'a>>,
|
||||
impls: Collection<'a, Loc<AssignedField<'a, TypeAnnotation<'a>>>>,
|
||||
},
|
||||
|
||||
// We preserve this for the formatter; canonicalization ignores it.
|
||||
SpaceBefore(&'a Derived<'a>, &'a [CommentOrNewline<'a>]),
|
||||
SpaceAfter(&'a Derived<'a>, &'a [CommentOrNewline<'a>]),
|
||||
SpaceBefore(&'a HasAbility<'a>, &'a [CommentOrNewline<'a>]),
|
||||
SpaceAfter(&'a HasAbility<'a>, &'a [CommentOrNewline<'a>]),
|
||||
}
|
||||
|
||||
impl Derived<'_> {
|
||||
pub fn collection(&self) -> &Collection<AbilityName> {
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub enum HasAbilities<'a> {
|
||||
/// `has [Eq { eq: myEq }, Hash]`
|
||||
Has(Collection<'a, Loc<HasAbility<'a>>>),
|
||||
|
||||
// We preserve this for the formatter; canonicalization ignores it.
|
||||
SpaceBefore(&'a HasAbilities<'a>, &'a [CommentOrNewline<'a>]),
|
||||
SpaceAfter(&'a HasAbilities<'a>, &'a [CommentOrNewline<'a>]),
|
||||
}
|
||||
|
||||
impl HasAbilities<'_> {
|
||||
pub fn collection(&self) -> &Collection<Loc<HasAbility>> {
|
||||
let mut it = self;
|
||||
loop {
|
||||
match it {
|
||||
|
@ -879,6 +893,12 @@ impl<'a, T: Debug> Debug for Collection<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Default for Collection<'a, T> {
|
||||
fn default() -> Self {
|
||||
Self::empty()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Spaceable<'a> {
|
||||
fn before(&'a self, _: &'a [CommentOrNewline<'a>]) -> Self;
|
||||
fn after(&'a self, _: &'a [CommentOrNewline<'a>]) -> Self;
|
||||
|
@ -967,12 +987,21 @@ impl<'a> Spaceable<'a> for Has<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Spaceable<'a> for Derived<'a> {
|
||||
impl<'a> Spaceable<'a> for HasAbility<'a> {
|
||||
fn before(&'a self, spaces: &'a [CommentOrNewline<'a>]) -> Self {
|
||||
Derived::SpaceBefore(self, spaces)
|
||||
HasAbility::SpaceBefore(self, spaces)
|
||||
}
|
||||
fn after(&'a self, spaces: &'a [CommentOrNewline<'a>]) -> Self {
|
||||
Derived::SpaceAfter(self, spaces)
|
||||
HasAbility::SpaceAfter(self, spaces)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Spaceable<'a> for HasAbilities<'a> {
|
||||
fn before(&'a self, spaces: &'a [CommentOrNewline<'a>]) -> Self {
|
||||
HasAbilities::SpaceBefore(self, spaces)
|
||||
}
|
||||
fn after(&'a self, spaces: &'a [CommentOrNewline<'a>]) -> Self {
|
||||
HasAbilities::SpaceAfter(self, spaces)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1059,6 +1088,7 @@ impl_extract_spaces!(Pattern);
|
|||
impl_extract_spaces!(Tag);
|
||||
impl_extract_spaces!(AssignedField<T>);
|
||||
impl_extract_spaces!(TypeAnnotation);
|
||||
impl_extract_spaces!(HasAbility);
|
||||
|
||||
impl<'a, T: Copy> ExtractSpaces<'a> for Spaced<'a, T> {
|
||||
type Item = T;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue