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

@ -2149,7 +2149,7 @@ fn ident_to_expr<'a>(arena: &'a Bump, src: Ident<'a>) -> Expr<'a> {
fn list_literal_help<'a>(min_indent: u16) -> impl Parser<'a, Expr<'a>, List<'a>> {
move |arena, state| {
let (_, (parsed_elems, final_comments), state) = collection_trailing_sep_e!(
let (_, elements, state) = collection_trailing_sep_e!(
word1(b'[', List::Open),
specialize_ref(List::Expr, move |a, s| parse_loc_expr_no_multi_backpassing(
min_indent, a, s
@ -2164,15 +2164,15 @@ fn list_literal_help<'a>(min_indent: u16) -> impl Parser<'a, Expr<'a>, List<'a>>
)
.parse(arena, state)?;
let mut allocated = Vec::with_capacity_in(parsed_elems.len(), arena);
let mut allocated = Vec::with_capacity_in(elements.items.len(), arena);
for parsed_elem in parsed_elems {
allocated.push(&*arena.alloc(parsed_elem));
for parsed_elem in elements.items {
allocated.push(parsed_elem);
}
let expr = Expr::List {
items: allocated.into_bump_slice(),
final_comments,
final_comments: elements.final_comments,
};
Ok((MadeProgress, expr, state))