mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 20:28:02 +00:00
ast::HasAbilities -> ast::ImplementsAbilities
This commit is contained in:
parent
9eb2180a0f
commit
4b90948fcf
6 changed files with 46 additions and 37 deletions
|
@ -174,7 +174,7 @@ enum PendingTypeDef<'a> {
|
|||
name: Loc<Symbol>,
|
||||
vars: Vec<Loc<Lowercase>>,
|
||||
ann: &'a Loc<ast::TypeAnnotation<'a>>,
|
||||
derived: Option<&'a Loc<ast::HasAbilities<'a>>>,
|
||||
derived: Option<&'a Loc<ast::ImplementsAbilities<'a>>>,
|
||||
},
|
||||
|
||||
Ability {
|
||||
|
@ -672,7 +672,7 @@ fn canonicalize_opaque<'a>(
|
|||
name_str: &'a str,
|
||||
ann: &'a Loc<ast::TypeAnnotation<'a>>,
|
||||
vars: &[Loc<Lowercase>],
|
||||
has_abilities: Option<&'a Loc<ast::HasAbilities<'a>>>,
|
||||
has_abilities: Option<&'a Loc<ast::ImplementsAbilities<'a>>>,
|
||||
) -> Result<CanonicalizedOpaque<'a>, ()> {
|
||||
let alias = canonicalize_alias(
|
||||
env,
|
||||
|
@ -1182,7 +1182,7 @@ fn canonicalize_type_defs<'a>(
|
|||
Loc<Symbol>,
|
||||
Vec<Loc<Lowercase>>,
|
||||
&'a Loc<ast::TypeAnnotation<'a>>,
|
||||
Option<&'a Loc<ast::HasAbilities<'a>>>,
|
||||
Option<&'a Loc<ast::ImplementsAbilities<'a>>>,
|
||||
),
|
||||
Ability(Loc<Symbol>, Vec<PendingAbilityMember<'a>>),
|
||||
}
|
||||
|
@ -2492,7 +2492,7 @@ fn to_pending_alias_or_opaque<'a>(
|
|||
name: &'a Loc<&'a str>,
|
||||
vars: &'a [Loc<ast::Pattern<'a>>],
|
||||
ann: &'a Loc<ast::TypeAnnotation<'a>>,
|
||||
opt_derived: Option<&'a Loc<ast::HasAbilities<'a>>>,
|
||||
opt_derived: Option<&'a Loc<ast::ImplementsAbilities<'a>>>,
|
||||
kind: AliasKind,
|
||||
) -> PendingTypeDef<'a> {
|
||||
let region = Region::span_across(&name.region, &ann.region);
|
||||
|
|
|
@ -4,8 +4,8 @@ use crate::{
|
|||
Buf,
|
||||
};
|
||||
use roc_parse::ast::{
|
||||
AbilityImpls, AssignedField, Collection, Expr, ExtractSpaces, HasAbilities, ImplementsAbility,
|
||||
ImplementsClause, RecordBuilderField, Tag, TypeAnnotation, TypeHeader,
|
||||
AbilityImpls, AssignedField, Collection, Expr, ExtractSpaces, ImplementsAbilities,
|
||||
ImplementsAbility, ImplementsClause, RecordBuilderField, Tag, TypeAnnotation, TypeHeader,
|
||||
};
|
||||
use roc_parse::ident::UppercaseIdent;
|
||||
use roc_region::all::Loc;
|
||||
|
@ -736,17 +736,17 @@ impl<'a> Formattable for ImplementsAbility<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Formattable for HasAbilities<'a> {
|
||||
impl<'a> Formattable for ImplementsAbilities<'a> {
|
||||
fn is_multiline(&self) -> bool {
|
||||
match self {
|
||||
HasAbilities::SpaceAfter(..) | HasAbilities::SpaceBefore(..) => true,
|
||||
HasAbilities::Has(has_abilities) => is_collection_multiline(has_abilities),
|
||||
ImplementsAbilities::SpaceAfter(..) | ImplementsAbilities::SpaceBefore(..) => true,
|
||||
ImplementsAbilities::Has(has_abilities) => is_collection_multiline(has_abilities),
|
||||
}
|
||||
}
|
||||
|
||||
fn format_with_options(&self, buf: &mut Buf, parens: Parens, newlines: Newlines, indent: u16) {
|
||||
match self {
|
||||
HasAbilities::Has(has_abilities) => {
|
||||
ImplementsAbilities::Has(has_abilities) => {
|
||||
if newlines == Newlines::Yes {
|
||||
buf.newline();
|
||||
buf.indent(indent);
|
||||
|
@ -755,13 +755,13 @@ impl<'a> Formattable for HasAbilities<'a> {
|
|||
buf.spaces(1);
|
||||
fmt_collection(buf, indent, Braces::Square, *has_abilities, Newlines::No);
|
||||
}
|
||||
HasAbilities::SpaceBefore(has_abilities, spaces) => {
|
||||
ImplementsAbilities::SpaceBefore(has_abilities, spaces) => {
|
||||
buf.newline();
|
||||
buf.indent(indent);
|
||||
fmt_comments_only(buf, spaces.iter(), NewlineAt::Bottom, indent);
|
||||
has_abilities.format_with_options(buf, parens, Newlines::No, indent)
|
||||
}
|
||||
HasAbilities::SpaceAfter(has_abilities, spaces) => {
|
||||
ImplementsAbilities::SpaceAfter(has_abilities, spaces) => {
|
||||
has_abilities.format_with_options(buf, parens, newlines, indent);
|
||||
fmt_comments_only(buf, spaces.iter(), NewlineAt::Bottom, indent);
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ use roc_module::called_via::{BinOp, UnaryOp};
|
|||
use roc_parse::{
|
||||
ast::{
|
||||
AbilityImpls, AbilityMember, AssignedField, Collection, CommentOrNewline, Defs, Expr,
|
||||
HasAbilities, Header, Implements, ImplementsAbility, ImplementsClause, Module, Pattern,
|
||||
RecordBuilderField, Spaced, Spaces, StrLiteral, StrSegment, Tag, TypeAnnotation, TypeDef,
|
||||
TypeHeader, ValueDef, WhenBranch,
|
||||
Header, Implements, ImplementsAbilities, ImplementsAbility, ImplementsClause, Module,
|
||||
Pattern, RecordBuilderField, Spaced, Spaces, StrLiteral, StrSegment, Tag, TypeAnnotation,
|
||||
TypeDef, TypeHeader, ValueDef, WhenBranch,
|
||||
},
|
||||
header::{
|
||||
AppHeader, ExposedName, HostedHeader, ImportsEntry, InterfaceHeader, KeywordItem,
|
||||
|
@ -914,13 +914,14 @@ impl<'a> RemoveSpaces<'a> for ImplementsAbility<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> RemoveSpaces<'a> for HasAbilities<'a> {
|
||||
impl<'a> RemoveSpaces<'a> for ImplementsAbilities<'a> {
|
||||
fn remove_spaces(&self, arena: &'a Bump) -> Self {
|
||||
match *self {
|
||||
HasAbilities::Has(derived) => HasAbilities::Has(derived.remove_spaces(arena)),
|
||||
HasAbilities::SpaceBefore(derived, _) | HasAbilities::SpaceAfter(derived, _) => {
|
||||
derived.remove_spaces(arena)
|
||||
ImplementsAbilities::Has(derived) => {
|
||||
ImplementsAbilities::Has(derived.remove_spaces(arena))
|
||||
}
|
||||
ImplementsAbilities::SpaceBefore(derived, _)
|
||||
| ImplementsAbilities::SpaceAfter(derived, _) => derived.remove_spaces(arena),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -394,7 +394,7 @@ pub enum TypeDef<'a> {
|
|||
Opaque {
|
||||
header: TypeHeader<'a>,
|
||||
typ: Loc<TypeAnnotation<'a>>,
|
||||
derived: Option<Loc<HasAbilities<'a>>>,
|
||||
derived: Option<Loc<ImplementsAbilities<'a>>>,
|
||||
},
|
||||
|
||||
/// An ability definition. E.g.
|
||||
|
@ -568,16 +568,16 @@ pub enum ImplementsAbility<'a> {
|
|||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub enum HasAbilities<'a> {
|
||||
pub enum ImplementsAbilities<'a> {
|
||||
/// `has [Eq { eq: myEq }, Hash]`
|
||||
Has(Collection<'a, Loc<ImplementsAbility<'a>>>),
|
||||
|
||||
// We preserve this for the formatter; canonicalization ignores it.
|
||||
SpaceBefore(&'a HasAbilities<'a>, &'a [CommentOrNewline<'a>]),
|
||||
SpaceAfter(&'a HasAbilities<'a>, &'a [CommentOrNewline<'a>]),
|
||||
SpaceBefore(&'a ImplementsAbilities<'a>, &'a [CommentOrNewline<'a>]),
|
||||
SpaceAfter(&'a ImplementsAbilities<'a>, &'a [CommentOrNewline<'a>]),
|
||||
}
|
||||
|
||||
impl HasAbilities<'_> {
|
||||
impl ImplementsAbilities<'_> {
|
||||
pub fn collection(&self) -> &Collection<Loc<ImplementsAbility>> {
|
||||
let mut it = self;
|
||||
loop {
|
||||
|
@ -1272,12 +1272,12 @@ impl<'a> Spaceable<'a> for ImplementsAbility<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Spaceable<'a> for HasAbilities<'a> {
|
||||
impl<'a> Spaceable<'a> for ImplementsAbilities<'a> {
|
||||
fn before(&'a self, spaces: &'a [CommentOrNewline<'a>]) -> Self {
|
||||
HasAbilities::SpaceBefore(self, spaces)
|
||||
ImplementsAbilities::SpaceBefore(self, spaces)
|
||||
}
|
||||
fn after(&'a self, spaces: &'a [CommentOrNewline<'a>]) -> Self {
|
||||
HasAbilities::SpaceAfter(self, spaces)
|
||||
ImplementsAbilities::SpaceAfter(self, spaces)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1720,11 +1720,13 @@ impl<'a> Malformed for ImplementsAbility<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Malformed for HasAbilities<'a> {
|
||||
impl<'a> Malformed for ImplementsAbilities<'a> {
|
||||
fn is_malformed(&self) -> bool {
|
||||
match self {
|
||||
HasAbilities::Has(abilities) => abilities.iter().any(|ability| ability.is_malformed()),
|
||||
HasAbilities::SpaceBefore(has, _) | HasAbilities::SpaceAfter(has, _) => {
|
||||
ImplementsAbilities::Has(abilities) => {
|
||||
abilities.iter().any(|ability| ability.is_malformed())
|
||||
}
|
||||
ImplementsAbilities::SpaceBefore(has, _) | ImplementsAbilities::SpaceAfter(has, _) => {
|
||||
has.is_malformed()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::ast::{
|
||||
AssignedField, Collection, CommentOrNewline, Defs, Expr, ExtractSpaces, HasAbilities,
|
||||
Implements, Pattern, RecordBuilderField, Spaceable, Spaces, TypeAnnotation, TypeDef,
|
||||
AssignedField, Collection, CommentOrNewline, Defs, Expr, ExtractSpaces, Implements,
|
||||
ImplementsAbilities, Pattern, RecordBuilderField, Spaceable, Spaces, TypeAnnotation, TypeDef,
|
||||
TypeHeader, ValueDef,
|
||||
};
|
||||
use crate::blankspace::{
|
||||
|
@ -1064,8 +1064,14 @@ fn alias_signature_with_space_before<'a>() -> impl Parser<'a, Loc<TypeAnnotation
|
|||
))
|
||||
}
|
||||
|
||||
fn opaque_signature_with_space_before<'a>(
|
||||
) -> impl Parser<'a, (Loc<TypeAnnotation<'a>>, Option<Loc<HasAbilities<'a>>>), EExpr<'a>> {
|
||||
fn opaque_signature_with_space_before<'a>() -> impl Parser<
|
||||
'a,
|
||||
(
|
||||
Loc<TypeAnnotation<'a>>,
|
||||
Option<Loc<ImplementsAbilities<'a>>>,
|
||||
),
|
||||
EExpr<'a>,
|
||||
> {
|
||||
and!(
|
||||
specialize(
|
||||
EExpr::Type,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::ast::{
|
||||
AbilityImpls, AssignedField, CommentOrNewline, Expr, HasAbilities, ImplementsAbility,
|
||||
AbilityImpls, AssignedField, CommentOrNewline, Expr, ImplementsAbilities, ImplementsAbility,
|
||||
ImplementsClause, Pattern, Spaceable, Spaced, Tag, TypeAnnotation, TypeHeader,
|
||||
};
|
||||
use crate::blankspace::{
|
||||
|
@ -521,7 +521,7 @@ fn implements_clause_chain<'a>(
|
|||
}
|
||||
|
||||
/// Parse a implements-abilities clause, e.g. `implements [Eq, Hash]`.
|
||||
pub fn implements_abilities<'a>() -> impl Parser<'a, Loc<HasAbilities<'a>>, EType<'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
|
||||
word10(
|
||||
|
@ -547,7 +547,7 @@ pub fn implements_abilities<'a>() -> impl Parser<'a, Loc<HasAbilities<'a>>, ETyp
|
|||
word1(b']', EType::TEnd),
|
||||
ImplementsAbility::SpaceBefore
|
||||
),
|
||||
HasAbilities::Has
|
||||
ImplementsAbilities::Has
|
||||
)),
|
||||
EType::TIndentEnd,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue