Introduce Collection as a general abstraction in the ast

This commit is contained in:
Joshua Warner 2021-11-11 14:24:15 -08:00
parent ac733b1805
commit 04d4a8ca79
10 changed files with 49 additions and 37 deletions

View file

@ -5,6 +5,18 @@ use bumpalo::Bump;
use roc_module::operator::{BinOp, CalledVia, UnaryOp};
use roc_region::all::{Loc, Position, Region};
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Collection<'a, T> {
pub items: &'a [T],
pub final_comments: &'a [CommentOrNewline<'a>],
}
impl<'a, T> Collection<'a, T> {
pub fn empty() -> Collection<'a, T> {
Collection { items: &[], final_comments: &[] }
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum Module<'a> {
Interface { header: InterfaceHeader<'a> },
@ -231,11 +243,11 @@ pub enum TypeAnnotation<'a> {
),
Record {
fields: &'a [Loc<AssignedField<'a, TypeAnnotation<'a>>>],
fields: Collection<'a, Loc<AssignedField<'a, TypeAnnotation<'a>>>>,
/// The row type variable in an open record, e.g. the `r` in `{ name: Str }r`.
/// This is None if it's a closed record annotation like `{ name: Str }`.
ext: Option<&'a Loc<TypeAnnotation<'a>>>,
final_comments: &'a [CommentOrNewline<'a>],
// final_comments: &'a [CommentOrNewline<'a>],
},
/// A tag union, e.g. `[