mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Un-macro collection_inner
This commit is contained in:
parent
02c98f7519
commit
1c916202e7
2 changed files with 48 additions and 44 deletions
|
@ -10,11 +10,11 @@ use crate::blankspace::{
|
||||||
use crate::ident::{integer_ident, lowercase_ident, parse_ident, Accessor, Ident};
|
use crate::ident::{integer_ident, lowercase_ident, parse_ident, Accessor, Ident};
|
||||||
use crate::keyword;
|
use crate::keyword;
|
||||||
use crate::parser::{
|
use crate::parser::{
|
||||||
self, and, backtrackable, between, byte, byte_indent, either, increment_min_indent,
|
self, and, backtrackable, between, byte, byte_indent, collection_inner, either,
|
||||||
indented_seq, line_min_indent, loc, map, map_with_arena, optional, reset_min_indent, sep_by1,
|
increment_min_indent, indented_seq, line_min_indent, loc, map, map_with_arena, optional,
|
||||||
sep_by1_e, set_min_indent, skip_first, skip_second, specialize_err, specialize_err_ref, then,
|
reset_min_indent, sep_by1, sep_by1_e, set_min_indent, skip_first, skip_second, specialize_err,
|
||||||
two_bytes, zero_or_more, EClosure, EExpect, EExpr, EIf, EInParens, EList, ENumber, EPattern,
|
specialize_err_ref, then, two_bytes, zero_or_more, EClosure, EExpect, EExpr, EIf, EInParens,
|
||||||
ERecord, EString, EType, EWhen, Either, ParseResult, Parser,
|
EList, ENumber, EPattern, ERecord, EString, EType, EWhen, Either, ParseResult, Parser,
|
||||||
};
|
};
|
||||||
use crate::pattern::{closure_param, loc_implements_parser};
|
use crate::pattern::{closure_param, loc_implements_parser};
|
||||||
use crate::state::State;
|
use crate::state::State;
|
||||||
|
@ -3080,7 +3080,7 @@ fn record_help<'a>() -> impl Parser<'a, RecordHelp<'a>, ERecord<'a>> {
|
||||||
),
|
),
|
||||||
byte(b'&', ERecord::Ampersand)
|
byte(b'&', ERecord::Ampersand)
|
||||||
))),
|
))),
|
||||||
fields: collection_inner!(
|
fields: collection_inner(
|
||||||
loc(record_field()),
|
loc(record_field()),
|
||||||
byte(b',', ERecord::End),
|
byte(b',', ERecord::End),
|
||||||
RecordField::SpaceBefore
|
RecordField::SpaceBefore
|
||||||
|
|
|
@ -1454,45 +1454,49 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
pub fn collection_inner<'a, Elem: 'a + crate::ast::Spaceable<'a> + Clone, E: 'a + SpaceProblem>(
|
||||||
macro_rules! collection_inner {
|
elem: impl Parser<'a, Loc<Elem>, E> + 'a,
|
||||||
($elem:expr, $delimiter:expr, $space_before:expr) => {
|
delimiter: impl Parser<'a, (), E>,
|
||||||
$crate::parser::map_with_arena(
|
space_before: impl Fn(&'a Elem, &'a [crate::ast::CommentOrNewline<'a>]) -> Elem,
|
||||||
$crate::parser::and(
|
) -> impl Parser<'a, crate::ast::Collection<'a, Loc<Elem>>, E> {
|
||||||
$crate::parser::and(
|
map_with_arena(
|
||||||
$crate::blankspace::spaces(),
|
and(
|
||||||
$crate::parser::trailing_sep_by0(
|
and(
|
||||||
$delimiter,
|
crate::blankspace::spaces(),
|
||||||
$crate::blankspace::spaces_before_optional_after($elem),
|
trailing_sep_by0(
|
||||||
),
|
delimiter,
|
||||||
|
crate::blankspace::spaces_before_optional_after(elem),
|
||||||
),
|
),
|
||||||
$crate::blankspace::spaces(),
|
|
||||||
),
|
),
|
||||||
|arena: &'a bumpalo::Bump,
|
crate::blankspace::spaces(),
|
||||||
((spaces, mut parsed_elems), mut final_comments): (
|
),
|
||||||
(
|
#[allow(clippy::type_complexity)]
|
||||||
&'a [$crate::ast::CommentOrNewline<'a>],
|
move |arena: &'a bumpalo::Bump,
|
||||||
bumpalo::collections::vec::Vec<'a, Loc<_>>,
|
out: (
|
||||||
),
|
(
|
||||||
&'a [$crate::ast::CommentOrNewline<'a>],
|
&'a [crate::ast::CommentOrNewline<'a>],
|
||||||
)| {
|
bumpalo::collections::Vec<'a, Loc<Elem>>,
|
||||||
if !spaces.is_empty() {
|
),
|
||||||
if let Some(first) = parsed_elems.first_mut() {
|
&'a [crate::ast::CommentOrNewline<'a>],
|
||||||
first.value = $space_before(arena.alloc(first.value), spaces)
|
)| {
|
||||||
} else {
|
let ((spaces, mut parsed_elems), mut final_comments) = out;
|
||||||
debug_assert!(final_comments.is_empty());
|
|
||||||
final_comments = spaces;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$crate::ast::Collection::with_items_and_comments(
|
if !spaces.is_empty() {
|
||||||
arena,
|
if let Some(first) = parsed_elems.first_mut() {
|
||||||
parsed_elems.into_bump_slice(),
|
first.value = space_before(arena.alloc(first.value.clone()), spaces);
|
||||||
final_comments,
|
} else {
|
||||||
)
|
debug_assert!(final_comments.is_empty());
|
||||||
},
|
final_comments = spaces;
|
||||||
)
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
crate::ast::Collection::with_items_and_comments(
|
||||||
|
arena,
|
||||||
|
parsed_elems.into_bump_slice(),
|
||||||
|
final_comments,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
@ -1500,10 +1504,10 @@ macro_rules! collection_trailing_sep_e {
|
||||||
($opening_brace:expr, $elem:expr, $delimiter:expr, $closing_brace:expr, $space_before:expr) => {
|
($opening_brace:expr, $elem:expr, $delimiter:expr, $closing_brace:expr, $space_before:expr) => {
|
||||||
$crate::parser::between(
|
$crate::parser::between(
|
||||||
$opening_brace,
|
$opening_brace,
|
||||||
$crate::parser::reset_min_indent($crate::collection_inner!(
|
$crate::parser::reset_min_indent($crate::parser::collection_inner(
|
||||||
$elem,
|
$elem,
|
||||||
$delimiter,
|
$delimiter,
|
||||||
$space_before
|
$space_before,
|
||||||
)),
|
)),
|
||||||
$closing_brace,
|
$closing_brace,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue