mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 06:55:15 +00:00
ast::HasClause -> ast::ImplementsClause
This commit is contained in:
parent
64c34a5c6d
commit
ebbdae6c28
6 changed files with 19 additions and 19 deletions
|
@ -1064,13 +1064,13 @@ fn canonicalize_has_clause(
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
introduced_variables: &mut IntroducedVariables,
|
introduced_variables: &mut IntroducedVariables,
|
||||||
clause: &Loc<roc_parse::ast::HasClause<'_>>,
|
clause: &Loc<roc_parse::ast::ImplementsClause<'_>>,
|
||||||
pending_abilities_in_scope: &PendingAbilitiesInScope,
|
pending_abilities_in_scope: &PendingAbilitiesInScope,
|
||||||
references: &mut VecSet<Symbol>,
|
references: &mut VecSet<Symbol>,
|
||||||
) -> Result<(), Type> {
|
) -> Result<(), Type> {
|
||||||
let Loc {
|
let Loc {
|
||||||
region,
|
region,
|
||||||
value: roc_parse::ast::HasClause { var, abilities },
|
value: roc_parse::ast::ImplementsClause { var, abilities },
|
||||||
} = clause;
|
} = clause;
|
||||||
let region = *region;
|
let region = *region;
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ use crate::{
|
||||||
Buf,
|
Buf,
|
||||||
};
|
};
|
||||||
use roc_parse::ast::{
|
use roc_parse::ast::{
|
||||||
AssignedField, Collection, Expr, ExtractSpaces, HasAbilities, HasAbility, HasClause, HasImpls,
|
AssignedField, Collection, Expr, ExtractSpaces, HasAbilities, HasAbility, HasImpls,
|
||||||
RecordBuilderField, Tag, TypeAnnotation, TypeHeader,
|
ImplementsClause, RecordBuilderField, Tag, TypeAnnotation, TypeHeader,
|
||||||
};
|
};
|
||||||
use roc_parse::ident::UppercaseIdent;
|
use roc_parse::ident::UppercaseIdent;
|
||||||
use roc_region::all::Loc;
|
use roc_region::all::Loc;
|
||||||
|
@ -645,7 +645,7 @@ impl<'a> Formattable for Tag<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Formattable for HasClause<'a> {
|
impl<'a> Formattable for ImplementsClause<'a> {
|
||||||
fn is_multiline(&self) -> bool {
|
fn is_multiline(&self) -> bool {
|
||||||
// No, always put abilities in a "has" clause on one line
|
// No, always put abilities in a "has" clause on one line
|
||||||
false
|
false
|
||||||
|
|
|
@ -4,9 +4,9 @@ use roc_module::called_via::{BinOp, UnaryOp};
|
||||||
use roc_parse::{
|
use roc_parse::{
|
||||||
ast::{
|
ast::{
|
||||||
AbilityMember, AssignedField, Collection, CommentOrNewline, Defs, Expr, HasAbilities,
|
AbilityMember, AssignedField, Collection, CommentOrNewline, Defs, Expr, HasAbilities,
|
||||||
HasAbility, HasClause, HasImpls, Header, Implements, Module, Pattern, RecordBuilderField,
|
HasAbility, HasImpls, Header, Implements, ImplementsClause, Module, Pattern,
|
||||||
Spaced, Spaces, StrLiteral, StrSegment, Tag, TypeAnnotation, TypeDef, TypeHeader, ValueDef,
|
RecordBuilderField, Spaced, Spaces, StrLiteral, StrSegment, Tag, TypeAnnotation, TypeDef,
|
||||||
WhenBranch,
|
TypeHeader, ValueDef, WhenBranch,
|
||||||
},
|
},
|
||||||
header::{
|
header::{
|
||||||
AppHeader, ExposedName, HostedHeader, ImportsEntry, InterfaceHeader, KeywordItem,
|
AppHeader, ExposedName, HostedHeader, ImportsEntry, InterfaceHeader, KeywordItem,
|
||||||
|
@ -862,9 +862,9 @@ impl<'a> RemoveSpaces<'a> for TypeAnnotation<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> RemoveSpaces<'a> for HasClause<'a> {
|
impl<'a> RemoveSpaces<'a> for ImplementsClause<'a> {
|
||||||
fn remove_spaces(&self, arena: &'a Bump) -> Self {
|
fn remove_spaces(&self, arena: &'a Bump) -> Self {
|
||||||
HasClause {
|
ImplementsClause {
|
||||||
var: self.var.remove_spaces(arena),
|
var: self.var.remove_spaces(arena),
|
||||||
abilities: self.abilities.remove_spaces(arena),
|
abilities: self.abilities.remove_spaces(arena),
|
||||||
}
|
}
|
||||||
|
|
|
@ -553,7 +553,7 @@ fn ability_member_type_to_docs(
|
||||||
let has_clauses = has_clauses
|
let has_clauses = has_clauses
|
||||||
.iter()
|
.iter()
|
||||||
.map(|hc| {
|
.map(|hc| {
|
||||||
let ast::HasClause { var, abilities } = hc.value;
|
let ast::ImplementsClause { var, abilities } = hc.value;
|
||||||
(
|
(
|
||||||
var.value.extract_spaces().item.to_string(),
|
var.value.extract_spaces().item.to_string(),
|
||||||
abilities
|
abilities
|
||||||
|
|
|
@ -538,7 +538,7 @@ impl<'a> Defs<'a> {
|
||||||
pub type AbilityName<'a> = Loc<TypeAnnotation<'a>>;
|
pub type AbilityName<'a> = Loc<TypeAnnotation<'a>>;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||||
pub struct HasClause<'a> {
|
pub struct ImplementsClause<'a> {
|
||||||
pub var: Loc<Spaced<'a, &'a str>>,
|
pub var: Loc<Spaced<'a, &'a str>>,
|
||||||
pub abilities: &'a [AbilityName<'a>],
|
pub abilities: &'a [AbilityName<'a>],
|
||||||
}
|
}
|
||||||
|
@ -642,7 +642,7 @@ pub enum TypeAnnotation<'a> {
|
||||||
Wildcard,
|
Wildcard,
|
||||||
|
|
||||||
/// A "where" clause demanding abilities designated by a `|`, e.g. `a -> U64 | a has Hash`
|
/// A "where" clause demanding abilities designated by a `|`, e.g. `a -> U64 | a has Hash`
|
||||||
Where(&'a Loc<TypeAnnotation<'a>>, &'a [Loc<HasClause<'a>>]),
|
Where(&'a Loc<TypeAnnotation<'a>>, &'a [Loc<ImplementsClause<'a>>]),
|
||||||
|
|
||||||
// We preserve this for the formatter; canonicalization ignores it.
|
// We preserve this for the formatter; canonicalization ignores it.
|
||||||
SpaceBefore(&'a TypeAnnotation<'a>, &'a [CommentOrNewline<'a>]),
|
SpaceBefore(&'a TypeAnnotation<'a>, &'a [CommentOrNewline<'a>]),
|
||||||
|
@ -1823,7 +1823,7 @@ impl<'a> Malformed for Tag<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Malformed for HasClause<'a> {
|
impl<'a> Malformed for ImplementsClause<'a> {
|
||||||
fn is_malformed(&self) -> bool {
|
fn is_malformed(&self) -> bool {
|
||||||
self.abilities.iter().any(|ability| ability.is_malformed())
|
self.abilities.iter().any(|ability| ability.is_malformed())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::ast::{
|
use crate::ast::{
|
||||||
AssignedField, CommentOrNewline, Expr, HasAbilities, HasAbility, HasClause, HasImpls, Pattern,
|
AssignedField, CommentOrNewline, Expr, HasAbilities, HasAbility, HasImpls, ImplementsClause,
|
||||||
Spaceable, Spaced, Tag, TypeAnnotation, TypeHeader,
|
Pattern, Spaceable, Spaced, Tag, TypeAnnotation, TypeHeader,
|
||||||
};
|
};
|
||||||
use crate::blankspace::{
|
use crate::blankspace::{
|
||||||
space0_around_ee, space0_before_e, space0_before_optional_after, space0_e,
|
space0_around_ee, space0_before_e, space0_before_optional_after, space0_e,
|
||||||
|
@ -444,7 +444,7 @@ fn ability_chain<'a>() -> impl Parser<'a, Vec<'a, Loc<TypeAnnotation<'a>>>, ETyp
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn implements_clause<'a>() -> impl Parser<'a, Loc<HasClause<'a>>, EType<'a>> {
|
fn implements_clause<'a>() -> impl Parser<'a, Loc<ImplementsClause<'a>>, EType<'a>> {
|
||||||
map!(
|
map!(
|
||||||
// Suppose we are trying to parse "a implements Hash"
|
// Suppose we are trying to parse "a implements Hash"
|
||||||
and!(
|
and!(
|
||||||
|
@ -482,7 +482,7 @@ fn implements_clause<'a>() -> impl Parser<'a, Loc<HasClause<'a>>, EType<'a>> {
|
||||||
&abilities.last().unwrap().region,
|
&abilities.last().unwrap().region,
|
||||||
);
|
);
|
||||||
let region = Region::span_across(&var.region, &abilities_region);
|
let region = Region::span_across(&var.region, &abilities_region);
|
||||||
let implements_clause = HasClause {
|
let implements_clause = ImplementsClause {
|
||||||
var,
|
var,
|
||||||
abilities: abilities.into_bump_slice(),
|
abilities: abilities.into_bump_slice(),
|
||||||
};
|
};
|
||||||
|
@ -494,7 +494,7 @@ fn implements_clause<'a>() -> impl Parser<'a, Loc<HasClause<'a>>, EType<'a>> {
|
||||||
/// Parse a chain of `implements` clauses, e.g. " | a implements Hash, b implements Eq".
|
/// Parse a chain of `implements` clauses, e.g. " | a implements Hash, b implements Eq".
|
||||||
/// Returns the clauses and spaces before the starting "|", if there were any.
|
/// Returns the clauses and spaces before the starting "|", if there were any.
|
||||||
fn implements_clause_chain<'a>(
|
fn implements_clause_chain<'a>(
|
||||||
) -> impl Parser<'a, (&'a [CommentOrNewline<'a>], &'a [Loc<HasClause<'a>>]), EType<'a>> {
|
) -> impl Parser<'a, (&'a [CommentOrNewline<'a>], &'a [Loc<ImplementsClause<'a>>]), EType<'a>> {
|
||||||
move |arena, state: State<'a>, min_indent: u32| {
|
move |arena, state: State<'a>, min_indent: u32| {
|
||||||
let (_, (spaces_before, ()), state) =
|
let (_, (spaces_before, ()), state) =
|
||||||
and!(space0_e(EType::TIndentStart), word1(b'|', EType::TWhereBar))
|
and!(space0_e(EType::TIndentStart), word1(b'|', EType::TWhereBar))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue