mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Parse has-derived clauses
This commit is contained in:
parent
a6ec43af5e
commit
fcf464e9da
9 changed files with 421 additions and 105 deletions
|
@ -297,6 +297,7 @@ pub enum TypeDef<'a> {
|
|||
Opaque {
|
||||
header: TypeHeader<'a>,
|
||||
typ: Loc<TypeAnnotation<'a>>,
|
||||
derived: Option<Loc<Derived<'a>>>,
|
||||
},
|
||||
|
||||
/// An ability definition. E.g.
|
||||
|
@ -380,11 +381,23 @@ impl<'a> From<ValueDef<'a>> for Def<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Should always be a zero-argument `Apply`; we'll check this in canonicalization
|
||||
pub type AbilityName<'a> = Loc<TypeAnnotation<'a>>;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub struct HasClause<'a> {
|
||||
pub var: Loc<Spaced<'a, &'a str>>,
|
||||
// Should always be a zero-argument `Apply`; we'll check this in canonicalization
|
||||
pub ability: Loc<TypeAnnotation<'a>>,
|
||||
pub ability: AbilityName<'a>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub enum Derived<'a> {
|
||||
/// `has [ Eq, Hash ]`
|
||||
Has(Collection<'a, AbilityName<'a>>),
|
||||
|
||||
// We preserve this for the formatter; canonicalization ignores it.
|
||||
SpaceBefore(&'a Derived<'a>, &'a [CommentOrNewline<'a>]),
|
||||
SpaceAfter(&'a Derived<'a>, &'a [CommentOrNewline<'a>]),
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
|
@ -901,6 +914,15 @@ impl<'a> Spaceable<'a> for Has<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Spaceable<'a> for Derived<'a> {
|
||||
fn before(&'a self, spaces: &'a [CommentOrNewline<'a>]) -> Self {
|
||||
Derived::SpaceBefore(self, spaces)
|
||||
}
|
||||
fn after(&'a self, spaces: &'a [CommentOrNewline<'a>]) -> Self {
|
||||
Derived::SpaceAfter(self, spaces)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Expr<'a> {
|
||||
pub fn loc_ref(&'a self, region: Region) -> Loc<&'a Self> {
|
||||
Loc {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue