mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-16 10:00:15 +00:00
Refactor collections
This commit is contained in:
parent
9ce2f4e1ff
commit
451b2c0ded
7 changed files with 54 additions and 53 deletions
|
@ -1330,33 +1330,38 @@ macro_rules! collection {
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! collection_trailing_sep_e {
|
||||
($opening_brace:expr, $elem:expr, $delimiter:expr, $closing_brace:expr, $open_problem:expr, $indent_problem:expr, $space_before:expr) => {
|
||||
skip_first!(
|
||||
$opening_brace,
|
||||
|arena, state, min_indent| {
|
||||
let (_, spaces, state) = space0_e($indent_problem)
|
||||
.parse(arena, state, min_indent)?;
|
||||
|
||||
let (_, (mut parsed_elems, mut final_comments), state) =
|
||||
and!(
|
||||
$crate::parser::trailing_sep_by0(
|
||||
$delimiter,
|
||||
$crate::blankspace::space0_before_optional_after(
|
||||
$elem,
|
||||
$indent_problem,
|
||||
$indent_problem
|
||||
)
|
||||
),
|
||||
$crate::parser::reset_min_indent($crate::blankspace::space0_e($indent_problem))
|
||||
).parse(arena, state, min_indent)?;
|
||||
|
||||
let (_,_, state) =
|
||||
if parsed_elems.is_empty() {
|
||||
one_of_with_error![$open_problem; $closing_brace].parse(arena, state, min_indent)?
|
||||
} else {
|
||||
$closing_brace.parse(arena, state, min_indent)?
|
||||
};
|
||||
|
||||
($opening_brace:expr, $elem:expr, $delimiter:expr, $closing_brace:expr, $indent_problem:expr, $space_before:expr) => {
|
||||
map_with_arena!(
|
||||
skip_first!(
|
||||
$opening_brace,
|
||||
and!(
|
||||
and!(
|
||||
space0_e($indent_problem),
|
||||
$crate::parser::trailing_sep_by0(
|
||||
$delimiter,
|
||||
$crate::blankspace::space0_before_optional_after(
|
||||
$elem,
|
||||
$indent_problem,
|
||||
$indent_problem
|
||||
)
|
||||
)
|
||||
),
|
||||
skip_second!(
|
||||
$crate::parser::reset_min_indent($crate::blankspace::space0_e(
|
||||
$indent_problem
|
||||
)),
|
||||
$closing_brace
|
||||
)
|
||||
)
|
||||
),
|
||||
|arena: &'a bumpalo::Bump,
|
||||
((spaces, mut parsed_elems), mut final_comments): (
|
||||
(
|
||||
&'a [$crate::ast::CommentOrNewline<'a>],
|
||||
bumpalo::collections::vec::Vec<'a, Loc<_>>
|
||||
),
|
||||
&'a [$crate::ast::CommentOrNewline<'a>]
|
||||
)| {
|
||||
if !spaces.is_empty() {
|
||||
if let Some(first) = parsed_elems.first_mut() {
|
||||
first.value = $space_before(arena.alloc(first.value), spaces)
|
||||
|
@ -1366,12 +1371,11 @@ macro_rules! collection_trailing_sep_e {
|
|||
}
|
||||
}
|
||||
|
||||
let collection = $crate::ast::Collection::with_items_and_comments(
|
||||
$crate::ast::Collection::with_items_and_comments(
|
||||
arena,
|
||||
parsed_elems.into_bump_slice(),
|
||||
final_comments);
|
||||
|
||||
Ok((MadeProgress, collection, state))
|
||||
final_comments,
|
||||
)
|
||||
}
|
||||
)
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue